]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
qcvm -trace now shows the current function name and nest-depth
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 11 Nov 2012 22:57:42 +0000 (23:57 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 11 Nov 2012 22:57:42 +0000 (23:57 +0100)
exec.c
gmqcc.h

diff --git a/exec.c b/exec.c
index c90444ad180831e65a6debc635f920d00b8aefba..724ff786843d764344791b0559cc92dce39d1279 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -50,6 +50,8 @@ MEM_VEC_FUN_RESIZE(qc_program,  size_t, profile)
 
 MEM_VEC_FUNCTIONS(qc_program,   prog_builtin, builtins)
 
+MEM_VEC_FUNCTIONS(qc_program,   const char*, function_stack)
+
 static void loaderror(const char *fmt, ...)
 {
     int     err = errno;
@@ -417,6 +419,12 @@ static void prog_print_statement(qc_program *prog, prog_section_statement *st)
         printf("<illegal instruction %d>\n", st->opcode);
         return;
     }
+    if ((prog->xflags & VMXF_TRACE) && prog->function_stack_count) {
+        size_t i;
+        for (i = 0; i < prog->function_stack_count; ++i)
+            printf("->");
+        printf("%s:", prog->function_stack[prog->function_stack_count-1]);
+    }
     printf(" <> %-12s", asm_instr[st->opcode].m);
     if (st->opcode >= INSTR_IF &&
         st->opcode <= INSTR_IFNOT)
@@ -514,6 +522,10 @@ static qcint prog_enterfunction(qc_program *prog, prog_section_function *func)
     st.stmt     = prog->statement;
     st.function = func;
 
+    if (prog->xflags & VMXF_TRACE) {
+        (void)!qc_program_function_stack_add(prog, prog_getstring(prog, func->name));
+    }
+
 #ifdef QCVM_BACKUP_STRATEGY_CALLER_VARS
     if (prog->stack_count)
     {
@@ -566,6 +578,11 @@ static qcint prog_leavefunction(qc_program *prog)
 
     qc_exec_stack st = prog->stack[prog->stack_count-1];
 
+    if (prog->xflags & VMXF_TRACE) {
+        if (prog->function_stack_count)
+            prog->function_stack_count--;
+    }
+
 #ifdef QCVM_BACKUP_STRATEGY_CALLER_VARS
     if (prog->stack_count > 1) {
         prev  = prog->stack[prog->stack_count-2].function;
diff --git a/gmqcc.h b/gmqcc.h
index 304cdaafe05eb27cb2668cbcf34d0fcaf7b2db04..ef1841f713f73948bad62a805dfbb80618a4831e 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -876,6 +876,8 @@ typedef struct qc_program_s {
     MEM_VECTOR_MAKE(qcint,                  entitydata);
     MEM_VECTOR_MAKE(bool,                   entitypool);
 
+    MEM_VECTOR_MAKE(const char*,            function_stack);
+
     uint16_t crc16;
 
     size_t tempstring_start;