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/. */
7 #ifndef mozilla_IntentionalCrash_h
8 #define mozilla_IntentionalCrash_h
17 # define getpid _getpid
24 inline void NoteIntentionalCrash(const char* aProcessType
, uint32_t aPid
= 0) {
25 // In opt builds we don't actually have the leak checking enabled, and the
26 // sandbox doesn't allow writing to this path, so we just disable this
27 // function's behaviour.
29 char* f
= getenv("XPCOM_MEM_BLOAT_LOG");
34 fprintf(stderr
, "XPCOM_MEM_BLOAT_LOG: %s\n", f
);
36 uint32_t processPid
= aPid
== 0 ? getpid() : aPid
;
38 std::ostringstream bloatName
;
39 std::string
processType(aProcessType
);
40 if (!processType
.compare("default")) {
43 std::string
bloatLog(f
);
46 if (bloatLog
.size() >= 4 &&
47 bloatLog
.compare(bloatLog
.size() - 4, 4, ".log", 4) == 0) {
49 bloatLog
.erase(bloatLog
.size() - 4, 4);
52 bloatName
<< bloatLog
<< "_" << processType
<< "_pid" << processPid
;
58 fprintf(stderr
, "Writing to log: %s\n", bloatName
.str().c_str());
60 FILE* processfd
= fopen(bloatName
.str().c_str(), "a");
62 fprintf(processfd
, "\n==> process %d will purposefully crash\n",
69 } // namespace mozilla
71 #endif // mozilla_IntentionalCrash_h