1 : #include <string>
2 : #include <sstream>
3 : #include <stdlib.h>
4 : #include <stdio.h>
5 :
6 : #ifdef XP_WIN
7 : #include <process.h>
8 : #define getpid _getpid
9 : #else
10 : #include <unistd.h>
11 : #endif
12 :
13 : #ifndef mozilla_IntentionalCrash_h
14 : #define mozilla_IntentionalCrash_h
15 :
16 : namespace mozilla {
17 :
18 : inline void
19 0 : NoteIntentionalCrash(const char* processType)
20 : {
21 0 : char* f = getenv("XPCOM_MEM_BLOAT_LOG");
22 0 : fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f);
23 0 : if (!f)
24 0 : return;
25 :
26 0 : std::string bloatLog(f);
27 :
28 0 : bool hasExt = false;
29 0 : if (bloatLog.size() >= 4 &&
30 0 : 0 == bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4)) {
31 0 : hasExt = true;
32 0 : bloatLog.erase(bloatLog.size() - 4, 4);
33 : }
34 :
35 0 : std::ostringstream bloatName;
36 0 : bloatName << bloatLog << "_" << processType << "_pid" << getpid();
37 0 : if (hasExt)
38 0 : bloatName << ".log";
39 :
40 0 : fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str());
41 :
42 0 : FILE* processfd = fopen(bloatName.str().c_str(), "a");
43 0 : fprintf(processfd, "==> process %d will purposefully crash\n", getpid());
44 0 : fclose(processfd);
45 : }
46 :
47 : } // namespace mozilla
48 :
49 : #endif // mozilla_IntentionalCrash_h
|