V8 Project
logging.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_BASE_LOGGING_H_
6 #define V8_BASE_LOGGING_H_
7 
8 #include <string.h>
9 
10 #include "include/v8stdint.h"
11 #include "src/base/build_config.h"
12 
13 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...);
14 
15 
16 // The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during
17 // development, but they should not be relied on in the final product.
18 #ifdef DEBUG
19 #define FATAL(msg) \
20  V8_Fatal(__FILE__, __LINE__, "%s", (msg))
21 #define UNIMPLEMENTED() \
22  V8_Fatal(__FILE__, __LINE__, "unimplemented code")
23 #define UNREACHABLE() \
24  V8_Fatal(__FILE__, __LINE__, "unreachable code")
25 #else
26 #define FATAL(msg) \
27  V8_Fatal("", 0, "%s", (msg))
28 #define UNIMPLEMENTED() \
29  V8_Fatal("", 0, "unimplemented code")
30 #define UNREACHABLE() ((void) 0)
31 #endif
32 
33 
34 // The CHECK macro checks that the given condition is true; if not, it
35 // prints a message to stderr and aborts.
36 #define CHECK(condition) do { \
37  if (!(condition)) { \
38  V8_Fatal(__FILE__, __LINE__, "CHECK(%s) failed", #condition); \
39  } \
40  } while (0)
41 
42 
43 // Helper function used by the CHECK_EQ function when given int
44 // arguments. Should not be called directly.
45 inline void CheckEqualsHelper(const char* file, int line,
46  const char* expected_source, int expected,
47  const char* value_source, int value) {
48  if (expected != value) {
49  V8_Fatal(file, line,
50  "CHECK_EQ(%s, %s) failed\n# Expected: %i\n# Found: %i",
51  expected_source, value_source, expected, value);
52  }
53 }
54 
55 
56 // Helper function used by the CHECK_EQ function when given int64_t
57 // arguments. Should not be called directly.
58 inline void CheckEqualsHelper(const char* file, int line,
59  const char* expected_source,
60  int64_t expected,
61  const char* value_source,
62  int64_t value) {
63  if (expected != value) {
64  // Print int64_t values in hex, as two int32s,
65  // to avoid platform-dependencies.
66  V8_Fatal(file, line,
67  "CHECK_EQ(%s, %s) failed\n#"
68  " Expected: 0x%08x%08x\n# Found: 0x%08x%08x",
69  expected_source, value_source,
70  static_cast<uint32_t>(expected >> 32),
71  static_cast<uint32_t>(expected),
72  static_cast<uint32_t>(value >> 32),
73  static_cast<uint32_t>(value));
74  }
75 }
76 
77 
78 // Helper function used by the CHECK_NE function when given int
79 // arguments. Should not be called directly.
80 inline void CheckNonEqualsHelper(const char* file,
81  int line,
82  const char* unexpected_source,
83  int unexpected,
84  const char* value_source,
85  int value) {
86  if (unexpected == value) {
87  V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %i",
88  unexpected_source, value_source, value);
89  }
90 }
91 
92 
93 // Helper function used by the CHECK function when given string
94 // arguments. Should not be called directly.
95 inline void CheckEqualsHelper(const char* file,
96  int line,
97  const char* expected_source,
98  const char* expected,
99  const char* value_source,
100  const char* value) {
101  if ((expected == NULL && value != NULL) ||
102  (expected != NULL && value == NULL) ||
103  (expected != NULL && value != NULL && strcmp(expected, value) != 0)) {
104  V8_Fatal(file, line,
105  "CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s",
106  expected_source, value_source, expected, value);
107  }
108 }
109 
110 
111 inline void CheckNonEqualsHelper(const char* file,
112  int line,
113  const char* expected_source,
114  const char* expected,
115  const char* value_source,
116  const char* value) {
117  if (expected == value ||
118  (expected != NULL && value != NULL && strcmp(expected, value) == 0)) {
119  V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s",
120  expected_source, value_source, value);
121  }
122 }
123 
124 
125 // Helper function used by the CHECK function when given pointer
126 // arguments. Should not be called directly.
127 inline void CheckEqualsHelper(const char* file,
128  int line,
129  const char* expected_source,
130  const void* expected,
131  const char* value_source,
132  const void* value) {
133  if (expected != value) {
134  V8_Fatal(file, line,
135  "CHECK_EQ(%s, %s) failed\n# Expected: %p\n# Found: %p",
136  expected_source, value_source,
137  expected, value);
138  }
139 }
140 
141 
142 inline void CheckNonEqualsHelper(const char* file,
143  int line,
144  const char* expected_source,
145  const void* expected,
146  const char* value_source,
147  const void* value) {
148  if (expected == value) {
149  V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %p",
150  expected_source, value_source, value);
151  }
152 }
153 
154 
155 inline void CheckNonEqualsHelper(const char* file,
156  int line,
157  const char* expected_source,
158  int64_t expected,
159  const char* value_source,
160  int64_t value) {
161  if (expected == value) {
162  V8_Fatal(file, line,
163  "CHECK_EQ(%s, %s) failed\n# Expected: %f\n# Found: %f",
164  expected_source, value_source, expected, value);
165  }
166 }
167 
168 
169 #define CHECK_EQ(expected, value) CheckEqualsHelper(__FILE__, __LINE__, \
170  #expected, expected, #value, value)
171 
172 
173 #define CHECK_NE(unexpected, value) CheckNonEqualsHelper(__FILE__, __LINE__, \
174  #unexpected, unexpected, #value, value)
175 
176 
177 #define CHECK_GT(a, b) CHECK((a) > (b))
178 #define CHECK_GE(a, b) CHECK((a) >= (b))
179 #define CHECK_LT(a, b) CHECK((a) < (b))
180 #define CHECK_LE(a, b) CHECK((a) <= (b))
181 
182 
183 namespace v8 {
184 namespace base {
185 
186 // Exposed for making debugging easier (to see where your function is being
187 // called, just add a call to DumpBacktrace).
188 void DumpBacktrace();
189 
190 } } // namespace v8::base
191 
192 
193 // The DCHECK macro is equivalent to CHECK except that it only
194 // generates code in debug builds.
195 #ifdef DEBUG
196 #define DCHECK_RESULT(expr) CHECK(expr)
197 #define DCHECK(condition) CHECK(condition)
198 #define DCHECK_EQ(v1, v2) CHECK_EQ(v1, v2)
199 #define DCHECK_NE(v1, v2) CHECK_NE(v1, v2)
200 #define DCHECK_GE(v1, v2) CHECK_GE(v1, v2)
201 #define DCHECK_LT(v1, v2) CHECK_LT(v1, v2)
202 #define DCHECK_LE(v1, v2) CHECK_LE(v1, v2)
203 #else
204 #define DCHECK_RESULT(expr) (expr)
205 #define DCHECK(condition) ((void) 0)
206 #define DCHECK_EQ(v1, v2) ((void) 0)
207 #define DCHECK_NE(v1, v2) ((void) 0)
208 #define DCHECK_GE(v1, v2) ((void) 0)
209 #define DCHECK_LT(v1, v2) ((void) 0)
210 #define DCHECK_LE(v1, v2) ((void) 0)
211 #endif
212 
213 #define DCHECK_NOT_NULL(p) DCHECK_NE(NULL, p)
214 
215 // "Extra checks" are lightweight checks that are enabled in some release
216 // builds.
217 #ifdef ENABLE_EXTRA_CHECKS
218 #define EXTRA_CHECK(condition) CHECK(condition)
219 #else
220 #define EXTRA_CHECK(condition) ((void) 0)
221 #endif
222 
223 #endif // V8_BASE_LOGGING_H_
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes A file to write the raw context snapshot bytes Write V8 startup blob file(mksnapshot only)") DEFINE_BOOL(profile_hydrogen_code_stub_compilation
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
void CheckEqualsHelper(const char *file, int line, const char *expected_source, int expected, const char *value_source, int value)
Definition: logging.h:45
void CheckNonEqualsHelper(const char *file, int line, const char *unexpected_source, int unexpected, const char *value_source, int value)
Definition: logging.h:80
void V8_Fatal(const char *file, int line, const char *format,...)
Definition: logging.cc:75
void DumpBacktrace()
Definition: logging.cc:22
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20