xpcom/glue/IntentionalCrash.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include <string>
     6 #include <sstream>
     7 #include <stdlib.h>
     8 #include <stdio.h>
    10 #ifdef XP_WIN
    11 #include <process.h>
    12 #define getpid _getpid
    13 #else
    14 #include <unistd.h>
    15 #endif
    17 #ifndef mozilla_IntentionalCrash_h
    18 #define mozilla_IntentionalCrash_h
    20 namespace mozilla {
    22 inline void
    23 NoteIntentionalCrash(const char* processType)
    24 {
    25   char* f = getenv("XPCOM_MEM_BLOAT_LOG");
    27   if (!f) 
    28     return;
    30   fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f);
    32   std::string bloatLog(f);
    34   bool hasExt = false;
    35   if (bloatLog.size() >= 4 &&
    36       0 == bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4)) {
    37     hasExt = true;
    38     bloatLog.erase(bloatLog.size() - 4, 4);
    39   }
    41   std::ostringstream bloatName;
    42   bloatName << bloatLog << "_" << processType << "_pid" << getpid();
    43   if (hasExt)
    44     bloatName << ".log";
    46   fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str());
    48   FILE* processfd = fopen(bloatName.str().c_str(), "a");
    49   fprintf(processfd, "==> process %d will purposefully crash\n", getpid());
    50   fclose(processfd);
    51 }
    53 } // namespace mozilla
    55 #endif // mozilla_IntentionalCrash_h

mercurial