[njs] Reporting filename in runtime errors.
Dmitry Volyntsev
xeioex at nginx.com
Tue Feb 5 16:07:31 UTC 2019
details: https://hg.nginx.org/njs/rev/4dfc639287f0
branches:
changeset: 761:4dfc639287f0
user: hongzhidao <hongzhidao at gmail.com>
date: Tue Feb 05 01:07:45 2019 +0800
description:
Reporting filename in runtime errors.
diffstat:
njs/njs_generator.c | 13 ++++++-------
njs/njs_vm.c | 42 ++++++++++++++++++++++++------------------
njs/njs_vm.h | 6 ++++--
3 files changed, 34 insertions(+), 27 deletions(-)
diffs (166 lines):
diff -r 334b9d9e4357 -r 4dfc639287f0 njs/njs_generator.c
--- a/njs/njs_generator.c Tue Feb 05 00:53:18 2019 +0800
+++ b/njs/njs_generator.c Tue Feb 05 01:07:45 2019 +0800
@@ -160,8 +160,7 @@ static nxt_noinline nxt_int_t njs_genera
njs_generator_t *generator, njs_index_t index);
static nxt_int_t njs_generate_function_debug(njs_vm_t *vm, nxt_str_t *name,
- njs_function_lambda_t *lambda, uint32_t line);
-
+ njs_function_lambda_t *lambda, njs_parser_node_t *node);
static void njs_generate_syntax_error(njs_vm_t *vm, njs_parser_node_t *node,
const char *fmt, ...);
@@ -1888,7 +1887,7 @@ njs_generate_function(njs_vm_t *vm, njs_
}
if (vm->debug != NULL) {
- ret = njs_generate_function_debug(vm, NULL, lambda, node->token_line);
+ ret = njs_generate_function_debug(vm, NULL, lambda, node);
if (nxt_slow_path(ret != NXT_OK)) {
return ret;
}
@@ -2269,8 +2268,7 @@ njs_generate_function_declaration(njs_vm
}
if (vm->debug != NULL) {
- ret = njs_generate_function_debug(vm, &var->name, lambda,
- node->token_line);
+ ret = njs_generate_function_debug(vm, &var->name, lambda, node);
}
return ret;
@@ -3137,7 +3135,7 @@ njs_generate_index_release(njs_vm_t *vm,
static nxt_int_t
njs_generate_function_debug(njs_vm_t *vm, nxt_str_t *name,
- njs_function_lambda_t *lambda, uint32_t line)
+ njs_function_lambda_t *lambda, njs_parser_node_t *node)
{
njs_function_debug_t *debug;
@@ -3154,7 +3152,8 @@ njs_generate_function_debug(njs_vm_t *vm
}
debug->lambda = lambda;
- debug->line = line;
+ debug->line = node->token_line;
+ debug->file = node->scope->file;
return NXT_OK;
}
diff -r 334b9d9e4357 -r 4dfc639287f0 njs/njs_vm.c
--- a/njs/njs_vm.c Tue Feb 05 00:53:18 2019 +0800
+++ b/njs/njs_vm.c Tue Feb 05 01:07:45 2019 +0800
@@ -3127,8 +3127,8 @@ again:
be = backtrace->start;
for (i = 0; i < backtrace->items; i++) {
- if (i != 0 && prev->name.start == be[i].name.start
- && prev->line == be[i].line)
+ if (i != 0 && prev->name.start == be->name.start
+ && prev->line == be->line)
{
count++;
@@ -3140,17 +3140,18 @@ again:
count = 0;
}
- if (be[i].line != 0) {
- len += nxt_length(" at (:)\n") + NXT_INT_T_LEN
- + be[i].name.length;
+ len += be->name.length + nxt_length(" at ()\n");
+
+ if (be->line != 0) {
+ len += be->file.length + NXT_INT_T_LEN + 1;
} else {
- len += nxt_length(" at (native)\n")
- + be[i].name.length;
+ len += nxt_length("native");
}
}
- prev = &be[i];
+ prev = be;
+ be++;
}
p = nxt_mp_alloc(vm->mem_pool, len);
@@ -3168,30 +3169,34 @@ again:
count = 0;
prev = NULL;
+ be = backtrace->start;
+
for (i = 0; i < backtrace->items; i++) {
- if (i != 0 && prev->name.start == be[i].name.start
- && prev->line == be[i].line)
+ if (i != 0 && prev->name.start == be->name.start
+ && prev->line == be->line)
{
count++;
} else {
if (count != 0) {
- p = nxt_sprintf(p, end,
- " repeats %uz times\n", count);
+ p = nxt_sprintf(p, end, " repeats %uz times\n",
+ count);
count = 0;
}
- if (be[i].line != 0) {
- p = nxt_sprintf(p, end, " at %V (:%uD)\n",
- &be[i].name, be[i].line);
+ p = nxt_sprintf(p, end, " at %V ", &be->name);
+
+ if (be->line != 0) {
+ p = nxt_sprintf(p, end, "(%V:%uD)\n", &be->file,
+ be->line);
} else {
- p = nxt_sprintf(p, end, " at %V (native)\n",
- &be[i].name);
+ p = nxt_sprintf(p, end, "(native)\n");
}
}
- prev = &be[i];
+ prev = be;
+ be++;
}
dst->start = start;
@@ -3549,6 +3554,7 @@ njs_vm_add_backtrace_entry(njs_vm_t *vm,
be->name = entry_anonymous;
}
+ be->file = debug_entry[i].file;
be->line = debug_entry[i].line;
return NXT_OK;
diff -r 334b9d9e4357 -r 4dfc639287f0 njs/njs_vm.h
--- a/njs/njs_vm.h Tue Feb 05 00:53:18 2019 +0800
+++ b/njs/njs_vm.h Tue Feb 05 01:07:45 2019 +0800
@@ -352,8 +352,9 @@ typedef union {
typedef struct {
- nxt_str_t name;
- uint32_t line;
+ nxt_str_t name;
+ nxt_str_t file;
+ uint32_t line;
} njs_backtrace_entry_t;
@@ -1012,6 +1013,7 @@ typedef struct {
typedef struct {
uint32_t line;
+ nxt_str_t file;
nxt_str_t name;
njs_function_lambda_t *lambda;
} njs_function_debug_t;
More information about the nginx-devel
mailing list