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: 17 17 100.0 %
Date: 2017-10-21 Branches: 12 14 85.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
8
  if (size <= 0) {
29
8
    return;
30
  }
31
58
  for (int i = 1; i < size; i += 1) {
32
50
    void* frame = frames[i];
33
50
    fprintf(fp, "%2d: ", i);
34
    Dl_info info;
35
50
    const bool have_info = dladdr(frame, &info);
36

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

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