1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 //-----------------------------------------------------------------------------
6 //-----------------------------------------------------------------------------
8 #ifndef __STACK_TRACE_H__
9 #define __STACK_TRACE_H__
11 HINSTANCE LoadImageHlp();
12 HINSTANCE LoadDbgHelp();
14 #include <specstrings.h>
17 //--- Constants ---------------------------------------------------------------
20 #define cchMaxAssertModuleLen 60
21 #define cchMaxAssertSymbolLen 257
22 #define cfrMaxAssertStackLevels 20
23 #define cchMaxAssertExprLen 257
27 #define cchMaxAssertStackLevelStringLen \
28 ((3 * 8) + cchMaxAssertModuleLen + cchMaxAssertSymbolLen + 13)
29 // 3 addresses of at most 8 char, module, symbol, and the extra chars:
30 // 0x<address>: <module>! <symbol> + 0x<offset>\n
31 //FMT_ADDR_BARE is defined as "%08x`%08x" on Win64, and as
32 //"%08x" on 32 bit platforms. Hence the difference in the definitions.
36 #define cchMaxAssertStackLevelStringLen \
37 ((2 * 8) + cchMaxAssertModuleLen + cchMaxAssertSymbolLen + 12)
38 // 2 addresses of at most 8 char, module, symbol, and the extra chars:
39 // 0x<address>: <module>! <symbol> + 0x<offset>\n
44 //--- Prototypes --------------------------------------------------------------
47 /****************************************************************************
51 * Cleans up for the symbol loading code. Should be called before
52 * exiting in order to free the dynamically loaded imagehlp.dll
53 ******************************************************************** robch */
54 void MagicDeinit(void);
56 /****************************************************************************
57 * GetStringFromStackLevels *
58 *--------------------------*
60 * Retrieves a string from the stack frame. If more than one frame, they
61 * are separated by newlines. Each fram appears in this format:
63 * 0x<address>: <module>! <symbol> + 0x<offset>
64 ******************************************************************** robch */
65 void GetStringFromStackLevels(UINT ifrStart, UINT cfrTotal, __out_ecount(cchMaxAssertStackLevelStringLen * cfrTotal) CHAR *pszString, struct _CONTEXT * pContext = NULL);
67 /****************************************************************************
71 * Builds a string from an address in the format:
73 * 0x<address>: <module>! <symbol> + 0x<offset>
74 ******************************************************************** robch */
75 void GetStringFromAddr(DWORD_PTR dwAddr, __out_ecount(cchMaxAssertStackLevelStringLen) LPSTR szString);
77 #if defined(_TARGET_X86_) && !defined(FEATURE_PAL)
78 /****************************************************************************
82 * Exactly the contents of RtlCaptureContext for Win7 - Win2K doesn't
83 * support this, so we need it for CoreCLR 4, if we require Win2K support
84 ****************************************************************************/
85 extern "C" void __stdcall ClrCaptureContext(__out PCONTEXT ctx);
86 #else // _TARGET_X86_ && FEATURE_CORECLR && !FEATURE_PAL
87 #define ClrCaptureContext RtlCaptureContext
88 #endif // _TARGET_X86_ && FEATURE_CORECLR && !FEATURE_PAL