GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/debug_utils.h Lines: 19 22 86.4 %
Date: 2019-01-07 12:15:22 Branches: 134 196 68.4 %

Line Branch Exec Source
1
#ifndef SRC_DEBUG_UTILS_H_
2
#define SRC_DEBUG_UTILS_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "async_wrap.h"
7
#include "env.h"
8
#include <string>
9
#include <sstream>
10
11
// Use FORCE_INLINE on functions that have a debug-category-enabled check first
12
// and then ideally only a single function call following it, to maintain
13
// performance for the common case (no debugging used).
14
#ifdef __GNUC__
15
#define FORCE_INLINE __attribute__((always_inline))
16
#define COLD_NOINLINE __attribute__((cold, noinline))
17
#else
18
#define FORCE_INLINE
19
#define COLD_NOINLINE
20
#endif
21
22
namespace node {
23
24
template <typename... Args>
25
inline void FORCE_INLINE Debug(Environment* env,
26
                               DebugCategory cat,
27
                               const char* format,
28
                               Args&&... args) {
29








10676
  if (!UNLIKELY(env->debug_enabled(cat)))
30
    return;
31
87
  fprintf(stderr, format, std::forward<Args>(args)...);
32
}
33
34
inline void FORCE_INLINE Debug(Environment* env,
35
                               DebugCategory cat,
36
                               const char* message) {
37
44
  if (!UNLIKELY(env->debug_enabled(cat)))
38
    return;
39
44
  fprintf(stderr, "%s", message);
40
}
41
42
template <typename... Args>
43
130
inline void Debug(Environment* env,
44
                  DebugCategory cat,
45
                  const std::string& format,
46
                  Args&&... args) {
47
130
  Debug(env, cat, format.c_str(), std::forward<Args>(args)...);
48
130
}
49
50
// Used internally by the 'real' Debug(AsyncWrap*, ...) functions below, so that
51
// the FORCE_INLINE flag on them doesn't apply to the contents of this function
52
// as well.
53
// We apply COLD_NOINLINE to tell the compiler that it's not worth optimizing
54
// this function for speed and it should rather focus on keeping it out of
55
// hot code paths. In particular, we want to keep the string concatenating code
56
// out of the function containing the original `Debug()` call.
57
template <typename... Args>
58
130
void COLD_NOINLINE UnconditionalAsyncWrapDebug(AsyncWrap* async_wrap,
59
                                               const char* format,
60
                                               Args&&... args) {
61
130
  Debug(async_wrap->env(),
62
130
        static_cast<DebugCategory>(async_wrap->provider_type()),
63
130
        async_wrap->diagnostic_name() + " " + format + "\n",
64
476
        std::forward<Args>(args)...);
65
130
}
66
67
template <typename... Args>
68
inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
69
                               const char* format,
70
                               Args&&... args) {
71
  DCHECK_NOT_NULL(async_wrap);
72
  DebugCategory cat =
73
677922
      static_cast<DebugCategory>(async_wrap->provider_type());
74







































677918
  if (!UNLIKELY(async_wrap->env()->debug_enabled(cat)))
75
    return;
76
130
  UnconditionalAsyncWrapDebug(async_wrap, format, std::forward<Args>(args)...);
77
}
78
79
template <typename... Args>
80
inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
81
                               const std::string& format,
82
                               Args&&... args) {
83
  Debug(async_wrap, format.c_str(), std::forward<Args>(args)...);
84
}
85
86
// Debug helper for inspecting the currently running `node` executable.
87
class NativeSymbolDebuggingContext {
88
 public:
89
  static std::unique_ptr<NativeSymbolDebuggingContext> New();
90
91
52
  class SymbolInfo {
92
   public:
93
    std::string name;
94
    std::string filename;
95
    size_t line = 0;
96
    size_t dis = 0;
97
98
    std::string Display() const;
99
  };
100
101
4
  NativeSymbolDebuggingContext() = default;
102
4
  virtual ~NativeSymbolDebuggingContext() {}
103
104
  virtual SymbolInfo LookupSymbol(void* address) { return {}; }
105
  virtual bool IsMapped(void* address) { return false; }
106
  virtual int GetStackTrace(void** frames, int count) { return 0; }
107
108
  NativeSymbolDebuggingContext(const NativeSymbolDebuggingContext&) = delete;
109
  NativeSymbolDebuggingContext(NativeSymbolDebuggingContext&&) = delete;
110
  NativeSymbolDebuggingContext operator=(NativeSymbolDebuggingContext&)
111
    = delete;
112
  NativeSymbolDebuggingContext operator=(NativeSymbolDebuggingContext&&)
113
    = delete;
114
  static std::vector<std::string> GetLoadedLibraries();
115
};
116
117
// Variant of `uv_loop_close` that tries to be as helpful as possible
118
// about giving information on currently existing handles, if there are any,
119
// but still aborts the process.
120
void CheckedUvLoopClose(uv_loop_t* loop);
121
122
}  // namespace node
123
124
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
125
126
#endif  // SRC_DEBUG_UTILS_H_