[njs] Reporting file name and function name in disassembler output.
Dmitry Volyntsev
xeioex at nginx.com
Tue Mar 12 16:30:28 UTC 2019
details: https://hg.nginx.org/njs/rev/dcc7965410bd
branches:
changeset: 827:dcc7965410bd
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue Mar 12 19:28:11 2019 +0300
description:
Reporting file name and function name in disassembler output.
diffstat:
njs/njs.c | 2 +-
njs/njs_disassembler.c | 2 ++
njs/njs_generator.c | 16 ++++++++++------
njs/njs_generator.h | 2 +-
njs/njs_vm.c | 19 ++++++++++---------
njs/njs_vm.h | 7 +++++++
6 files changed, 31 insertions(+), 17 deletions(-)
diffs (192 lines):
diff -r 49f4eb5afc9b -r dcc7965410bd njs/njs.c
--- a/njs/njs.c Mon Mar 11 18:31:40 2019 +0300
+++ b/njs/njs.c Tue Mar 12 19:28:11 2019 +0300
@@ -271,7 +271,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
nxt_memzero(&generator, sizeof(njs_generator_t));
- ret = njs_generate_scope(vm, &generator, scope);
+ ret = njs_generate_scope(vm, &generator, scope, &njs_entry_main);
if (nxt_slow_path(ret != NXT_OK)) {
goto fail;
}
diff -r 49f4eb5afc9b -r dcc7965410bd njs/njs_disassembler.c
--- a/njs/njs_disassembler.c Mon Mar 11 18:31:40 2019 +0300
+++ b/njs/njs_disassembler.c Tue Mar 12 19:28:11 2019 +0300
@@ -139,6 +139,8 @@ njs_disassembler(njs_vm_t *vm)
n = vm->code->items;
while (n != 0) {
+ printf("%.*s:%.*s\n", (int) code->file.length, code->file.start,
+ (int) code->name.length, code->name.start);
njs_disassemble(code->start, code->end);
code++;
n--;
diff -r 49f4eb5afc9b -r dcc7965410bd njs/njs_generator.c
--- a/njs/njs_generator.c Mon Mar 11 18:31:40 2019 +0300
+++ b/njs/njs_generator.c Tue Mar 12 19:28:11 2019 +0300
@@ -138,7 +138,8 @@ static nxt_int_t njs_generate_inc_dec_op
static nxt_int_t njs_generate_function_declaration(njs_vm_t *vm,
njs_generator_t *generator, njs_parser_node_t *node);
static nxt_int_t njs_generate_function_scope(njs_vm_t *vm,
- njs_function_lambda_t *lambda, njs_parser_node_t *node);
+ njs_function_lambda_t *lambda, njs_parser_node_t *node,
+ const nxt_str_t *name);
static nxt_int_t njs_generate_argument_closures(njs_vm_t *vm,
njs_generator_t *generator, njs_parser_node_t *node);
static nxt_int_t njs_generate_return_statement(njs_vm_t *vm,
@@ -1913,7 +1914,7 @@ njs_generate_function(njs_vm_t *vm, njs_
lambda = node->u.value.data.u.lambda;
- ret = njs_generate_function_scope(vm, lambda, node);
+ ret = njs_generate_function_scope(vm, lambda, node, &njs_entry_anonymous);
if (nxt_slow_path(ret != NXT_OK)) {
return ret;
@@ -2269,7 +2270,8 @@ njs_generate_function_declaration(njs_vm
lambda = var->value.data.u.function->u.lambda;
- ret = njs_generate_function_scope(vm, lambda, node);
+ ret = njs_generate_function_scope(vm, lambda, node,
+ &node->u.reference.name);
if (nxt_slow_path(ret != NXT_OK)) {
return ret;
}
@@ -2284,7 +2286,7 @@ njs_generate_function_declaration(njs_vm
static nxt_int_t
njs_generate_function_scope(njs_vm_t *vm, njs_function_lambda_t *lambda,
- njs_parser_node_t *node)
+ njs_parser_node_t *node, const nxt_str_t *name)
{
size_t size;
nxt_int_t ret;
@@ -2295,7 +2297,7 @@ njs_generate_function_scope(njs_vm_t *vm
nxt_memzero(&generator, sizeof(njs_generator_t));
- ret = njs_generate_scope(vm, &generator, node->scope);
+ ret = njs_generate_scope(vm, &generator, node->scope, name);
if (nxt_fast_path(ret == NXT_OK)) {
size = 0;
@@ -2323,7 +2325,7 @@ njs_generate_function_scope(njs_vm_t *vm
nxt_int_t
njs_generate_scope(njs_vm_t *vm, njs_generator_t *generator,
- njs_parser_scope_t *scope)
+ njs_parser_scope_t *scope, const nxt_str_t *name)
{
u_char *p;
size_t size;
@@ -2393,6 +2395,8 @@ njs_generate_scope(njs_vm_t *vm, njs_gen
code->start = generator->code_start;
code->end = generator->code_end;
+ code->file = scope->file;
+ code->name = *name;
return NXT_OK;
}
diff -r 49f4eb5afc9b -r dcc7965410bd njs/njs_generator.h
--- a/njs/njs_generator.h Mon Mar 11 18:31:40 2019 +0300
+++ b/njs/njs_generator.h Tue Mar 12 19:28:11 2019 +0300
@@ -28,7 +28,7 @@ struct njs_generator_s {
nxt_int_t njs_generate_scope(njs_vm_t *vm, njs_generator_t *generator,
- njs_parser_scope_t *scope);
+ njs_parser_scope_t *scope, const nxt_str_t *name);
#endif /* _NJS_GENERATOR_H_INCLUDED_ */
diff -r 49f4eb5afc9b -r dcc7965410bd njs/njs_vm.c
--- a/njs/njs_vm.c Mon Mar 11 18:31:40 2019 +0300
+++ b/njs/njs_vm.c Tue Mar 12 19:28:11 2019 +0300
@@ -95,6 +95,12 @@ const njs_value_t njs_string_function =
const njs_value_t njs_string_memory_error = njs_string("MemoryError");
+const nxt_str_t njs_entry_main = nxt_string("main");
+const nxt_str_t njs_entry_native = nxt_string("native");
+const nxt_str_t njs_entry_unknown = nxt_string("unknown");
+const nxt_str_t njs_entry_anonymous = nxt_string("anonymous");
+
+
/*
* The nJSVM is optimized for an ABIs where the first several arguments
* are passed in registers (AMD64, ARM32/64): two pointers to the operand
@@ -3497,11 +3503,6 @@ njs_vm_add_backtrace_entry(njs_vm_t *vm,
njs_function_lambda_t *lambda;
njs_backtrace_entry_t *be;
- static const nxt_str_t entry_main = nxt_string("main");
- static const nxt_str_t entry_native = nxt_string("native");
- static const nxt_str_t entry_unknown = nxt_string("unknown");
- static const nxt_str_t entry_anonymous = nxt_string("anonymous");
-
native_frame = &frame->native;
function = native_frame->function;
@@ -3513,7 +3514,7 @@ njs_vm_add_backtrace_entry(njs_vm_t *vm,
be->line = 0;
if (function == NULL) {
- be->name = entry_main;
+ be->name = njs_entry_main;
return NXT_OK;
}
@@ -3529,7 +3530,7 @@ njs_vm_add_backtrace_entry(njs_vm_t *vm,
return NXT_OK;
}
- be->name = entry_native;
+ be->name = njs_entry_native;
return NXT_OK;
}
@@ -3543,7 +3544,7 @@ njs_vm_add_backtrace_entry(njs_vm_t *vm,
be->name = debug_entry[i].name;
} else {
- be->name = entry_anonymous;
+ be->name = njs_entry_anonymous;
}
be->file = debug_entry[i].file;
@@ -3553,7 +3554,7 @@ njs_vm_add_backtrace_entry(njs_vm_t *vm,
}
}
- be->name = entry_unknown;
+ be->name = njs_entry_unknown;
return NXT_OK;
}
diff -r 49f4eb5afc9b -r dcc7965410bd njs/njs_vm.h
--- a/njs/njs_vm.h Mon Mar 11 18:31:40 2019 +0300
+++ b/njs/njs_vm.h Tue Mar 12 19:28:11 2019 +0300
@@ -1095,6 +1095,8 @@ struct njs_vm_s {
typedef struct {
u_char *start;
u_char *end;
+ nxt_str_t file;
+ nxt_str_t name;
} njs_vm_code_t;
@@ -1297,6 +1299,11 @@ extern const njs_value_t njs_string_nan
extern const njs_value_t njs_string_internal_error;
extern const njs_value_t njs_string_memory_error;
+extern const nxt_str_t njs_entry_main;
+extern const nxt_str_t njs_entry_native;
+extern const nxt_str_t njs_entry_unknown;
+extern const nxt_str_t njs_entry_anonymous;
+
extern const nxt_mem_proto_t njs_array_mem_proto;
extern const nxt_lvlhsh_proto_t njs_object_hash_proto;
More information about the nginx-devel
mailing list