Bug 1932613 - temporarily disable browser_ml_end_to_end.js for permanent failures...
[gecko.git] / xpcom / base / IntentionalCrash.h
blob3ee751f7c714d7a4cf9ac3d33e55261624871a98
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
10 #include <string>
11 #include <sstream>
12 #include <stdlib.h>
13 #include <stdio.h>
15 #ifdef XP_WIN
16 # include <process.h>
17 # define getpid _getpid
18 #else
19 # include <unistd.h>
20 #endif
22 namespace mozilla {
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.
28 #ifdef MOZ_DEBUG
29 char* f = getenv("XPCOM_MEM_BLOAT_LOG");
30 if (!f) {
31 return;
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")) {
41 bloatName << f;
42 } else {
43 std::string bloatLog(f);
45 bool hasExt = false;
46 if (bloatLog.size() >= 4 &&
47 bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4) == 0) {
48 hasExt = true;
49 bloatLog.erase(bloatLog.size() - 4, 4);
52 bloatName << bloatLog << "_" << processType << "_pid" << processPid;
53 if (hasExt) {
54 bloatName << ".log";
58 fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str());
60 FILE* processfd = fopen(bloatName.str().c_str(), "a");
61 if (processfd) {
62 fprintf(processfd, "\n==> process %d will purposefully crash\n",
63 processPid);
64 fclose(processfd);
66 #endif
69 } // namespace mozilla
71 #endif // mozilla_IntentionalCrash_h