[njs] Added generator debug.

Dmitry Volyntsev xeioex at nginx.com
Wed May 18 07:02:37 UTC 2022


details:   https://hg.nginx.org/njs/rev/c48ecb7b24d7
branches:  
changeset: 1858:c48ecb7b24d7
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue May 17 23:26:09 2022 -0700
description:
Added generator debug.

diffstat:

 src/njs_generator.c |  22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diffs (74 lines):

diff -r 3e754413e907 -r c48ecb7b24d7 src/njs_generator.c
--- a/src/njs_generator.c	Tue May 17 23:26:05 2022 -0700
+++ b/src/njs_generator.c	Tue May 17 23:26:09 2022 -0700
@@ -427,6 +427,16 @@ static njs_int_t njs_generate_index_rele
                           ##__VA_ARGS__)
 
 
+#ifdef NJS_GENERATOR_DEBUG
+#define njs_generator_debug(msg, ...) njs_printf(msg "\n", ##__VA_ARGS__)
+#define njs_generator_debug_code(code)                                        \
+        njs_disassemble((u_char *) code, NULL, 1, NULL)
+#else
+#define njs_generator_debug(msg, ...)
+#define njs_generator_debug_code(code)
+#endif
+
+
 static const njs_str_t  no_label     = njs_str("");
 static const njs_str_t  return_label = njs_str("@return");
 /* GCC and Clang complain about NULL argument passed to memcmp(). */
@@ -725,7 +735,6 @@ njs_generate(njs_vm_t *vm, njs_generator
         return njs_generate_await(vm, generator, node);
 
     default:
-        njs_thread_log_debug("unknown token: %d", node->token);
         njs_internal_error(vm, "Generator failed: unknown token");
 
         return NJS_ERROR;
@@ -3368,8 +3377,7 @@ njs_generate_3addr_operation_end(njs_vm_
 
     code->dst = node->index;
 
-    njs_thread_log_debug("CODE3  %p, %p, %p",
-                         code->dst, code->src1, code->src2);
+    njs_generator_debug_code(code);
 
     return njs_generator_stack_pop(vm, generator, generator->context);
 }
@@ -3404,7 +3412,7 @@ njs_generate_2addr_operation_end(njs_vm_
 
     code->dst = node->index;
 
-    njs_thread_log_debug("CODE2  %p, %p", code->dst, code->src);
+    njs_generator_debug_code(code);
 
     return njs_generator_stack_pop(vm, generator, NULL);
 }
@@ -3453,7 +3461,7 @@ njs_generate_typeof_operation_end(njs_vm
 
     code->dst = node->index;
 
-    njs_thread_log_debug("CODE2  %p, %p", code->dst, code->src);
+    njs_generator_debug_code(code);
 
     return njs_generator_stack_pop(vm, generator, NULL);
 }
@@ -4898,7 +4906,7 @@ njs_generate_temp_index_get(njs_vm_t *vm
     if (cache != NULL && cache->items != 0) {
         last = njs_arr_remove_last(cache);
 
-        njs_thread_log_debug("CACHE %p", *last);
+        njs_generator_debug("INDEX REUSE  %04Xz", (size_t) *last);
 
         return *last;
     }
@@ -4964,7 +4972,7 @@ njs_generate_index_release(njs_vm_t *vm,
     njs_arr_t    *cache;
     njs_index_t  *last;
 
-    njs_thread_log_debug("RELEASE %p", index);
+    njs_generator_debug("INDEX RELEASE %04Xz", (size_t) index);
 
     cache = generator->index_cache;
 



More information about the nginx-devel mailing list