2014-06-30 19:39:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2019-11-12 19:13:14 +03:00
|
|
|
#ifndef mozilla_IntentionalCrash_h
|
|
|
|
#define mozilla_IntentionalCrash_h
|
|
|
|
|
2010-11-17 23:55:25 +03:00
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
# include <process.h>
|
|
|
|
# define getpid _getpid
|
2010-11-18 02:14:11 +03:00
|
|
|
#else
|
|
|
|
# include <unistd.h>
|
2010-11-17 23:55:25 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
inline void NoteIntentionalCrash(const char* aProcessType) {
|
2017-12-07 21:36:49 +03:00
|
|
|
// In opt builds we don't actually have the leak checking enabled, and the
|
|
|
|
// sandbox doesn't allow writing to this path, so we just disable this
|
|
|
|
// function's behaviour.
|
2019-11-12 19:13:14 +03:00
|
|
|
#ifdef MOZ_DEBUG
|
2010-11-17 23:55:25 +03:00
|
|
|
char* f = getenv("XPCOM_MEM_BLOAT_LOG");
|
2014-06-27 05:35:39 +04:00
|
|
|
if (!f) {
|
2010-11-17 23:55:25 +03:00
|
|
|
return;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2010-11-17 23:55:25 +03:00
|
|
|
|
2013-04-08 22:35:31 +04:00
|
|
|
fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f);
|
|
|
|
|
2019-11-26 00:42:04 +03:00
|
|
|
std::ostringstream bloatName;
|
|
|
|
std::string processType(aProcessType);
|
|
|
|
if (!processType.compare("default")) {
|
|
|
|
bloatName << f;
|
|
|
|
} else {
|
|
|
|
std::string bloatLog(f);
|
2014-06-27 05:35:39 +04:00
|
|
|
|
2019-11-26 00:42:04 +03:00
|
|
|
bool hasExt = false;
|
|
|
|
if (bloatLog.size() >= 4 &&
|
|
|
|
bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4) == 0) {
|
|
|
|
hasExt = true;
|
|
|
|
bloatLog.erase(bloatLog.size() - 4, 4);
|
|
|
|
}
|
2010-11-17 23:55:25 +03:00
|
|
|
|
2019-11-26 00:42:04 +03:00
|
|
|
bloatName << bloatLog << "_" << processType << "_pid" << getpid();
|
|
|
|
if (hasExt) {
|
|
|
|
bloatName << ".log";
|
|
|
|
}
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2010-11-17 23:55:25 +03:00
|
|
|
|
|
|
|
fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str());
|
|
|
|
|
|
|
|
FILE* processfd = fopen(bloatName.str().c_str(), "a");
|
2017-11-30 22:41:00 +03:00
|
|
|
if (processfd) {
|
|
|
|
fprintf(processfd, "==> process %d will purposefully crash\n", getpid());
|
|
|
|
fclose(processfd);
|
|
|
|
}
|
2019-11-12 19:13:14 +03:00
|
|
|
#endif
|
2010-11-17 23:55:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_IntentionalCrash_h
|