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:
Stephen Dolan committed 2013-05-05 23:12:10 +01:00
1 parent c1748fa633
commit 1741d8c161
7 files changed
+31 -25

No files matched your search

+3 -7
View File
@@ -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_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
$(CC) $(CFLAGS) $(CFLAGS_OPT) -o $@ $^
test: jq_test
valgrind --error-exitcode=1 -q --leak-check=full ./jq_test --run-tests >/dev/null
test: jq
valgrind --error-exitcode=1 -q --leak-check=full ./jq --run-tests >/dev/null
LIBRARIES=libjq
BINARIES=jq jq_test
BINARIES=jq
PLATFORMS=linux32 linux64 osx32 osx64 win32 win64
build/linux32%: CC='x86_64-linux-gnu-gcc -m32'
+13 -7
View File
@@ -29,6 +29,7 @@ struct jq_state {
struct forkable_stack fork_stk;
jv* pathbuf;
int pathsize; // number of allocated elements
int debug_trace_enabled;
};
int path_push(jq_state *jq, stackval sv, jv val) {
@@ -162,7 +163,7 @@ jv jq_next(jq_state *jq) {
while (1) {
uint16_t opcode = *pc;
#if JQ_DEBUG
if (jq->debug_trace_enabled) {
dump_operation(frame_current_bytecode(&jq->frame_stk), pc);
printf("\t");
const struct opcode_description* opdesc = opcode_describe(opcode);
@@ -184,7 +185,7 @@ jv jq_next(jq_state *jq) {
if (backtracking) printf("\t<backtracking>");
printf("\n");
#endif
}
if (backtracking) {
opcode = ON_BACKTRACK(opcode);
backtracking = 0;
@@ -265,11 +266,11 @@ jv jq_next(jq_state *jq) {
uint16_t v = *pc++;
frame_ptr fp = frame_get_level(&jq->frame_stk, frame_current(&jq->frame_stk), level);
jv* var = frame_local_var(fp, v);
#if JQ_DEBUG
if (jq->debug_trace_enabled) {
printf("V%d = ", v);
jv_dump(jv_copy(*var), 0);
printf("\n");
#endif
}
stack_push(jq, stackval_replace(stack_pop(jq), jv_copy(*var)));
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);
jv* var = frame_local_var(fp, v);
stackval val = stack_pop(jq);
#if JQ_DEBUG
if (jq->debug_trace_enabled) {
printf("V%d = ", v);
jv_dump(jv_copy(val.value), 0);
printf("\n");
#endif
}
jv_free(*var);
*var = val.value;
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;
new_jq = jv_mem_alloc(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};
frame_push(&new_jq->frame_stk, top, 0);
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;
}
+2 -1
View File
@@ -6,8 +6,9 @@
struct bytecode* jq_compile(const char* str);
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 *);
void jq_teardown(jq_state **);
+1 -1
View File
@@ -59,7 +59,7 @@ static void run_jq_tests() {
fgets(buf, sizeof(buf), testdata);
jv input = jv_parse(buf);
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)) {
if (skipline(buf)) break;
+1 -1
View File
@@ -27,7 +27,7 @@ void* jv_mem_realloc(void* p, size_t sz) {
return p;
}
#if JQ_DEBUG
#ifndef NDEBUG
volatile char jv_mem_uninitialised;
__attribute__((constructor)) void jv_mem_uninit_setup(){
char* p = malloc(1);
+2 -2
View File
@@ -3,12 +3,12 @@
#include <stddef.h>
#if JQ_DEBUG
#ifndef NDEBUG
extern volatile char jv_mem_uninitialised;
#endif
static void jv_mem_invalidate(void* mem, size_t n) {
#if JQ_DEBUG
#ifndef NDEBUG
char* m = mem;
while (n--) *m++ ^= jv_mem_uninitialised ^ jv_mem_uninitialised;
#endif
+9 -6
View File
@@ -64,9 +64,9 @@ enum {
static int options = 0;
static struct bytecode* bc;
static void process(jv value) {
static void process(jv value, int flags) {
jq_state *jq = NULL;
jq_init(bc, value, &jq);
jq_init(bc, value, &jq, flags);
jv result;
while (jv_is_valid(result = jq_next(jq))) {
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);
ninput_files = 0;
int further_args_are_files = 0;
int jq_flags = 0;
for (int i=1; i<argc; i++) {
if (further_args_are_files) {
input_filenames[ninput_files++] = argv[i];
@@ -185,6 +186,8 @@ int main(int argc, char* argv[]) {
options |= FROM_FILE;
} else if (isoption(argv[i], 0, "debug-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")) {
usage();
} else if (isoption(argv[i], 'V', "version")) {
@@ -224,7 +227,7 @@ int main(int argc, char* argv[]) {
}
if (options & PROVIDE_NULL) {
process(jv_null());
process(jv_null(), jq_flags);
} else {
jv slurped;
if (options & SLURP) {
@@ -245,7 +248,7 @@ int main(int argc, char* argv[]) {
slurped = jv_string_concat(slurped, jv_string(buf));
} else {
if (buf[len-1] == '\n') buf[len-1] = 0;
process(jv_string(buf));
process(jv_string(buf), jq_flags);
}
}
} else {
@@ -255,7 +258,7 @@ int main(int argc, char* argv[]) {
if (options & SLURP) {
slurped = jv_array_append(slurped, value);
} else {
process(value);
process(value, jq_flags);
}
}
if (jv_invalid_has_msg(jv_copy(value))) {
@@ -270,7 +273,7 @@ int main(int argc, char* argv[]) {
}
jv_parser_free(&parser);
if (options & SLURP) {
process(slurped);
process(slurped, jq_flags);
}
}
jv_mem_free(input_filenames);