Changeset 7452 for code/trunk/src/libraries/util
- Timestamp:
- Sep 14, 2010, 2:35:57 AM (14 years ago)
- Location:
- code/trunk/src/libraries/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/util/SignalHandler.cc
r7450 r7452 335 335 #include <dbghelp.h> 336 336 337 #ifdef ORXONOX_COMPILER_GCC 338 # include <cxxabi.h> 339 #endif 340 337 341 namespace orxonox 338 342 { … … 435 439 { 436 440 // Initialise the symbol table to get function names: 441 SymSetOptions 442 ( 443 SYMOPT_DEFERRED_LOADS 444 #ifndef ORXONOX_COMPILER_GCC 445 | SYMOPT_UNDNAME 446 #endif 447 ); 437 448 SymInitialize(GetCurrentProcess(), 0, true); 438 449 439 450 // Store the current stack frame here: 440 STACKFRAME frame;441 memset(&frame, 0, sizeof(STACKFRAME ));451 STACKFRAME64 frame; 452 memset(&frame, 0, sizeof(STACKFRAME64)); 442 453 443 454 // Get processor information for the current thread: … … 466 477 467 478 // set the flags and initialize the stackframe struct 468 479 #ifdef _M_IX86 469 480 type = IMAGE_FILE_MACHINE_I386; 470 481 471 frame.AddrPC.Offset = context.Eip; // Current location in program472 frame.AddrPC.Mode = AddrModeFlat; // Address mode for this pointer: flat 32 bit addressing473 frame.Addr Stack.Offset = context.Esp; // Stack pointers current value474 frame.Addr Stack.Mode = AddrModeFlat; // Address mode for this pointer: flat 32 bit addressing475 frame.Addr Frame.Offset = context.Ebp; // Value of register used to access local function variables.476 frame.Addr Frame.Mode = AddrModeFlat; // Address mode for this pointer: flat 32 bit addressing477 482 frame.AddrPC.Offset = context.Eip; // program counter 483 frame.AddrPC.Mode = AddrModeFlat; 484 frame.AddrFrame.Offset = context.Ebp; // frame pointer (for function arguments) 485 frame.AddrFrame.Mode = AddrModeFlat; 486 frame.AddrStack.Offset = context.Esp; // stack pointer 487 frame.AddrStack.Mode = AddrModeFlat; 488 #elif _M_X64 478 489 type = IMAGE_FILE_MACHINE_AMD64; 479 490 480 frame.AddrPC.Offset = context.Rip; // Current location in program481 frame.AddrPC.Mode = AddrModeFlat; // Address mode for this pointer: flat 32 bit addressing482 frame.Addr Stack.Offset = context.Rsp; // Stack pointers current value483 frame.Addr Stack.Mode = AddrModeFlat; // Address mode for this pointer: flat 32 bit addressing484 frame.Addr Frame.Offset = context.Rsp; // Value of register used to access local function variables.485 frame.Addr Frame.Mode = AddrModeFlat; // Address mode for this pointer: flat 32 bit addressing486 491 frame.AddrPC.Offset = context.Rip; // program counter 492 frame.AddrPC.Mode = AddrModeFlat; 493 frame.AddrFrame.Offset = context.Rbp; // (or Rdi) // frame pointer (for function arguments) 494 frame.AddrFrame.Mode = AddrModeFlat; 495 frame.AddrStack.Offset = context.Rsp; // stack pointer 496 frame.AddrStack.Mode = AddrModeFlat; 497 #elif _M_IA64 487 498 type = IMAGE_FILE_MACHINE_IA64; 488 499 489 frame.AddrPC.Offset = context.StIIP; // Current location in program490 frame.AddrPC.Mode = AddrModeFlat; // Address mode for this pointer: flat 32 bit addressing491 frame.Addr Stack.Offset = context.IntSp; // Stack pointers current value492 frame.Addr Stack.Mode = AddrModeFlat; // Address mode for this pointer: flat 32 bit addressing493 frame.Addr Frame.Offset = context.IntSp; // Value of register used to access local function variables.494 frame.Addr Frame.Mode = AddrModeFlat; // Address mode for this pointer: flat 32 bit addressing495 frame.AddrBStore.Offset = context.RsBSP; //496 frame.AddrBStore.Mode = AddrModeFlat; //497 500 frame.AddrPC.Offset = context.StIIP; // program counter 501 frame.AddrPC.Mode = AddrModeFlat; 502 frame.AddrFrame.Offset = context.RsBSP; // frame pointer (for function arguments) // <-- unneeded on Intel IPF, may be removed 503 frame.AddrFrame.Mode = AddrModeFlat; 504 frame.AddrStack.Offset = context.IntSp; // stack pointer 505 frame.AddrStack.Mode = AddrModeFlat; 506 frame.AddrBStore.Offset = context.RsBSP; // backing store 507 frame.AddrBStore.Mode = AddrModeFlat; 508 #else 498 509 return 499 510 #endif 500 511 501 512 std::string output; … … 503 514 // Keep getting stack frames from windows till there are no more left: 504 515 for (int i = 0; 505 StackWalk 516 StackWalk64 506 517 ( 507 type , // MachineType508 GetCurrentProcess() , // Process to get stack trace for509 GetCurrentThread() , // Thread to get stack trace for510 &frame , // Where to store next stack frame511 &context , // Pointer to processor context record512 0 , // Routine to read process memory: use the default ReadProcessMemory513 &SymFunctionTableAccess 514 &SymGetModuleBase 515 0 // Something to do with 16-bit code. Not needed.518 type , // MachineType 519 GetCurrentProcess() , // Process to get stack trace for 520 GetCurrentThread() , // Thread to get stack trace for 521 &frame , // Where to store next stack frame 522 &context , // Pointer to processor context record 523 0 , // Routine to read process memory: use the default ReadProcessMemory 524 &SymFunctionTableAccess64 , // Routine to access the modules symbol table 525 &SymGetModuleBase64 , // Routine to access the modules base address 526 0 // Something to do with 16-bit code. Not needed. 516 527 ); 517 528 ++i … … 523 534 // it must be declared as a raw byte buffer. 524 535 //------------------------------------------------------------------ 525 static char symbolBuffer[sizeof( IMAGEHLP_SYMBOL) + 255];526 memset(symbolBuffer, 0, sizeof( IMAGEHLP_SYMBOL) + 255);536 static char symbolBuffer[sizeof(SYMBOL_INFO) + 255]; 537 memset(symbolBuffer, 0, sizeof(symbolBuffer)); 527 538 528 539 // Cast it to a symbol struct: 529 IMAGEHLP_SYMBOL * symbol = (IMAGEHLP_SYMBOL*)symbolBuffer;530 531 // Need to set t he first two fields of this symbol before obtaining name info:532 symbol->SizeOfStruct = sizeof( IMAGEHLP_SYMBOL) + 255;533 symbol->MaxNameLen gth = 254;540 SYMBOL_INFO* symbol = (SYMBOL_INFO*)symbolBuffer; 541 542 // Need to set two fields of this symbol before obtaining name info: 543 symbol->SizeOfStruct = sizeof(SYMBOL_INFO); 544 symbol->MaxNameLen = 255; 534 545 535 546 // The displacement from the beginning of the symbol is stored here: pretty useless 536 unsigned displacement = 0; 537 547 long long unsigned int displacement = 0; 548 549 if (i < 10) 550 output += " "; 538 551 output += multi_cast<std::string>(i) + ": "; 552 553 // Print the function's address: 554 output += SignalHandler::pointerToString(frame.AddrPC.Offset); 539 555 540 556 // Get the symbol information from the address of the instruction pointer register: 541 557 if 542 558 ( 543 Sym GetSymFromAddr559 SymFromAddr 544 560 ( 545 GetCurrentProcess() 546 frame.AddrPC.Offset 547 (DWORD*) &displacement , // Displacement from the beginning of the symbol: what is this for ?548 symbol 561 GetCurrentProcess() , // Process to get symbol information for 562 frame.AddrPC.Offset , // Address to get symbol for: instruction pointer register 563 &displacement , // Displacement from the beginning of the symbol 564 symbol // Where to save the symbol 549 565 ) 550 566 ) 551 567 { 552 568 // Add the name of the function to the function list: 553 output += SignalHandler::pointerToString(frame.AddrPC.Offset) + " " + symbol->Name; 569 output += " "; 570 571 #ifdef ORXONOX_COMPILER_GCC 572 int status; 573 char* demangled = __cxxabiv1::__cxa_demangle(symbol->Name, NULL, NULL, &status); 574 if (demangled) 575 { 576 output += demangled; 577 free(demangled); 578 } 579 else 580 #endif 581 { 582 output += symbol->Name; 583 } 554 584 } 555 else 556 { 557 // Print an unknown location: 558 output += SignalHandler::pointerToString(frame.AddrPC.Offset); 559 } 560 561 // output += " (" + SignalHandler::pointerToString(displacement) + ")"; 585 586 // output += " (+" + SignalHandler::pointerToString(displacement) + ")"; 587 562 588 output += "\n"; 563 589 } -
code/trunk/src/libraries/util/SignalHandler.h
r7449 r7452 115 115 void doCatch( const std::string & appName, const std::string & filename ); 116 116 117 static std::string getStackTrace(PEXCEPTION_POINTERS pExceptionInfo = NULL); 118 static std::string getExceptionType(PEXCEPTION_POINTERS pExceptionInfo); 119 117 120 private: 118 121 static LONG WINAPI exceptionFilter(PEXCEPTION_POINTERS pExceptionInfo); 119 122 120 static std::string getStackTrace(PEXCEPTION_POINTERS pExceptionInfo = NULL);121 static std::string getExceptionType(PEXCEPTION_POINTERS pExceptionInfo);122 123 static std::string getModuleName(const std::string& path); 123 124 static DWORD getModuleBase(DWORD dwAddress);
Note: See TracChangeset
for help on using the changeset viewer.