GCC Code Coverage Report
Directory: ../src/ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/src/backtrace_posix.cc Lines: 0 16 0.0 %
Date: 2016-07-12 Branches: 0 14 0.0 %

Line Exec Source
1
#include "node.h"
2
3
#if defined(__linux__)
4
#include <features.h>
5
#endif
6
7
#if defined(__linux__) && !defined(__GLIBC__) || defined(_AIX)
8
#define HAVE_EXECINFO_H 0
9
#else
10
#define HAVE_EXECINFO_H 1
11
#endif
12
13
#if HAVE_EXECINFO_H
14
#include <cxxabi.h>
15
#include <dlfcn.h>
16
#include <execinfo.h>
17
#include <stdio.h>
18
#endif
19
20
namespace node {
21
22
void DumpBacktrace(FILE* fp) {
23
#if HAVE_EXECINFO_H
24
  void* frames[256];
25
  const int size = backtrace(frames, arraysize(frames));
26
  if (size <= 0) {
27
    return;
28
  }
29
  for (int i = 1; i < size; i += 1) {
30
    void* frame = frames[i];
31
    fprintf(fp, "%2d: ", i);
32
    Dl_info info;
33
    const bool have_info = dladdr(frame, &info);
34
    if (!have_info || info.dli_sname == nullptr) {
35
      fprintf(fp, "%p", frame);
36
    } else if (char* demangled = abi::__cxa_demangle(info.dli_sname, 0, 0, 0)) {
37
      fprintf(fp, "%s", demangled);
38
      free(demangled);
39
    } else {
40
      fprintf(fp, "%s", info.dli_sname);
41
    }
42
    if (have_info && info.dli_fname != nullptr) {
43
      fprintf(fp, " [%s]", info.dli_fname);
44
    }
45
    fprintf(fp, "\n");
46
  }
47
#endif  // HAVE_EXECINFO_H
48
}
49
50
}  // namespace node