Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include <string>
8 : #include <sstream>
9 : #include <stdlib.h>
10 : #include <stdio.h>
11 :
12 : #ifdef XP_WIN
13 : #include <process.h>
14 : #define getpid _getpid
15 : #else
16 : #include <unistd.h>
17 : #endif
18 :
19 : #ifndef mozilla_IntentionalCrash_h
20 : #define mozilla_IntentionalCrash_h
21 :
22 : namespace mozilla {
23 :
24 : inline void
25 0 : NoteIntentionalCrash(const char* aProcessType)
26 : {
27 0 : char* f = getenv("XPCOM_MEM_BLOAT_LOG");
28 0 : if (!f) {
29 0 : return;
30 : }
31 :
32 0 : fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f);
33 :
34 0 : std::string bloatLog(f);
35 :
36 0 : bool hasExt = false;
37 0 : if (bloatLog.size() >= 4 &&
38 0 : bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4) == 0) {
39 0 : hasExt = true;
40 0 : bloatLog.erase(bloatLog.size() - 4, 4);
41 : }
42 :
43 0 : std::ostringstream bloatName;
44 0 : bloatName << bloatLog << "_" << aProcessType << "_pid" << getpid();
45 0 : if (hasExt) {
46 0 : bloatName << ".log";
47 : }
48 :
49 0 : fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str());
50 :
51 0 : FILE* processfd = fopen(bloatName.str().c_str(), "a");
52 0 : fprintf(processfd, "==> process %d will purposefully crash\n", getpid());
53 0 : fclose(processfd);
54 : }
55 :
56 : } // namespace mozilla
57 :
58 : #endif // mozilla_IntentionalCrash_h
|