vld.h 10 KB

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