diff --git a/libs/gamecode/engine/pr_edict.c b/libs/gamecode/engine/pr_edict.c index 4cf3230d4..4ef278688 100644 --- a/libs/gamecode/engine/pr_edict.c +++ b/libs/gamecode/engine/pr_edict.c @@ -43,6 +43,7 @@ static const char rcsid[] = #include "QF/idparse.h" #include "QF/crc.h" #include "QF/cvar.h" +#include "QF/dstring.h" #include "QF/hash.h" #include "QF/progs.h" #include "QF/qdefs.h" @@ -341,27 +342,29 @@ PR_UglyValueString (progs_t * pr, etype_t type, pr_type_t *val) /* PR_GlobalString - Returns a string with a description and the contents of a global, - padded to 20 field width + Returns a string with a description and the contents of a global */ -char * +dstring_t * PR_GlobalString (progs_t * pr, int ofs, etype_t type) { - char *s; - int i; - ddef_t *def = 0; - static char line[128]; + ddef_t *def = NULL; + static dstring_t *line = NULL; + char *s; + + if (!line) + line = dstring_newstr(); if (type == ev_short) { - snprintf (line, sizeof (line), "%-20d", (short) ofs); + dsprintf (line, "%04x", (short) ofs); return line; } + if (pr_debug->int_val && pr->debug) def = PR_Get_Local_Def (pr, ofs); if (!def) def = ED_GlobalAtOfs (pr, ofs); if (!def && type == ev_void) - snprintf (line, sizeof (line), "%i(?)", ofs); + dsprintf (line, "[%04x]", ofs); else { char *name = "?"; char *oi = ""; @@ -370,48 +373,53 @@ PR_GlobalString (progs_t * pr, int ofs, etype_t type) type = def->type; name = PR_GetString (pr, def->s_name); if (type != (def->type & ~DEF_SAVEGLOBAL)) - oi = "!"; + oi = "?"; } + if (ofs > pr->globals_size) s = "Out of bounds"; else s = PR_ValueString (pr, type, &pr->pr_globals[ofs]); - snprintf (line, sizeof (line), "%i(%s%s)%s", ofs, oi, name, s); + + if (strequal(name, "IMMEDIATE") || strequal(name, ".imm")) { + if (type == ev_string) + dsprintf (line, "\"%s\"", s); + else + dsprintf (line, "%s", s); + } else if (strequal(name, "?")) + dsprintf (line, "[%04x]", ofs); + else { + if (type == ev_func) + dsprintf (line, "%s%s", name, oi); + else + dsprintf (line, "%s%s(%s)", name, oi, s); + } } - - i = strlen (line); - for (; i < 20; i++) - strncat (line, " ", sizeof (line) - strlen (line)); - strncat (line, " ", sizeof (line) - strlen (line)); - return line; } -char * +dstring_t * PR_GlobalStringNoContents (progs_t * pr, int ofs, etype_t type) { - int i; - ddef_t *def = 0; - static char line[128]; + static dstring_t *line = NULL; + ddef_t *def = NULL; + + if (!line) + line = dstring_newstr(); if (type == ev_short) { - snprintf (line, sizeof (line), "%-20d", (short) ofs); + dsprintf (line, "%x", (short) ofs); return line; } + 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); + dsprintf (line, "[%x]", ofs); else - snprintf (line, sizeof (line), "%i(%s)", ofs, - PR_GetString (pr, def->s_name)); - - i = strlen (line); - for (; i < 20; i++) - strncat (line, " ", sizeof (line) - strlen (line)); - strncat (line, " ", sizeof (line) - strlen (line)); + dsprintf (line, "%s", PR_GetString (pr, def->s_name)); return line; } diff --git a/libs/gamecode/engine/pr_exec.c b/libs/gamecode/engine/pr_exec.c index 904dc1b0d..97124ffe3 100644 --- a/libs/gamecode/engine/pr_exec.c +++ b/libs/gamecode/engine/pr_exec.c @@ -48,12 +48,12 @@ static const char rcsid[] = #include "compat.h" - void PR_PrintStatement (progs_t * pr, dstatement_t *s) { int addr = s - pr->pr_statements; - opcode_t *op; + int ofs; + opcode_t *op; if (pr_debug->int_val && pr->debug) { const char *source_line = PR_Get_Source_Line (pr, addr); @@ -61,41 +61,65 @@ PR_PrintStatement (progs_t * pr, dstatement_t *s) if (source_line) Sys_Printf ("%s\n", source_line); } - Sys_Printf ("%-7d ", addr); + op = PR_Opcode (s->op); if (!op) { - Sys_Printf ("unknown opcode %d\n", s->op); + Sys_Printf ("Unknown instruction %d\n", s->op); return; } - Sys_Printf ("%-9s ", op->opname); - if (s->op == OP_IF || s->op == OP_IFNOT || s->op == OP_IFBE - || s->op == OP_IFB || s->op == OP_IFAE || s->op == OP_IFA) { - int ofs = (short) s->b; - Sys_Printf ("%sbranch %i (%i)", - PR_GlobalString (pr, s->a, ev_integer), ofs, addr + ofs); - } else if (s->op == OP_GOTO) { - int ofs = (short) s->a; - Sys_Printf ("branch %i (%i)", ofs, addr + ofs); - } else if (s->op == OP_RETURN || s->op == OP_DONE) { - Sys_Printf ("%s", PR_GlobalString (pr, s->a, ev_void)); - } else { - if (op->type_a != ev_void) - Sys_Printf ("%s", PR_GlobalString (pr, s->a, op->type_a)); - if (op->type_b != ev_void) { - if (op->type_c != ev_void) - Sys_Printf ("%s", PR_GlobalString (pr, s->b, op->type_b)); - else - Sys_Printf ("%s", PR_GlobalStringNoContents (pr, s->b, - op->type_b)); - } - if (op->type_c != ev_void) { - if (op->type_b == ev_pointer && op->type_c == ev_integer) - Sys_Printf ("%s", PR_GlobalString (pr, s->c, op->type_c)); - else - Sys_Printf ("%s", PR_GlobalStringNoContents (pr, s->c, - op->type_c)); - } + Sys_Printf ("%04x ", addr); + if (pr_debug->int_val > 1) + Sys_Printf ("%02x %04x(%s) %04x(%s) %04x(%s)\t", + s->op, + s->a, pr_type_name[op->type_a], + s->b, pr_type_name[op->type_b], + s->c, pr_type_name[op->type_c]); + + Sys_Printf ("%s ", op->opname); + + switch (s->op) { + case OP_IF: + case OP_IFNOT: + case OP_IFBE: + case OP_IFB: + case OP_IFAE: + case OP_IFA: + ofs = (short) s->b; + + Sys_Printf ("%s branch %i (%i)", + PR_GlobalString (pr, s->a, ev_integer)->str, ofs, addr + ofs); + break; + + case OP_GOTO: + ofs = (short) s->a; + Sys_Printf ("branch %i (%i)", ofs, addr + ofs); + break; + + case OP_RETURN: + case OP_DONE: + Sys_Printf ("%s", PR_GlobalString (pr, s->a, ev_void)->str); + break; + + default: + if (op->type_a != ev_void) + Sys_Printf ("%s", PR_GlobalString (pr, s->a, op->type_a)->str); + + if (op->type_b != ev_void) { + if (op->type_c != ev_void) + Sys_Printf (", %s", PR_GlobalString (pr, s->b, op->type_b)->str); + else + Sys_Printf (", %s", + PR_GlobalStringNoContents (pr, s->b, op->type_b)->str); + } + + if (op->type_c != ev_void) { + if (op->type_b == ev_pointer && op->type_c == ev_integer) + Sys_Printf (", %s", PR_GlobalString (pr, s->c, op->type_c)->str); + else + Sys_Printf (", %s", + PR_GlobalStringNoContents (pr, s->c, op->type_c)->str); + } } Sys_Printf ("\n"); }