]> granicus.if.org Git - jq/commitdiff
Add --debug-trace=all for detailed debug output
authorWilliam Langford <wlangfor@gmail.com>
Mon, 20 Feb 2017 05:49:28 +0000 (00:49 -0500)
committerNicolas Williams <nico@cryptonector.com>
Sun, 26 Mar 2017 10:36:22 +0000 (05:36 -0500)
When tracing execution, print the whole stack, not just the items used by the
current opcode

src/execute.c
src/jq.h
src/main.c

index 0fcaaf02692d2745927f71c37c9d1644b110dbd2..d5672165e3cba5356115b29f5da1befe4a47a188 100644 (file)
@@ -365,10 +365,9 @@ jv jq_next(jq_state *jq) {
       if (!backtracking) {
         int stack_in = opdesc->stack_in;
         if (stack_in == -1) stack_in = pc[1];
+        param = jq->stk_top;
         for (int i=0; i<stack_in; i++) {
-          if (i == 0) {
-            param = jq->stk_top;
-          } else {
+          if (i != 0) {
             printf(" | ");
             param = *stack_block_next(&jq->stk, param);
           }
@@ -378,6 +377,12 @@ jv jq_next(jq_state *jq) {
           //printf(" -- ");
           //jv_dump(jv_copy(jq->path), 0);
         }
+        if (jq->debug_trace_enabled & JQ_DEBUG_TRACE_DETAIL) {
+          while ((param = *stack_block_next(&jq->stk, param))) {
+            printf(" || ");
+            jv_dump(jv_copy(*(jv*)stack_block(&jq->stk, param)), JV_PRINT_REFCOUNT);
+          }
+        }
       } else {
         printf("\t<backtracking>");
       }
@@ -1033,11 +1038,7 @@ void jq_start(jq_state *jq, jv input, int flags) {
 
   stack_push(jq, input);
   stack_save(jq, jq->bc->code, stack_get_pos(jq));
-  if (flags & JQ_DEBUG_TRACE) {
-    jq->debug_trace_enabled = 1;
-  } else {
-    jq->debug_trace_enabled = 0;
-  }
+  jq->debug_trace_enabled = flags & JQ_DEBUG_TRACE_ALL;
   jq->initial_execution = 1;
 }
 
index b80d442f491f37ceae7a3d193d8ecd6aaee5fbfc..3067d8ae3962b6c41597b7467a7e2d7da183b079 100644 (file)
--- a/src/jq.h
+++ b/src/jq.h
@@ -4,7 +4,11 @@
 #include <stdio.h>
 #include "jv.h"
 
-enum {JQ_DEBUG_TRACE = 1};
+enum {
+  JQ_DEBUG_TRACE = 1,
+  JQ_DEBUG_TRACE_DETAIL = 2,
+  JQ_DEBUG_TRACE_ALL = JQ_DEBUG_TRACE | JQ_DEBUG_TRACE_DETAIL,
+};
 
 typedef struct jq_state jq_state;
 typedef void (*jq_msg_cb)(void *, jv);
index 6d3964b1e73e3984db4c1b193d6ec9afb62f00a7..3cbf31526a8096b26e8c182087eb4054e735a9f9 100644 (file)
@@ -475,6 +475,10 @@ int main(int argc, char* argv[]) {
         options |= DUMP_DISASM;
         continue;
       }
+      if (isoption(argv[i],  0,  "debug-trace=all", &short_opts)) {
+        jq_flags |= JQ_DEBUG_TRACE_ALL;
+        if (!short_opts) continue;
+      }
       if (isoption(argv[i],  0,  "debug-trace", &short_opts)) {
         jq_flags |= JQ_DEBUG_TRACE;
         continue;