Skip to content

Commit c1d4b09

Browse files
committed
ADD Visual Leak Detector
1 parent 1c303fd commit c1d4b09

File tree

7 files changed

+413
-0
lines changed

7 files changed

+413
-0
lines changed

3rdParty/VLD/vld.h

Lines changed: 350 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,350 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Visual Leak Detector - Import Library Header
4+
// Copyright (c) 2005-2014 VLD Team
5+
//
6+
// This library is free software; you can redistribute it and/or
7+
// modify it under the terms of the GNU Lesser General Public
8+
// License as published by the Free Software Foundation; either
9+
// version 2.1 of the License, or (at your option) any later version.
10+
//
11+
// This library is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
// Lesser General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU Lesser General Public
17+
// License along with this library; if not, write to the Free Software
18+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
//
20+
// See COPYING.txt for the full terms of the GNU Lesser General Public License.
21+
//
22+
////////////////////////////////////////////////////////////////////////////////
23+
24+
#pragma once
25+
26+
#include "vld_def.h"
27+
28+
typedef int VLD_BOOL;
29+
typedef unsigned int VLD_UINT;
30+
typedef size_t VLD_SIZET;
31+
typedef void* VLD_HMODULE;
32+
33+
#if defined _DEBUG || defined VLD_FORCE_ENABLE
34+
35+
#ifdef __AFXWIN_H__
36+
#error[VLD COMPILE ERROR] '#include <vld.h>' should appear before '#include <afxwin.h>' in file stdafx.h
37+
#endif
38+
39+
#pragma comment(lib, "vld.lib")
40+
41+
// Force a symbolic reference to the global VisualLeakDetector class object from
42+
// the DLL. This ensures that the DLL is loaded and linked with the program,
43+
// even if no code otherwise imports any of the DLL's exports.
44+
#pragma comment(linker, "/include:__imp_?g_vld@@3VVisualLeakDetector@@A")
45+
46+
////////////////////////////////////////////////////////////////////////////////
47+
//
48+
// Visual Leak Detector APIs
49+
//
50+
51+
#ifdef __cplusplus
52+
extern "C" {
53+
#endif // __cplusplus
54+
55+
// VLDDisable - Disables Visual Leak Detector's memory leak detection at
56+
// runtime. If memory leak detection is already disabled, then calling this
57+
// function has no effect.
58+
//
59+
// Note: In multithreaded programs, this function operates on a per-thread
60+
// basis. In other words, if you call this function from one thread, then
61+
// memory leak detection is only disabled for that thread. If memory leak
62+
// detection is enabled for other threads, then it will remain enabled for
63+
// those other threads. It was designed to work this way to insulate you,
64+
// the programmer, from having to ensure thread synchronization when calling
65+
// VLDEnable() and VLDDisable(). Without this, calling these two functions
66+
// unsynchronized could result in unpredictable and unintended behavior.
67+
// But this also means that if you want to disable memory leak detection
68+
// process-wide, then you need to call this function from every thread in
69+
// the process.
70+
//
71+
// Return Value:
72+
//
73+
// None.
74+
//
75+
__declspec(dllimport) void VLDDisable ();
76+
77+
// VLDEnable - Enables Visual Leak Detector's memory leak detection at runtime.
78+
// If memory leak detection is already enabled, which it is by default, then
79+
// calling this function has no effect.
80+
//
81+
// Note: In multithreaded programs, this function operates on a per-thread
82+
// basis. In other words, if you call this function from one thread, then
83+
// memory leak detection is only enabled for that thread. If memory leak
84+
// detection is disabled for other threads, then it will remain disabled for
85+
// those other threads. It was designed to work this way to insulate you,
86+
// the programmer, from having to ensure thread synchronization when calling
87+
// VLDEnable() and VLDDisable(). Without this, calling these two functions
88+
// unsynchronized could result in unpredictable and unintended behavior.
89+
// But this also means that if you want to enable memory leak detection
90+
// process-wide, then you need to call this function from every thread in
91+
// the process.
92+
//
93+
// Return Value:
94+
//
95+
// None.
96+
//
97+
__declspec(dllimport) void VLDEnable ();
98+
99+
// VLDRestore - Restore Visual Leak Detector's previous state.
100+
//
101+
// Return Value:
102+
//
103+
// None.
104+
//
105+
__declspec(dllimport) void VLDRestore ();
106+
107+
// VLDGlobalDisable - Disables Visual Leak Detector's memory leak detection at
108+
// runtime in all threads. If memory leak detection is already disabled,
109+
// then calling this function has no effect.
110+
//
111+
// Return Value:
112+
//
113+
// None.
114+
//
115+
__declspec(dllimport) void VLDGlobalDisable ();
116+
117+
// VLDGlobalEnable - Enables Visual Leak Detector's memory leak detection
118+
// at runtime in all threads. If memory leak detection is already enabled,
119+
// which it is by default, then calling this function has no effect.
120+
//
121+
// Return Value:
122+
//
123+
// None.
124+
//
125+
__declspec(dllimport) void VLDGlobalEnable ();
126+
127+
// VLDReportLeaks - Report leaks up to the execution point.
128+
//
129+
// Return Value:
130+
//
131+
// None.
132+
//
133+
__declspec(dllimport) VLD_UINT VLDReportLeaks ();
134+
135+
// VLDReportThreadLeaks - Report thread leaks up to the execution point.
136+
//
137+
// threadId: thread Id.
138+
//
139+
// Return Value:
140+
//
141+
// None.
142+
//
143+
__declspec(dllimport) VLD_UINT VLDReportThreadLeaks (VLD_UINT threadId);
144+
145+
// VLDGetLeaksCount - Return memory leaks count to the execution point.
146+
//
147+
// Return Value:
148+
//
149+
// None.
150+
//
151+
__declspec(dllimport) VLD_UINT VLDGetLeaksCount ();
152+
153+
// VLDGetThreadLeaksCount - Return thread memory leaks count to the execution point.
154+
//
155+
// threadId: thread Id.
156+
//
157+
// Return Value:
158+
//
159+
// None.
160+
//
161+
__declspec(dllimport) VLD_UINT VLDGetThreadLeaksCount (VLD_UINT threadId);
162+
163+
// VLDMarkAllLeaksAsReported - Mark all leaks as reported.
164+
//
165+
// Return Value:
166+
//
167+
// None.
168+
//
169+
__declspec(dllimport) void VLDMarkAllLeaksAsReported ();
170+
171+
// VLDMarkThreadLeaksAsReported - Mark thread leaks as reported.
172+
//
173+
// threadId: thread Id.
174+
//
175+
// Return Value:
176+
//
177+
// None.
178+
//
179+
__declspec(dllimport) void VLDMarkThreadLeaksAsReported (VLD_UINT threadId);
180+
181+
182+
// VLDRefreshModules - Look for recently loaded DLLs and patch them if necessary.
183+
//
184+
// Return Value:
185+
//
186+
// None.
187+
//
188+
__declspec(dllimport) void VLDRefreshModules();
189+
190+
191+
// VLDEnableModule - Enable Memory leak checking on the specified module.
192+
//
193+
// module: module handle.
194+
//
195+
// Return Value:
196+
//
197+
// None.
198+
//
199+
200+
__declspec(dllimport) void VLDEnableModule(VLD_HMODULE module);
201+
202+
203+
// VLDDisableModule - Disable Memory leak checking on the specified module.
204+
//
205+
// module: module handle.
206+
//
207+
// Return Value:
208+
//
209+
// None.
210+
//
211+
__declspec(dllimport) void VLDDisableModule(VLD_HMODULE module);
212+
213+
// VLDGetOptions - Return all current options.
214+
//
215+
// Return Value:
216+
//
217+
// Mask of current options.
218+
//
219+
__declspec(dllimport) VLD_UINT VLDGetOptions();
220+
221+
// VLDGetReportFilename - Return current report filename.
222+
//
223+
// filename: current report filename (max characters - MAX_PATH).
224+
//
225+
// Return Value:
226+
//
227+
// None.
228+
//
229+
__declspec(dllimport) void VLDGetReportFilename(wchar_t *filename);
230+
231+
// VLDSetOptions - Update the report options via function call rather than INI file.
232+
//
233+
// option_mask: Only the following flags are checked
234+
// VLD_OPT_AGGREGATE_DUPLICATES
235+
// VLD_OPT_MODULE_LIST_INCLUDE
236+
// VLD_OPT_SAFE_STACK_WALK
237+
// VLD_OPT_SLOW_DEBUGGER_DUMP
238+
// VLD_OPT_TRACE_INTERNAL_FRAMES
239+
// VLD_OPT_START_DISABLED
240+
// VLD_OPT_SKIP_HEAPFREE_LEAKS
241+
// VLD_OPT_VALIDATE_HEAPFREE
242+
//
243+
// maxDataDump: maximum number of user-data bytes to dump for each leaked block.
244+
//
245+
// maxTraceFrames: maximum number of frames per stack trace for each leaked block.
246+
//
247+
// Return Value:
248+
//
249+
// None.
250+
//
251+
__declspec(dllimport) void VLDSetOptions(VLD_UINT option_mask, VLD_SIZET maxDataDump, VLD_UINT maxTraceFrames);
252+
253+
// VLDSetModulesList - Set list of modules included/excluded in leak detection
254+
// depending on parameter "includeModules".
255+
//
256+
// modules: list of modules to be forcefully included/excluded in leak detection.
257+
//
258+
// includeModules: include or exclude that modules.
259+
//
260+
// Return Value:
261+
//
262+
// None.
263+
//
264+
__declspec(dllimport) void VLDSetModulesList(const wchar_t *modules, VLD_BOOL includeModules);
265+
266+
// VLDGetModulesList - Return current list of included/excluded modules
267+
// depending on flag VLD_OPT_TRACE_INTERNAL_FRAMES.
268+
//
269+
// modules: destination string for list of included/excluded modules (maximum length 512 characters).
270+
//
271+
// size: maximum string size.
272+
//
273+
// Return Value:
274+
//
275+
// VLD_BOOL: TRUE if include modules, otherwise FALSE.
276+
//
277+
__declspec(dllimport) VLD_BOOL VLDGetModulesList(wchar_t *modules, VLD_UINT size);
278+
279+
// VLDSetReportOptions - Update the report options via function call rather than INI file.
280+
//
281+
// Only the following flags are checked
282+
// VLD_OPT_REPORT_TO_DEBUGGER
283+
// VLD_OPT_REPORT_TO_FILE
284+
// VLD_OPT_REPORT_TO_STDOUT
285+
// VLD_OPT_UNICODE_REPORT
286+
//
287+
// filename is optional and can be NULL.
288+
//
289+
// Return Value:
290+
//
291+
// None.
292+
//
293+
__declspec(dllimport) void VLDSetReportOptions(VLD_UINT option_mask, const wchar_t *filename);
294+
295+
// VLDSetReportHook - Installs or uninstalls a client-defined reporting function by hooking it
296+
// into the C run-time debug reporting process (debug version only).
297+
//
298+
// mode: The action to take: VLD_RPTHOOK_INSTALL or VLD_RPTHOOK_REMOVE.
299+
//
300+
// pfnNewHook: Report hook to install or remove.
301+
//
302+
// Return Value:
303+
//
304+
// int: 0 if success.
305+
//
306+
__declspec(dllimport) int VLDSetReportHook(int mode, VLD_REPORT_HOOK pfnNewHook);
307+
308+
// VLDResolveCallstacks - Performs symbol resolution for all saved extent CallStack's that have
309+
// been tracked by Visual Leak Detector. This function is necessary for applications that
310+
// dynamically load and unload modules, and through which memory leaks might be included.
311+
// If this is NOT called, stack traces may have stack frames with no symbol information. This
312+
// happens because the symbol API's cannot look up symbols for a binary / module that has been unloaded
313+
// from the process.
314+
//
315+
// Return Value:
316+
//
317+
// int: 0 if successfully resolved all callstacks.
318+
//
319+
__declspec(dllexport) int VLDResolveCallstacks();
320+
321+
#ifdef __cplusplus
322+
}
323+
#endif // __cplusplus
324+
325+
#else // !_DEBUG
326+
327+
#define VLDEnable()
328+
#define VLDDisable()
329+
#define VLDRestore()
330+
#define VLDGlobalDisable()
331+
#define VLDGlobalEnable()
332+
#define VLDReportLeaks() (0)
333+
#define VLDReportThreadLeaks() (0)
334+
#define VLDGetLeaksCount() (0)
335+
#define VLDGetThreadLeaksCount() (0)
336+
#define VLDMarkAllLeaksAsReported()
337+
#define VLDMarkThreadLeaksAsReported(a)
338+
#define VLDRefreshModules()
339+
#define VLDEnableModule(a)
340+
#define VLDDisableModule(b)
341+
#define VLDGetOptions() (0)
342+
#define VLDGetReportFilename(a)
343+
#define VLDSetOptions(a, b, c)
344+
#define VLDSetReportHook(a, b)
345+
#define VLDSetModulesList(a)
346+
#define VLDGetModulesList(a, b) (FALSE)
347+
#define VLDSetReportOptions(a, b)
348+
#define VLDResolveCallstacks() (0)
349+
350+
#endif // _DEBUG

0 commit comments

Comments
 (0)