ref: 1b5cc3a0821aba5224b812d2cc4a9923fa0ea09c
parent: 361b6ca99727ff48295eaecc0a9eb9f456e9264d
author: Tor Andersson <tor.andersson@artifex.com>
date: Thu Apr 28 09:33:58 EDT 2016
Improve debugging stack trace print-out.
--- a/jserror.c
+++ b/jserror.c
@@ -9,14 +9,17 @@
{
int n;
char buf[256];
- for (n = J->tracetop - skip; n >= 0; --n) {
+ for (n = J->tracetop - skip; n > 0; --n) {
const char *name = J->trace[n].name;
const char *file = J->trace[n].file;
int line = J->trace[n].line;
- if (line > 0)
- snprintf(buf, sizeof buf, "\n\t%s:%d: in function '%s'", file, line, name);
- else
- snprintf(buf, sizeof buf, "\n\t%s: in function '%s'", file, name);
+ if (line > 0) {
+ if (name[0])
+ snprintf(buf, sizeof buf, "\n\tat %s (%s:%d)", name, file, line);
+ else
+ snprintf(buf, sizeof buf, "\n\tat %s:%d", file, line);
+ } else
+ snprintf(buf, sizeof buf, "\n\tat %s (%s)", name, file);
js_pushstring(J, buf);
if (n < J->tracetop - skip)
js_concat(J);
--- a/jsrun.c
+++ b/jsrun.c
@@ -1052,7 +1052,7 @@
jsR_callscript(J, n, obj->u.f.function, obj->u.f.scope);
--J->tracetop;
} else if (obj->type == JS_CCFUNCTION) {
- jsR_pushtrace(J, obj->u.c.name, "[C]", 0);
+ jsR_pushtrace(J, obj->u.c.name, "native", 0);
jsR_callcfunction(J, n, obj->u.c.length, obj->u.c.function);
--J->tracetop;
}
@@ -1079,7 +1079,7 @@
js_rot(J, n + 1);
BOT = TOP - n - 1;
- jsR_pushtrace(J, obj->u.c.name, "[C]", 0);
+ jsR_pushtrace(J, obj->u.c.name, "native", 0);
jsR_callcfunction(J, n, obj->u.c.length, obj->u.c.constructor);
--J->tracetop;
@@ -1233,10 +1233,13 @@
const char *name = J->trace[n].name;
const char *file = J->trace[n].file;
int line = J->trace[n].line;
- if (line > 0)
- printf("\t%s:%d: in function '%s'\n", file, line, name);
- else
- printf("\t%s: in function '%s'\n", file, name);
+ if (line > 0) {
+ if (name[0])
+ printf("\tat %s (%s:%d)\n", name, file, line);
+ else
+ printf("\tat %s:%d\n", file, line);
+ } else
+ printf("\tat %s (%s)\n", name, file);
}
}
--- a/jsstate.c
+++ b/jsstate.c
@@ -192,8 +192,8 @@
if (flags & JS_STRICT)
J->strict = 1;
- J->trace[0].name = "?";
- J->trace[0].file = "[C]";
+ J->trace[0].name = "-top-";
+ J->trace[0].file = "native";
J->trace[0].line = 0;
J->panic = js_defaultpanic;