My Project
Loading...
Searching...
No Matches
omDebug.h
Go to the documentation of this file.
1/*******************************************************************
2 * File: omDebug.h
3 * Purpose: declaration of common Debug/Check/Track stuff
4 * Author: [email protected] (Olaf Bachmann)
5 * Created: 7/00
6 *******************************************************************/
7#ifndef OM_DEBUG_H
8#define OM_DEBUG_H
9
10
11#if defined(OM_NDEBUG) || ! defined(OM_HAVE_TRACK)
12#define omIsTrackAddr(addr) 0
13#define omIsTrackAddrPage(page) 0
14#define omIsNormalBinPageAddr(addr) omIsBinPageAddr(addr)
15#define omIsBinAddrTrackAddr(addr) 0
16#else
17#define omIsTrackAddrBinPage(bin_page) ((bin_page)->used_blocks < 0)
18#define omIsBinAddrTrackAddr(addr) omIsTrackAddrBinPage(omGetBinPageOfAddr(addr))
19#define omIsTrackAddr(addr) (omIsBinPageAddr(addr) && omIsBinAddrTrackAddr(addr))
20#define omIsNormalBinPageAddr(addr) (omIsBinPageAddr(addr) && !omIsBinAddrTrackAddr(addr))
21#endif
22
23#if defined(OM_NDEBUG)
24#define omMarkAsStaticAddr(addr) do {} while (0)
25#define omMarkMemoryAsStatic() do {} while (0)
26#define omUnMarkAsStaticAddr() do {} while (0)
27#define omUnMarkMemoryAsStatic() do {} while (0)
28#define omFreeKeptAddr() do {} while (0)
29#define omPrintUsedAddrs(fd,m) do {} while (0)
30#define omPrintUsedTrackAddrs(fd,m) do {} while (0)
31#else
32#define OM_FBIN 1 /* size_bin is bin */
33#define OM_FSIZE 2 /* size_bin is size */
34#define OM_FUSED 4 /* is in use, if set */
35#define OM_FKEPT 8 /* had been freed, if set */
36#define OM_FSTATIC 16 /* if set, considered to be static, i.e. never be freed */
37#define OM_FZERO 32 /* for Alloc0 */
38#define OM_FALIGN 64 /* for AllocAligned */
39#define OM_FSLOPPY 128 /* be sloppy about arguments */
40#define OM_FBINADDR 256 /* addr is bin addr */
41#define OM_FKEEP 512 /* addr is never really freed */
42/* maximal flag: OM_FBIN and OM_FSIZE can not be at the same time,
43 and so can't OM_USED and OM_KEPT. Hence 1024 - BIN - USED*/
44#define OM_FMAX 1024 - OM_FBIN - OM_FUSED
45typedef unsigned short omTrackFlags_t;
46
47void* _omDebugAlloc(void* size_bin, omTrackFlags_t flags, OM_CTFL_DECL);
48void* _omDebugRealloc(void* old_addr, void* old_size_bin, void* new_size_bin,
49 omTrackFlags_t old_flags, omTrackFlags_t new_flags, OM_CTFL_DECL);
50void _omDebugFree(void* addr, void* size_bin, omTrackFlags_t flags, OM_CFL_DECL);
51void* _omDebugMemDup(void* addr, omTrackFlags_t flags, OM_CTFL_DECL);
52char* _omDebugStrDup(const char* addr, OM_TFL_DECL);
53
54omError_t _omDebugBin(omBin bin, OM_CFL_DECL);
55omError_t _omDebugMemory(OM_CFL_DECL);
56omError_t _omDebugAddr(void* addr, void* bin_size, omTrackFlags_t flags, OM_CFL_DECL);
57
58void omFreeKeptAddr();
59void omPrintUsedAddrs(FILE* fd, int max_frames);
60void omPrintUsedTrackAddrs(FILE* fd, int max_frames);
61
62void omMarkAsStaticAddr(void* addr);
64void omUnMarkAsStaticAddr(void* addr);
66#endif /* ! OM_NDEBUG */
67
68
69#ifdef OM_TRACK_CUSTOM
70#ifdef OM_NDEBUG
71#define omSetCustomOfAddr(addr,value) do {} while (0)
72#define omGetCustomOfAddr(addr) ((void*)0)
73#define omSetCustomOfTrackAddr(addr,value) do {} while (0)
74#define omGetCustomOfTrackAddr(addr) ((void*)0)
75#else
76void omSetCustomOfTrackAddr(void* addr, void* value);
77void* omGetCustomOfTrackAddr(void* addr);
78#define omSetCustomOfAddr(addr,value) \
79 do{if (omIsTrackAddr(addr)) omSetCustomOfTrackAddr(addr,value);}while(0)
80#define omGetCustomOfAddr(addr) \
81 (omIsTrackAddr(addr) ? omGetCustomOfTrackAddr(addr) : NULL)
82#endif /* OM_NDEBUG */
83#endif /* OM_TRACK_CUSTOM */
84
85/*BEGINPRIVATE*/
86
87#if defined(OM_NDEBUG) || ! defined(OM_HAVE_TRACK)
88#define omGetUsedBlocksOfPage(page) (page->used_blocks)
89#else
90#define omGetUsedBlocksOfPage(page) ((long)(page->used_blocks & ~(((unsigned long) 1) << (BIT_SIZEOF_LONG -1))))
91#endif
92
93#ifndef OM_NDEBUG
94extern void* om_KeptAddr;
95extern void* om_LastKeptAddr;
96extern unsigned long om_MaxAddr;
97extern unsigned long om_MinAddr;
98extern void* om_AlwaysKeptAddrs;
99
101/***********************************************************************
102 *
103 * omDebugCheck.c
104 *
105 **********************************************************************/
106omError_t omCheckPtr(const void* ptr, omError_t report, OM_FLR_DECL);
107omError_t _omCheckAddr(void* addr, void* size_bin, omTrackFlags_t flags, char check,
108 omError_t report, OM_FLR_DECL);
109omError_t omDoCheckBinAddr(void* addr, void* bin_size, omTrackFlags_t flags, char level,
110 omError_t report, OM_FLR_DECL);
111omError_t _omCheckBin(omBin bin, int normal_bin, char check, omError_t report, OM_FLR_DECL);
112omError_t _omCheckMemory(char check, omError_t report, OM_FLR_DECL);
114 void* bin_size, omTrackFlags_t flags,
115 OM_FLR_DECL, const char* fmt, ...);
116omError_t omDoCheckBin(omBin bin, int normal_bin, char level,
117 omError_t report, OM_FLR_DECL);
118void omIterateTroughAddrs(int normal, int track, void (*CallBackUsed)(void*), void (*CallBackFree)(void*));
119void omIterateTroughBinAddrs(omBin bin, void (*CallBackUsed)(void*), void (*CallBackFree)(void*));
120omError_t omDoCheckAddr(void* addr, void* bin_size, omTrackFlags_t flags, char level,
121 omError_t report, OM_FLR_DECL);
122int omIsInKeptAddrList(void* addr);
123
124/***********************************************************************
125 *
126 * omDebugTrack.c
127 *
128 **********************************************************************/
129#ifdef OM_HAVE_TRACK
130extern omBin_t om_StaticTrackBin[];
131extern omBin om_Size2TrackBin[];
132#define omSmallSize2TrackBin(size) om_Size2TrackBin[((size) -1)>>LOG_SIZEOF_OM_ALIGNMENT]
133extern omBinPage om_JustFreedPage;
134extern void omFreeTrackAddr(void* addr);
135extern size_t omOutSizeOfTrackAddr(void* addr);
136extern omSpecBin om_SpecTrackBin;
137
138void* omAllocTrackAddr(void* bin_size, omTrackFlags_t flags, char track, OM_FLR_DECL);
139void* omMarkAsFreeTrackAddr(void* addr, int keep, omTrackFlags_t *flags, OM_FLR_DECL);
140omError_t omCheckTrackAddr(void* addr, void* bin_size, omTrackFlags_t flags, char level,
141 omError_t report_error, OM_FLR_DECL);
142void omPrintTrackAddrInfo(FILE* fd, void* addr, int max_frames);
143omBin omGetOrigSpecBinOfTrackAddr(void* addr);
144size_t omOutSizeOfTrackAddr(void* addr);
145extern int omIsStaticTrackAddr(void* addr);
146#define omSetTrackOfUsedBlocks(ub) (ub |= (((unsigned long) 1) << (BIT_SIZEOF_LONG -1)))
147#define omUnsetTrackOfUsedBlocks(ub) (ub &= ~(((unsigned long) 1) << (BIT_SIZEOF_LONG -1)))
148#define omIsSetTrackOfUsedBlocks(ub) (ub & (((unsigned long) 1) << (BIT_SIZEOF_LONG -1)))
149#else
150#define omIsStaticTrackAddr(addr) 0
151#endif
152void* omAddr_2_OutAddr(void* addr);
153
154/***********************************************************************
155 *
156 * omBinPage.c
157 *
158 **********************************************************************/
160omError_t omCheckBinPageRegion(omBinPageRegion region, int level, omError_t report, OM_FLR_DECL);
161omError_t omCheckBinPageRegions(int level, omError_t report, OM_FLR_DECL);
163int omIsAddrOnFreeBinPage(void* addr);
164
165/***********************************************************************
166 *
167 * Some Handy Macros
168 *
169 **********************************************************************/
170#define omCheckReturn(cond) \
171 do {omError_t _status = cond; if (_status) return _status;} while (0)
172#define omCheckReturnError(cond, error) \
173 do {if (cond) return omReportError(error, report, OM_FLR_VAL, "");} while (0)
174#define omCheckReturnCorrupted(cond) \
175 omCheckReturnError(cond, omError_MemoryCorrupted)
176#define omAddrCheckReturn(cond) \
177do \
178{ \
179 omError_t _status = cond; \
180 if (_status && (_status != omError_MaxError)) \
181 { \
182 _omPrintAddrInfo(stderr, _status, addr, bin_size, flags, 10, " occurred for"); \
183 return _status; \
184 } \
185} while (0)
186#define omAddrCheckReturnError(cond, error) \
187 do {if (cond) return omReportAddrError(error, report, addr, bin_size, flags, OM_FLR_VAL, "");} while (0)
188#define omAddrCheckReturnCorrupted(cond) \
189 omAddrCheckReturnError(cond, omError_MemoryCorrupted)
190
191#else
192#define omFreeKeptAddrFromBin(bin) do {} while (0)
193#endif /* ! OM_NDEBUG */
194/*ENDPRIVATE*/
195
196#endif /* OM_DEBUG_H */
int level(const CanonicalForm &f)
VAR int check
Definition: libparse.cc:1106
#define error(a)
Definition: mpr_numeric.cc:966
unsigned long om_MaxAddr
Definition: omDebugCheck.c:19
void omUnMarkMemoryAsStatic()
void * om_AlwaysKeptAddrs
Definition: omDebug.c:31
omError_t omCheckBinPageRegions(int level, omError_t report, OM_FLR_DECL)
Definition: omBinPage.c:531
omError_t _omCheckBin(omBin bin, int normal_bin, char check, omError_t report, OM_FLR_DECL)
Definition: omDebugCheck.c:49
void * _omDebugRealloc(void *old_addr, void *old_size_bin, void *new_size_bin, omTrackFlags_t old_flags, omTrackFlags_t new_flags, OM_CTFL_DECL)
Definition: omDebug.c:147
void * _omDebugMemDup(void *addr, omTrackFlags_t flags, OM_CTFL_DECL)
Definition: omDebug.c:201
void * omAddr_2_OutAddr(void *addr)
void * _omDebugAlloc(void *size_bin, omTrackFlags_t flags, OM_CTFL_DECL)
Definition: omDebug.c:110
omError_t _omCheckAddr(void *addr, void *size_bin, omTrackFlags_t flags, char check, omError_t report, OM_FLR_DECL)
Definition: omDebugCheck.c:36
omError_t omDoCheckAddr(void *addr, void *bin_size, omTrackFlags_t flags, char level, omError_t report, OM_FLR_DECL)
Definition: omDebugCheck.c:146
unsigned long om_MinAddr
Definition: omDebugCheck.c:20
void omMarkMemoryAsStatic()
omBinPageRegion omFindRegionOfAddr(void *addr)
Definition: omBinPage.c:578
omError_t _omCheckMemory(char check, omError_t report, OM_FLR_DECL)
Definition: omDebugCheck.c:58
omError_t _omDebugBin(omBin bin, OM_CFL_DECL)
Definition: omDebug.c:293
void omFreeKeptAddr()
Definition: omDebug.c:609
omError_t omDoCheckBin(omBin bin, int normal_bin, char level, omError_t report, OM_FLR_DECL)
Definition: omDebugCheck.c:253
omError_t omCheckPtr(const void *ptr, omError_t report, OM_FLR_DECL)
Definition: omDebugCheck.c:136
int omIsKnownMemoryRegion(omBinPageRegion region)
Definition: omBinPage.c:489
void omIterateTroughBinAddrs(omBin bin, void(*CallBackUsed)(void *), void(*CallBackFree)(void *))
Definition: omDebugCheck.c:464
unsigned short omTrackFlags_t
Definition: omDebug.h:45
char * _omDebugStrDup(const char *addr, OM_TFL_DECL)
Definition: omDebug.c:231
#define omIsStaticTrackAddr(addr)
Definition: omDebug.h:150
omError_t omCheckBinPageRegion(omBinPageRegion region, int level, omError_t report, OM_FLR_DECL)
Definition: omBinPage.c:505
void omFreeKeptAddrFromBin(omBin bin)
Definition: omDebug.c:542
omError_t _omDebugAddr(void *addr, void *bin_size, omTrackFlags_t flags, OM_CFL_DECL)
Definition: omDebug.c:278
omError_t omReportAddrError(omError_t error, omError_t report, void *addr, void *bin_size, omTrackFlags_t flags, OM_FLR_DECL, const char *fmt,...)
Definition: omDebugCheck.c:394
void omIterateTroughAddrs(int normal, int track, void(*CallBackUsed)(void *), void(*CallBackFree)(void *))
Definition: omDebugCheck.c:503
int omIsAddrOnFreeBinPage(void *addr)
Definition: omBinPage.c:595
void omUnMarkAsStaticAddr(void *addr)
void * om_KeptAddr
Definition: omDebug.c:28
omError_t omDoCheckBinAddr(void *addr, void *bin_size, omTrackFlags_t flags, char level, omError_t report, OM_FLR_DECL)
Definition: omDebugCheck.c:198
void * om_LastKeptAddr
Definition: omDebug.c:30
void _omDebugFree(void *addr, void *size_bin, omTrackFlags_t flags, OM_CFL_DECL)
Definition: omDebug.c:182
int omIsInKeptAddrList(void *addr)
Definition: omDebugTrack.c:743
omError_t _omDebugMemory(OM_CFL_DECL)
Definition: omDebug.c:286
enum omError_e omError_t
Definition: omError.h:44
omBinPage_t * omBinPage
Definition: omStructs.h:16
omBin_t * omBin
Definition: omStructs.h:12
omSpecBin_t * omSpecBin
Definition: omStructs.h:30
omBinPageRegion_t * omBinPageRegion
Definition: omStructs.h:20
int status int void size_t count int const void size_t count const char int flags
Definition: si_signals.h:73
int status int fd
Definition: si_signals.h:59
#define omPrintUsedAddrs(F, max)
Definition: xalloc.h:268
#define omMarkAsStaticAddr(A)
Definition: xalloc.h:245
#define omPrintUsedTrackAddrs(F, max)
Definition: xalloc.h:266