VR-Link API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlMiniDumper.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 1992-2026 MAK Technologies, Inc
3  * All rights reserved.
4  ****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vlutil/vlMachineTypes.h>
13 #include <string>
14 #include <vlutil/vlMutex.h>
15 
16 // Preprocessor Directive which allows reuse in MAK RTI applications and VR-Link based applications.
17 #ifdef DtUSE_UTILITIES_NAMESPACE
18  #define DtMiniDumper Dt##MAKRti##MiniDumper
19 #endif
20 
21 #ifdef WIN32
22 
23  #if _MSC_VER < 1300
24  #define DECLSPEC_DEPRECATED
25  // VC6: change this path to your Platform SDK headers
26  #include "M:\\dev7\\vs\\devtools\\common\\win32sdk\\include\\dbghelp.h" // must be XP version of file
27  #else
28  // VC7: ships with updated headers
29  #define _WINSOCKAPI_
30  #include <windows.h>
31  #include "dbghelp.h"
32  #endif
33 
34 // based on dbghelp.h
35 typedef BOOL(WINAPI* MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType,
36  CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
37  CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
38 
44 {
45 public:
53  const char* szAppName, bool promptUser = true, const char* svnRev = nullptr, bool skipRichCallStack = false);
54 
55  static bool isPdbInCurrentWorkinDirectory(const std::string& module);
56 
60  static std::string backTrace(int skip = 0, int maxDepth = 100);
61 
62 protected:
65  static LONG WINAPI TopLevelFilter(struct _EXCEPTION_POINTERS* pExceptionInfo);
66 
70  static LONG WINAPI VectoredExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo);
71 
74  static BOOL CALLBACK TopLevelFilterCallback(
75  PVOID pParam, const PMINIDUMP_CALLBACK_INPUT pInput, PMINIDUMP_CALLBACK_OUTPUT pOutput);
76 
78  enum DtMiniDumpType
79  {
80  MINIDUMP_TINY = MiniDumpNormal,
81  MINIDUMP_MINI = (MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory | MiniDumpWithModuleHeaders |
82  MiniDumpWithDataSegs),
83  MINIDUMP_MIDI = (MiniDumpWithPrivateReadWriteMemory | MiniDumpWithDataSegs | MiniDumpWithHandleData |
84  MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo | MiniDumpWithUnloadedModules),
85  MINIDUMP_MAX = (MiniDumpWithFullMemory | MiniDumpWithFullMemoryInfo | MiniDumpWithHandleData |
86  MiniDumpWithThreadInfo | MiniDumpWithUnloadedModules)
87  };
88 
89 protected:
90  static char* m_szAppName;
91  static bool myPrompt;
92  static bool myDisableHandler;
93  static DtMiniDumper::DtMiniDumpType myMiniDumpType;
94  #ifdef DtUSE_UTILITIES_NAMESPACE
95  static DtUSE_UTILITIES_NAMESPACE::DtMutex theMutex;
96  #else
97  static DtMutex theMutex;
98  #endif
99 };
100 
101  // When the including product defines SVN_REV (the same macro the About box
102  // uses), forward it so the crash-log header reports the product's own revision.
103  #ifdef SVN_REV
104  #define DtINIT_MINIDUMPER(execName) DtMiniDumper miniDump(execName, true, SVN_REV);
105  #define DtINIT_MINIDUMPER_NO_PROMPT(execName) DtMiniDumper miniDump(execName, false, SVN_REV);
106  #else
107  #define DtINIT_MINIDUMPER(execName) DtMiniDumper miniDump(execName);
108  #define DtINIT_MINIDUMPER_NO_PROMPT(execName) DtMiniDumper miniDump(execName, false);
109  #endif
110 
111  #define DtSILENTLY_CRASH(unused) \
112  { \
113  ::SetUnhandledExceptionFilter(0); \
114  SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); \
115  }
116 #else // WIN32
117 
118  #include <map>
119  #include <string>
120  #include <iosfwd>
121  #include <signal.h>
122  #include <execinfo.h>
123  #include <ucontext.h>
124 
133 {
134 public:
148  DtMiniDumper(
149  const char* szAppName, bool promptUser = true, const char* svnRev = nullptr, bool skipRichCallStack = false);
150 
152  static void printCallStack(int sig, siginfo_t* info, void* secret);
153 
159  static std::string backTrace(int skip = 0, int maxDepth = 100, const void* crashAddress = nullptr);
160 
161  static std::string myApplicationName;
162 
163 protected:
166  static void initializeAddressSpace();
167 
169  static void objFileAndNameFromStack(char* stackEntry, std::string& objFile, std::string& objFileName);
170 
172  static std::string lookupFileInfo(const std::string& objFile, unsigned long offset);
173 
177  static void appendAddr2LineDetail(std::ostream& strm);
178 
179 protected:
181  typedef std::map<std::string, unsigned long> AddressSpaceMap;
182 
185 
190  static bool mySkipRichCallStack;
191 
197  static char myCallstackLogPath[4096];
198 };
199 
201 typedef void (*SigActionCb)(int, siginfo_t*, void*);
202  // When the including product defines SVN_REV (the same macro the About box
203  // uses), forward it so the crash-log header reports the product's own revision.
204  #ifdef SVN_REV
205  #define DtINIT_MINIDUMPER(execName) DtMiniDumper miniDump(execName, true, SVN_REV);
206  #define DtINIT_MINIDUMPER_NO_PROMPT(execName) DtMiniDumper miniDump(execName, false, SVN_REV);
207  // Installs the handler but suppresses the non-async-signal-safe rich pass; use in
208  // automated tests where a crash inside malloc/free could otherwise deadlock and hang.
209  #define DtINIT_MINIDUMPER_RAW_ONLY(execName) DtMiniDumper miniDump(execName, false, SVN_REV, true);
210  #else
211  #define DtINIT_MINIDUMPER(execName) DtMiniDumper miniDump(execName);
212  #define DtINIT_MINIDUMPER_NO_PROMPT(execName) DtMiniDumper miniDump(execName, false);
213  // Installs the handler but suppresses the non-async-signal-safe rich pass; use in
214  // automated tests where a crash inside malloc/free could otherwise deadlock and hang.
215  #define DtINIT_MINIDUMPER_RAW_ONLY(execName) DtMiniDumper miniDump(execName, false, nullptr, true);
216  #endif
217 
218  #define DtSILENTLY_CRASH(unused) \
219  { \
220  }
221 #endif
This file contains the declaration of DtMutex.
std::map< std::string, unsigned long > AddressSpaceMap
Definition: vlMiniDumper.h:181
void(* SigActionCb)(int, siginfo_t *, void *)
Definition: vlMiniDumper.h:201
static bool mySkipRichCallStack
When true, printCallStack skips the non-async-signal-safe boost::stacktrace/addr2line pass and leaves...
Definition: vlMiniDumper.h:190
This class contains the logic necesary for printing a stack trace.
Definition: vlMiniDumper.h:132
instances of DtMutex are used to provide a platform independent mutual exclusion mechanism ...
Definition: vlMutex.h:31
static AddressSpaceMap myAddressSpaceMap
Maps loaded object file names to base addresses in memory.
Definition: vlMiniDumper.h:184
static std::string myApplicationName
Definition: vlMiniDumper.h:161
This file contains typedefs for machine dependant types.
#define DT_DLL_VLUTIL
Definition: vlMachineTypes.h:121

Document ID: Generated on Mon Sep 28 00:09:32 EDT 2026 from SVN revision 295353
Copyright © 1992-2025 MAK Technologies. All Rights Reserved (www.mak.com)