Pārlūkot izejas kodu

moved syscall debugging to a new file

master
root pirms 5 gadiem
vecāks
revīzija
0d0bc34cb6
2 mainītis faili ar 44 papildinājumiem un 0 dzēšanām
  1. 20
    0
      inc/lc6_debug.h
  2. 24
    0
      src/lc6_debug.c

+ 20
- 0
inc/lc6_debug.h Parādīt failu

@@ -0,0 +1,20 @@
#ifdef LC6_DEBUG

#ifndef LC6_DEBUG_H
#define LC6_DEBUG_H

// DO NOT include the common.h here.
// because we're overriding functions
// #include "../inc/lc6_common.h"

void* lc6debug_malloc(size_t, char *, const char*, int);
void* lc6debug_realloc(void *ptr, size_t, char *, const char*, int);
void lc6debug_free(void *ptr, char *, const char*, int);

#define malloc(x) lc6debug_malloc(x, __FILE__, __func__, __LINE__)
#define realloc(x,y) lc6debug_realloc(x, y, __FILE__, __func__, __LINE__)
#define free(x) lc6debug_free(x, __FILE__, __func__, __LINE__)

#endif

#endif

+ 24
- 0
src/lc6_debug.c Parādīt failu

@@ -0,0 +1,24 @@
#ifdef LC6_DEBUG

#include <stdio.h>
#include <stdlib.h>

#include "../inc/lc6_debug.h"


void* lc6debug_malloc(size_t size, char *file, const char *func, int line) {
printf("[%s:%d] %s called malloc(%lu)\n", file, line, func, size);
return malloc(size);
}

void* lc6debug_realloc(void *ptr, size_t size, char *file, const char *func, int line) {
printf("[%s:%d] %s called realloc(%p, %lu)\n", file, line, func, ptr, size);
return realloc(ptr, size);
}

void lc6debug_free(void *ptr, char *file, const char *func, int line) {
printf("[%s:%d] %s called free(%p)\n", file, line, func, ptr);
free(ptr);
}

#endif

Notiek ielāde…
Atcelt
Saglabāt