瀏覽代碼

moved syscall debugging to a new file

master
root 5 年之前
父節點
當前提交
0d0bc34cb6
共有 2 個文件被更改,包括 44 次插入0 次删除
  1. 20
    0
      inc/lc6_debug.h
  2. 24
    0
      src/lc6_debug.c

+ 20
- 0
inc/lc6_debug.h 查看文件

@@ -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 查看文件

@@ -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

Loading…
取消
儲存