From 62b7599359946181abaacebf0ad8a12f3c67aaa5 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Fri, 4 Apr 2008 10:39:22 +0000 Subject: [PATCH] Mac: Fix bugs in new backtrace code svn path=/trunk/boinc/; revision=15015 --- checkin_notes | 9 ++++- lib/mac/mac_backtrace.C | 82 +++++++++++++++++++++++++---------------- 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/checkin_notes b/checkin_notes index 4de72644af..6085ccf988 100644 --- a/checkin_notes +++ b/checkin_notes @@ -2571,7 +2571,7 @@ Charlie Mar 20 2008 lib/ mac/ mac_backtrace.C -Å buildWxMac.sh + buildWxMac.sh David Mar 20 2008 - updated GeoIP stuff @@ -3077,3 +3077,10 @@ Charlie April 3 2008 mac_build/ HowToBuildBOINC_XCode.rtf + +Charlie April 4 2008 + Mac: Fix bugs in new backtrace code. + + lib/ + mac/ + mac_backtrace.C diff --git a/lib/mac/mac_backtrace.C b/lib/mac/mac_backtrace.C index 1e2277cd4b..3377d907b4 100644 --- a/lib/mac/mac_backtrace.C +++ b/lib/mac/mac_backtrace.C @@ -82,14 +82,15 @@ enum { #define SKIPFRAME 4 /* Number frames overhead for signal handler and backtrace */ static char * PersistentFGets(char *buf, size_t buflen, FILE *f); -static void GetNameOfThisApp(char *nameBuf, int buflen); +static void GetPathToThisProcess(char* outbuf, size_t maxLen); static void PrintOSVersion(char *minorVersion); void PrintBacktrace(void) { int err; QCrashReportRef crRef = NULL; - char nameBuf[1024]; + char pathToThisProcess[1024], pipeBuf[1024], *nameBuf; + const NXArchInfo *localArch; char OSMinorVersion; time_t t; @@ -120,10 +121,18 @@ void PrintBacktrace(void) { } #endif - GetNameOfThisApp(nameBuf, sizeof(nameBuf)); - if (nameBuf[0]) + GetPathToThisProcess(pathToThisProcess, sizeof(pathToThisProcess)); + + nameBuf = strrchr(pathToThisProcess, '/'); + if (nameBuf) { + ++nameBuf; // Advance over the separator + } else { + nameBuf = pathToThisProcess; + } + if (nameBuf[0]) { fprintf(stderr, "\nCrashed executable name: %s\n", nameBuf); - + } + #ifdef BOINC_VERSION_STRING fprintf(stderr, "built using BOINC library version %s\n", BOINC_VERSION_STRING); #endif @@ -145,7 +154,7 @@ void PrintBacktrace(void) { err = QCRCreateFromSelf(&crRef); // Use new backtrace functions if available (only in OS 10.5 and later) - systemlib = dlopen ("libSystem.dylib", RTLD_NOW ); + systemlib = dlopen ("/usr/lib/libSystem.dylib", RTLD_NOW ); if (systemlib) { myBacktraceProc = (backtraceProc)dlsym(systemlib, "backtrace"); } @@ -164,17 +173,17 @@ void PrintBacktrace(void) { } setenv("NSUnbufferedIO", "YES", 1); - snprintf(nameBuf, sizeof(nameBuf), "/usr/bin/atos -p %d", getpid()); - f = popen(nameBuf, "r+"); + snprintf(pipeBuf, sizeof(pipeBuf), "/usr/bin/atos -o %s", pathToThisProcess); + f = popen(pipeBuf, "r+"); if (f) { setbuf(f, 0); for (i=0; i=0; --i) { - if (nameBuf[i] <= ' ') - nameBuf[i] = 0; // Strip off trailing spaces, newlines, etc. - else - break; + *outbuf = '\0'; + + sprintf(buf, "ps -xwo command -p %d", (int)aPID); + f = popen(buf, "r"); + if (f == NULL) + return; + + PersistentFGets (outbuf, maxLen, f); // Discard header line + PersistentFGets (outbuf, maxLen, f); + pclose(f); + + // Remove trailing newline if present + p = strchr(outbuf, '\n'); + if (p) + *p = '\0'; + + // Strip off any arguments + p = strstr(outbuf, " -"); + q = p; + if (p) { + while (*p == ' ') { + q = p; + if (--p < outbuf) + break; + } } + + if (q) + *q = '\0'; }