]> git.proxmox.com Git - libgit2.git/blob - src/win32/w32_crtdbg_stacktrace.h
Merge branch 'portable-zu'
[libgit2.git] / src / win32 / w32_crtdbg_stacktrace.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_w32_crtdbg_stacktrace_h__
8 #define INCLUDE_w32_crtdbg_stacktrace_h__
9
10 #if defined(GIT_MSVC_CRTDBG)
11
12 /**
13 * Initialize our memory leak tracking and de-dup data structures.
14 * This should ONLY be called by git_libgit2_init().
15 */
16 void git_win32__crtdbg_stacktrace_init(void);
17
18 /**
19 * Shutdown our memory leak tracking and dump summary data.
20 * This should ONLY be called by git_libgit2_shutdown().
21 *
22 * We explicitly call _CrtDumpMemoryLeaks() during here so
23 * that we can compute summary data for the leaks. We print
24 * the stacktrace of each unique leak.
25 *
26 * This cleanup does not happen if the app calls exit()
27 * without calling the libgit2 shutdown code.
28 *
29 * This info we print here is independent of any automatic
30 * reporting during exit() caused by _CRTDBG_LEAK_CHECK_DF.
31 * Set it in your app if you also want traditional reporting.
32 */
33 void git_win32__crtdbg_stacktrace_cleanup(void);
34
35 /**
36 * Checkpoint options.
37 */
38 typedef enum git_win32__crtdbg_stacktrace_options {
39 /**
40 * Set checkpoint marker.
41 */
42 GIT_WIN32__CRTDBG_STACKTRACE__SET_MARK = (1 << 0),
43
44 /**
45 * Dump leaks since last checkpoint marker.
46 * May not be combined with __LEAKS_TOTAL.
47 *
48 * Note that this may generate false positives for global TLS
49 * error state and other global caches that aren't cleaned up
50 * until the thread/process terminates. So when using this
51 * around a region of interest, also check the final (at exit)
52 * dump before digging into leaks reported here.
53 */
54 GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK = (1 << 1),
55
56 /**
57 * Dump leaks since init. May not be combined
58 * with __LEAKS_SINCE_MARK.
59 */
60 GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_TOTAL = (1 << 2),
61
62 /**
63 * Suppress printing during dumps.
64 * Just return leak count.
65 */
66 GIT_WIN32__CRTDBG_STACKTRACE__QUIET = (1 << 3),
67
68 } git_win32__crtdbg_stacktrace_options;
69
70 /**
71 * Checkpoint memory state and/or dump unique stack traces of
72 * current memory leaks.
73 *
74 * @return number of unique leaks (relative to requested starting
75 * point) or error.
76 */
77 GIT_EXTERN(int) git_win32__crtdbg_stacktrace__dump(
78 git_win32__crtdbg_stacktrace_options opt,
79 const char *label);
80
81 /**
82 * Construct stacktrace and append it to the global buffer.
83 * Return pointer to start of this string. On any error or
84 * lack of buffer space, just return the given file buffer
85 * so it will behave as usual.
86 *
87 * This should ONLY be called by our internal memory allocations
88 * routines.
89 */
90 const char *git_win32__crtdbg_stacktrace(int skip, const char *file);
91
92 #endif
93 #endif