1
1
#include < cerrno>
2
2
#include < cstdarg>
3
+ #include < sstream>
3
4
4
5
#include " debug_utils-inl.h"
5
6
#include " node_errors.h"
@@ -185,23 +186,29 @@ static std::string GetErrorSource(Isolate* isolate,
185
186
return buf + std::string (underline_buf, off);
186
187
}
187
188
188
- static std::string FormatStackTrace (Isolate* isolate, Local<StackTrace> stack) {
189
+ static std::string FormatStackTrace (
190
+ Isolate* isolate,
191
+ Local<StackTrace> stack,
192
+ StackTracePrefix prefix = StackTracePrefix::kAt ) {
189
193
std::string result;
190
194
for (int i = 0 ; i < stack->GetFrameCount (); i++) {
191
195
Local<StackFrame> stack_frame = stack->GetFrame (isolate, i);
192
196
node::Utf8Value fn_name_s (isolate, stack_frame->GetFunctionName ());
193
197
node::Utf8Value script_name (isolate, stack_frame->GetScriptName ());
194
198
const int line_number = stack_frame->GetLineNumber ();
195
199
const int column = stack_frame->GetColumn ();
196
-
200
+ std::string prefix_str = prefix == StackTracePrefix::kAt
201
+ ? " at "
202
+ : std::to_string (i + 1 ) + " : " ;
197
203
if (stack_frame->IsEval ()) {
198
204
if (stack_frame->GetScriptId () == Message::kNoScriptIdInfo ) {
199
- result += SPrintF (" at [eval]:%i:%i\n " , line_number, column);
205
+ result += SPrintF (" %s [eval]:%i:%i\n " , prefix_str , line_number, column);
200
206
} else {
201
207
std::vector<char > buf (script_name.length () + 64 );
202
208
snprintf (buf.data (),
203
209
buf.size (),
204
- " at [eval] (%s:%i:%i)\n " ,
210
+ " %s[eval] (%s:%i:%i)\n " ,
211
+ prefix_str.c_str (),
205
212
*script_name,
206
213
line_number,
207
214
column);
@@ -214,7 +221,8 @@ static std::string FormatStackTrace(Isolate* isolate, Local<StackTrace> stack) {
214
221
std::vector<char > buf (script_name.length () + 64 );
215
222
snprintf (buf.data (),
216
223
buf.size (),
217
- " at %s:%i:%i\n " ,
224
+ " %s%s:%i:%i\n " ,
225
+ prefix_str.c_str (),
218
226
*script_name,
219
227
line_number,
220
228
column);
@@ -223,7 +231,8 @@ static std::string FormatStackTrace(Isolate* isolate, Local<StackTrace> stack) {
223
231
std::vector<char > buf (fn_name_s.length () + script_name.length () + 64 );
224
232
snprintf (buf.data (),
225
233
buf.size (),
226
- " at %s (%s:%i:%i)\n " ,
234
+ " %s%s (%s:%i:%i)\n " ,
235
+ prefix_str.c_str (),
227
236
*fn_name_s,
228
237
*script_name,
229
238
line_number,
@@ -239,8 +248,10 @@ static void PrintToStderrAndFlush(const std::string& str) {
239
248
fflush (stderr);
240
249
}
241
250
242
- void PrintStackTrace (Isolate* isolate, Local<StackTrace> stack) {
243
- PrintToStderrAndFlush (FormatStackTrace (isolate, stack));
251
+ void PrintStackTrace (Isolate* isolate,
252
+ Local<StackTrace> stack,
253
+ StackTracePrefix prefix) {
254
+ PrintToStderrAndFlush (FormatStackTrace (isolate, stack, prefix));
244
255
}
245
256
246
257
std::string FormatCaughtException (Isolate* isolate,
@@ -329,7 +340,8 @@ void AppendExceptionLine(Environment* env,
329
340
}
330
341
331
342
[[noreturn]] void Abort () {
332
- DumpBacktrace (stderr);
343
+ DumpNativeBacktrace (stderr);
344
+ DumpJavaScriptBacktrace (stderr);
333
345
fflush (stderr);
334
346
ABORT_NO_BACKTRACE ();
335
347
}
@@ -338,14 +350,15 @@ void AppendExceptionLine(Environment* env,
338
350
std::string name = GetHumanReadableProcessName ();
339
351
340
352
fprintf (stderr,
341
- " %s: %s:%s%s Assertion `%s' failed.\n " ,
353
+ " \n "
354
+ " # %s: %s at %s\n "
355
+ " # Assertion failed: %s\n\n " ,
342
356
name.c_str (),
343
- info.file_line ,
344
- info.function ,
345
- *info.function ? " :" : " " ,
357
+ info.function ? info.function : " (unknown function)" ,
358
+ info.file_line ? info.file_line : " (unknown source location)" ,
346
359
info.message );
347
- fflush (stderr);
348
360
361
+ fflush (stderr);
349
362
Abort ();
350
363
}
351
364
0 commit comments