VR-Link API Documentation for HLA 1.3
 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-2025 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,
36  MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
37  CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
38  CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam );
39 
45 {
46 
47 public:
48 
50  DtMiniDumper( const char* szAppName, bool promptUser = true );
51 
52  static bool isPdbInCurrentWorkinDirectory(const std::string& module);
53  static std::string backTrace();
54 protected:
55 
58  static LONG WINAPI TopLevelFilter( struct _EXCEPTION_POINTERS* pExceptionInfo );
59 
62  static LONG WINAPI VectoredExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo);
63 
66  static BOOL CALLBACK TopLevelFilterCallback(PVOID pParam, const PMINIDUMP_CALLBACK_INPUT pInput, PMINIDUMP_CALLBACK_OUTPUT pOutput);
67 
69  enum DtMiniDumpType
70  {
71  MINIDUMP_TINY = MiniDumpNormal,
72  MINIDUMP_MINI = (MiniDumpWithIndirectlyReferencedMemory |
73  MiniDumpScanMemory),
74  MINIDUMP_MIDI = (MiniDumpWithPrivateReadWriteMemory |
75  MiniDumpWithDataSegs |
76  MiniDumpWithHandleData |
77  MiniDumpWithFullMemoryInfo |
78  MiniDumpWithThreadInfo |
79  MiniDumpWithUnloadedModules),
80  MINIDUMP_MAX = (MiniDumpWithFullMemory |
81  MiniDumpWithFullMemoryInfo |
82  MiniDumpWithHandleData |
83  MiniDumpWithThreadInfo |
84  MiniDumpWithUnloadedModules)
85  };
86 protected:
87 
88  static char* m_szAppName;
89  static bool myPrompt;
90  static bool myDisableHandler;
91  static DtMiniDumper::DtMiniDumpType myMiniDumpType;
92 #ifdef DtUSE_UTILITIES_NAMESPACE
93  static DtUSE_UTILITIES_NAMESPACE::DtMutex theMutex;
94 #else
95  static DtMutex theMutex;
96 #endif
97 };
98 
99 #define DtINIT_MINIDUMPER( execName ) DtMiniDumper miniDump( execName );
100 #define DtINIT_MINIDUMPER_NO_PROMPT( execName ) DtMiniDumper miniDump( execName, false );
101 
102 #define DtSILENTLY_CRASH( unused ) \
103 { \
104  ::SetUnhandledExceptionFilter(0); \
105  SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); \
106 }
107 #else // WIN32
108 
109 #include <map>
110 #include <string>
111 #include <signal.h>
112 #include <execinfo.h>
113 #include <ucontext.h>
114 
120 {
121 public:
122 
124  static void printCallStack( int sig, siginfo_t* info, void* secret );
125 
126  static std::string myApplicationName;
127 protected:
128 
131  static void initializeAddressSpace();
132 
134  static void objFileAndNameFromStack( char* stackEntry,
135  std::string& objFile, std::string& objFileName );
136 
138  static std::string lookupFileInfo( const std::string& objFile,
139  unsigned long offset );
140 
141 private:
142 
144  DtMiniDumper();
145 
146 protected:
147 
149  typedef std::map<std::string,unsigned long> AddressSpaceMap;
150 
153 
154 };
155 
157 typedef void (*SigActionCb)( int, siginfo_t*, void* );
158 #define DtINIT_MINIDUMPER( execName ) \
159 { \
160  struct sigaction sa; \
161  DtMiniDumper::myApplicationName = execName; \
162  sa.sa_sigaction = (SigActionCb) DtMiniDumper::printCallStack; \
163  sa.sa_flags = SA_SIGINFO; \
164  sigemptyset( &sa.sa_mask ); \
165  sigaction( SIGSEGV, &sa, 0 ); \
166  sigaction( SIGABRT, &sa, 0 ); \
167  sigaction( SIGFPE, &sa, 0 ); \
168 }
169 
170 // TODO
171 #define DtINIT_MINIDUMPER_NO_PROMPT( unused ) \
172 { \
173  struct sigaction sa; \
174  sa.sa_sigaction = (SigActionCb) DtMiniDumper::printCallStack; \
175  sa.sa_flags = SA_SIGINFO; \
176  sigemptyset( &sa.sa_mask ); \
177  sigaction( SIGSEGV, &sa, 0 ); \
178 }
179 
180 // TODO
181 #define DtSILENTLY_CRASH( unused ) \
182 { \
183 }
184 #endif
This file contains the declaration of DtMutex.
void(* SigActionCb)(int, siginfo_t *, void *)
Definition: vlMiniDumper.h:157
This class contains the logic necesary for printing a stack trace.
Definition: vlMiniDumper.h:119
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:152
static std::string myApplicationName
Definition: vlMiniDumper.h:126
std::map< std::string, unsigned long > AddressSpaceMap
Definition: vlMiniDumper.h:149
This file contains typedefs for machine dependant types.
#define DT_DLL_VLUTIL
Definition: vlMachineTypes.h:109

Document ID: Generated on Thu Oct 16 00:12:25 EDT 2025 from SVN revision 280738
Copyright © 1992-2025 MAK Technologies. All Rights Reserved (www.mak.com)