diff -r 000000000000 -r 6474c204b198 xpcom/glue/IntentionalCrash.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xpcom/glue/IntentionalCrash.h Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,55 @@ +/* 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/. */ + +#include +#include +#include +#include + +#ifdef XP_WIN +#include +#define getpid _getpid +#else +#include +#endif + +#ifndef mozilla_IntentionalCrash_h +#define mozilla_IntentionalCrash_h + +namespace mozilla { + +inline void +NoteIntentionalCrash(const char* processType) +{ + char* f = getenv("XPCOM_MEM_BLOAT_LOG"); + + if (!f) + return; + + fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f); + + std::string bloatLog(f); + + bool hasExt = false; + if (bloatLog.size() >= 4 && + 0 == bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4)) { + hasExt = true; + bloatLog.erase(bloatLog.size() - 4, 4); + } + + std::ostringstream bloatName; + bloatName << bloatLog << "_" << processType << "_pid" << getpid(); + if (hasExt) + bloatName << ".log"; + + fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str()); + + FILE* processfd = fopen(bloatName.str().c_str(), "a"); + fprintf(processfd, "==> process %d will purposefully crash\n", getpid()); + fclose(processfd); +} + +} // namespace mozilla + +#endif // mozilla_IntentionalCrash_h