diff --git a/include/QF/progs.h b/include/QF/progs.h index 7ccb962d2..e6ea11575 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -292,9 +292,9 @@ void ED_Count (progs_t *pr); qboolean PR_EdictValid (progs_t *pr, pr_int_t e) __attribute__((pure)); // pr_debug.c -void ED_Print (progs_t *pr, edict_t *ed); +void ED_Print (progs_t *pr, edict_t *ed, const char *fieldname); void ED_PrintEdicts (progs_t *pr, const char *fieldval); -void ED_PrintNum (progs_t *pr, pr_int_t ent); +void ED_PrintNum (progs_t *pr, pr_int_t ent, const char *fieldname); // pr_parse.c struct script_s; diff --git a/libs/gamecode/pr_debug.c b/libs/gamecode/pr_debug.c index 6a73f762d..535bcab5b 100644 --- a/libs/gamecode/pr_debug.c +++ b/libs/gamecode/pr_debug.c @@ -1716,23 +1716,42 @@ PR_Profile (progs_t * pr) } while (best); } +static void +print_field (progs_t *pr, edict_t *ed, pr_def_t *d) +{ + prdeb_resources_t *res = pr->pr_debug_resources; + int l; + pr_type_t *v; + qfot_type_t dummy_type = { }; + qfot_type_t *type; + pr_debug_data_t data = {pr, res->dstr}; + const char *name; + + name = PR_GetString (pr, d->name); + type = get_def_type (pr, d, &dummy_type); + v = &E_fld (ed, d->ofs); + + l = 15 - strlen (name); + if (l < 1) + l = 1; + + dstring_clearstr (res->dstr); + value_string (&data, type, v); + Sys_Printf ("%s%*s%s\n", name, l, "", res->dstr->str); +} + /* ED_Print For debugging */ VISIBLE void -ED_Print (progs_t *pr, edict_t *ed) +ED_Print (progs_t *pr, edict_t *ed, const char *fieldname) { - prdeb_resources_t *res = pr->pr_debug_resources; - int l; pr_uint_t i, j; const char *name; pr_def_t *d; - pr_type_t *v; - qfot_type_t dummy_type = { }; - qfot_type_t *type; - pr_debug_data_t data = {pr, res->dstr}; + int l; if (ed->free) { Sys_Printf ("FREE\n"); @@ -1740,14 +1759,23 @@ ED_Print (progs_t *pr, edict_t *ed) } Sys_Printf ("\nEDICT %d:\n", NUM_FOR_BAD_EDICT (pr, ed)); + + if (fieldname) { + d = PR_FindField(pr, fieldname); + if (!d) { + Sys_Printf ("unknown field '%s'\n", fieldname); + } else { + print_field (pr, ed, d); + } + return; + } for (i = 0; i < pr->progs->numfielddefs; i++) { d = &pr->pr_fielddefs[i]; if (!d->name) // null field def (probably 1st) continue; - type = get_def_type (pr, d, &dummy_type); name = PR_GetString (pr, d->name); - if (name[strlen (name) - 2] == '_' - && strchr ("xyz", name[strlen (name) -1])) + l = strlen (name); + if (l >= 2 && name[l - 2] == '_' && strchr ("xyz", name[l - 1])) continue; // skip _x, _y, _z vars for (j = 0; j < d->size; j++) { @@ -1759,15 +1787,7 @@ ED_Print (progs_t *pr, edict_t *ed) continue; } - v = &E_fld (ed, d->ofs); - - l = 15 - strlen (name); - if (l < 1) - l = 1; - - dstring_clearstr (res->dstr); - value_string (&data, type, v); - Sys_Printf ("%s%*s%s\n", name, l, "", res->dstr->str); + print_field (pr, ed, d); } } diff --git a/libs/gamecode/pr_edict.c b/libs/gamecode/pr_edict.c index 55a96124e..60233a0ce 100644 --- a/libs/gamecode/pr_edict.c +++ b/libs/gamecode/pr_edict.c @@ -132,13 +132,13 @@ ED_Free (progs_t *pr, edict_t *ed) VISIBLE void -ED_PrintNum (progs_t *pr, pr_int_t ent) +ED_PrintNum (progs_t *pr, pr_int_t ent, const char *fieldname) { if (!pr->num_edicts) { Sys_Printf ("Edicts not supported in this VM\n"); return; } - ED_Print (pr, EDICT_NUM (pr, ent)); + ED_Print (pr, EDICT_NUM (pr, ent), fieldname); } /* @@ -164,13 +164,13 @@ ED_PrintEdicts (progs_t *pr, const char *fieldval) for (i = 0; i < *pr->num_edicts; i++) if (strequal(fieldval, E_GSTRING (pr, EDICT_NUM(pr, i), def->ofs))) { - ED_PrintNum (pr, i); + ED_PrintNum (pr, i, 0); count++; } Sys_Printf ("%i entities\n", count); } else { for (i = 0; i < *pr->num_edicts; i++) - ED_PrintNum (pr, i); + ED_PrintNum (pr, i, 0); Sys_Printf ("%i entities\n", *pr->num_edicts); } } diff --git a/libs/gamecode/pr_parse.c b/libs/gamecode/pr_parse.c index a4c327940..cfc170815 100644 --- a/libs/gamecode/pr_parse.c +++ b/libs/gamecode/pr_parse.c @@ -475,7 +475,7 @@ ED_SpawnEntities (progs_t *pr, plitem_t *entity_list) func = PR_FindFunction (pr, classname); if (!func) { Sys_Printf ("No spawn function for :\n"); - ED_Print (pr, ent); + ED_Print (pr, ent, 0); ED_Free (pr, ent); continue; } diff --git a/libs/ruamoko/pr_cmds.c b/libs/ruamoko/pr_cmds.c index 8836de8c9..16f5a21f4 100644 --- a/libs/ruamoko/pr_cmds.c +++ b/libs/ruamoko/pr_cmds.c @@ -343,7 +343,7 @@ PF_traceoff (progs_t *pr) static void PF_eprint (progs_t *pr) { - ED_PrintNum (pr, P_EDICTNUM (pr, 0)); + ED_PrintNum (pr, P_EDICTNUM (pr, 0), 0); } /* diff --git a/nq/source/sv_pr_cmds.c b/nq/source/sv_pr_cmds.c index 7bb54d429..c39afff9e 100644 --- a/nq/source/sv_pr_cmds.c +++ b/nq/source/sv_pr_cmds.c @@ -74,7 +74,7 @@ PF_error (progs_t *pr) Sys_Printf ("======SERVER ERROR in %s:\n%s\n", PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s); ed = PROG_TO_EDICT (pr, *sv_globals.self); - ED_Print (pr, ed); + ED_Print (pr, ed, 0); Host_Error ("Program error"); } @@ -98,7 +98,7 @@ PF_objerror (progs_t *pr) Sys_Printf ("======OBJECT ERROR in %s:\n%s\n", PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s); ed = PROG_TO_EDICT (pr, *sv_globals.self); - ED_Print (pr, ed); + ED_Print (pr, ed, 0); ED_Free (pr, ed); Host_Error ("Program error"); diff --git a/nq/source/sv_progs.c b/nq/source/sv_progs.c index 4cc567c16..58f79bc7e 100644 --- a/nq/source/sv_progs.c +++ b/nq/source/sv_progs.c @@ -126,10 +126,17 @@ static void ED_PrintEdict_f (void) { int i; + const char *fieldname = 0; + if (Cmd_Argc () < 2) { + Sys_Printf ("edict num [fieldname]\n"); + return; + } + if (Cmd_Argc () >= 3) { + fieldname = Cmd_Argv (2); + } i = atoi (Cmd_Argv (1)); - Sys_Printf ("\n EDICT %i:\n", i); - ED_PrintNum (&sv_pr_state, i); + ED_PrintNum (&sv_pr_state, i, fieldname); } static void diff --git a/qw/source/sv_pr_cmds.c b/qw/source/sv_pr_cmds.c index 965c79727..2b924ed52 100644 --- a/qw/source/sv_pr_cmds.c +++ b/qw/source/sv_pr_cmds.c @@ -76,7 +76,7 @@ PF_error (progs_t *pr) Sys_Printf ("======SERVER ERROR in %s:\n%s\n", PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s); ed = PROG_TO_EDICT (pr, *sv_globals.self); - ED_Print (pr, ed); + ED_Print (pr, ed, 0); Sys_Error ("Program error"); } @@ -100,7 +100,7 @@ PF_objerror (progs_t *pr) Sys_Printf ("======OBJECT ERROR in %s:\n%s\n", PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s); ed = PROG_TO_EDICT (pr, *sv_globals.self); - ED_Print (pr, ed); + ED_Print (pr, ed, 0); ED_Free (pr, ed); PR_RunError (pr, "object error"); diff --git a/qw/source/sv_progs.c b/qw/source/sv_progs.c index acb39f63c..124a78dd3 100644 --- a/qw/source/sv_progs.c +++ b/qw/source/sv_progs.c @@ -151,10 +151,17 @@ static void ED_PrintEdict_f (void) { int i; + const char *fieldname = 0; + if (Cmd_Argc () < 2) { + SV_Printf ("edict num [fieldname]\n"); + return; + } + if (Cmd_Argc () >= 3) { + fieldname = Cmd_Argv (2); + } i = atoi (Cmd_Argv (1)); - SV_Printf ("\n EDICT %i:\n", i); - ED_PrintNum (&sv_pr_state, i); + ED_PrintNum (&sv_pr_state, i, fieldname); } static void