Bug 1686838 [wpt PR 27194] - [webcodecs] Deprecate VideoFrame.destroy()., a=testonly
[gecko.git] / xpcom / base / IntentionalCrash.h
blob6c1f3496c8ab7b8f43f7387318702418069bcc44
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) {
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 std::ostringstream bloatName;
37 std::string processType(aProcessType);
38 if (!processType.compare("default")) {
39 bloatName << f;
40 } else {
41 std::string bloatLog(f);
43 bool hasExt = false;
44 if (bloatLog.size() >= 4 &&
45 bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4) == 0) {
46 hasExt = true;
47 bloatLog.erase(bloatLog.size() - 4, 4);
50 bloatName << bloatLog << "_" << processType << "_pid" << getpid();
51 if (hasExt) {
52 bloatName << ".log";
56 fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str());
58 FILE* processfd = fopen(bloatName.str().c_str(), "a");
59 if (processfd) {
60 fprintf(processfd, "==> process %d will purposefully crash\n", getpid());
61 fclose(processfd);
63 #endif
66 } // namespace mozilla
68 #endif // mozilla_IntentionalCrash_h