Torque3D Documentation / _generateds / winStackWalker.h

winStackWalker.h

Engine/source/platformWin32/minidump/winStackWalker.h

More...

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef  __WIN_PLATFORM_STACKWALKER__
 25#define  __WIN_PLATFORM_STACKWALKER__
 26
 27#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
 28
 29#include <windows.h>
 30#include <dbghelp.h>
 31
 32#include "platform/types.h"
 33
 34class StackWalker
 35{
 36public:
 37
 38   typedef enum StackWalkOptions
 39   {
 40      //    RetrieveNone = 0,          // No additional info will be retrieved (only the address is available)
 41      //    RetrieveSymbol = 1,        // Try to get the symbol-name
 42      //    RetrieveLine = 2,          // Try to get the line for this symbol
 43      //    RetrieveModuleInfo = 4,    // Try to retrieve the module-infos
 44      RetrieveFileVersion = 8,   // Also retrieve the version for the DLL/EXE
 45      RetrieveVerbose = 0xF,     // Contains all of the above retrieve options
 46
 47      SymBuildPath = 0x10,       // Generate a "good" symbol-search-path
 48      SymUseSymSrv = 0x20,       // Also use a public Symbol Server
 49      SymAll = 0x30,             // Contains all of the above Symbol options
 50
 51      OutputSymPath = 0x80,      //print out the symbol path
 52      OutputOS = 0x100,          //print out the OS path
 53      OutputModules = 0x200,     //print out the Modules
 54
 55      OptionsDefault = 0x3F,     // Less verbose output (default)
 56      OptionsAll = 0x2FF         // Contains all options
 57   };
 58
 59   StackWalker(DWORD optionFlags = OptionsDefault, LPCSTR szSymPath = NULL);
 60   virtual ~StackWalker();
 61
 62   typedef BOOL (__stdcall *PReadProcessMemoryRoutine)(HANDLE      hProcess,
 63      DWORD64     qwBaseAddress,
 64      PVOID       lpBuffer,
 65      DWORD       nSize,
 66      LPDWORD     lpNumberOfBytesRead,
 67      LPVOID      pUserData  // optional data, which was passed in "ShowCallstack"
 68      );
 69
 70   // pUserData is optional to identify some data in the 'readMemoryFunction'-callback
 71   bool ShowCallstack(HANDLE hThread,  CONTEXT const & Context, PReadProcessMemoryRoutine readMemoryFunction = NULL, LPVOID pUserData = NULL);
 72
 73   void setOutputBuffer(char * buffer);
 74
 75private:
 76   typedef enum CallstackEntryType {firstEntry, nextEntry, lastEntry};
 77
 78   HANDLE m_hProcess;
 79   DWORD m_dwProcessId;
 80   bool m_modulesLoaded;
 81   LPSTR m_szSymPath;
 82   S32 m_options;
 83   char * m_pOutputBuffer;
 84
 85   static BOOL __stdcall myReadProcMem(HANDLE hProcess, DWORD64 qwBaseAddress, PVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead);
 86
 87   bool Init(LPCSTR szSymPath);
 88
 89   virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName);
 90   virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion);
 91   virtual void OnCallstackEntry(CallstackEntryType eType, struct CallstackEntry &entry);
 92   virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr);
 93   virtual void OnOutput(LPCSTR szText);
 94
 95   bool LoadModules();
 96   DWORD LoadModule(HANDLE hProcess, LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size);
 97   bool GetModuleListTH32(HANDLE hProcess, DWORD pid);
 98   bool GetModuleListPSAPI(HANDLE hProcess);
 99   bool GetModuleInfo(HANDLE hProcess, DWORD64 baseAddr, IMAGEHLP_MODULE64 *pModuleInfo);
100};
101
102void dGetStackTrace(char * traceBuffer, CONTEXT const & ContextRecord);
103
104#endif
105#endif
106