Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/IntentionalCrash.h
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#include <string>
8
#include <sstream>
9
#include <stdlib.h>
10
#include <stdio.h>
11
12
#ifdef XP_WIN
13
#include <process.h>
14
#define getpid _getpid
15
#else
16
#include <unistd.h>
17
#endif
18
19
#ifndef mozilla_IntentionalCrash_h
20
#define mozilla_IntentionalCrash_h
21
22
namespace mozilla {
23
24
inline void
25
NoteIntentionalCrash(const char* aProcessType)
26
0
{
27
0
// In opt builds we don't actually have the leak checking enabled, and the
28
0
// sandbox doesn't allow writing to this path, so we just disable this
29
0
// function's behaviour.
30
#ifdef MOZ_DEBUG
31
  char* f = getenv("XPCOM_MEM_BLOAT_LOG");
32
  if (!f) {
33
    return;
34
  }
35
36
  fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f);
37
38
  std::string bloatLog(f);
39
40
  bool hasExt = false;
41
  if (bloatLog.size() >= 4 &&
42
      bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4) == 0) {
43
    hasExt = true;
44
    bloatLog.erase(bloatLog.size() - 4, 4);
45
  }
46
47
  std::ostringstream bloatName;
48
  bloatName << bloatLog << "_" << aProcessType << "_pid" << getpid();
49
  if (hasExt) {
50
    bloatName << ".log";
51
  }
52
53
  fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str());
54
55
  FILE* processfd = fopen(bloatName.str().c_str(), "a");
56
  if (processfd) {
57
    fprintf(processfd, "==> process %d will purposefully crash\n", getpid());
58
    fclose(processfd);
59
  }
60
#endif
61
}
62
63
} // namespace mozilla
64
65
#endif // mozilla_IntentionalCrash_h