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 | //----------------------------------------------------------------------------- |
5 | |
6 | //----------------------------------------------------------------------------- |
7 | |
8 | #ifndef __STACK_TRACE_H__ |
9 | #define __STACK_TRACE_H__ |
10 | |
11 | HINSTANCE LoadImageHlp(); |
12 | HINSTANCE LoadDbgHelp(); |
13 | |
14 | #include <specstrings.h> |
15 | |
16 | // |
17 | //--- Constants --------------------------------------------------------------- |
18 | // |
19 | |
20 | #define cchMaxAssertModuleLen 60 |
21 | #define cchMaxAssertSymbolLen 257 |
22 | #define cfrMaxAssertStackLevels 20 |
23 | #define cchMaxAssertExprLen 257 |
24 | |
25 | #ifdef _WIN64 |
26 | |
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. |
33 | |
34 | #else |
35 | |
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 |
40 | |
41 | #endif |
42 | |
43 | // |
44 | //--- Prototypes -------------------------------------------------------------- |
45 | // |
46 | |
47 | /**************************************************************************** |
48 | * MagicDeinit * |
49 | *-------------* |
50 | * Description: |
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); |
55 | |
56 | /**************************************************************************** |
57 | * GetStringFromStackLevels * |
58 | *--------------------------* |
59 | * Description: |
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: |
62 | * |
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); |
66 | |
67 | /**************************************************************************** |
68 | * GetStringFromAddr * |
69 | *-------------------* |
70 | * Description: |
71 | * Builds a string from an address in the format: |
72 | * |
73 | * 0x<address>: <module>! <symbol> + 0x<offset> |
74 | ******************************************************************** robch */ |
75 | void GetStringFromAddr(DWORD_PTR dwAddr, __out_ecount(cchMaxAssertStackLevelStringLen) LPSTR szString); |
76 | |
77 | #if defined(_TARGET_X86_) && !defined(FEATURE_PAL) |
78 | /**************************************************************************** |
79 | * ClrCaptureContext * |
80 | *-------------------* |
81 | * Description: |
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_PAL |
87 | #define ClrCaptureContext RtlCaptureContext |
88 | #endif // _TARGET_X86_ && !FEATURE_PAL |
89 | |
90 | |
91 | #endif |
92 | |