From edcc313501772bcf3317dd8f7658bccd468ca741 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 19 Jul 2001 07:27:14 +0000 Subject: [PATCH] debug info for local variables is now used. only works when tracing atm:/ --- include/QF/progs.h | 2 ++ libs/gamecode/pr_debug.c | 41 ++++++++++++++++++++++++++++++++++------ libs/gamecode/pr_edict.c | 18 +++++++++++++----- libs/gamecode/pr_exec.c | 12 ++++-------- tools/qwaq/main.qc | 13 ++++++++++++- 5 files changed, 66 insertions(+), 20 deletions(-) diff --git a/include/QF/progs.h b/include/QF/progs.h index ce6941ffb..e3a11f112 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -176,6 +176,7 @@ unsigned long PR_Get_Lineno_Line (progs_t *pr, pr_lineno_t *lineno); pr_lineno_t *PR_Find_Lineno (progs_t *pr, unsigned long addr); const char *PR_Get_Source_File (progs_t *pr, pr_lineno_t *lineno); const char *PR_Get_Source_Line (progs_t *pr, unsigned long addr); +ddef_t *PR_Get_Local_Def (progs_t *pr, int offs); extern struct cvar_s *pr_debug; @@ -256,6 +257,7 @@ struct progs_s { char *debugfile; struct pr_debug_header_s *debug; struct pr_auxfunction_s *auxfunctions; + struct pr_auxfunction_s **auxfunction_map; struct pr_lineno_s *linenos; ddef_t *local_defs; diff --git a/libs/gamecode/pr_debug.c b/libs/gamecode/pr_debug.c index 0d413cdd6..e9d120198 100644 --- a/libs/gamecode/pr_debug.c +++ b/libs/gamecode/pr_debug.c @@ -123,6 +123,15 @@ PR_LoadDebug (progs_t *pr) char *sym_path; ddef_t *def; + pr->debug = 0; + pr->auxfunctions = 0; + pr->auxfunction_map = 0; + pr->linenos = 0; + pr->local_defs = 0; + + if (!pr_debug->int_val) + return; + def = PR_FindGlobal (pr, ".debug_file"); if (def) str = &pr->pr_globals[def->ofs]; @@ -150,9 +159,6 @@ PR_LoadDebug (progs_t *pr) pr->debug->version & 0xfff); Hunk_FreeToLowMark (start); pr->debug = 0; - pr->auxfunctions = 0; - pr->linenos = 0; - pr->local_defs = 0; return; } pr->debug->crc = LittleShort (pr->debug->crc); @@ -164,9 +170,6 @@ PR_LoadDebug (progs_t *pr) pr->crc); Hunk_FreeToLowMark (start); pr->debug = 0; - pr->auxfunctions = 0; - pr->linenos = 0; - pr->local_defs = 0; return; } pr->debug->you_tell_me_and_we_will_both_know = LittleShort (pr->debug->you_tell_me_and_we_will_both_know); @@ -181,12 +184,17 @@ PR_LoadDebug (progs_t *pr) pr->linenos = (pr_lineno_t*)((char*)pr->debug + pr->debug->linenos); pr->local_defs = (ddef_t*)((char*)pr->debug + pr->debug->locals); + pr->auxfunction_map = Hunk_Alloc (pr->progs->numfunctions + * sizeof (pr_auxfunction_t*)); + for (i = 0; i < pr->debug->num_auxfunctions; i++) { pr->auxfunctions[i].function = LittleLong (pr->auxfunctions[i].function); pr->auxfunctions[i].source_line = LittleLong (pr->auxfunctions[i].source_line); pr->auxfunctions[i].line_info = LittleLong (pr->auxfunctions[i].line_info); pr->auxfunctions[i].local_defs = LittleLong (pr->auxfunctions[i].local_defs); pr->auxfunctions[i].num_locals = LittleLong (pr->auxfunctions[i].num_locals); + + pr->auxfunction_map[pr->auxfunctions[i].function] = &pr->auxfunctions[i]; } for (i = 0; i < pr->debug->num_linenos; i++) { pr->linenos[i].fa.func = LittleLong (pr->linenos[i].fa.func); @@ -292,6 +300,27 @@ PR_Get_Source_Line (progs_t *pr, unsigned long addr) return str; } +ddef_t * +PR_Get_Local_Def (progs_t *pr, int offs) +{ + int i; + dfunction_t *func = pr->pr_xfunction; + pr_auxfunction_t *aux_func; + + if (!func) + return 0; + aux_func = pr->auxfunction_map[func - pr->pr_functions]; + if (!aux_func) + return 0; + offs -= func->parm_start; + if (offs < 0 || offs >= func->locals) + return 0; + for (i = 0; i < aux_func->num_locals; i++) + if (pr->local_defs[aux_func->local_defs + i].ofs == offs) + return &pr->local_defs[aux_func->local_defs + i]; + return 0; +} + static const char * file_get_key (void *_f, void *unused) { diff --git a/libs/gamecode/pr_edict.c b/libs/gamecode/pr_edict.c index 1884b7a22..204cf356b 100644 --- a/libs/gamecode/pr_edict.c +++ b/libs/gamecode/pr_edict.c @@ -451,12 +451,15 @@ PR_GlobalString (progs_t * pr, int ofs) { char *s; int i; - ddef_t *def; + ddef_t *def = 0; void *val; static char line[128]; + if (pr_debug->int_val && pr->debug) + def = PR_Get_Local_Def (pr, ofs); val = (void *) &pr->pr_globals[ofs]; - def = ED_GlobalAtOfs (pr, ofs); + if (!def) + def = ED_GlobalAtOfs (pr, ofs); if (!def) snprintf (line, sizeof (line), "%i(?)", ofs); else { @@ -477,10 +480,13 @@ char * PR_GlobalStringNoContents (progs_t * pr, int ofs) { int i; - ddef_t *def; + ddef_t *def = 0; static char line[128]; - def = ED_GlobalAtOfs (pr, ofs); + if (pr_debug->int_val && pr->debug) + def = PR_Get_Local_Def (pr, ofs); + if (!def) + def = ED_GlobalAtOfs (pr, ofs); if (!def) snprintf (line, sizeof (line), "%i(?)", ofs); else @@ -1160,7 +1166,9 @@ PR_LoadProgs (progs_t * pr, const char *progsname) PR_LoadDebug (pr); // LordHavoc: bounds check anything static - for (i = 0, st = pr->pr_statements; i < pr->progs->numstatements; i++, st++) { + for (i = 0, st = pr->pr_statements; + i < pr->progs->numstatements; + i++, st++) { switch (st->op) { case OP_IF: case OP_IFNOT: diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index 389fcdb95..bf3166808 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -58,7 +58,7 @@ PR_PrintStatement (progs_t * pr, dstatement_t *s) int addr = s - pr->pr_statements; opcode_t *op; - if (pr_debug->int_val) { + if (pr_debug->int_val && pr->debug) { const char *source_line = PR_Get_Source_Line (pr, addr); if (source_line) @@ -169,7 +169,7 @@ PR_RunError (progs_t * pr, const char *error, ...) vsnprintf (string, sizeof (string), error, argptr); va_end (argptr); - if (pr_debug->int_val) { + if (pr_debug->int_val && pr->debug) { int addr = pr->pr_xstatement; while (!PR_Get_Source_Line (pr, addr)) @@ -187,12 +187,6 @@ PR_RunError (progs_t * pr, const char *error, ...) PR_Error (pr, "Program error"); } -/* - PR_ExecuteProgram - - The interpretation main loop -*/ - /* PR_EnterFunction @@ -265,6 +259,8 @@ PR_LeaveFunction (progs_t * pr) /* PR_ExecuteProgram + + The interpretation main loop */ #define OPA (pr->pr_globals[(unsigned short) st->a]) #define OPB (pr->pr_globals[(unsigned short) st->b]) diff --git a/tools/qwaq/main.qc b/tools/qwaq/main.qc index 6cb5af71d..d75d19ce8 100644 --- a/tools/qwaq/main.qc +++ b/tools/qwaq/main.qc @@ -1,3 +1,9 @@ +#define NIT_TESLA 32768 //The *real* bug zapper! +#define NIT_SECURITY_CAMERA 65536 //CH Security Camera +#define NIT_TELEPORTER 131072 //CH Teleporter +#define PC_ENGINEER_TF_ITEMS NIT_TESLA | NIT_SECURITY_CAMERA | NIT_TELEPORTER + +//float messed_or = PC_ENGINEER_TF_ITEMS; float foo = 1; float bar = 1; float snafu = 2; @@ -7,9 +13,12 @@ void () eek; float () main = { + local float messed_or; local float handle; local string buffer; + traceon(); + messed_or = PC_ENGINEER_TF_ITEMS; handle = open ("main.qc", 0); if (handle == -1) { print (strerror (errno ()) + "\n"); @@ -59,10 +68,12 @@ void () blarg = } }; +.entity owner; +entity sent; void () eek = { traceon(); - if (self && self.origin) + if (sent && sent.owner != self ) self.origin = '0 0 0'; self.origin = self.origin + '1 2 3'; traceoff();