Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

<bugfixes> NOTE: the tag bugfixes_base was made prior to this commit,…

… in case you need a "clean" copy of the prior state of bugfixes.

Cleaned up with astyle with these options:
--suffix=none
--style=allman
--indent=tab
--indent-cases
--indent-namespaces
--pad-oper
--pad-header
--unpad-paren
--add-brackets
--align-pointer=name
--min-conditional-indent=0
--indent-preprocessor
--keep-one-line-statements
  • Loading branch information...
commit b8ce4995a09b2ea6cbca85394bcce63aeb905e81 1 parent 837d79f
@vexed vexed authored
Showing with 8,402 additions and 7,152 deletions.
  1. +44 −32 lib/exceptionhandler/dumpinfo.cpp
  2. +1 −1  lib/exceptionhandler/dumpinfo.h
  3. +187 −163 lib/exceptionhandler/exceptionhandler.cpp
  4. +1 −1  lib/exceptionhandler/exceptionhandler.h
  5. +516 −368 lib/exceptionhandler/exchndl.cpp
  6. +1 −1  lib/framework/cocoa_wrapper.h
  7. +16 −16 lib/framework/crc.cpp
  8. +91 −63 lib/framework/debug.cpp
  9. +64 −58 lib/framework/debug.h
  10. +9 −9 lib/framework/endian_hack.h
  11. +5 −5 lib/framework/file.h
  12. +4 −1 lib/framework/fixedpoint.h
  13. +21 −17 lib/framework/frame.cpp
  14. +3 −3 lib/framework/frame.h
  15. +85 −79 lib/framework/frameresource.cpp
  16. +8 −8 lib/framework/frameresource.h
  17. +49 −49 lib/framework/geometry.cpp
  18. +22 −20 lib/framework/geometry.h
  19. +107 −91 lib/framework/gettext.h
  20. +15 −13 lib/framework/i18n.cpp
  21. +2 −2 lib/framework/i18n.h
  22. +6 −3 lib/framework/input.h
  23. +37 −37 lib/framework/lexer_input.cpp
  24. +9 −9 lib/framework/lexer_input.h
  25. +41 −41 lib/framework/listmacs.h
  26. +4 −4 lib/framework/macros.h
  27. +35 −13 lib/framework/math_ext.h
  28. +16 −14 lib/framework/physfs_ext.h
  29. +72 −21 lib/framework/rational.h
  30. +17 −15 lib/framework/stdio_ext.cpp
  31. +22 −22 lib/framework/stdio_ext.h
  32. +17 −11 lib/framework/string_ext.h
  33. +7 −7 lib/framework/strres.cpp
  34. +4 −4 lib/framework/strres.h
  35. +3 −3 lib/framework/strresly.h
  36. +22 −16 lib/framework/treap.cpp
  37. +5 −5 lib/framework/treap.h
  38. +39 −39 lib/framework/trig.cpp
  39. +1 −1  lib/framework/trig.h
  40. +45 −33 lib/framework/utf.cpp
  41. +233 −58 lib/framework/vector.h
  42. +12 −3 lib/framework/wzconfig.cpp
  43. +8 −2 lib/framework/wzconfig.h
  44. +143 −32 lib/framework/wzfs.h
  45. +34 −16 lib/framework/wzglobal.h
  46. +39 −39 lib/gamelib/anim.cpp
  47. +11 −11 lib/gamelib/anim.h
  48. +45 −45 lib/gamelib/animobj.cpp
  49. +18 −18 lib/gamelib/animobj.h
  50. +18 −18 lib/gamelib/gtime.cpp
  51. +5 −5 lib/gamelib/gtime.h
  52. +77 −77 lib/gamelib/hashtable.cpp
  53. +15 −15 lib/gamelib/hashtable.h
  54. +1 −1  lib/gamelib/parser.h
  55. +19 −13 lib/ivis_opengl/bitimage.cpp
  56. +2 −2 lib/ivis_opengl/bitimage.h
  57. +1 −1  lib/ivis_opengl/imd.h
  58. +36 −36 lib/ivis_opengl/imdload.cpp
  59. +1 −1  lib/ivis_opengl/ivisdef.h
  60. +102 −62 lib/ivis_opengl/jpeg_encoder.cpp
  61. +1 −1  lib/ivis_opengl/jpeg_encoder.h
  62. +39 −31 lib/ivis_opengl/pieblitfunc.cpp
  63. +2 −2 lib/ivis_opengl/pieblitfunc.h
  64. +6 −6 lib/ivis_opengl/pieclip.cpp
  65. +3 −3 lib/ivis_opengl/pieclip.h
  66. +2 −2 lib/ivis_opengl/piedef.h
  67. +68 −58 lib/ivis_opengl/piedraw.cpp
  68. +49 −49 lib/ivis_opengl/piefunc.cpp
  69. +1 −1  lib/ivis_opengl/piefunc.h
  70. +34 −33 lib/ivis_opengl/piematrix.cpp
  71. +9 −3 lib/ivis_opengl/piematrix.h
  72. +9 −6 lib/ivis_opengl/piemode.cpp
  73. +1 −1  lib/ivis_opengl/piemode.h
  74. +37 −37 lib/ivis_opengl/piepalette.cpp
  75. +84 −76 lib/ivis_opengl/piestate.cpp
  76. +8 −8 lib/ivis_opengl/piestate.h
  77. +34 −17 lib/ivis_opengl/png_util.cpp
  78. +1 −1  lib/ivis_opengl/rendmode.cpp
  79. +36 −27 lib/ivis_opengl/screen.cpp
  80. +2 −2 lib/ivis_opengl/screen.h
  81. +18 −17 lib/ivis_opengl/tex.cpp
  82. +3 −3 lib/ivis_opengl/tex.h
  83. +54 −54 lib/ivis_opengl/textdraw.cpp
  84. +9 −8 lib/ivis_opengl/textdraw.h
  85. +22 −16 lib/netplay/netlog.cpp
  86. +1 −1  lib/netplay/netlog.h
  87. +482 −439 lib/netplay/netplay.cpp
  88. +12 −12 lib/netplay/netplay.h
  89. +4 −4 lib/netplay/netqueue.cpp
  90. +22 −5 lib/netplay/netqueue.h
  91. +223 −212 lib/netplay/netsocket.cpp
  92. +2 −2 lib/netplay/netsocket.h
  93. +38 −38 lib/netplay/nettypes.cpp
  94. +54 −14 lib/netplay/nettypes.h
  95. +2 −2 lib/qtgame/macosx_screen_resolutions.cpp
  96. +6 −4 lib/qtgame/main_qt.cpp
  97. +5 −3 lib/qtgame/qtgame.cpp
  98. +40 −10 lib/qtgame/qtgame.h
  99. +15 −7 lib/qtgame/swapinterval.cpp
  100. +1 −1  lib/qtgame/swapinterval.h
  101. +264 −203 lib/qtgame/wzapp_qt.cpp
  102. +8 −2 lib/qtgame/wzapp_qt.h
  103. +111 −111 lib/script/codeprint.cpp
  104. +68 −66 lib/script/event.cpp
  105. +5 −5 lib/script/event.h
  106. +5 −5 lib/script/eventsave.cpp
  107. +199 −180 lib/script/interpreter.cpp
  108. +1 −1  lib/script/interpreter.h
  109. +11 −11 lib/script/parse.h
  110. +72 −61 lib/script/script.cpp
  111. +2 −2 lib/script/script.h
  112. +192 −170 lib/script/stack.cpp
  113. +1,093 −1,066 lib/sdl/cursors_sdl.cpp
  114. +223 −209 lib/sdl/main_sdl.cpp
  115. +342 −320 lib/sdl/scrap.cpp
  116. +167 −165 lib/sdl/wz2100icon.h
  117. +39 −29 lib/sequence/sequence.cpp
  118. +6 −5 lib/sequence/sequence.h
  119. +1 −1  lib/sequence/timer.cpp
  120. +1 −1  lib/sequence/timer.h
  121. +2 −2 lib/sound/aud.h
  122. +154 −150 lib/sound/audio.cpp
  123. +25 −25 lib/sound/audio.h
  124. +455 −455 lib/sound/audio_id.cpp
  125. +24 −24 lib/sound/audio_id.h
  126. +17 −15 lib/sound/cdaudio.cpp
  127. +1 −1  lib/sound/cdaudio.h
  128. +1 −1  lib/sound/mixer.h
  129. +76 −61 lib/sound/oggvorbis.cpp
  130. +4 −4 lib/sound/oggvorbis.h
  131. +56 −52 lib/sound/openal_error.cpp
  132. +2 −2 lib/sound/openal_error.h
  133. +120 −118 lib/sound/openal_track.cpp
  134. +11 −11 lib/sound/playlist.cpp
  135. +3 −3 lib/sound/playlist.h
  136. +51 −47 lib/sound/track.cpp
  137. +39 −39 lib/sound/track.h
  138. +25 −25 lib/sound/tracklib.h
  139. +43 −43 lib/widget/bar.cpp
  140. +1 −1  lib/widget/bar.h
  141. +61 −53 lib/widget/button.cpp
  142. +1 −1  lib/widget/button.h
  143. +45 −39 lib/widget/editbox.cpp
  144. +1 −1  lib/widget/editbox.h
  145. +352 −288 lib/widget/form.cpp
  146. +6 −6 lib/widget/form.h
  147. +22 −22 lib/widget/label.cpp
  148. +1 −1  lib/widget/label.h
  149. +80 −79 lib/widget/slider.cpp
  150. +1 −1  lib/widget/slider.h
Sorry, we could not display the entire diff because too many files (344) changed.
View
76 lib/exceptionhandler/dumpinfo.cpp
@@ -50,13 +50,13 @@ using std::string;
static const std::size_t max_debug_messages = 20;
-static char* dbgHeader = NULL;
+static char *dbgHeader = NULL;
static std::deque<std::vector<char> > dbgMessages;
// used to add custom info to the crash log
static std::vector<char> miscData;
-static void dumpstr(const DumpFileHandle file, const char * const str, std::size_t const size)
+static void dumpstr(const DumpFileHandle file, const char *const str, std::size_t const size)
{
#if defined(WZ_OS_WIN)
DWORD lNumberOfBytesWritten;
@@ -70,14 +70,14 @@ static void dumpstr(const DumpFileHandle file, const char * const str, std::size
{
switch (errno)
{
- case EAGAIN:
- // Sleep to prevent wasting of CPU in case of non-blocking I/O
- usleep(1);
- case EINTR:
- continue;
- default:
- // TODO find a decent way to deal with the fatal errors
- return;
+ case EAGAIN:
+ // Sleep to prevent wasting of CPU in case of non-blocking I/O
+ usleep(1);
+ case EINTR:
+ continue;
+ default:
+ // TODO find a decent way to deal with the fatal errors
+ return;
}
}
@@ -86,7 +86,7 @@ static void dumpstr(const DumpFileHandle file, const char * const str, std::size
#endif
}
-static void dumpstr(const DumpFileHandle file, const char * const str)
+static void dumpstr(const DumpFileHandle file, const char *const str)
{
dumpstr(file, str, strlen(str));
}
@@ -96,7 +96,7 @@ static void dumpEOL(const DumpFileHandle file)
dumpstr(file, endl);
}
-static void debug_exceptionhandler_data(void **, const char * const str)
+static void debug_exceptionhandler_data(void **, const char *const str)
{
/* Can't use ASSERT here as that will cause us to be invoked again.
* Possibly resulting in infinite recursion.
@@ -105,14 +105,16 @@ static void debug_exceptionhandler_data(void **, const char * const str)
// For non-debug builds
if (str == NULL)
+ {
return;
+ }
// Push this message on the message list
- const char * last = &str[strlen(str)];
+ const char *last = &str[strlen(str)];
// Strip finishing newlines
while (last != str
- && *(last - 1) == '\n')
+ && *(last - 1) == '\n')
{
--last;
}
@@ -161,7 +163,7 @@ void dbgDumpLog(DumpFileHandle file)
dumpEOL(file);
}
-static std::string getProgramPath(const char* programCommand)
+static std::string getProgramPath(const char *programCommand)
{
std::vector<char> buf(PATH_MAX);
@@ -172,8 +174,8 @@ static std::string getProgramPath(const char* programCommand)
}
#elif defined(WZ_OS_UNIX) && !defined(WZ_OS_MAC)
{
- FILE * whichProgramStream;
- char* whichProgramCommand;
+ FILE *whichProgramStream;
+ char *whichProgramCommand;
sasprintf(&whichProgramCommand, "which %s", programCommand);
whichProgramStream = popen(whichProgramCommand, "r");
@@ -187,7 +189,9 @@ static std::string getProgramPath(const char* programCommand)
while (!feof(whichProgramStream))
{
if (read == buf.size())
+ {
buf.resize(buf.size() * 2);
+ }
read += fread(&buf[read], 1, buf.size() - read, whichProgramStream);
}
@@ -202,11 +206,15 @@ static std::string getProgramPath(const char* programCommand)
// `which' adds a \n which confuses exec()
std::string::size_type eol = programPath.find('\n');
if (eol != std::string::npos)
+ {
programPath.erase(eol);
+ }
// Strip any NUL chars
std::string::size_type nul = programPath.find('\0');
if (nul != std::string::npos)
+ {
programPath.erase(nul);
+ }
debug(LOG_WZ, "Found us at %s", programPath.c_str());
}
else
@@ -253,7 +261,7 @@ static std::string getCurTime()
for (string::reverse_iterator
newline = time.rbegin();
newline != time.rend()
- && *newline == '\n';
+ && *newline == '\n';
++newline)
{
*newline = '\0';
@@ -262,20 +270,22 @@ static std::string getCurTime()
// Remove everything after, and including, the first NUL character
string::size_type newline = time.find_first_of('\0');
if (newline != string::npos)
+ {
time.erase(newline);
+ }
return time;
}
template <typename CharT, typename Traits>
-std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, PHYSFS_Version const& ver)
+std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os, PHYSFS_Version const &ver)
{
return os << static_cast<unsigned int>(ver.major)
- << "." << static_cast<unsigned int>(ver.minor)
- << "." << static_cast<unsigned int>(ver.patch);
+ << "." << static_cast<unsigned int>(ver.minor)
+ << "." << static_cast<unsigned int>(ver.patch);
}
-static void createHeader(int const argc, const char** argv, const char *packageVersion)
+static void createHeader(int const argc, const char **argv, const char *packageVersion)
{
std::ostringstream os;
@@ -286,7 +296,9 @@ static void createHeader(int const argc, const char** argv, const char *packageV
* separated by spaces.
*/
for (int i = 0; i < argc; ++i)
+ {
os << "\"" << argv[i] << "\" ";
+ }
os << endl;
@@ -295,22 +307,22 @@ static void createHeader(int const argc, const char** argv, const char *packageV
<< "Compiled on: " __DATE__ " " __TIME__ << endl
<< "Compiled by: "
#if defined(WZ_CC_GNU) && !defined(WZ_CC_INTEL)
- << "GCC " __VERSION__ << endl
+ << "GCC " __VERSION__ << endl
#elif defined(WZ_CC_INTEL)
- // Intel includes the compiler name within the version string
- << __VERSION__ << endl
+ // Intel includes the compiler name within the version string
+ << __VERSION__ << endl
#else
- << "UNKNOWN" << endl
+ << "UNKNOWN" << endl
#endif
<< "Compiled mode: "
#ifdef DEBUG
- << "Debug build" << endl
+ << "Debug build" << endl
#else
- << "Release build" << endl
+ << "Release build" << endl
#endif
<< "Executed on: " << getCurTime() << endl
<< getSysinfo() << endl
- << "Pointers: " << (sizeof(void*) * CHAR_BIT) << "bit" << endl
+ << "Pointers: " << (sizeof(void *) * CHAR_BIT) << "bit" << endl
<< endl;
PHYSFS_Version physfs_version;
@@ -338,7 +350,7 @@ void addDumpInfo(const char *inbuffer)
char ourtime[sizeof("HH:MM:SS")];
const time_t curtime = time(NULL);
- struct tm* const timeinfo = localtime(&curtime);
+ struct tm *const timeinfo = localtime(&curtime);
strftime(ourtime, sizeof(ourtime), "%H:%M:%S", timeinfo);
@@ -351,8 +363,8 @@ void addDumpInfo(const char *inbuffer)
miscData.insert(miscData.end(), msg.begin(), msg.end());
}
-void dbgDumpInit(int argc, const char** argv, const char *packageVersion)
+void dbgDumpInit(int argc, const char **argv, const char *packageVersion)
{
- debug_register_callback(&debug_exceptionhandler_data, NULL, NULL, NULL );
+ debug_register_callback(&debug_exceptionhandler_data, NULL, NULL, NULL);
createHeader(argc, argv, packageVersion);
}
View
2  lib/exceptionhandler/dumpinfo.h
@@ -38,7 +38,7 @@ extern void dbgDumpHeader(DumpFileHandle file);
*/
extern void dbgDumpLog(DumpFileHandle file);
-extern void dbgDumpInit(int argc, const char** argv, const char* packageVersion);
+extern void dbgDumpInit(int argc, const char **argv, const char *packageVersion);
extern void addDumpInfo(const char *inbuffer);
View
350 lib/exceptionhandler/exceptionhandler.cpp
@@ -64,24 +64,24 @@ static LONG WINAPI windowsExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo)
sstrcat(miniDumpPath, ".mdmp");
*/
- if ( MessageBoxA( NULL, "Warzone crashed unexpectedly, would you like to save a diagnostic file?", applicationName, MB_YESNO ) == IDYES )
+ if (MessageBoxA(NULL, "Warzone crashed unexpectedly, would you like to save a diagnostic file?", applicationName, MB_YESNO) == IDYES)
{
- HANDLE miniDumpFile = CreateFileA( miniDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
+ HANDLE miniDumpFile = CreateFileA(miniDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (miniDumpFile != INVALID_HANDLE_VALUE)
{
- MINIDUMP_USER_STREAM uStream = { LastReservedStream+1, strlen(PACKAGE_VERSION), PACKAGE_VERSION };
+ MINIDUMP_USER_STREAM uStream = { LastReservedStream + 1, strlen(PACKAGE_VERSION), PACKAGE_VERSION };
MINIDUMP_USER_STREAM_INFORMATION uInfo = { 1, &uStream };
MINIDUMP_EXCEPTION_INFORMATION eInfo = { GetCurrentThreadId(), pExceptionInfo, false };
- if ( MiniDumpWriteDump(
- GetCurrentProcess(),
- GetCurrentProcessId(),
- miniDumpFile,
- MiniDumpNormal,
- pExceptionInfo ? &eInfo : NULL,
- &uInfo,
- NULL ) )
+ if (MiniDumpWriteDump(
+ GetCurrentProcess(),
+ GetCurrentProcessId(),
+ miniDumpFile,
+ MiniDumpNormal,
+ pExceptionInfo ? &eInfo : NULL,
+ &uInfo,
+ NULL))
{
snprintf(resultMessage, sizeof(resultMessage), "Saved dump file to '%s'", miniDumpPath);
}
@@ -97,13 +97,17 @@ static LONG WINAPI windowsExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo)
snprintf(resultMessage, sizeof(resultMessage), "Failed to create dump file '%s' (error %d)", miniDumpPath, (int)GetLastError());
}
- MessageBoxA( NULL, resultMessage, applicationName, MB_OK );
+ MessageBoxA(NULL, resultMessage, applicationName, MB_OK);
}
if (prevExceptionHandler)
+ {
return prevExceptionHandler(pExceptionInfo);
+ }
else
+ {
return EXCEPTION_CONTINUE_SEARCH;
+ }
}
#endif
@@ -163,11 +167,11 @@ static struct sigaction oldAction[NSIG];
static struct utsname sysInfo;
static bool gdbIsAvailable = false, programIsAvailable = false, sysInfoValid = false;
static char
- executionDate[MAX_DATE_STRING] = {'\0'},
- programPID[MAX_PID_STRING] = {'\0'},
- programPath[PATH_MAX] = {'\0'},
- gdbPath[PATH_MAX] = {'\0'},
- WritePath[PATH_MAX] = {'\0'};
+executionDate[MAX_DATE_STRING] = {'\0'},
+ programPID[MAX_PID_STRING] = {'\0'},
+ programPath[PATH_MAX] = {'\0'},
+ gdbPath[PATH_MAX] = {'\0'},
+ WritePath[PATH_MAX] = {'\0'};
/**
@@ -179,122 +183,122 @@ static char
* \return String with the description of the signal. "Unknown signal" when no description is available.
*/
#ifdef SA_SIGINFO
-static const char * wz_strsignal(int signum, int sigcode)
+static const char *wz_strsignal(int signum, int sigcode)
{
switch (signum)
{
- case SIGABRT:
- return "SIGABRT: Process abort signal";
- case SIGALRM:
- return "SIGALRM: Alarm clock";
- case SIGBUS:
- switch (sigcode)
- {
- case BUS_ADRALN:
- return "SIGBUS: Access to an undefined portion of a memory object: Invalid address alignment";
- case BUS_ADRERR:
- return "SIGBUS: Access to an undefined portion of a memory object: Nonexistent physical address";
- case BUS_OBJERR:
- return "SIGBUS: Access to an undefined portion of a memory object: Object-specific hardware error";
- default:
- return "SIGBUS: Access to an undefined portion of a memory object";
- }
- case SIGFPE:
- switch (sigcode)
- {
- case FPE_INTDIV:
- return "SIGFPE: Erroneous arithmetic operation: Integer divide by zero";
- case FPE_INTOVF:
- return "SIGFPE: Erroneous arithmetic operation: Integer overflow";
- case FPE_FLTDIV:
- return "SIGFPE: Erroneous arithmetic operation: Floating-point divide by zero";
- case FPE_FLTOVF:
- return "SIGFPE: Erroneous arithmetic operation: Floating-point overflow";
- case FPE_FLTUND:
- return "SIGFPE: Erroneous arithmetic operation: Floating-point underflow";
- case FPE_FLTRES:
- return "SIGFPE: Erroneous arithmetic operation: Floating-point inexact result";
- case FPE_FLTINV:
- return "SIGFPE: Erroneous arithmetic operation: Invalid floating-point operation";
- case FPE_FLTSUB:
- return "SIGFPE: Erroneous arithmetic operation: Subscript out of range";
- default:
- return "SIGFPE: Erroneous arithmetic operation";
- };
- case SIGHUP:
- return "SIGHUP: Hangup";
- case SIGILL:
- switch (sigcode)
- {
- case ILL_ILLOPC:
- return "SIGILL: Illegal instruction: Illegal opcode";
- case ILL_ILLOPN:
- return "SIGILL: Illegal instruction: Illegal operand";
- case ILL_ILLADR:
- return "SIGILL: Illegal instruction: Illegal addressing mode";
- case ILL_ILLTRP:
- return "SIGILL: Illegal instruction: Illegal trap";
- case ILL_PRVOPC:
- return "SIGILL: Illegal instruction: Privileged opcode";
- case ILL_PRVREG:
- return "SIGILL: Illegal instruction: Privileged register";
- case ILL_COPROC:
- return "SIGILL: Illegal instruction: Coprocessor error";
- case ILL_BADSTK:
- return "SIGILL: Illegal instruction: Internal stack error";
- default:
- return "SIGILL: Illegal instruction";
- }
- case SIGINT:
- return "SIGINT: Terminal interrupt signal";
- case SIGKILL:
- return "SIGKILL: Kill";
- case SIGPIPE:
- return "SIGPIPE: Write on a pipe with no one to read it";
- case SIGQUIT:
- return "SIGQUIT: Terminal quit signal";
- case SIGSEGV:
- switch (sigcode)
- {
- case SEGV_MAPERR:
- return "SIGSEGV: Invalid memory reference: Address not mapped to object";
- case SEGV_ACCERR:
- return "SIGSEGV: Invalid memory reference: Invalid permissions for mapped object";
- default:
- return "SIGSEGV: Invalid memory reference";
- }
- case SIGTERM:
- return "SIGTERM: Termination signal";
- case SIGUSR1:
- return "SIGUSR1: User-defined signal 1";
- case SIGUSR2:
- return "SIGUSR2: User-defined signal 2";
+ case SIGABRT:
+ return "SIGABRT: Process abort signal";
+ case SIGALRM:
+ return "SIGALRM: Alarm clock";
+ case SIGBUS:
+ switch (sigcode)
+ {
+ case BUS_ADRALN:
+ return "SIGBUS: Access to an undefined portion of a memory object: Invalid address alignment";
+ case BUS_ADRERR:
+ return "SIGBUS: Access to an undefined portion of a memory object: Nonexistent physical address";
+ case BUS_OBJERR:
+ return "SIGBUS: Access to an undefined portion of a memory object: Object-specific hardware error";
+ default:
+ return "SIGBUS: Access to an undefined portion of a memory object";
+ }
+ case SIGFPE:
+ switch (sigcode)
+ {
+ case FPE_INTDIV:
+ return "SIGFPE: Erroneous arithmetic operation: Integer divide by zero";
+ case FPE_INTOVF:
+ return "SIGFPE: Erroneous arithmetic operation: Integer overflow";
+ case FPE_FLTDIV:
+ return "SIGFPE: Erroneous arithmetic operation: Floating-point divide by zero";
+ case FPE_FLTOVF:
+ return "SIGFPE: Erroneous arithmetic operation: Floating-point overflow";
+ case FPE_FLTUND:
+ return "SIGFPE: Erroneous arithmetic operation: Floating-point underflow";
+ case FPE_FLTRES:
+ return "SIGFPE: Erroneous arithmetic operation: Floating-point inexact result";
+ case FPE_FLTINV:
+ return "SIGFPE: Erroneous arithmetic operation: Invalid floating-point operation";
+ case FPE_FLTSUB:
+ return "SIGFPE: Erroneous arithmetic operation: Subscript out of range";
+ default:
+ return "SIGFPE: Erroneous arithmetic operation";
+ };
+ case SIGHUP:
+ return "SIGHUP: Hangup";
+ case SIGILL:
+ switch (sigcode)
+ {
+ case ILL_ILLOPC:
+ return "SIGILL: Illegal instruction: Illegal opcode";
+ case ILL_ILLOPN:
+ return "SIGILL: Illegal instruction: Illegal operand";
+ case ILL_ILLADR:
+ return "SIGILL: Illegal instruction: Illegal addressing mode";
+ case ILL_ILLTRP:
+ return "SIGILL: Illegal instruction: Illegal trap";
+ case ILL_PRVOPC:
+ return "SIGILL: Illegal instruction: Privileged opcode";
+ case ILL_PRVREG:
+ return "SIGILL: Illegal instruction: Privileged register";
+ case ILL_COPROC:
+ return "SIGILL: Illegal instruction: Coprocessor error";
+ case ILL_BADSTK:
+ return "SIGILL: Illegal instruction: Internal stack error";
+ default:
+ return "SIGILL: Illegal instruction";
+ }
+ case SIGINT:
+ return "SIGINT: Terminal interrupt signal";
+ case SIGKILL:
+ return "SIGKILL: Kill";
+ case SIGPIPE:
+ return "SIGPIPE: Write on a pipe with no one to read it";
+ case SIGQUIT:
+ return "SIGQUIT: Terminal quit signal";
+ case SIGSEGV:
+ switch (sigcode)
+ {
+ case SEGV_MAPERR:
+ return "SIGSEGV: Invalid memory reference: Address not mapped to object";
+ case SEGV_ACCERR:
+ return "SIGSEGV: Invalid memory reference: Invalid permissions for mapped object";
+ default:
+ return "SIGSEGV: Invalid memory reference";
+ }
+ case SIGTERM:
+ return "SIGTERM: Termination signal";
+ case SIGUSR1:
+ return "SIGUSR1: User-defined signal 1";
+ case SIGUSR2:
+ return "SIGUSR2: User-defined signal 2";
#if _XOPEN_UNIX
- case SIGPROF:
- return "SIGPROF: Profiling timer expired";
- case SIGSYS:
- return "SIGSYS: Bad system call";
- case SIGTRAP:
- switch (sigcode)
- {
- case TRAP_BRKPT:
- return "SIGTRAP: Trace/breakpoint trap: Process breakpoint";
- case TRAP_TRACE:
- return "SIGTRAP: Trace/breakpoint trap: Process trace trap";
- default:
- return "SIGTRAP: Trace/breakpoint trap";
- }
+ case SIGPROF:
+ return "SIGPROF: Profiling timer expired";
+ case SIGSYS:
+ return "SIGSYS: Bad system call";
+ case SIGTRAP:
+ switch (sigcode)
+ {
+ case TRAP_BRKPT:
+ return "SIGTRAP: Trace/breakpoint trap: Process breakpoint";
+ case TRAP_TRACE:
+ return "SIGTRAP: Trace/breakpoint trap: Process trace trap";
+ default:
+ return "SIGTRAP: Trace/breakpoint trap";
+ }
#endif // _XOPEN_UNIX
#if _XOPEN_UNIX
- case SIGVTALRM:
- return "SIGVTALRM: Virtual timer expired";
- case SIGXCPU:
- return "SIGXCPU: CPU time limit exceeded";
- case SIGXFSZ:
- return "SIGXFSZ: File size limit exceeded";
+ case SIGVTALRM:
+ return "SIGVTALRM: Virtual timer expired";
+ case SIGXCPU:
+ return "SIGXCPU: CPU time limit exceeded";
+ case SIGXFSZ:
+ return "SIGXFSZ: File size limit exceeded";
#endif // _XOPEN_UNIX
- default:
- return "Unknown signal";
+ default:
+ return "Unknown signal";
}
}
#endif // SA_SIGINFO
@@ -319,40 +323,58 @@ static void setFatalSignalHandler(SigActionHandler signalHandler)
sigaction(SIGABRT, NULL, &oldAction[SIGABRT]);
if (oldAction[SIGABRT].sa_handler != SIG_IGN)
+ {
sigaction(SIGABRT, &new_handler, NULL);
+ }
sigaction(SIGBUS, NULL, &oldAction[SIGBUS]);
if (oldAction[SIGBUS].sa_handler != SIG_IGN)
+ {
sigaction(SIGBUS, &new_handler, NULL);
+ }
sigaction(SIGFPE, NULL, &oldAction[SIGFPE]);
if (oldAction[SIGFPE].sa_handler != SIG_IGN)
+ {
sigaction(SIGFPE, &new_handler, NULL);
+ }
sigaction(SIGILL, NULL, &oldAction[SIGILL]);
if (oldAction[SIGILL].sa_handler != SIG_IGN)
+ {
sigaction(SIGILL, &new_handler, NULL);
+ }
sigaction(SIGQUIT, NULL, &oldAction[SIGQUIT]);
if (oldAction[SIGQUIT].sa_handler != SIG_IGN)
+ {
sigaction(SIGQUIT, &new_handler, NULL);
+ }
sigaction(SIGSEGV, NULL, &oldAction[SIGSEGV]);
if (oldAction[SIGSEGV].sa_handler != SIG_IGN)
+ {
sigaction(SIGSEGV, &new_handler, NULL);
+ }
#if _XOPEN_UNIX
sigaction(SIGSYS, NULL, &oldAction[SIGSYS]);
if (oldAction[SIGSYS].sa_handler != SIG_IGN)
+ {
sigaction(SIGSYS, &new_handler, NULL);
+ }
sigaction(SIGXCPU, NULL, &oldAction[SIGXCPU]);
if (oldAction[SIGXCPU].sa_handler != SIG_IGN)
+ {
sigaction(SIGXCPU, &new_handler, NULL);
+ }
sigaction(SIGXFSZ, NULL, &oldAction[SIGXFSZ]);
if (oldAction[SIGXFSZ].sa_handler != SIG_IGN)
+ {
sigaction(SIGXFSZ, &new_handler, NULL);
+ }
// ignore SIGTRAP
new_handler.sa_handler = SIG_IGN;
@@ -381,7 +403,7 @@ static void setFatalSignalHandler(SigActionHandler signalHandler)
* function was unsuccessful and returned zero *gdbWritePipe's value will
* be unchanged.
*/
-static pid_t execGdb(int const dumpFile, int* gdbWritePipe)
+static pid_t execGdb(int const dumpFile, int *gdbWritePipe)
{
int gdbPipe[2];
pid_t pid;
@@ -391,20 +413,20 @@ static pid_t execGdb(int const dumpFile, int* gdbWritePipe)
* to our program's binary.
*/
if (!programIsAvailable
- || !gdbIsAvailable)
+ || !gdbIsAvailable)
{
write(dumpFile, "No extended backtrace dumped:\n",
- strlen("No extended backtrace dumped:\n"));
+ strlen("No extended backtrace dumped:\n"));
if (!programIsAvailable)
{
write(dumpFile, "- Program path not available\n",
- strlen("- Program path not available\n"));
+ strlen("- Program path not available\n"));
}
if (!gdbIsAvailable)
{
write(dumpFile, "- GDB not available\n",
- strlen("- GDB not available\n"));
+ strlen("- GDB not available\n"));
}
return 0;
@@ -414,7 +436,7 @@ static pid_t execGdb(int const dumpFile, int* gdbWritePipe)
if (pipe(gdbPipe) == -1)
{
write(dumpFile, "Pipe failed\n",
- strlen("Pipe failed\n"));
+ strlen("Pipe failed\n"));
printf("Pipe failed\n");
@@ -426,7 +448,7 @@ static pid_t execGdb(int const dumpFile, int* gdbWritePipe)
if (pid == -1)
{
write(dumpFile, "Fork failed\n",
- strlen("Fork failed\n"));
+ strlen("Fork failed\n"));
printf("Fork failed\n");
@@ -457,7 +479,7 @@ static pid_t execGdb(int const dumpFile, int* gdbWritePipe)
dup2(dumpFile, STDOUT_FILENO); // STDOUT to dumpFile
write(dumpFile, "GDB extended backtrace:\n",
- strlen("GDB extended backtrace:\n"));
+ strlen("GDB extended backtrace:\n"));
/* If execve() is successful it effectively prevents further
* execution of this function.
@@ -466,7 +488,7 @@ static pid_t execGdb(int const dumpFile, int* gdbWritePipe)
// If we get here it means that execve failed!
write(dumpFile, "execcv(\"gdb\") failed\n",
- strlen("execcv(\"gdb\") failed\n"));
+ strlen("execcv(\"gdb\") failed\n"));
// Terminate the child, indicating failure
_exit(1);
@@ -481,7 +503,7 @@ static pid_t execGdb(int const dumpFile, int* gdbWritePipe)
* backtrace.
*/
#ifdef SA_SIGINFO
-static bool gdbExtendedBacktrace(int const dumpFile, const ucontext_t* sigcontext)
+static bool gdbExtendedBacktrace(int const dumpFile, const ucontext_t *sigcontext)
#else
static bool gdbExtendedBacktrace(int const dumpFile)
#endif
@@ -496,13 +518,13 @@ static bool gdbExtendedBacktrace(int const dumpFile)
* previous frame pointer and the return address). Hence the
* additions to the frame-pointer register's content.
*/
- void const * const frame =
+ void const *const frame =
#if defined(SA_SIGINFO) && defined(REG_RBP)
- sigcontext ? (void*)(sigcontext->uc_mcontext.gregs[REG_RBP] + sizeof(greg_t) + sizeof(void (*)(void))) : NULL;
+ sigcontext ? (void *)(sigcontext->uc_mcontext.gregs[REG_RBP] + sizeof(greg_t) + sizeof(void (*)(void))) : NULL;
#elif defined(SA_SIGINFO) && defined(REG_EBP)
- sigcontext ? (void*)(sigcontext->uc_mcontext.gregs[REG_EBP] + sizeof(greg_t) + sizeof(void (*)(void))) : NULL;
+ sigcontext ? (void *)(sigcontext->uc_mcontext.gregs[REG_EBP] + sizeof(greg_t) + sizeof(void (*)(void))) : NULL;
#else
- NULL;
+ NULL;
#endif
/*
@@ -510,18 +532,18 @@ static bool gdbExtendedBacktrace(int const dumpFile)
*/
void (*instruction)(void) =
#if defined(SA_SIGINFO) && defined(REG_RIP)
- sigcontext ? (void (*)(void))sigcontext->uc_mcontext.gregs[REG_RIP] : NULL;
+ sigcontext ? (void (*)(void))sigcontext->uc_mcontext.gregs[REG_RIP] : NULL;
#elif defined(SA_SIGINFO) && defined(REG_EIP)
- sigcontext ? (void (*)(void))sigcontext->uc_mcontext.gregs[REG_EIP] : NULL;
+ sigcontext ? (void (*)(void))sigcontext->uc_mcontext.gregs[REG_EIP] : NULL;
#else
- NULL;
+ NULL;
#endif
// Spawn a GDB instance and retrieve a pipe to its stdin
int gdbPipe;
int status;
pid_t wpid;
- // Retrieve a full stack backtrace
+ // Retrieve a full stack backtrace
static const char gdbCommands[] = "thread apply all backtrace full\n"
// Move to the stack frame where we triggered the crash
@@ -542,14 +564,14 @@ static bool gdbExtendedBacktrace(int const dumpFile)
// Disassemble the faulting instruction (if we know it)
if (instruction)
{
- dprintf(gdbPipe, "x/i %p\n", (void*)instruction);
+ dprintf(gdbPipe, "x/i %p\n", (void *)instruction);
}
// We have an intelligent guess for the *correct* frame, disassemble *that* one.
if (frame)
{
dprintf(gdbPipe, "frame %p\n"
- "disassemble /m\n", frame);
+ "disassemble /m\n", frame);
}
write(gdbPipe, gdbCommands, strlen(gdbCommands));
@@ -569,7 +591,7 @@ static bool gdbExtendedBacktrace(int const dumpFile)
if (wpid == -1)
{
write(dumpFile, "GDB failed\n",
- strlen("GDB failed\n"));
+ strlen("GDB failed\n"));
printf("GDB failed\n");
return false;
@@ -588,10 +610,10 @@ static bool gdbExtendedBacktrace(int const dumpFile)
* return code.
*/
if (!WIFEXITED(status)
- || WEXITSTATUS(status) != 0)
+ || WEXITSTATUS(status) != 0)
{
write(dumpFile, "GDB failed\n",
- strlen("GDB failed\n"));
+ strlen("GDB failed\n"));
printf("GDB failed\n");
return false;
@@ -610,7 +632,7 @@ static bool gdbExtendedBacktrace(int const dumpFile)
* \param sigcontext Signal context
*/
#ifdef SA_SIGINFO
-static void posixExceptionHandler(int signum, siginfo_t * siginfo, void * sigcontext)
+static void posixExceptionHandler(int signum, siginfo_t *siginfo, void *sigcontext)
#else
static void posixExceptionHandler(int signum)
#endif
@@ -623,12 +645,14 @@ static void posixExceptionHandler(int signum)
int dumpFile;
const char *signal;
# if defined(__GLIBC__)
- void * btBuffer[MAX_BACKTRACE] = {NULL};
+ void *btBuffer[MAX_BACKTRACE] = {NULL};
uint32_t btSize = backtrace(btBuffer, MAX_BACKTRACE);
# endif
if (allreadyRunning)
+ {
raise(signum);
+ }
allreadyRunning = 1;
// we use our write directory (which is the only directory that wz should have access to)
// and stuff it into our logs directory (same as on windows)
@@ -663,7 +687,7 @@ static void posixExceptionHandler(int signum)
write(dumpFile, "\n", 1);
# else
write(dumpFile, "GLIBC not available, no raw backtrace dumped\n\n",
- strlen("GLIBC not available, no raw backtrace dumped\n\n"));
+ strlen("GLIBC not available, no raw backtrace dumped\n\n"));
# endif
@@ -672,7 +696,7 @@ static void posixExceptionHandler(int signum)
// Use 'gdb' to provide an "extended" backtrace
#ifdef SA_SIGINFO
- gdbExtendedBacktrace(dumpFile, (ucontext_t*)sigcontext);
+ gdbExtendedBacktrace(dumpFile, (ucontext_t *)sigcontext);
#else
gdbExtendedBacktrace(dumpFile);
#endif
@@ -690,7 +714,7 @@ static void posixExceptionHandler(int signum)
#endif // WZ_OS_*
#if defined(WZ_OS_UNIX) && !defined(WZ_OS_MAC)
-static bool fetchProgramPath(char * const programPath, size_t const bufSize, const char * const programCommand)
+static bool fetchProgramPath(char *const programPath, size_t const bufSize, const char *const programCommand)
{
FILE *whichProgramStream;
size_t bytesRead;
@@ -742,7 +766,7 @@ static bool fetchProgramPath(char * const programPath, size_t const bufSize, con
*
* \param programCommand Command used to launch this program. Only used for POSIX handler.
*/
-void setupExceptionHandler(int argc, const char ** argv, const char *packageVersion)
+void setupExceptionHandler(int argc, const char **argv, const char *packageVersion)
{
#if defined(WZ_OS_UNIX) && !defined(WZ_OS_MAC)
const char *programCommand;
@@ -792,14 +816,14 @@ bool OverrideRPTDirectory(char *newPath)
TCHAR szBuffer[4196];
FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dw,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &lpMsgBuf,
- 0, NULL );
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dw,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf,
+ 0, NULL);
wsprintf(szBuffer, _T("Exception handler failed setting new directory with error %d: %s\n"), dw, lpMsgBuf);
MessageBox((HWND)MB_ICONEXCLAMATION, szBuffer, _T("Error"), MB_OK);
View
2  lib/exceptionhandler/exceptionhandler.h
@@ -20,7 +20,7 @@
#ifndef __INCLUDED_LIB_EXCEPTIONHANDLER_EXCEPTIONHANDLER_H__
#define __INCLUDED_LIB_EXCEPTIONHANDLER_EXCEPTIONHANDLER_H__
-extern void setupExceptionHandler(int argc, const char ** argv, const char* packageVersion);
+extern void setupExceptionHandler(int argc, const char **argv, const char *packageVersion);
extern bool OverrideRPTDirectory(char *newPath);
View
884 lib/exceptionhandler/exchndl.cpp
@@ -46,10 +46,10 @@
static wchar_t szLogFileName[MAX_PATH] = L"";
static LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter = NULL;
static HANDLE hReportFile;
-static char* formattedVersionString = NULL;
+static char *formattedVersionString = NULL;
static
-int __cdecl rprintf(const TCHAR * format, ...)
+int __cdecl rprintf(const TCHAR *format, ...)
{
TCHAR szBuff[4096];
int retValue;
@@ -83,30 +83,38 @@ extern "C"
#include "include/demangle.h"
// cross compiler does not like these...
#if !defined(WZ_CC_MINGW)
- #include "include/coff/internal.h"
- #include "include/libcoff.h"
+#include "include/coff/internal.h"
+#include "include/libcoff.h"
#endif
}
// Read in the symbol table.
static bfd_boolean
-slurp_symtab (bfd *abfd, asymbol ***syms, long *symcount)
+slurp_symtab(bfd *abfd, asymbol ***syms, long *symcount)
{
long storage;
- if ((bfd_get_file_flags (abfd) & HAS_SYMS) == 0)
+ if ((bfd_get_file_flags(abfd) & HAS_SYMS) == 0)
+ {
return FALSE;
+ }
- storage = bfd_get_symtab_upper_bound (abfd);
+ storage = bfd_get_symtab_upper_bound(abfd);
if (storage < 0)
+ {
return FALSE;
+ }
*syms = (asymbol **) GlobalAlloc(GMEM_FIXED, storage);
if (*syms == NULL)
+ {
return FALSE;
+ }
- if((*symcount = bfd_canonicalize_symtab (abfd, *syms)) < 0)
+ if ((*symcount = bfd_canonicalize_symtab(abfd, *syms)) < 0)
+ {
return FALSE;
+ }
return TRUE;
}
@@ -123,28 +131,36 @@ struct find_handle
};
// Look for an address in a section. This is called via bfd_map_over_sections.
-static void find_address_in_section (bfd *abfd, asection *section, PTR data)
+static void find_address_in_section(bfd *abfd, asection *section, PTR data)
{
struct find_handle *info = (struct find_handle *) data;
bfd_vma vma;
bfd_size_type size;
if (info->found)
+ {
return;
+ }
- if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0)
+ if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0)
+ {
return;
+ }
- vma = bfd_get_section_vma (abfd, section);
- size = bfd_get_section_size (section);
+ vma = bfd_get_section_vma(abfd, section);
+ size = bfd_get_section_size(section);
- if (info->pc < (vma = bfd_get_section_vma (abfd, section)))
+ if (info->pc < (vma = bfd_get_section_vma(abfd, section)))
+ {
return;
+ }
- if (info->pc >= vma + (size = bfd_get_section_size (section)))
+ if (info->pc >= vma + (size = bfd_get_section_size(section)))
+ {
return;
+ }
- info->found = bfd_find_nearest_line (abfd, section, info->syms, info->pc - vma, &info->filename, &info->functionname, &info->line);
+ info->found = bfd_find_nearest_line(abfd, section, info->syms, info->pc - vma, &info->filename, &info->functionname, &info->line);
}
static
@@ -154,7 +170,7 @@ bool BfdDemangleSymName(LPCTSTR lpName, LPTSTR lpDemangledName, DWORD nSize)
assert(lpName != NULL);
- if((res = cplus_demangle(lpName, DMGL_ANSI /*| DMGL_PARAMS*/)) == NULL)
+ if ((res = cplus_demangle(lpName, DMGL_ANSI /*| DMGL_PARAMS*/)) == NULL)
{
lstrcpyn(lpDemangledName, lpName, nSize);
return FALSE;
@@ -162,7 +178,7 @@ bool BfdDemangleSymName(LPCTSTR lpName, LPTSTR lpDemangledName, DWORD nSize)
else
{
lstrcpyn(lpDemangledName, res, nSize);
- free (res);
+ free(res);
return TRUE;
}
}
@@ -173,24 +189,32 @@ bool BfdGetSymFromAddr(bfd *abfd, asymbol **syms, long symcount, DWORD dwAddress
HMODULE hModule;
struct find_handle info;
- if(!(hModule = (HMODULE) GetModuleBase(dwAddress)))
+ if (!(hModule = (HMODULE) GetModuleBase(dwAddress)))
+ {
return FALSE;
+ }
info.pc = dwAddress;
- if(!(bfd_get_file_flags (abfd) & HAS_SYMS) || !symcount)
+ if (!(bfd_get_file_flags(abfd) & HAS_SYMS) || !symcount)
+ {
return FALSE;
+ }
info.syms = syms;
info.found = FALSE;
- bfd_map_over_sections (abfd, find_address_in_section, (PTR) &info);
+ bfd_map_over_sections(abfd, find_address_in_section, (PTR) &info);
if (info.found == FALSE || info.line == 0)
+ {
return FALSE;
+ }
assert(lpSymName);
- if(info.functionname == NULL && *info.functionname == '\0')
+ if (info.functionname == NULL && *info.functionname == '\0')
+ {
return FALSE;
+ }
lstrcpyn(lpSymName, info.functionname, nSize);
@@ -203,20 +227,26 @@ bool BfdGetLineFromAddr(bfd *abfd, asymbol **syms, long symcount, DWORD dwAddres
HMODULE hModule;
struct find_handle info;
- if(!(hModule = (HMODULE) GetModuleBase(dwAddress)))
+ if (!(hModule = (HMODULE) GetModuleBase(dwAddress)))
+ {
return FALSE;
+ }
info.pc = dwAddress;
- if(!(bfd_get_file_flags (abfd) & HAS_SYMS) || !symcount)
+ if (!(bfd_get_file_flags(abfd) & HAS_SYMS) || !symcount)
+ {
return FALSE;
+ }
info.syms = syms;
info.found = FALSE;
- bfd_map_over_sections (abfd, find_address_in_section, (PTR) &info);
+ bfd_map_over_sections(abfd, find_address_in_section, (PTR) &info);
if (info.found == FALSE || info.line == 0)
+ {
return FALSE;
+ }
assert(lpFileName && lpLineNumber);
@@ -240,13 +270,17 @@ static PFNSYMINITIALIZE pfnSymInitialize = NULL;
static
bool WINAPI j_SymInitialize(HANDLE hProcess, PSTR UserSearchPath, bool fInvadeProcess)
{
- if(
- (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
- (pfnSymInitialize || (pfnSymInitialize = (PFNSYMINITIALIZE) GetProcAddress(hModule_Imagehlp, "SymInitialize")))
+ if (
+ (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+ (pfnSymInitialize || (pfnSymInitialize = (PFNSYMINITIALIZE) GetProcAddress(hModule_Imagehlp, "SymInitialize")))
)
+ {
return pfnSymInitialize(hProcess, UserSearchPath, fInvadeProcess);
+ }
else
+ {
return FALSE;
+ }
}
typedef bool (WINAPI *PFNSYMCLEANUP)(HANDLE);
@@ -255,13 +289,17 @@ static PFNSYMCLEANUP pfnSymCleanup = NULL;
static
bool WINAPI j_SymCleanup(HANDLE hProcess)
{
- if(
- (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
- (pfnSymCleanup || (pfnSymCleanup = (PFNSYMCLEANUP) GetProcAddress(hModule_Imagehlp, "SymCleanup")))
+ if (
+ (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+ (pfnSymCleanup || (pfnSymCleanup = (PFNSYMCLEANUP) GetProcAddress(hModule_Imagehlp, "SymCleanup")))
)
+ {
return pfnSymCleanup(hProcess);
+ }
else
+ {
return FALSE;
+ }
}
typedef DWORD (WINAPI *PFNSYMSETOPTIONS)(DWORD);
@@ -270,13 +308,17 @@ static PFNSYMSETOPTIONS pfnSymSetOptions = NULL;
static
DWORD WINAPI j_SymSetOptions(DWORD SymOptions)
{
- if(
- (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
- (pfnSymSetOptions || (pfnSymSetOptions = (PFNSYMSETOPTIONS) GetProcAddress(hModule_Imagehlp, "SymSetOptions")))
+ if (
+ (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+ (pfnSymSetOptions || (pfnSymSetOptions = (PFNSYMSETOPTIONS) GetProcAddress(hModule_Imagehlp, "SymSetOptions")))
)
+ {
return pfnSymSetOptions(SymOptions);
+ }
else
+ {
return FALSE;
+ }
}
typedef bool (WINAPI *PFNSYMUNDNAME)(PIMAGEHLP_SYMBOL, PSTR, DWORD);
@@ -285,13 +327,17 @@ static PFNSYMUNDNAME pfnSymUnDName = NULL;
static
bool WINAPI j_SymUnDName(PIMAGEHLP_SYMBOL Symbol, PSTR UnDecName, DWORD UnDecNameLength)
{
- if(
- (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
- (pfnSymUnDName || (pfnSymUnDName = (PFNSYMUNDNAME) GetProcAddress(hModule_Imagehlp, "SymUnDName")))
+ if (
+ (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+ (pfnSymUnDName || (pfnSymUnDName = (PFNSYMUNDNAME) GetProcAddress(hModule_Imagehlp, "SymUnDName")))
)
+ {
return pfnSymUnDName(Symbol, UnDecName, UnDecNameLength);
+ }
else
+ {
return FALSE;
+ }
}
typedef PFUNCTION_TABLE_ACCESS_ROUTINE PFNSYMFUNCTIONTABLEACCESS;
@@ -300,13 +346,17 @@ static PFNSYMFUNCTIONTABLEACCESS pfnSymFunctionTableAccess = NULL;
static
PVOID WINAPI j_SymFunctionTableAccess(HANDLE hProcess, DWORD AddrBase)
{
- if(
- (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
- (pfnSymFunctionTableAccess || (pfnSymFunctionTableAccess = (PFNSYMFUNCTIONTABLEACCESS) GetProcAddress(hModule_Imagehlp, "SymFunctionTableAccess")))
+ if (
+ (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+ (pfnSymFunctionTableAccess || (pfnSymFunctionTableAccess = (PFNSYMFUNCTIONTABLEACCESS) GetProcAddress(hModule_Imagehlp, "SymFunctionTableAccess")))
)
+ {
return pfnSymFunctionTableAccess(hProcess, AddrBase);
+ }
else
+ {
return NULL;
+ }
}
typedef PGET_MODULE_BASE_ROUTINE PFNSYMGETMODULEBASE;
@@ -315,13 +365,17 @@ static PFNSYMGETMODULEBASE pfnSymGetModuleBase = NULL;
static
DWORD WINAPI j_SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
{
- if(
- (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
- (pfnSymGetModuleBase || (pfnSymGetModuleBase = (PFNSYMGETMODULEBASE) GetProcAddress(hModule_Imagehlp, "SymGetModuleBase")))
+ if (
+ (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+ (pfnSymGetModuleBase || (pfnSymGetModuleBase = (PFNSYMGETMODULEBASE) GetProcAddress(hModule_Imagehlp, "SymGetModuleBase")))
)
+ {
return pfnSymGetModuleBase(hProcess, dwAddr);
+ }
else
+ {
return 0;
+ }
}
typedef bool (WINAPI *PFNSTACKWALK)(DWORD, HANDLE, HANDLE, LPSTACKFRAME, LPVOID, PREAD_PROCESS_MEMORY_ROUTINE, PFUNCTION_TABLE_ACCESS_ROUTINE, PGET_MODULE_BASE_ROUTINE, PTRANSLATE_ADDRESS_ROUTINE);
@@ -329,34 +383,36 @@ static PFNSTACKWALK pfnStackWalk = NULL;
static
bool WINAPI j_StackWalk(
- DWORD MachineType,
- HANDLE hProcess,
- HANDLE hThread,
- LPSTACKFRAME StackFrame,
- PVOID ContextRecord,
- PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,
- PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
- PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
- PTRANSLATE_ADDRESS_ROUTINE TranslateAddress
+ DWORD MachineType,
+ HANDLE hProcess,
+ HANDLE hThread,
+ LPSTACKFRAME StackFrame,
+ PVOID ContextRecord,
+ PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,
+ PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
+ PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
+ PTRANSLATE_ADDRESS_ROUTINE TranslateAddress
)
{
- if(
- (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
- (pfnStackWalk || (pfnStackWalk = (PFNSTACKWALK) GetProcAddress(hModule_Imagehlp, "StackWalk")))
+ if (
+ (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+ (pfnStackWalk || (pfnStackWalk = (PFNSTACKWALK) GetProcAddress(hModule_Imagehlp, "StackWalk")))
)
return pfnStackWalk(
- MachineType,
- hProcess,
- hThread,
- StackFrame,
- ContextRecord,
- ReadMemoryRoutine,
- FunctionTableAccessRoutine,
- GetModuleBaseRoutine,
- TranslateAddress
- );
+ MachineType,
+ hProcess,
+ hThread,
+ StackFrame,
+ ContextRecord,
+ ReadMemoryRoutine,
+ FunctionTableAccessRoutine,
+ GetModuleBaseRoutine,
+ TranslateAddress
+ );
else
+ {
return FALSE;
+ }
}
typedef bool (WINAPI *PFNSYMGETSYMFROMADDR)(HANDLE, DWORD, LPDWORD, PIMAGEHLP_SYMBOL);
@@ -365,13 +421,17 @@ static PFNSYMGETSYMFROMADDR pfnSymGetSymFromAddr = NULL;
static
bool WINAPI j_SymGetSymFromAddr(HANDLE hProcess, DWORD Address, PDWORD Displacement, PIMAGEHLP_SYMBOL Symbol)
{
- if(
- (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
- (pfnSymGetSymFromAddr || (pfnSymGetSymFromAddr = (PFNSYMGETSYMFROMADDR) GetProcAddress(hModule_Imagehlp, "SymGetSymFromAddr")))
+ if (
+ (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+ (pfnSymGetSymFromAddr || (pfnSymGetSymFromAddr = (PFNSYMGETSYMFROMADDR) GetProcAddress(hModule_Imagehlp, "SymGetSymFromAddr")))
)
+ {
return pfnSymGetSymFromAddr(hProcess, Address, Displacement, Symbol);
+ }
else
+ {
return FALSE;
+ }
}
typedef bool (WINAPI *PFNSYMGETLINEFROMADDR)(HANDLE, DWORD, LPDWORD, PIMAGEHLP_LINE);
@@ -380,13 +440,17 @@ static PFNSYMGETLINEFROMADDR pfnSymGetLineFromAddr = NULL;
static
bool WINAPI j_SymGetLineFromAddr(HANDLE hProcess, DWORD dwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE Line)
{
- if(
- (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
- (pfnSymGetLineFromAddr || (pfnSymGetLineFromAddr = (PFNSYMGETLINEFROMADDR) GetProcAddress(hModule_Imagehlp, "SymGetLineFromAddr")))
+ if (
+ (hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+ (pfnSymGetLineFromAddr || (pfnSymGetLineFromAddr = (PFNSYMGETLINEFROMADDR) GetProcAddress(hModule_Imagehlp, "SymGetLineFromAddr")))
)
+ {
return pfnSymGetLineFromAddr(hProcess, dwAddr, pdwDisplacement, Line);
+ }
else
+ {
return FALSE;
+ }
}
static
@@ -395,15 +459,17 @@ bool ImagehlpDemangleSymName(LPCTSTR lpName, LPTSTR lpDemangledName, DWORD nSize
BYTE symbolBuffer[sizeof(IMAGEHLP_SYMBOL) + 512];
PIMAGEHLP_SYMBOL pSymbol = (PIMAGEHLP_SYMBOL) symbolBuffer;
- memset( symbolBuffer, 0, sizeof(symbolBuffer) );
+ memset(symbolBuffer, 0, sizeof(symbolBuffer));
pSymbol->SizeOfStruct = sizeof(symbolBuffer);
pSymbol->MaxNameLength = 512;
lstrcpyn((LPTSTR)pSymbol->Name, lpName, pSymbol->MaxNameLength);
- if(!j_SymUnDName(pSymbol, (PSTR)lpDemangledName, nSize))
+ if (!j_SymUnDName(pSymbol, (PSTR)lpDemangledName, nSize))
+ {
return FALSE;
+ }
return TRUE;
}
@@ -428,8 +494,10 @@ bool ImagehlpGetSymFromAddr(HANDLE hProcess, DWORD dwAddress, LPTSTR lpSymName,
assert(bSymInitialized);
- if(!j_SymGetSymFromAddr(hProcess, dwAddress, &dwDisplacement, pSymbol))
+ if (!j_SymGetSymFromAddr(hProcess, dwAddress, &dwDisplacement, pSymbol))
+ {
return FALSE;
+ }
lstrcpyn(lpSymName, (LPCTSTR)pSymbol->Name, nSize);
@@ -456,19 +524,27 @@ bool ImagehlpGetLineFromAddr(HANDLE hProcess, DWORD dwAddress, LPTSTR lpFileNam
// find the line and return the proper displacement.
DWORD dwTempDisp = 0 ;
while (dwTempDisp < 100 && !j_SymGetLineFromAddr(hProcess, dwAddress - dwTempDisp, &dwDisplacement, &Line))
+ {
++dwTempDisp;
+ }
- if(dwTempDisp >= 100)
+ if (dwTempDisp >= 100)
+ {
return FALSE;
+ }
// It was found and the source line information is correct so
// change the displacement if it was looked up multiple times.
- if (dwTempDisp < 100 && dwTempDisp != 0 )
+ if (dwTempDisp < 100 && dwTempDisp != 0)
+ {
dwDisplacement = dwTempDisp;
+ }
}
#else
- if(!j_SymGetLineFromAddr(hProcess, dwAddress, &dwDisplacement, &Line))
+ if (!j_SymGetLineFromAddr(hProcess, dwAddress, &dwDisplacement, &Line))
+ {
return FALSE;
+ }
#endif
assert(lpFileName && lpLineNumber);
@@ -489,8 +565,10 @@ bool PEGetSymFromAddr(HANDLE hProcess, DWORD dwAddress, LPTSTR lpSymName, DWORD
DWORD dwNearestAddress = 0, dwNearestName;
int i;
- if(!(hModule = (HMODULE) GetModuleBase(dwAddress)))
+ if (!(hModule = (HMODULE) GetModuleBase(dwAddress)))
+ {
return FALSE;
+ }
{
PIMAGE_DOS_HEADER pDosHdr;
@@ -500,16 +578,20 @@ bool PEGetSymFromAddr(HANDLE hProcess, DWORD dwAddress, LPTSTR lpSymName, DWORD
pDosHdr = (PIMAGE_DOS_HEADER)hModule;
// From the DOS header, find the NT (PE) header
- if(!ReadProcessMemory(hProcess, &pDosHdr->e_lfanew, &e_lfanew, sizeof(e_lfanew), NULL))
+ if (!ReadProcessMemory(hProcess, &pDosHdr->e_lfanew, &e_lfanew, sizeof(e_lfanew), NULL))
+ {
return FALSE;
+ }
pNtHdr = (PIMAGE_NT_HEADERS)((DWORD)hModule + (DWORD)e_lfanew);
- if(!ReadProcessMemory(hProcess, pNtHdr, &NtHdr, sizeof(IMAGE_NT_HEADERS), NULL))
+ if (!ReadProcessMemory(hProcess, pNtHdr, &NtHdr, sizeof(IMAGE_NT_HEADERS), NULL))
+ {
return FALSE;
+ }
}
- pSection = (PIMAGE_SECTION_HEADER) ((DWORD)pNtHdr + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + NtHdr.FileHeader.SizeOfOptionalHeader);
+ pSection = (PIMAGE_SECTION_HEADER)((DWORD)pNtHdr + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + NtHdr.FileHeader.SizeOfOptionalHeader);
// Look for export section
for (i = 0; i < NtHdr.FileHeader.NumberOfSections; i++, pSection++)
@@ -518,52 +600,68 @@ bool PEGetSymFromAddr(HANDLE hProcess, DWORD dwAddress, LPTSTR lpSymName, DWORD
PIMAGE_EXPORT_DIRECTORY pExportDir = NULL;
BYTE ExportSectionName[IMAGE_SIZEOF_SHORT_NAME] = {'.', 'e', 'd', 'a', 't', 'a', '\0', '\0'};
- if(!ReadProcessMemory(hProcess, pSection, &Section, sizeof(IMAGE_SECTION_HEADER), NULL))
+ if (!ReadProcessMemory(hProcess, pSection, &Section, sizeof(IMAGE_SECTION_HEADER), NULL))
+ {
return FALSE;
+ }
- if(memcmp(Section.Name, ExportSectionName, IMAGE_SIZEOF_SHORT_NAME) == 0)
+ if (memcmp(Section.Name, ExportSectionName, IMAGE_SIZEOF_SHORT_NAME) == 0)
+ {
pExportDir = (PIMAGE_EXPORT_DIRECTORY) Section.VirtualAddress;
+ }
else if ((NtHdr.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress >= Section.VirtualAddress) && (NtHdr.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress < (Section.VirtualAddress + Section.SizeOfRawData)))
+ {
pExportDir = (PIMAGE_EXPORT_DIRECTORY) NtHdr.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
+ }
- if(pExportDir)
+ if (pExportDir)
{
IMAGE_EXPORT_DIRECTORY ExportDir;
- if(!ReadProcessMemory(hProcess, (PVOID)((DWORD)hModule + (DWORD)pExportDir), &ExportDir, sizeof(IMAGE_EXPORT_DIRECTORY), NULL))
+ if (!ReadProcessMemory(hProcess, (PVOID)((DWORD)hModule + (DWORD)pExportDir), &ExportDir, sizeof(IMAGE_EXPORT_DIRECTORY), NULL))
+ {
return FALSE;
+ }
{
- PDWORD *AddressOfFunctions = (PDWORD *)alloca(ExportDir.NumberOfFunctions*sizeof(PDWORD));
+ PDWORD *AddressOfFunctions = (PDWORD *)alloca(ExportDir.NumberOfFunctions * sizeof(PDWORD));
int j;
- if(!ReadProcessMemory(hProcess, (PVOID)((DWORD)hModule + (DWORD)ExportDir.AddressOfFunctions), AddressOfFunctions, ExportDir.NumberOfFunctions*sizeof(PDWORD), NULL))
- return FALSE;
+ if (!ReadProcessMemory(hProcess, (PVOID)((DWORD)hModule + (DWORD)ExportDir.AddressOfFunctions), AddressOfFunctions, ExportDir.NumberOfFunctions * sizeof(PDWORD), NULL))
+ {
+ return FALSE;
+ }
- for(j = 0; j < ExportDir.NumberOfNames; ++j)
+ for (j = 0; j < ExportDir.NumberOfNames; ++j)
{
DWORD pFunction = (DWORD)hModule + (DWORD)AddressOfFunctions[j];
//ReadProcessMemory(hProcess, (DWORD) hModule + (DWORD) (&ExportDir.AddressOfFunctions[j]), &pFunction, sizeof(pFunction), NULL);
- if(pFunction <= dwAddress && pFunction > dwNearestAddress)
+ if (pFunction <= dwAddress && pFunction > dwNearestAddress)
{
dwNearestAddress = pFunction;
- if(!ReadProcessMemory(hProcess, (PVOID)((DWORD)hModule + (DWORD)(&ExportDir.AddressOfNames)[j]), &dwNearestName, sizeof(dwNearestName), NULL))
+ if (!ReadProcessMemory(hProcess, (PVOID)((DWORD)hModule + (DWORD)(&ExportDir.AddressOfNames)[j]), &dwNearestName, sizeof(dwNearestName), NULL))
+ {
return FALSE;
+ }
dwNearestName = (DWORD) hModule + dwNearestName;
}
}
}
}
- }
+ }
- if(!dwNearestAddress)
+ if (!dwNearestAddress)
+ {
return FALSE;
+ }
- if(!ReadProcessMemory(hProcess, (PVOID)dwNearestName, lpSymName, nSize, NULL))
+ if (!ReadProcessMemory(hProcess, (PVOID)dwNearestName, lpSymName, nSize, NULL))
+ {
return FALSE;
+ }
lpSymName[nSize - 1] = 0;
return TRUE;
@@ -575,30 +673,38 @@ bool PEGetSymFromAddr(HANDLE hProcess, DWORD dwAddress, LPTSTR lpSymName, DWORD
struct ItDoesntMatterIfItsADWORDOrAVoidPointer_JustCompileTheDamnThing
{
ItDoesntMatterIfItsADWORDOrAVoidPointer_JustCompileTheDamnThing(void *whatever) : whatever(whatever) {}
- operator void *() const { return whatever; } // Oooh, look compiler1, I'm a void *, just what you wanted!
- operator DWORD() const { return (DWORD)whatever; } // Oooh, look compiler2, I'm a DWORD, just what you wanted!
+ operator void *() const
+ {
+ return whatever; // Oooh, look compiler1, I'm a void *, just what you wanted!
+ }
+ operator DWORD() const
+ {
+ return (DWORD)whatever; // Oooh, look compiler2, I'm a DWORD, just what you wanted!
+ }
void *whatever;
};
static
bool WINAPI IntelStackWalk(
- DWORD MachineType,
- HANDLE hProcess,
- WZ_DECL_UNUSED HANDLE hThread,
- LPSTACKFRAME StackFrame,
- PCONTEXT ContextRecord,
- PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,
- WZ_DECL_UNUSED PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
- WZ_DECL_UNUSED PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
- WZ_DECL_UNUSED PTRANSLATE_ADDRESS_ROUTINE TranslateAddress
+ DWORD MachineType,
+ HANDLE hProcess,
+ WZ_DECL_UNUSED HANDLE hThread,
+ LPSTACKFRAME StackFrame,
+ PCONTEXT ContextRecord,
+ PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,
+ WZ_DECL_UNUSED PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
+ WZ_DECL_UNUSED PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
+ WZ_DECL_UNUSED PTRANSLATE_ADDRESS_ROUTINE TranslateAddress
)
{
assert(MachineType == IMAGE_FILE_MACHINE_I386);
- if(ReadMemoryRoutine == NULL)
+ if (ReadMemoryRoutine == NULL)
+ {
ReadMemoryRoutine = (PREAD_PROCESS_MEMORY_ROUTINE)ReadProcessMemory;
+ }
- if(!StackFrame->Reserved[0])
+ if (!StackFrame->Reserved[0])
{
StackFrame->Reserved[0] = 1;
@@ -615,20 +721,26 @@ bool WINAPI IntelStackWalk(
// c:\warzone\lib\exceptionhandler\exchndl.cpp 599
// ../../../../lib/exceptionhandler/exchndl.cpp: In function ‘bool IntelStackWalk(DWORD, void*, void*, _tagSTACKFRAME*, CONTEXT*, bool (*)(void*, const void*, void*, DWORD, DWORD*), void* (*)(void*, DWORD), DWORD (*)(void*, DWORD), DWORD (*)(void*, void*, _tagADDRESS*))’:
// ../../../../lib/exceptionhandler/exchndl.cpp:599: error: invalid conversion from ‘long unsigned int’ to ‘const void*’
- if(!ReadMemoryRoutine((HANDLE)hProcess, ItDoesntMatterIfItsADWORDOrAVoidPointer_JustCompileTheDamnThing((void *) (StackFrame->AddrFrame.Offset + sizeof(DWORD))), (void *)&StackFrame->AddrReturn.Offset, sizeof(DWORD), NULL))
+ if (!ReadMemoryRoutine((HANDLE)hProcess, ItDoesntMatterIfItsADWORDOrAVoidPointer_JustCompileTheDamnThing((void *)(StackFrame->AddrFrame.Offset + sizeof(DWORD))), (void *)&StackFrame->AddrReturn.Offset, sizeof(DWORD), NULL))
+ {
return FALSE;
+ }
}
else
{
StackFrame->AddrPC.Offset = StackFrame->AddrReturn.Offset;
//AddrStack = AddrFrame + 2*sizeof(DWORD);
- if(!ReadMemoryRoutine((HANDLE)hProcess, ItDoesntMatterIfItsADWORDOrAVoidPointer_JustCompileTheDamnThing((void *) StackFrame->AddrFrame.Offset), (void *)&StackFrame->AddrFrame.Offset, sizeof(DWORD), NULL))
+ if (!ReadMemoryRoutine((HANDLE)hProcess, ItDoesntMatterIfItsADWORDOrAVoidPointer_JustCompileTheDamnThing((void *) StackFrame->AddrFrame.Offset), (void *)&StackFrame->AddrFrame.Offset, sizeof(DWORD), NULL))
+ {
return FALSE;
- if(!ReadMemoryRoutine((HANDLE)hProcess, ItDoesntMatterIfItsADWORDOrAVoidPointer_JustCompileTheDamnThing((void *) (StackFrame->AddrFrame.Offset + sizeof(DWORD))), (void *)&StackFrame->AddrReturn.Offset, sizeof(DWORD), NULL))
+ }
+ if (!ReadMemoryRoutine((HANDLE)hProcess, ItDoesntMatterIfItsADWORDOrAVoidPointer_JustCompileTheDamnThing((void *)(StackFrame->AddrFrame.Offset + sizeof(DWORD))), (void *)&StackFrame->AddrReturn.Offset, sizeof(DWORD), NULL))
+ {
return FALSE;
+ }
}
- ReadMemoryRoutine((HANDLE)hProcess, ItDoesntMatterIfItsADWORDOrAVoidPointer_JustCompileTheDamnThing((void *) (StackFrame->AddrFrame.Offset + 2*sizeof(DWORD))), (void *)StackFrame->Params, sizeof(StackFrame->Params), NULL);
+ ReadMemoryRoutine((HANDLE)hProcess, ItDoesntMatterIfItsADWORDOrAVoidPointer_JustCompileTheDamnThing((void *)(StackFrame->AddrFrame.Offset + 2 * sizeof(DWORD))), (void *)StackFrame->Params, sizeof(StackFrame->Params), NULL);
return TRUE;
}
@@ -650,10 +762,12 @@ bool StackBackTrace(HANDLE hProcess, HANDLE hThread, PCONTEXT pContext)
assert(!bSymInitialized);
j_SymSetOptions(/* SYMOPT_UNDNAME | */ SYMOPT_LOAD_LINES);
- if(j_SymInitialize(hProcess, NULL, TRUE))
+ if (j_SymInitialize(hProcess, NULL, TRUE))
+ {
bSymInitialized = TRUE;
+ }
- memset( &StackFrame, 0, sizeof(StackFrame) );
+ memset(&StackFrame, 0, sizeof(StackFrame));
// Initialize the STACKFRAME structure for the first call. This is only
// necessary for Intel CPUs, and isn't mentioned in the documentation.
@@ -664,12 +778,14 @@ bool StackBackTrace(HANDLE hProcess, HANDLE hThread, PCONTEXT pContext)
StackFrame.AddrFrame.Offset = pContext->Ebp;
StackFrame.AddrFrame.Mode = AddrModeFlat;
- rprintf( _T("Call stack:\r\n") );
+ rprintf(_T("Call stack:\r\n"));
- if(0)
- rprintf( _T("AddrPC AddrReturn AddrFrame AddrStack\r\n") );
+ if (0)
+ {
+ rprintf(_T("AddrPC AddrReturn AddrFrame AddrStack\r\n"));
+ }
- while ( 1 )
+ while (1)
{
bool bSuccess = FALSE;
#ifdef HAVE_BFD
@@ -679,91 +795,101 @@ bool StackBackTrace(HANDLE hProcess, HANDLE hThread, PCONTEXT pContext)
TCHAR szFileName[MAX_PATH] = _T("");
DWORD LineNumber = 0;
- if(bSymInitialized)
+ if (bSymInitialized)
{
- if(!j_StackWalk(
- IMAGE_FILE_MACHINE_I386,
- hProcess,
- hThread,
- &StackFrame,
- pContext,
- NULL,
- j_SymFunctionTableAccess,
- j_SymGetModuleBase,
- NULL
- )
- )
+ if (!j_StackWalk(
+ IMAGE_FILE_MACHINE_I386,
+ hProcess,
+ hThread,
+ &StackFrame,
+ pContext,
+ NULL,
+ j_SymFunctionTableAccess,
+ j_SymGetModuleBase,
+ NULL
+ )
+ )
+ {
break;
+ }
}
else
{
- if(!IntelStackWalk(
- IMAGE_FILE_MACHINE_I386,
- hProcess,
- hThread,
- &StackFrame,
- pContext,
- NULL,
- NULL,
- NULL,
- NULL
- )
- )
+ if (!IntelStackWalk(
+ IMAGE_FILE_MACHINE_I386,
+ hProcess,
+ hThread,
+ &StackFrame,
+ pContext,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ )
+ )
+ {
break;
+ }
}
// Basic sanity check to make sure the frame is OK. Bail if not.
- if ( 0 == StackFrame.AddrFrame.Offset )
+ if (0 == StackFrame.AddrFrame.Offset)
+ {
break;
+ }
- if(0)
+ if (0)
{
rprintf(
- _T("%08lX %08lX %08lX %08lX\r\n"),
- StackFrame.AddrPC.Offset,
- StackFrame.AddrReturn.Offset,
- StackFrame.AddrFrame.Offset,
- StackFrame.AddrStack.Offset
+ _T("%08lX %08lX %08lX %08lX\r\n"),
+ StackFrame.AddrPC.Offset,
+ StackFrame.AddrReturn.Offset,
+ StackFrame.AddrFrame.Offset,
+ StackFrame.AddrStack.Offset
);
rprintf(
- _T("%08lX %08lX %08lX %08lX\r\n"),
- StackFrame.Params[0],
- StackFrame.Params[1],
- StackFrame.Params[2],
- StackFrame.Params[3]
+ _T("%08lX %08lX %08lX %08lX\r\n"),
+ StackFrame.Params[0],
+ StackFrame.Params[1],
+ StackFrame.Params[2],
+ StackFrame.Params[3]
);
}
- rprintf( _T("%08lX"), StackFrame.AddrPC.Offset);
+ rprintf(_T("%08lX"), StackFrame.AddrPC.Offset);
- if((hModule = (HMODULE) GetModuleBase(StackFrame.AddrPC.Offset)) && GetModuleFileName(hModule, szModule, sizeof(szModule)))
+ if ((hModule = (HMODULE) GetModuleBase(StackFrame.AddrPC.Offset)) && GetModuleFileName(hModule, szModule, sizeof(szModule)))
{
#ifndef HAVE_BFD
- rprintf( _T(" %s:ModulBase %08lX"), szModule, hModule);
+ rprintf(_T(" %s:ModulBase %08lX"), szModule, hModule);
#else /* HAVE_BFD */
- rprintf( _T(" %s:%08lX"), szModule, StackFrame.AddrPC.Offset);
+ rprintf(_T(" %s:%08lX"), szModule, StackFrame.AddrPC.Offset);
- if(hModule != hPrevModule)
+ if (hModule != hPrevModule)
{
- if(syms)
+ if (syms)
{
GlobalFree(syms);
syms = NULL;
symcount = 0;
}
- if(abfd)
+ if (abfd)
+ {
bfd_close(abfd);
+ }
- if((abfd = bfd_openr (szModule, NULL)))
- if(bfd_check_format(abfd, bfd_object))
- if(bfd_get_file_flags(abfd) & HAS_SYMS)
+ if ((abfd = bfd_openr(szModule, NULL)))
+ if (bfd_check_format(abfd, bfd_object))
+ if (bfd_get_file_flags(abfd) & HAS_SYMS)
/* Read in the symbol table. */
+ {
slurp_symtab(abfd, &syms, &symcount);
+ }
}
- if(!bSuccess && abfd && syms && symcount)
- if((bSuccess = BfdGetSymFromAddr(abfd, syms, symcount, StackFrame.AddrPC.Offset, szSymName, 512)))
+ if (!bSuccess && abfd && syms && symcount)
+ if ((bSuccess = BfdGetSymFromAddr(abfd, syms, symcount, StackFrame.AddrPC.Offset, szSymName, 512)))
{
/*
framepointer = StackFrame.AddrFrame.Offset;
@@ -772,48 +898,58 @@ bool StackBackTrace(HANDLE hProcess, HANDLE hThread, PCONTEXT pContext)
BfdDemangleSymName(szSymName, szSymName, 512);
- rprintf( _T(" %s"), szSymName);
+ rprintf(_T(" %s"), szSymName);
- if(BfdGetLineFromAddr(abfd, syms, symcount, StackFrame.AddrPC.Offset, szFileName, MAX_PATH, &LineNumber))
- rprintf( _T(" %s:%ld"), szFileName, LineNumber);
+ if (BfdGetLineFromAddr(abfd, syms, symcount, StackFrame.AddrPC.Offset, szFileName, MAX_PATH, &LineNumber))
+ {
+ rprintf(_T(" %s:%ld"), szFileName, LineNumber);
+ }
}
#endif /* HAVE_BFD */
- if(!bSuccess && bSymInitialized)
- if((bSuccess = ImagehlpGetSymFromAddr(hProcess, StackFrame.AddrPC.Offset, szSymName, 512)))
+ if (!bSuccess && bSymInitialized)
+ if ((bSuccess = ImagehlpGetSymFromAddr(hProcess, StackFrame.AddrPC.Offset, szSymName, 512)))
{
- rprintf( _T(" %s"), szSymName);
+ rprintf(_T(" %s"), szSymName);
ImagehlpDemangleSymName(szSymName, szSymName, 512);
- if(ImagehlpGetLineFromAddr(hProcess, StackFrame.AddrPC.Offset, szFileName, MAX_PATH, &LineNumber))
- rprintf( _T(" %s:%ld"), szFileName, LineNumber);
+ if (ImagehlpGetLineFromAddr(hProcess, StackFrame.AddrPC.Offset, szFileName, MAX_PATH, &LineNumber))
+ {
+ rprintf(_T(" %s:%ld"), szFileName, LineNumber);
+ }
}
- if(!bSuccess)
- if((bSuccess = PEGetSymFromAddr(hProcess, StackFrame.AddrPC.Offset, szSymName, 512)))
- rprintf( _T(" %s"), szSymName);
+ if (!bSuccess)
+ if ((bSuccess = PEGetSymFromAddr(hProcess, StackFrame.AddrPC.Offset, szSymName, 512)))
+ {
+ rprintf(_T(" %s"), szSymName);
+ }
}
rprintf(_T("\r\n"));
}
#ifdef HAVE_BFD
- if(syms)
+ if (syms)
{
GlobalFree(syms);
syms = NULL;
symcount = 0;
}
- if(abfd)
+ if (abfd)
+ {
bfd_close(abfd);
+ }
#endif /* HAVE_BFD */
- if(bSymInitialized)
+ if (bSymInitialized)
{
- if(!j_SymCleanup(hProcess))
+ if (!j_SymCleanup(hProcess))
+ {
assert(0);
+ }
bSymInitialized = FALSE;
}
@@ -833,7 +969,8 @@ void GenerateExceptionReport(PEXCEPTION_POINTERS pExceptionInfo)
rprintf(_T("-------------------\r\n\r\n"));
{
- const TCHAR *lpDayOfWeek[] = {
+ const TCHAR *lpDayOfWeek[] =
+ {
_T("Sunday"),
_T("Monday"),
_T("Tuesday"),
@@ -842,7 +979,8 @@ void GenerateExceptionReport(PEXCEPTION_POINTERS pExceptionInfo)
_T("Friday"),
_T("Saturday")
};
- const TCHAR *lpMonth[] = {
+ const TCHAR *lpMonth[] =
+ {
NULL,
_T("January"),
_T("February"),
@@ -861,14 +999,14 @@ void GenerateExceptionReport(PEXCEPTION_POINTERS pExceptionInfo)
GetLocalTime(&SystemTime);
rprintf(_T("Error occured on %s, %s %i, %i at %02i:%02i:%02i.\r\n\r\n"),
- lpDayOfWeek[SystemTime.wDayOfWeek],
- lpMonth[SystemTime.wMonth],
- SystemTime.wDay,
- SystemTime.wYear,
- SystemTime.wHour,
- SystemTime.wMinute,
- SystemTime.wSecond
- );
+ lpDayOfWeek[SystemTime.wDayOfWeek],
+ lpMonth[SystemTime.wMonth],
+ SystemTime.wDay,
+ SystemTime.wYear,
+ SystemTime.wHour,
+ SystemTime.wMinute,
+ SystemTime.wSecond
+ );
}
// Dump a generic info header
@@ -876,144 +1014,148 @@ void GenerateExceptionReport(PEXCEPTION_POINTERS pExceptionInfo)
// First print information about the type of fault
rprintf(_T("\r\n%s caused "), GetModuleFileName(NULL, szModule, MAX_PATH) ? szModule : _T("Application"));
- switch(pExceptionRecord->ExceptionCode)
+ switch (pExceptionRecord->ExceptionCode)
{
- case EXCEPTION_ACCESS_VIOLATION:
- rprintf(_T("an Access Violation"));
- break;
+ case EXCEPTION_ACCESS_VIOLATION:
+ rprintf(_T("an Access Violation"));
+ break;
- case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
- rprintf(_T("an Array Bound Exceeded"));
- break;
+ case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
+ rprintf(_T("an Array Bound Exceeded"));
+ break;
- case EXCEPTION_BREAKPOINT:
- rprintf(_T("a Breakpoint"));
- break;
+ case EXCEPTION_BREAKPOINT:
+ rprintf(_T("a Breakpoint"));
+ break;
- case EXCEPTION_DATATYPE_MISALIGNMENT:
- rprintf(_T("a Datatype Misalignment"));
- break;
+ case EXCEPTION_DATATYPE_MISALIGNMENT:
+ rprintf(_T("a Datatype Misalignment"));
+ break;
- case EXCEPTION_FLT_DENORMAL_OPERAND:
- rprintf(_T("a Float Denormal Operand"));
- break;
+ case EXCEPTION_FLT_DENORMAL_OPERAND:
+ rprintf(_T("a Float Denormal Operand"));
+ break;
- case EXCEPTION_FLT_DIVIDE_BY_ZERO:
- rprintf(_T("a Float Divide By Zero"));
- break;
+ case EXCEPTION_FLT_DIVIDE_BY_ZERO:
+ rprintf(_T("a Float Divide By Zero"));
+ break;
- case EXCEPTION_FLT_INEXACT_RESULT:
- rprintf(_T("a Float Inexact Result"));
- break;
+ case EXCEPTION_FLT_INEXACT_RESULT:
+ rprintf(_T("a Float Inexact Result"));
+ break;
- case EXCEPTION_FLT_INVALID_OPERATION:
- rprintf(_T("a Float Invalid Operation"));
- break;
+ case EXCEPTION_FLT_INVALID_OPERATION:
+ rprintf(_T("a Float Invalid Operation"));
+ break;
- case EXCEPTION_FLT_OVERFLOW:
- rprintf(_T("a Float Overflow"));
- break;
+ case EXCEPTION_FLT_OVERFLOW:
+ rprintf(_T("a Float Overflow"));
+ break;
- case EXCEPTION_FLT_STACK_CHECK:
- rprintf(_T("a Float Stack Check"));
- break;
+ case EXCEPTION_FLT_STACK_CHECK:
+ rprintf(_T("a Float Stack Check"));
+ break;
- case EXCEPTION_FLT_UNDERFLOW:
- rprintf(_T("a Float Underflow"));
- break;
+ case EXCEPTION_FLT_UNDERFLOW:
+ rprintf(_T("a Float Underflow"));
+ break;
- case EXCEPTION_GUARD_PAGE:
- rprintf(_T("a Guard Page"));
- break;
+ case EXCEPTION_GUARD_PAGE:
+ rprintf(_T("a Guard Page"));
+ break;
- case EXCEPTION_ILLEGAL_INSTRUCTION:
- rprintf(_T("an Illegal Instruction"));
- break;
+ case EXCEPTION_ILLEGAL_INSTRUCTION:
+ rprintf(_T("an Illegal Instruction"));
+ break;
- case EXCEPTION_IN_PAGE_ERROR:
- rprintf(_T("an In Page Error