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) 2015 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 protected:
127 
130  static void initializeAddressSpace();
131 
133  static void objFileAndNameFromStack( char* stackEntry,
134  std::string& objFile, std::string& objFileName );
135 
137  static std::string lookupFileInfo( const std::string& objFile,
138  unsigned long offset );
139 
140 private:
141 
143  DtMiniDumper();
144 
145 protected:
146 
148  typedef std::map<std::string,unsigned long> AddressSpaceMap;
149 
152 
153 };
154 
156 typedef void (*SigActionCb)( int, siginfo_t*, void* );
157 #define DtINIT_MINIDUMPER( unused ) \
158 { \
159  struct sigaction sa; \
160  sa.sa_sigaction = (SigActionCb) DtMiniDumper::printCallStack; \
161  sa.sa_flags = SA_SIGINFO; \
162  sigemptyset( &sa.sa_mask ); \
163  sigaction( SIGSEGV, &sa, 0 ); \
164 }
165 
166 // TODO
167 #define DtINIT_MINIDUMPER_NO_PROMPT( unused ) \
168 { \
169  struct sigaction sa; \
170  sa.sa_sigaction = (SigActionCb) DtMiniDumper::printCallStack; \
171  sa.sa_flags = SA_SIGINFO; \
172  sigemptyset( &sa.sa_mask ); \
173  sigaction( SIGSEGV, &sa, 0 ); \
174 }
175 
176 // TODO
177 #define DtSILENTLY_CRASH( unused ) \
178 { \
179 }
180 #endif
This file contains the declaration of DtMutex.
void(* SigActionCb)(int, siginfo_t *, void *)
Definition: vlMiniDumper.h:156
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:151
std::map< std::string, unsigned long > AddressSpaceMap
Definition: vlMiniDumper.h:148
This file contains typedefs for machine dependant types.
#define DT_DLL_VLUTIL
Definition: vlMachineTypes.h:109

Document ID: Generated on Wed Mar 27 02:04:30 EDT 2024 from SVN revision 264570
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)