Skip to content
Myr

Add --debug-trace=all for detailed debug output

Before adoption: this commit came in with the history the project adopted, so no landing records it.

When tracing execution, print the whole stack, not just the items used by the current opcode

authored by William Langford · committed by Nicolas Williams · parent c8a2a0a · Browse files · 3 files+18 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+18 added−9 removed

  • other:+18 added−9 removed

3 files+18 added−9 removed

modified:src/execute.c+9 added-8 removed
363 unmodified lines
364 stack_ptr param = 0;365 if (!backtracking) {366 int stack_in = opdesc->stack_in;367 if (stack_in == -1) stack_in = pc[1];368 param = jq->stk_top;369 for (int i=0; i<stack_in; i++) {369 if (i == 0) {370 param = jq->stk_top;371 } else {370 if (i != 0) {371 printf(" | ");372 param = *stack_block_next(&jq->stk, param);373 }374 if (!param) break;
1 unmodified line
376 //printf("<%d>", jv_get_refcnt(param->val));377 //printf(" -- ");378 //jv_dump(jv_copy(jq->path), 0);379 }380 if (jq->debug_trace_enabled & JQ_DEBUG_TRACE_DETAIL) {381 while ((param = *stack_block_next(&jq->stk, param))) {382 printf(" || ");383 jv_dump(jv_copy(*(jv*)stack_block(&jq->stk, param)), JV_PRINT_REFCOUNT);384 }385 }386 } else {387 printf("\t<backtracking>");388 }389
647 unmodified lines
1037 top_frame->retaddr = 0;10381039 stack_push(jq, input);1040 stack_save(jq, jq->bc->code, stack_get_pos(jq));1036 if (flags & JQ_DEBUG_TRACE) {1037 jq->debug_trace_enabled = 1;1041 jq->debug_trace_enabled = flags & JQ_DEBUG_TRACE_ALL;1038 } else {1039 jq->debug_trace_enabled = 0;1040 }1042 jq->initial_execution = 1;1043}10441045void jq_teardown(jq_state **jq) {
205 unmodified lines
modified:src/jq.h+5 added-1 removed
2 unmodified lines
34#include <stdio.h>5#include "jv.h"67enum {JQ_DEBUG_TRACE = 1};7enum {8 JQ_DEBUG_TRACE = 1,9 JQ_DEBUG_TRACE_DETAIL = 2,10 JQ_DEBUG_TRACE_ALL = JQ_DEBUG_TRACE | JQ_DEBUG_TRACE_DETAIL,11};1213typedef struct jq_state jq_state;14typedef void (*jq_msg_cb)(void *, jv);15
54 unmodified lines
modified:src/main.c+4 added
473 unmodified lines
474 if (isoption(argv[i], 0, "debug-dump-disasm", &short_opts)) {475 options |= DUMP_DISASM;476 continue;477 }478 if (isoption(argv[i], 0, "debug-trace=all", &short_opts)) {479 jq_flags |= JQ_DEBUG_TRACE_ALL;480 if (!short_opts) continue;481 }482 if (isoption(argv[i], 0, "debug-trace", &short_opts)) {483 jq_flags |= JQ_DEBUG_TRACE;484 continue;485 }
171 unmodified lines