Changeset 7455 for code/trunk/src/libraries
- Timestamp:
- Sep 15, 2010, 6:14:37 PM (14 years ago)
- Location:
- code/trunk/src/libraries/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/util/SignalHandler.cc
r7452 r7455 333 333 #include <iomanip> 334 334 #include <fstream> 335 #include <ctime> 335 336 #include <dbghelp.h> 337 #include <tlhelp32.h> 338 339 #include "Convert.h" 336 340 337 341 #ifdef ORXONOX_COMPILER_GCC 338 342 # include <cxxabi.h> 343 #endif 344 345 #ifdef ORXONOX_COMPILER_GCC 346 _UtilExport void __cdecl abort() 347 { 348 COUT(1) << "This application has requested the Runtime to terminate it in an unusual way." << std::endl; 349 COUT(1) << "Please contact the application's support team for more information." << std::endl; 350 DebugBreak(); 351 exit(0x3); 352 } 353 354 _UtilExport void __cdecl _assert(const char* expression, const char* file, int line) 355 { 356 COUT(1) << "Assertion failed: " << expression << ", file " << file << ", line " << line << std::endl; 357 COUT(1) << std::endl; 358 abort(); 359 } 339 360 #endif 340 361 … … 370 391 // Install the unhandled exception filter function 371 392 this->prevExceptionFilter_ = SetUnhandledExceptionFilter(&SignalHandler::exceptionFilter); 393 394 // std::set_terminate(&myterminate); 395 /* 396 #ifdef ORXONOX_COMPILER_GCC 397 MODULEENTRY32 module; 398 memset(&module, 0, sizeof(MODULEENTRY32)); 399 module.dwSize = sizeof(MODULEENTRY32); 400 401 HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0); 402 403 BOOL result = Module32First(snapshot, &module); 404 405 COUT(0) << SignalHandler::pointerToString((unsigned)_assert) << std::endl; 406 407 while (result) 408 { 409 COUT(0) << module.szModule << std::endl; 410 COUT(0) << SignalHandler::pointerToString((unsigned)module.modBaseAddr) << " / " << SignalHandler::pointerToString(*module.modBaseAddr) << std::endl;; 411 412 FARPROC procAssert = GetProcAddress(module.hModule, "__ZSt13set_terminatePFvvE"); 413 if (procAssert) 414 { 415 COUT(0) << "yes1 --------------------------------------------------------" << std::endl; 416 COUT(0) << SignalHandler::pointerToString((unsigned)procAssert) << std::endl; 417 // *(volatile unsigned*)procAssert = 0xcc; 418 } 419 420 result = Module32Next(snapshot, &module); 421 } 422 423 // *(volatile unsigned*)abort = 0xcc; 424 // *(volatile unsigned*)_assert = 0xcc; 425 #endif 426 */ 372 427 } 373 428 } … … 383 438 bExecuting = true; 384 439 440 COUT(1) << std::endl; 385 441 386 442 // if the signalhandler has already been destroyed then don't do anything … … 466 522 467 523 // Load the RTLCapture context function: 468 H INSTANCE kernel32 = LoadLibrary("Kernel32.dll");524 HMODULE kernel32 = LoadLibrary("Kernel32.dll"); 469 525 typedef void (*RtlCaptureContextFunc) (CONTEXT* ContextRecord); 470 526 RtlCaptureContextFunc rtlCaptureContext = (RtlCaptureContextFunc) GetProcAddress(kernel32, "RtlCaptureContext"); … … 481 537 482 538 frame.AddrPC.Offset = context.Eip; // program counter 483 frame.AddrPC.Mode = AddrModeFlat;484 539 frame.AddrFrame.Offset = context.Ebp; // frame pointer (for function arguments) 485 frame.AddrFrame.Mode = AddrModeFlat;486 540 frame.AddrStack.Offset = context.Esp; // stack pointer 487 frame.AddrStack.Mode = AddrModeFlat;488 541 #elif _M_X64 489 542 type = IMAGE_FILE_MACHINE_AMD64; 490 543 491 544 frame.AddrPC.Offset = context.Rip; // program counter 492 frame.AddrPC.Mode = AddrModeFlat;493 545 frame.AddrFrame.Offset = context.Rbp; // (or Rdi) // frame pointer (for function arguments) 494 frame.AddrFrame.Mode = AddrModeFlat;495 546 frame.AddrStack.Offset = context.Rsp; // stack pointer 496 frame.AddrStack.Mode = AddrModeFlat;497 547 #elif _M_IA64 498 548 type = IMAGE_FILE_MACHINE_IA64; 499 549 500 550 frame.AddrPC.Offset = context.StIIP; // program counter 501 frame.AddrPC.Mode = AddrModeFlat;502 551 frame.AddrFrame.Offset = context.RsBSP; // frame pointer (for function arguments) // <-- unneeded on Intel IPF, may be removed 503 frame.AddrFrame.Mode = AddrModeFlat;504 552 frame.AddrStack.Offset = context.IntSp; // stack pointer 505 frame.AddrStack.Mode = AddrModeFlat;506 553 frame.AddrBStore.Offset = context.RsBSP; // backing store 507 554 frame.AddrBStore.Mode = AddrModeFlat; 508 555 #else 509 return 556 return ""; 510 557 #endif 558 559 frame.AddrPC.Mode = AddrModeFlat; 560 frame.AddrFrame.Mode = AddrModeFlat; 561 frame.AddrStack.Mode = AddrModeFlat; 511 562 512 563 std::string output; … … 582 633 output += symbol->Name; 583 634 } 635 636 output += " +" + SignalHandler::pointerToString(displacement, false); 584 637 } 585 638 586 // output += " (+" + SignalHandler::pointerToString(displacement) + ")"; 587 639 /* 640 IMAGEHLP_MODULE64 module; 641 memset(&module, 0, sizeof(IMAGEHLP_MODULE64)); 642 module.SizeOfStruct = sizeof(IMAGEHLP_MODULE64); 643 644 if 645 ( 646 SymGetModuleInfo64 647 ( 648 GetCurrentProcess(), 649 frame.AddrPC.Offset, 650 &module 651 ) 652 ) 653 { 654 IMAGEHLP_LINE64 line; 655 memset(&line, 0, sizeof(IMAGEHLP_LINE64)); 656 line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); 657 658 DWORD displacement2 = displacement; 659 660 if 661 ( 662 SymGetLineFromAddr64 663 ( 664 GetCurrentProcess(), 665 frame.AddrPC.Offset, 666 &displacement2, 667 &line 668 ) 669 ) 670 { 671 output += "\n"; 672 output += " "; 673 output += line.FileName; 674 output += ":"; 675 output += multi_cast<std::string>(line.LineNumber); 676 } 677 } 678 */ 588 679 output += "\n"; 589 680 } … … 676 767 /// Converts a value to string, formatted as pointer. 677 768 template <typename T> 678 /* static */ std::string SignalHandler::pointerToString(T pointer )769 /* static */ std::string SignalHandler::pointerToString(T pointer, bool bFillZeros) 679 770 { 680 771 std::ostringstream oss; 681 772 682 oss << std::setw(8) << std::setfill('0') << std::hex << pointer; 773 if (bFillZeros) 774 oss << std::setw(8) << std::setfill('0'); 775 776 oss << std::hex << pointer; 683 777 684 778 return std::string("0x") + oss.str(); -
code/trunk/src/libraries/util/SignalHandler.h
r7452 r7455 43 43 #include "SpecialConfig.h" 44 44 45 namespace orxonox46 {47 typedef int (*SignalCallback)( void * someData );48 }49 50 45 #if defined(ORXONOX_PLATFORM_LINUX) 51 46 … … 55 50 namespace orxonox 56 51 { 52 typedef int (*SignalCallback)( void * someData ); 53 57 54 struct SignalRec 58 55 { … … 109 106 { 110 107 friend class Singleton<SignalHandler>; 111 public:112 SignalHandler();113 ~SignalHandler();114 108 115 void doCatch( const std::string & appName, const std::string & filename ); 109 public: 110 SignalHandler(); 111 ~SignalHandler(); 116 112 117 static std::string getStackTrace(PEXCEPTION_POINTERS pExceptionInfo = NULL); 118 static std::string getExceptionType(PEXCEPTION_POINTERS pExceptionInfo); 113 void doCatch(const std::string& appName, const std::string& filename); 119 114 120 private:121 static LONG WINAPI exceptionFilter(PEXCEPTION_POINTERS pExceptionInfo);115 static std::string getStackTrace(PEXCEPTION_POINTERS pExceptionInfo = NULL); 116 static std::string getExceptionType(PEXCEPTION_POINTERS pExceptionInfo); 122 117 123 static std::string getModuleName(const std::string& path);124 static DWORD getModuleBase(DWORD dwAddress);118 private: 119 static LONG WINAPI exceptionFilter(PEXCEPTION_POINTERS pExceptionInfo); 125 120 126 template <typename T> 127 static std::string pointerToString(T pointer); 128 template <typename T> 129 static std::string pointerToString(T* pointer); 121 static std::string getModuleName(const std::string& path); 122 static DWORD getModuleBase(DWORD dwAddress); 130 123 131 static SignalHandler* singletonPtr_s; 124 template <typename T> 125 static std::string pointerToString(T pointer, bool bFillZeros = true); 126 template <typename T> 127 static std::string pointerToString(T* pointer); 132 128 133 std::string filename_; 134 LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter_; 129 static SignalHandler* singletonPtr_s; 130 131 std::string filename_; 132 LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter_; 135 133 }; 136 134 } … … 144 142 { 145 143 friend class Singleton<SignalHandler>; 146 public:147 void doCatch( const std::string & appName, const std::string & filename ) {}148 144 149 private: 150 static SignalHandler* singletonPtr_s; 145 public: 146 void doCatch(const std::string& appName, const std::string& filename) {} 147 148 private: 149 static SignalHandler* singletonPtr_s; 151 150 }; 152 151 }
Note: See TracChangeset
for help on using the changeset viewer.