[Orxonox-commit 2750] r7455 - code/trunk/src/libraries/util
landauf at orxonox.net
landauf at orxonox.net
Wed Sep 15 18:14:38 CEST 2010
Author: landauf
Date: 2010-09-15 18:14:37 +0200 (Wed, 15 Sep 2010)
New Revision: 7455
Modified:
code/trunk/src/libraries/util/SignalHandler.cc
code/trunk/src/libraries/util/SignalHandler.h
Log:
added special implementation of abort() and _assert() for mingw which contain a break point.
also added displacement to the callstack
Modified: code/trunk/src/libraries/util/SignalHandler.cc
===================================================================
--- code/trunk/src/libraries/util/SignalHandler.cc 2010-09-14 18:49:45 UTC (rev 7454)
+++ code/trunk/src/libraries/util/SignalHandler.cc 2010-09-15 16:14:37 UTC (rev 7455)
@@ -332,12 +332,33 @@
#include <iostream>
#include <iomanip>
#include <fstream>
+#include <ctime>
#include <dbghelp.h>
+#include <tlhelp32.h>
+#include "Convert.h"
+
#ifdef ORXONOX_COMPILER_GCC
# include <cxxabi.h>
#endif
+#ifdef ORXONOX_COMPILER_GCC
+_UtilExport void __cdecl abort()
+{
+ COUT(1) << "This application has requested the Runtime to terminate it in an unusual way." << std::endl;
+ COUT(1) << "Please contact the application's support team for more information." << std::endl;
+ DebugBreak();
+ exit(0x3);
+}
+
+_UtilExport void __cdecl _assert(const char* expression, const char* file, int line)
+{
+ COUT(1) << "Assertion failed: " << expression << ", file " << file << ", line " << line << std::endl;
+ COUT(1) << std::endl;
+ abort();
+}
+#endif
+
namespace orxonox
{
/// Constructor: Initializes the values, but doesn't register the exception handler.
@@ -369,6 +390,40 @@
{
// Install the unhandled exception filter function
this->prevExceptionFilter_ = SetUnhandledExceptionFilter(&SignalHandler::exceptionFilter);
+
+// std::set_terminate(&myterminate);
+/*
+#ifdef ORXONOX_COMPILER_GCC
+ MODULEENTRY32 module;
+ memset(&module, 0, sizeof(MODULEENTRY32));
+ module.dwSize = sizeof(MODULEENTRY32);
+
+ HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
+
+ BOOL result = Module32First(snapshot, &module);
+
+ COUT(0) << SignalHandler::pointerToString((unsigned)_assert) << std::endl;
+
+ while (result)
+ {
+ COUT(0) << module.szModule << std::endl;
+ COUT(0) << SignalHandler::pointerToString((unsigned)module.modBaseAddr) << " / " << SignalHandler::pointerToString(*module.modBaseAddr) << std::endl;;
+
+ FARPROC procAssert = GetProcAddress(module.hModule, "__ZSt13set_terminatePFvvE");
+ if (procAssert)
+ {
+ COUT(0) << "yes1 --------------------------------------------------------" << std::endl;
+ COUT(0) << SignalHandler::pointerToString((unsigned)procAssert) << std::endl;
+ // *(volatile unsigned*)procAssert = 0xcc;
+ }
+
+ result = Module32Next(snapshot, &module);
+ }
+
+// *(volatile unsigned*)abort = 0xcc;
+// *(volatile unsigned*)_assert = 0xcc;
+#endif
+*/
}
}
@@ -382,6 +437,7 @@
{
bExecuting = true;
+ COUT(1) << std::endl;
// if the signalhandler has already been destroyed then don't do anything
if (SignalHandler::singletonPtr_s == 0)
@@ -465,7 +521,7 @@
context.ContextFlags = CONTEXT_FULL;
// Load the RTLCapture context function:
- HINSTANCE kernel32 = LoadLibrary("Kernel32.dll");
+ HMODULE kernel32 = LoadLibrary("Kernel32.dll");
typedef void (*RtlCaptureContextFunc) (CONTEXT* ContextRecord);
RtlCaptureContextFunc rtlCaptureContext = (RtlCaptureContextFunc) GetProcAddress(kernel32, "RtlCaptureContext");
@@ -480,35 +536,30 @@
type = IMAGE_FILE_MACHINE_I386;
frame.AddrPC.Offset = context.Eip; // program counter
- frame.AddrPC.Mode = AddrModeFlat;
frame.AddrFrame.Offset = context.Ebp; // frame pointer (for function arguments)
- frame.AddrFrame.Mode = AddrModeFlat;
frame.AddrStack.Offset = context.Esp; // stack pointer
- frame.AddrStack.Mode = AddrModeFlat;
#elif _M_X64
type = IMAGE_FILE_MACHINE_AMD64;
frame.AddrPC.Offset = context.Rip; // program counter
- frame.AddrPC.Mode = AddrModeFlat;
frame.AddrFrame.Offset = context.Rbp; // (or Rdi) // frame pointer (for function arguments)
- frame.AddrFrame.Mode = AddrModeFlat;
frame.AddrStack.Offset = context.Rsp; // stack pointer
- frame.AddrStack.Mode = AddrModeFlat;
#elif _M_IA64
type = IMAGE_FILE_MACHINE_IA64;
frame.AddrPC.Offset = context.StIIP; // program counter
- frame.AddrPC.Mode = AddrModeFlat;
frame.AddrFrame.Offset = context.RsBSP; // frame pointer (for function arguments) // <-- unneeded on Intel IPF, may be removed
- frame.AddrFrame.Mode = AddrModeFlat;
frame.AddrStack.Offset = context.IntSp; // stack pointer
- frame.AddrStack.Mode = AddrModeFlat;
frame.AddrBStore.Offset = context.RsBSP; // backing store
frame.AddrBStore.Mode = AddrModeFlat;
#else
- return
+ return "";
#endif
+ frame.AddrPC.Mode = AddrModeFlat;
+ frame.AddrFrame.Mode = AddrModeFlat;
+ frame.AddrStack.Mode = AddrModeFlat;
+
std::string output;
// Keep getting stack frames from windows till there are no more left:
@@ -581,10 +632,50 @@
{
output += symbol->Name;
}
+
+ output += " +" + SignalHandler::pointerToString(displacement, false);
}
-// output += " (+" + SignalHandler::pointerToString(displacement) + ")";
+/*
+ IMAGEHLP_MODULE64 module;
+ memset(&module, 0, sizeof(IMAGEHLP_MODULE64));
+ module.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
+ if
+ (
+ SymGetModuleInfo64
+ (
+ GetCurrentProcess(),
+ frame.AddrPC.Offset,
+ &module
+ )
+ )
+ {
+ IMAGEHLP_LINE64 line;
+ memset(&line, 0, sizeof(IMAGEHLP_LINE64));
+ line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
+
+ DWORD displacement2 = displacement;
+
+ if
+ (
+ SymGetLineFromAddr64
+ (
+ GetCurrentProcess(),
+ frame.AddrPC.Offset,
+ &displacement2,
+ &line
+ )
+ )
+ {
+ output += "\n";
+ output += " ";
+ output += line.FileName;
+ output += ":";
+ output += multi_cast<std::string>(line.LineNumber);
+ }
+ }
+*/
output += "\n";
}
@@ -675,12 +766,15 @@
/// Converts a value to string, formatted as pointer.
template <typename T>
- /* static */ std::string SignalHandler::pointerToString(T pointer)
+ /* static */ std::string SignalHandler::pointerToString(T pointer, bool bFillZeros)
{
std::ostringstream oss;
- oss << std::setw(8) << std::setfill('0') << std::hex << pointer;
+ if (bFillZeros)
+ oss << std::setw(8) << std::setfill('0');
+ oss << std::hex << pointer;
+
return std::string("0x") + oss.str();
}
Modified: code/trunk/src/libraries/util/SignalHandler.h
===================================================================
--- code/trunk/src/libraries/util/SignalHandler.h 2010-09-14 18:49:45 UTC (rev 7454)
+++ code/trunk/src/libraries/util/SignalHandler.h 2010-09-15 16:14:37 UTC (rev 7455)
@@ -42,11 +42,6 @@
#include "Singleton.h"
#include "SpecialConfig.h"
-namespace orxonox
-{
- typedef int (*SignalCallback)( void * someData );
-}
-
#if defined(ORXONOX_PLATFORM_LINUX)
#include <list>
@@ -54,6 +49,8 @@
namespace orxonox
{
+ typedef int (*SignalCallback)( void * someData );
+
struct SignalRec
{
int signal;
@@ -108,30 +105,31 @@
class _UtilExport SignalHandler : public Singleton<SignalHandler>
{
friend class Singleton<SignalHandler>;
- public:
- SignalHandler();
- ~SignalHandler();
- void doCatch( const std::string & appName, const std::string & filename );
+ public:
+ SignalHandler();
+ ~SignalHandler();
- static std::string getStackTrace(PEXCEPTION_POINTERS pExceptionInfo = NULL);
- static std::string getExceptionType(PEXCEPTION_POINTERS pExceptionInfo);
+ void doCatch(const std::string& appName, const std::string& filename);
- private:
- static LONG WINAPI exceptionFilter(PEXCEPTION_POINTERS pExceptionInfo);
+ static std::string getStackTrace(PEXCEPTION_POINTERS pExceptionInfo = NULL);
+ static std::string getExceptionType(PEXCEPTION_POINTERS pExceptionInfo);
- static std::string getModuleName(const std::string& path);
- static DWORD getModuleBase(DWORD dwAddress);
+ private:
+ static LONG WINAPI exceptionFilter(PEXCEPTION_POINTERS pExceptionInfo);
- template <typename T>
- static std::string pointerToString(T pointer);
- template <typename T>
- static std::string pointerToString(T* pointer);
+ static std::string getModuleName(const std::string& path);
+ static DWORD getModuleBase(DWORD dwAddress);
- static SignalHandler* singletonPtr_s;
+ template <typename T>
+ static std::string pointerToString(T pointer, bool bFillZeros = true);
+ template <typename T>
+ static std::string pointerToString(T* pointer);
- std::string filename_;
- LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter_;
+ static SignalHandler* singletonPtr_s;
+
+ std::string filename_;
+ LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter_;
};
}
@@ -143,11 +141,12 @@
class _UtilExport SignalHandler : public Singleton<SignalHandler>
{
friend class Singleton<SignalHandler>;
- public:
- void doCatch( const std::string & appName, const std::string & filename ) {}
- private:
- static SignalHandler* singletonPtr_s;
+ public:
+ void doCatch(const std::string& appName, const std::string& filename) {}
+
+ private:
+ static SignalHandler* singletonPtr_s;
};
}
More information about the Orxonox-commit
mailing list