Remove JQ_DEBUG #define and jq_test binary, simplifying build.
The debugging features previously available via JQ_DEBUG are now command-line options.
This commit is contained in:
1 parent
c1748fa633
commit
1741d8c161
7 files changed
+56
-50
No files matched your search
@@ -26,19 +26,15 @@ main.c: version.gen.h
|
|||||||
|
|
||||||
JQ_SRC=parser.gen.c lexer.gen.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c jv_aux.c jv_alloc.c
|
JQ_SRC=parser.gen.c lexer.gen.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c jv_aux.c jv_alloc.c
|
||||||
|
|
||||||
jq_test: CFLAGS += -DJQ_DEBUG=1
|
|
||||||
jq_test: $(JQ_SRC) main.c jq_test.c
|
|
||||||
$(CC) $(CFLAGS) $(CFLAGS_DEBUG) -o $@ $^
|
|
||||||
|
|
||||||
jq: CFLAGS += -O -DJQ_DEBUG=0
|
|
||||||
jq: $(JQ_SRC) main.c jq_test.c
|
jq: $(JQ_SRC) main.c jq_test.c
|
||||||
$(CC) $(CFLAGS) $(CFLAGS_OPT) -o $@ $^
|
$(CC) $(CFLAGS) $(CFLAGS_OPT) -o $@ $^
|
||||||
|
|
||||||
test: jq_test
|
test: jq
|
||||||
valgrind --error-exitcode=1 -q --leak-check=full ./jq_test --run-tests >/dev/null
|
valgrind --error-exitcode=1 -q --leak-check=full ./jq --run-tests >/dev/null
|
||||||
|
|
||||||
LIBRARIES=libjq
|
LIBRARIES=libjq
|
||||||
BINARIES=jq jq_test
|
BINARIES=jq
|
||||||
PLATFORMS=linux32 linux64 osx32 osx64 win32 win64
|
PLATFORMS=linux32 linux64 osx32 osx64 win32 win64
|
||||||
|
|
||||||
build/linux32%: CC='x86_64-linux-gnu-gcc -m32'
|
build/linux32%: CC='x86_64-linux-gnu-gcc -m32'
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ struct jq_state {
|
|||||||
struct forkable_stack fork_stk;
|
struct forkable_stack fork_stk;
|
||||||
jv* pathbuf;
|
jv* pathbuf;
|
||||||
int pathsize; // number of allocated elements
|
int pathsize; // number of allocated elements
|
||||||
|
int debug_trace_enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
int path_push(jq_state *jq, stackval sv, jv val) {
|
int path_push(jq_state *jq, stackval sv, jv val) {
|
||||||
@@ -162,29 +163,29 @@ jv jq_next(jq_state *jq) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
uint16_t opcode = *pc;
|
uint16_t opcode = *pc;
|
||||||
|
|
||||||
#if JQ_DEBUG
|
if (jq->debug_trace_enabled) {
|
||||||
dump_operation(frame_current_bytecode(&jq->frame_stk), pc);
|
dump_operation(frame_current_bytecode(&jq->frame_stk), pc);
|
||||||
printf("\t");
|
printf("\t");
|
||||||
const struct opcode_description* opdesc = opcode_describe(opcode);
|
const struct opcode_description* opdesc = opcode_describe(opcode);
|
||||||
data_stk_elem* param;
|
data_stk_elem* param;
|
||||||
int stack_in = opdesc->stack_in;
|
int stack_in = opdesc->stack_in;
|
||||||
if (stack_in == -1) stack_in = pc[1];
|
if (stack_in == -1) stack_in = pc[1];
|
||||||
for (int i=0; i<stack_in; i++) {
|
for (int i=0; i<stack_in; i++) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
param = forkable_stack_peek(&jq->data_stk);
|
param = forkable_stack_peek(&jq->data_stk);
|
||||||
} else {
|
} else {
|
||||||
printf(" | ");
|
printf(" | ");
|
||||||
param = forkable_stack_peek_next(&jq->data_stk, param);
|
param = forkable_stack_peek_next(&jq->data_stk, param);
|
||||||
|
}
|
||||||
|
if (!param) break;
|
||||||
|
jv_dump(jv_copy(param->sv.value), 0);
|
||||||
|
printf("<%d>", jv_get_refcnt(param->sv.value));
|
||||||
}
|
}
|
||||||
if (!param) break;
|
|
||||||
jv_dump(jv_copy(param->sv.value), 0);
|
if (backtracking) printf("\t<backtracking>");
|
||||||
printf("<%d>", jv_get_refcnt(param->sv.value));
|
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (backtracking) printf("\t<backtracking>");
|
|
||||||
|
|
||||||
printf("\n");
|
|
||||||
#endif
|
|
||||||
if (backtracking) {
|
if (backtracking) {
|
||||||
opcode = ON_BACKTRACK(opcode);
|
opcode = ON_BACKTRACK(opcode);
|
||||||
backtracking = 0;
|
backtracking = 0;
|
||||||
@@ -265,11 +266,11 @@ jv jq_next(jq_state *jq) {
|
|||||||
uint16_t v = *pc++;
|
uint16_t v = *pc++;
|
||||||
frame_ptr fp = frame_get_level(&jq->frame_stk, frame_current(&jq->frame_stk), level);
|
frame_ptr fp = frame_get_level(&jq->frame_stk, frame_current(&jq->frame_stk), level);
|
||||||
jv* var = frame_local_var(fp, v);
|
jv* var = frame_local_var(fp, v);
|
||||||
#if JQ_DEBUG
|
if (jq->debug_trace_enabled) {
|
||||||
printf("V%d = ", v);
|
printf("V%d = ", v);
|
||||||
jv_dump(jv_copy(*var), 0);
|
jv_dump(jv_copy(*var), 0);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
}
|
||||||
stack_push(jq, stackval_replace(stack_pop(jq), jv_copy(*var)));
|
stack_push(jq, stackval_replace(stack_pop(jq), jv_copy(*var)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -280,11 +281,11 @@ jv jq_next(jq_state *jq) {
|
|||||||
frame_ptr fp = frame_get_level(&jq->frame_stk, frame_current(&jq->frame_stk), level);
|
frame_ptr fp = frame_get_level(&jq->frame_stk, frame_current(&jq->frame_stk), level);
|
||||||
jv* var = frame_local_var(fp, v);
|
jv* var = frame_local_var(fp, v);
|
||||||
stackval val = stack_pop(jq);
|
stackval val = stack_pop(jq);
|
||||||
#if JQ_DEBUG
|
if (jq->debug_trace_enabled) {
|
||||||
printf("V%d = ", v);
|
printf("V%d = ", v);
|
||||||
jv_dump(jv_copy(val.value), 0);
|
jv_dump(jv_copy(val.value), 0);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
}
|
||||||
jv_free(*var);
|
jv_free(*var);
|
||||||
*var = val.value;
|
*var = val.value;
|
||||||
break;
|
break;
|
||||||
@@ -463,7 +464,7 @@ jv jq_next(jq_state *jq) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void jq_init(struct bytecode* bc, jv input, jq_state **jq) {
|
void jq_init(struct bytecode* bc, jv input, jq_state **jq, int flags) {
|
||||||
jq_state *new_jq;
|
jq_state *new_jq;
|
||||||
new_jq = jv_mem_alloc(sizeof(*new_jq));
|
new_jq = jv_mem_alloc(sizeof(*new_jq));
|
||||||
memset(new_jq, 0, sizeof(*new_jq));
|
memset(new_jq, 0, sizeof(*new_jq));
|
||||||
@@ -475,6 +476,11 @@ void jq_init(struct bytecode* bc, jv input, jq_state **jq) {
|
|||||||
struct closure top = {bc, -1};
|
struct closure top = {bc, -1};
|
||||||
frame_push(&new_jq->frame_stk, top, 0);
|
frame_push(&new_jq->frame_stk, top, 0);
|
||||||
frame_push_backtrack(&new_jq->frame_stk, bc->code);
|
frame_push_backtrack(&new_jq->frame_stk, bc->code);
|
||||||
|
if (flags & JQ_DEBUG_TRACE) {
|
||||||
|
new_jq->debug_trace_enabled = 1;
|
||||||
|
} else {
|
||||||
|
new_jq->debug_trace_enabled = 0;
|
||||||
|
}
|
||||||
*jq = new_jq;
|
*jq = new_jq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
struct bytecode* jq_compile(const char* str);
|
struct bytecode* jq_compile(const char* str);
|
||||||
|
|
||||||
typedef struct jq_state jq_state;
|
typedef struct jq_state jq_state;
|
||||||
|
enum {JQ_DEBUG_TRACE = 1};
|
||||||
|
|
||||||
void jq_init(struct bytecode* bc, jv value, jq_state **);
|
void jq_init(struct bytecode* bc, jv value, jq_state **, int flags);
|
||||||
jv jq_next(jq_state *);
|
jv jq_next(jq_state *);
|
||||||
void jq_teardown(jq_state **);
|
void jq_teardown(jq_state **);
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ static void run_jq_tests() {
|
|||||||
fgets(buf, sizeof(buf), testdata);
|
fgets(buf, sizeof(buf), testdata);
|
||||||
jv input = jv_parse(buf);
|
jv input = jv_parse(buf);
|
||||||
if (!jv_is_valid(input)){ invalid++; continue; }
|
if (!jv_is_valid(input)){ invalid++; continue; }
|
||||||
jq_init(bc, input, &jq);
|
jq_init(bc, input, &jq, JQ_DEBUG_TRACE);
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), testdata)) {
|
while (fgets(buf, sizeof(buf), testdata)) {
|
||||||
if (skipline(buf)) break;
|
if (skipline(buf)) break;
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ void* jv_mem_realloc(void* p, size_t sz) {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if JQ_DEBUG
|
#ifndef NDEBUG
|
||||||
volatile char jv_mem_uninitialised;
|
volatile char jv_mem_uninitialised;
|
||||||
__attribute__((constructor)) void jv_mem_uninit_setup(){
|
__attribute__((constructor)) void jv_mem_uninit_setup(){
|
||||||
char* p = malloc(1);
|
char* p = malloc(1);
|
||||||
|
|||||||
+2
-2
@@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#if JQ_DEBUG
|
#ifndef NDEBUG
|
||||||
extern volatile char jv_mem_uninitialised;
|
extern volatile char jv_mem_uninitialised;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void jv_mem_invalidate(void* mem, size_t n) {
|
static void jv_mem_invalidate(void* mem, size_t n) {
|
||||||
#if JQ_DEBUG
|
#ifndef NDEBUG
|
||||||
char* m = mem;
|
char* m = mem;
|
||||||
while (n--) *m++ ^= jv_mem_uninitialised ^ jv_mem_uninitialised;
|
while (n--) *m++ ^= jv_mem_uninitialised ^ jv_mem_uninitialised;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ enum {
|
|||||||
static int options = 0;
|
static int options = 0;
|
||||||
static struct bytecode* bc;
|
static struct bytecode* bc;
|
||||||
|
|
||||||
static void process(jv value) {
|
static void process(jv value, int flags) {
|
||||||
jq_state *jq = NULL;
|
jq_state *jq = NULL;
|
||||||
jq_init(bc, value, &jq);
|
jq_init(bc, value, &jq, flags);
|
||||||
jv result;
|
jv result;
|
||||||
while (jv_is_valid(result = jq_next(jq))) {
|
while (jv_is_valid(result = jq_next(jq))) {
|
||||||
if ((options & RAW_OUTPUT) && jv_get_kind(result) == JV_KIND_STRING) {
|
if ((options & RAW_OUTPUT) && jv_get_kind(result) == JV_KIND_STRING) {
|
||||||
@@ -153,6 +153,7 @@ int main(int argc, char* argv[]) {
|
|||||||
input_filenames = jv_mem_alloc(sizeof(const char*) * argc);
|
input_filenames = jv_mem_alloc(sizeof(const char*) * argc);
|
||||||
ninput_files = 0;
|
ninput_files = 0;
|
||||||
int further_args_are_files = 0;
|
int further_args_are_files = 0;
|
||||||
|
int jq_flags = 0;
|
||||||
for (int i=1; i<argc; i++) {
|
for (int i=1; i<argc; i++) {
|
||||||
if (further_args_are_files) {
|
if (further_args_are_files) {
|
||||||
input_filenames[ninput_files++] = argv[i];
|
input_filenames[ninput_files++] = argv[i];
|
||||||
@@ -185,6 +186,8 @@ int main(int argc, char* argv[]) {
|
|||||||
options |= FROM_FILE;
|
options |= FROM_FILE;
|
||||||
} else if (isoption(argv[i], 0, "debug-dump-disasm")) {
|
} else if (isoption(argv[i], 0, "debug-dump-disasm")) {
|
||||||
options |= DUMP_DISASM;
|
options |= DUMP_DISASM;
|
||||||
|
} else if (isoption(argv[i], 0, "debug-trace")) {
|
||||||
|
jq_flags |= JQ_DEBUG_TRACE;
|
||||||
} else if (isoption(argv[i], 'h', "help")) {
|
} else if (isoption(argv[i], 'h', "help")) {
|
||||||
usage();
|
usage();
|
||||||
} else if (isoption(argv[i], 'V', "version")) {
|
} else if (isoption(argv[i], 'V', "version")) {
|
||||||
@@ -224,7 +227,7 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options & PROVIDE_NULL) {
|
if (options & PROVIDE_NULL) {
|
||||||
process(jv_null());
|
process(jv_null(), jq_flags);
|
||||||
} else {
|
} else {
|
||||||
jv slurped;
|
jv slurped;
|
||||||
if (options & SLURP) {
|
if (options & SLURP) {
|
||||||
@@ -245,7 +248,7 @@ int main(int argc, char* argv[]) {
|
|||||||
slurped = jv_string_concat(slurped, jv_string(buf));
|
slurped = jv_string_concat(slurped, jv_string(buf));
|
||||||
} else {
|
} else {
|
||||||
if (buf[len-1] == '\n') buf[len-1] = 0;
|
if (buf[len-1] == '\n') buf[len-1] = 0;
|
||||||
process(jv_string(buf));
|
process(jv_string(buf), jq_flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -255,7 +258,7 @@ int main(int argc, char* argv[]) {
|
|||||||
if (options & SLURP) {
|
if (options & SLURP) {
|
||||||
slurped = jv_array_append(slurped, value);
|
slurped = jv_array_append(slurped, value);
|
||||||
} else {
|
} else {
|
||||||
process(value);
|
process(value, jq_flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (jv_invalid_has_msg(jv_copy(value))) {
|
if (jv_invalid_has_msg(jv_copy(value))) {
|
||||||
@@ -270,7 +273,7 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
jv_parser_free(&parser);
|
jv_parser_free(&parser);
|
||||||
if (options & SLURP) {
|
if (options & SLURP) {
|
||||||
process(slurped);
|
process(slurped, jq_flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jv_mem_free(input_filenames);
|
jv_mem_free(input_filenames);
|
||||||
|
|||||||
Reference in new issue
Block a user