-
Notifications
You must be signed in to change notification settings - Fork 2
/
PancakeDebug.h
73 lines (58 loc) · 2.38 KB
/
PancakeDebug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _PANCAKE_DEBUG_H
#define _PANCAKE_DEBUG_H
#include "Pancake.h"
#ifdef PANCAKE_DEBUG
#ifdef HAVE_EXECINFO_H
# include <execinfo.h>
#endif
/* Forward declarations */
typedef struct _PancakeNetworkBuffer PancakeNetworkBuffer;
#undef uthash_fatal
#define uthash_fatal(msg) _PancakeAssert(0, "uthash: " msg, __FILE__, __LINE__)
PANCAKE_API void _PancakeAssert(Native result, Byte *condition, Byte *file, Int32 line);
PANCAKE_API void *_PancakeAllocate(Native size, Byte *file, Int32 line);
PANCAKE_API void _PancakeFree(void *ptr, Byte *file, Int32 line);
PANCAKE_API void *_PancakeReallocate(void *ptr, Native size, Byte *file, Int32 line);
PANCAKE_API Byte *_PancakeDuplicateString(Byte *string, Byte *file, Int32 line);
PANCAKE_API Byte *_PancakeDuplicateStringLength(Byte *string, Int32 length, Byte *file, Int32 line);
PANCAKE_API void PancakeDumpHeap();
PANCAKE_API void PancakeDumpMemoryUsage();
PANCAKE_API void PancakeCheckHeap();
PANCAKE_API void PancakePrintString(String *string);
PANCAKE_API void PancakePrintNetworkBuffer(PancakeNetworkBuffer *buf);
PANCAKE_API void PancakeBacktrace();
PANCAKE_API void PancakeFreeAllocatorMeta();
#if defined(HAVE_UCONTEXT_H) && defined(HAVE_EXECINFO_H)
# define HAVE_PANCAKE_SIGSEGV
void PancakeDebugHandleSegfault(Int32 signum, siginfo_t *info, void *context);
#endif
typedef struct _PancakeAllocatedMemory {
void *ptr;
Byte *file;
Int32 line;
UInt32 size;
UT_hash_handle hh;
} PancakeAllocatedMemory;
# define STATIC
# define PancakeAssert(condition) _PancakeAssert(condition, #condition, __FILE__, __LINE__)
# define PancakeAllocate(size) _PancakeAllocate(size, __FILE__, __LINE__)
# define PancakeDuplicateStringLength(string, length) _PancakeDuplicateStringLength(string, length, __FILE__, __LINE__)
# define PancakeDuplicateString(string) _PancakeDuplicateString(string, __FILE__, __LINE__)
# define PancakeFree(ptr) _PancakeFree(ptr, __FILE__, __LINE__)
# define PancakeReallocate(ptr, size) _PancakeReallocate(ptr, size, __FILE__, __LINE__)
# define PancakeDebug
#else
# define PancakeAssert
# define PancakeDumpHeap()
# define PancakeCheckHeap()
# define PancakeDumpMemoryUsage()
# define PancakeFreeAllocatorMeta()
# define PancakeAllocate malloc
# define PancakeDuplicateStringLength strndup
# define PancakeDuplicateString strdup
# define PancakeFree free
# define PancakeReallocate realloc
# define PancakeDebug if(0)
# define STATIC static
#endif
#endif