source: trunk/include/helpers/memdebug.h@ 123

Last change on this file since 123 was 123, checked in by umoeller, 24 years ago

Lots of changes for icons and refresh.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1
2/*
3 *@@sourcefile memdebug.h:
4 * header file for memdebug.c.
5 * See remarks there.
6 *
7 * The following macros are used:
8 *
9 * -- __XWPMEMDEBUG__: if defined, memory debugging is generally
10 * enabled. This must be set in setup.h.
11 *
12 * -- __DEBUG_MALLOC_ENABLED__: malloc etc. have been replaced
13 * with memdMalloc etc. This is automatically
14 * defined by this header if __XWPMEMDEBUG__
15 * is defined, unless DONT_REPLACE_MALLOC
16 * is also defined.
17 *
18 * Note: Version numbering in this file relates to XWorkplace version
19 * numbering.
20 *
21 *@@include #include <os2.h>
22 *@@include #include "helpers\memdebug.h"
23 */
24
25/* Copyright (C) 2000 Ulrich M”ller.
26 * This file is part of the "XWorkplace helpers" source package.
27 * This is free software; you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published
29 * by the Free Software Foundation, in version 2 as it comes in the
30 * "COPYING" file of the XWorkplace main distribution.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
35 */
36
37#if __cplusplus
38extern "C" {
39#endif
40
41#ifndef MEMDEBUG_HEADER_INCLUDED
42 #define MEMDEBUG_HEADER_INCLUDED
43
44 #ifndef __stdlib_h // <stdlib.h>
45 #error stdlib.h must be included before memdebug.h.
46 #endif
47
48 typedef void (FNCBMEMDLOG)(const char*); // message
49 typedef FNCBMEMDLOG *PFNCBMEMDLOG;
50
51 // global variable for memory error logger func
52 extern PFNCBMEMDLOG G_pMemdLogFunc;
53
54 /* ******************************************************************
55 *
56 * Private declarations
57 *
58 ********************************************************************/
59
60 #ifdef MEMDEBUG_PRIVATE
61
62 BOOL memdLock(VOID);
63
64 VOID memdUnlock(VOID);
65
66 /*
67 *@@ HEAPITEM:
68 * informational structure created for each
69 * malloc() call by memdMalloc. These are stored
70 * in a global linked list (G_pHeapItemsRoot).
71 *
72 * We cannot use the linklist.c functions for
73 * managing the linked list because these use
74 * malloc in turn, which would lead to infinite
75 * loops.
76 *
77 *@@added V0.9.3 (2000-04-11) [umoeller]
78 */
79
80 typedef struct _HEAPITEM
81 {
82 // struct _HEAPITEM *pNext; // next item in linked list or NULL if last
83
84 TREE Tree; // tree node for tree.* functions;
85 // ulKey has the pointer that is returned
86 // by memdMalloc and points to after the
87 // magic string (in the buffer that was
88 // really allocated). Using this as the
89 // tree sort key allows us to do fast
90 // searches in memdFree.
91
92 // void *pAfterMagic; // memory pointer returned by memdMalloc;
93 // this points to after the magic string
94
95 unsigned long ulSize; // requested size (without magic head and tail)
96
97 const char *pcszSourceFile; // as passed to memdMalloc
98 unsigned long ulLine; // as passed to memdMalloc
99 const char *pcszFunction; // as passed to memdMalloc
100
101 DATETIME dtAllocated; // system date/time at time of memdMalloc call
102
103 ULONG ulTID; // thread ID that memdMalloc was running on
104
105 BOOL fFreed; // TRUE only after item has been freed by memdFree
106 } HEAPITEM, *PHEAPITEM;
107
108 extern TREE *G_pHeapItemsRoot;
109 extern LONG G_cHeapItems;
110 extern ULONG G_ulItemsReleased;
111 extern ULONG G_ulBytesReleased;
112
113 #endif // MEMDEBUG_PRIVATE
114
115 /* ******************************************************************
116 *
117 * Publics
118 *
119 ********************************************************************/
120
121 void* memdMalloc(size_t stSize,
122 const char *pcszSourceFile,
123 unsigned long ulLine,
124 const char *pcszFunction);
125
126 void* memdCalloc(size_t num,
127 size_t stSize,
128 const char *pcszSourceFile,
129 unsigned long ulLine,
130 const char *pcszFunction);
131
132 void memdFree(void *p,
133 const char *pcszSourceFile,
134 unsigned long ulLine,
135 const char *pcszFunction);
136
137 void* memdRealloc(void *p,
138 size_t stSize,
139 const char *pcszSourceFile,
140 unsigned long ulLine,
141 const char *pcszFunction);
142
143 unsigned long memdReleaseFreed(void);
144
145 #ifdef __XWPMEMDEBUG__
146
147 #ifndef DONT_REPLACE_MALLOC
148 #define malloc(ul) memdMalloc(ul, __FILE__, __LINE__, __FUNCTION__)
149 #define calloc(n, size) memdCalloc(n, size, __FILE__, __LINE__, __FUNCTION__)
150 #define realloc(p, ul) memdRealloc(p, ul, __FILE__, __LINE__, __FUNCTION__)
151 #define free(p) memdFree(p, __FILE__, __LINE__, __FUNCTION__)
152
153 #ifdef __string_h
154 // string.h included and debugging is on:
155 // redefine strdup to use memory debugging
156 #define strdup(psz) \
157 strcpy( (char*)memdMalloc(strlen(psz) + 1, __FILE__, __LINE__, __FUNCTION__), psz)
158 // the original crashes also if psz is NULL
159 #endif
160
161 #define __DEBUG_MALLOC_ENABLED__
162
163 #endif
164 #endif
165
166 #ifdef PM_INCLUDED
167 /********************************************************************
168 *
169 * XFolder debugging helpers
170 *
171 ********************************************************************/
172
173 #ifdef _PMPRINTF_
174 void memdDumpMemoryBlock(PBYTE pb,
175 ULONG ulSize,
176 ULONG ulIndent);
177 #else
178 // _PMPRINTF not #define'd: do nothing
179 #define memdDumpMemoryBlock(pb, ulSize, ulIndent)
180 #endif
181
182 /* ******************************************************************
183 *
184 * Heap debugging window
185 *
186 ********************************************************************/
187
188 MRESULT EXPENTRY memd_fnwpMemDebug(HWND hwndClient, ULONG msg, MPARAM mp1, MPARAM mp2);
189
190 VOID memdCreateMemDebugWindow(VOID);
191 #endif
192
193#endif
194
195#if __cplusplus
196}
197#endif
198
Note: See TracBrowser for help on using the repository browser.