[njs] Improved OPCODE debug.

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


details:   https://hg.nginx.org/njs/rev/3e754413e907
branches:  
changeset: 1857:3e754413e907
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue May 17 23:26:05 2022 -0700
description:
Improved OPCODE debug.

diffstat:

 src/njs_vmcode.c |  31 -------------------------------
 src/njs_vmcode.h |  13 +++++++++++++
 2 files changed, 13 insertions(+), 31 deletions(-)

diffs (115 lines):

diff -r 30e03dbc6baf -r 3e754413e907 src/njs_vmcode.c
--- a/src/njs_vmcode.c	Mon May 16 22:57:27 2022 -0700
+++ b/src/njs_vmcode.c	Tue May 17 23:26:05 2022 -0700
@@ -79,11 +79,6 @@ static njs_jump_off_t njs_function_frame
     } while (0)
 
 
-#ifdef NJS_OPCODE_DEBUG
-void njs_vmcode_debug(njs_vm_t *vm, u_char *pc, const char *prefix);
-#endif
-
-
 njs_int_t
 njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, void *promise_cap,
     void *async_ctx)
@@ -122,9 +117,7 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_c
     njs_vmcode_try_trampoline_t  *try_trampoline;
     njs_vmcode_function_frame_t  *function_frame;
 
-#ifdef NJS_OPCODE_DEBUG
     njs_vmcode_debug(vm, pc, "ENTER");
-#endif
 
 next:
 
@@ -663,9 +656,7 @@ next:
                 njs_vmcode_operand(vm, (njs_index_t) value2, value2);
                 vm->retval = *value2;
 
-#ifdef NJS_OPCODE_DEBUG
                 njs_vmcode_debug(vm, pc, "EXIT STOP");
-#endif
 
                 return NJS_OK;
 
@@ -741,9 +732,7 @@ next:
             case NJS_VMCODE_RETURN:
                 njs_vmcode_operand(vm, (njs_index_t) value2, value2);
 
-#ifdef NJS_OPCODE_DEBUG
                 njs_vmcode_debug(vm, pc, "EXIT RETURN");
-#endif
 
                 return njs_vmcode_return(vm, NULL, value2);
 
@@ -865,9 +854,7 @@ next:
             case NJS_VMCODE_AWAIT:
                 await = (njs_vmcode_await_t *) pc;
 
-#ifdef NJS_OPCODE_DEBUG
                 njs_vmcode_debug(vm, pc, "EXIT AWAIT");
-#endif
 
                 return njs_vmcode_await(vm, await, promise_cap, async_ctx);
 
@@ -933,9 +920,7 @@ next:
                 switch (ret) {
                 case NJS_OK:
 
-#ifdef NJS_OPCODE_DEBUG
                     njs_vmcode_debug(vm, pc, "EXIT FINALLY");
-#endif
 
                     return NJS_OK;
                 case NJS_ERROR:
@@ -1053,9 +1038,7 @@ error:
         }
     }
 
-#ifdef NJS_OPCODE_DEBUG
     njs_vmcode_debug(vm, pc, "EXIT ERROR");
-#endif
 
     return NJS_ERROR;
 }
@@ -2180,17 +2163,3 @@ njs_vmcode_error(njs_vm_t *vm, u_char *p
         njs_error_fmt_new(vm, &vm->retval, err->type, "%V", &err->u.message);
     }
 }
-
-
-#ifdef NJS_OPCODE_DEBUG
-void
-njs_vmcode_debug(njs_vm_t *vm, u_char *pc, const char *prefix)
-{
-    njs_vm_code_t  *code;
-
-    code = njs_lookup_code(vm, pc);
-
-    njs_printf("%s %V\n", prefix,
-               (code != NULL) ? &code->name : &njs_entry_unknown);
-}
-#endif
diff -r 30e03dbc6baf -r 3e754413e907 src/njs_vmcode.h
--- a/src/njs_vmcode.h	Mon May 16 22:57:27 2022 -0700
+++ b/src/njs_vmcode.h	Tue May 17 23:26:05 2022 -0700
@@ -450,5 +450,18 @@ njs_int_t njs_vmcode_interpreter(njs_vm_
 
 njs_object_t *njs_function_new_object(njs_vm_t *vm, njs_value_t *constructor);
 
+#ifdef NJS_OPCODE_DEBUG
+#define njs_vmcode_debug(vm, pc, prefix) {                                    \
+    do {                                                                      \
+        njs_vm_code_t  *code;                                                 \
+                                                                              \
+        code = njs_lookup_code(vm, pc);                                       \
+                                                                              \
+        njs_printf("%s %V\n", prefix,                                         \
+                   (code != NULL) ? &code->name : &njs_entry_unknown);        \
+    } while (0)
+#else
+#define njs_vmcode_debug(vm, pc, prefix)
+#endif
 
 #endif /* _NJS_VMCODE_H_INCLUDED_ */



More information about the nginx-devel mailing list