GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/backtrace_posix.cc Lines: 16 16 100.0 %
Date: 2017-12-18 Branches: 11 12 91.7 %

Line Branch Exec Source
1
#include "node_internals.h"
2
3
#if defined(__linux__)
4
#include <features.h>
5
#endif
6
7
#if defined(__linux__) && !defined(__GLIBC__) || \
8
    defined(__UCLIBC__) || \
9
    defined(_AIX)
10
#define HAVE_EXECINFO_H 0
11
#else
12
#define HAVE_EXECINFO_H 1
13
#endif
14
15
#if HAVE_EXECINFO_H
16
#include <cxxabi.h>
17
#include <dlfcn.h>
18
#include <execinfo.h>
19
#include <stdio.h>
20
#endif
21
22
namespace node {
23
24
8
void DumpBacktrace(FILE* fp) {
25
#if HAVE_EXECINFO_H
26
  void* frames[256];
27
8
  const int size = backtrace(frames, arraysize(frames));
28
58
  for (int i = 1; i < size; i += 1) {
29
50
    void* frame = frames[i];
30
50
    fprintf(fp, "%2d: ", i);
31
    Dl_info info;
32
50
    const bool have_info = dladdr(frame, &info);
33

50
    if (!have_info || info.dli_sname == nullptr) {
34
14
      fprintf(fp, "%p", frame);
35
36
    } else if (char* demangled = abi::__cxa_demangle(info.dli_sname, 0, 0, 0)) {
36
32
      fprintf(fp, "%s", demangled);
37
32
      free(demangled);
38
    } else {
39
4
      fprintf(fp, "%s", info.dli_sname);
40
    }
41

50
    if (have_info && info.dli_fname != nullptr) {
42
44
      fprintf(fp, " [%s]", info.dli_fname);
43
    }
44
50
    fprintf(fp, "\n");
45
  }
46
#endif  // HAVE_EXECINFO_H
47
8
}
48
49
}  // namespace node