2001-07-14 23:53:59 +00:00
|
|
|
/*
|
|
|
|
pr_debug.c
|
|
|
|
|
|
|
|
progs debugging
|
|
|
|
|
|
|
|
Copyright (C) 2001 Bill Currie <bill@tanwiha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@tanwiha.org>
|
|
|
|
Date: 2001/7/13
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2007-04-28 01:40:08 +00:00
|
|
|
#include <ctype.h>
|
2001-09-10 12:56:23 +00:00
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
2002-10-23 20:42:02 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-07-14 23:53:59 +00:00
|
|
|
#include "QF/hash.h"
|
|
|
|
#include "QF/pr_debug.h"
|
|
|
|
#include "QF/progs.h"
|
|
|
|
#include "QF/qendian.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-07-14 23:53:59 +00:00
|
|
|
#include "QF/sys.h"
|
2004-01-30 07:55:32 +00:00
|
|
|
#include "QF/va.h"
|
2001-07-14 23:53:59 +00:00
|
|
|
#include "QF/zone.h"
|
|
|
|
|
2003-02-24 16:01:52 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
typedef struct {
|
|
|
|
char *text;
|
|
|
|
size_t len;
|
|
|
|
} line_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *name;
|
|
|
|
char *text;
|
|
|
|
line_t *lines;
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t num_lines;
|
2002-06-11 17:24:37 +00:00
|
|
|
progs_t *pr;
|
2001-07-14 23:53:59 +00:00
|
|
|
} file_t;
|
|
|
|
|
2003-03-12 22:31:44 +00:00
|
|
|
cvar_t *pr_debug;
|
|
|
|
cvar_t *pr_source_path;
|
|
|
|
static hashtab_t *file_hash;
|
|
|
|
static char *source_path_string;
|
|
|
|
static char **source_paths;
|
2001-07-14 23:53:59 +00:00
|
|
|
|
2001-09-10 12:56:23 +00:00
|
|
|
|
2001-10-08 03:46:44 +00:00
|
|
|
static const char *
|
|
|
|
file_get_key (void *_f, void *unused)
|
|
|
|
{
|
|
|
|
return ((file_t*)_f)->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_free (void *_f, void *unused)
|
|
|
|
{
|
2002-06-11 17:24:37 +00:00
|
|
|
file_t *f = (file_t*)_f;
|
|
|
|
progs_t *pr = f->pr;
|
|
|
|
|
2001-10-08 03:46:44 +00:00
|
|
|
free (f->lines);
|
2002-06-11 17:24:37 +00:00
|
|
|
((progs_t *) pr)->free_progs_mem (pr, f->text);
|
2001-10-08 03:46:44 +00:00
|
|
|
free (f->name);
|
|
|
|
free (f);
|
|
|
|
}
|
|
|
|
|
2003-03-12 22:31:44 +00:00
|
|
|
static void
|
|
|
|
source_path_f (cvar_t *var)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (source_path_string)
|
|
|
|
free (source_path_string);
|
|
|
|
source_path_string = strdup (var->string);
|
|
|
|
if (source_paths)
|
|
|
|
free (source_paths);
|
|
|
|
for (i = 2, s = source_path_string; *s; s++)
|
|
|
|
if (*s == ';')
|
|
|
|
i++;
|
|
|
|
source_paths = malloc (i * sizeof (char **));
|
|
|
|
source_paths[0] = source_path_string;
|
|
|
|
for (i = 1, s = source_path_string; *s; s++)
|
|
|
|
if (*s == ';') {
|
|
|
|
*s++ = 0;
|
|
|
|
source_paths[i++] = s;
|
|
|
|
}
|
|
|
|
source_paths[i] = 0;
|
|
|
|
}
|
|
|
|
|
2001-10-08 03:46:44 +00:00
|
|
|
void
|
|
|
|
PR_Debug_Init (void)
|
|
|
|
{
|
|
|
|
file_hash = Hash_NewTable (1024, file_get_key, file_free, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PR_Debug_Init_Cvars (void)
|
|
|
|
{
|
|
|
|
pr_debug = Cvar_Get ("pr_debug", "0", CVAR_NONE, NULL,
|
|
|
|
"enable progs debugging");
|
2003-03-12 22:31:44 +00:00
|
|
|
pr_source_path = Cvar_Get ("pr_source_path", ".", CVAR_NONE, source_path_f,
|
|
|
|
"where to look (within gamedir) for source "
|
|
|
|
"files");
|
2001-10-08 03:46:44 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static file_t *
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_Load_Source_File (progs_t *pr, const char *fname)
|
|
|
|
{
|
2007-04-28 01:40:08 +00:00
|
|
|
char *path = 0, *l, *p, **dir;
|
2003-03-12 22:38:02 +00:00
|
|
|
file_t *f = Hash_Find (file_hash, fname);
|
2001-07-14 23:53:59 +00:00
|
|
|
|
|
|
|
if (f)
|
|
|
|
return f;
|
2003-03-12 22:31:44 +00:00
|
|
|
f = calloc (1, sizeof (file_t));
|
2001-07-14 23:53:59 +00:00
|
|
|
if (!f)
|
|
|
|
return 0;
|
2003-03-12 22:31:44 +00:00
|
|
|
for (dir = source_paths; *dir && !f->text; dir++) {
|
2004-11-02 04:59:00 +00:00
|
|
|
f->text = pr->load_file (pr, va ("%s%s%s", *dir, **dir ? "/" : "",
|
|
|
|
fname));
|
2003-03-12 22:31:44 +00:00
|
|
|
}
|
2001-07-14 23:53:59 +00:00
|
|
|
if (!f->text) {
|
2003-03-12 22:31:44 +00:00
|
|
|
pr->file_error (pr, path);
|
2001-07-14 23:53:59 +00:00
|
|
|
free (f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (f->num_lines = 1, l = f->text; *l; l++)
|
|
|
|
if (*l == '\n')
|
|
|
|
f->num_lines++;
|
|
|
|
f->name = strdup (fname);
|
|
|
|
if (!f->name) {
|
2002-06-11 17:24:37 +00:00
|
|
|
pr->free_progs_mem (pr, f->text);
|
2001-07-14 23:53:59 +00:00
|
|
|
free (f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
f->lines = malloc (f->num_lines * sizeof (line_t));
|
|
|
|
if (!f->lines) {
|
|
|
|
free (f->name);
|
2002-06-11 17:24:37 +00:00
|
|
|
pr->free_progs_mem (pr, f->text);
|
2001-07-14 23:53:59 +00:00
|
|
|
free (f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
f->lines[0].text = f->text;
|
|
|
|
for (f->num_lines = 0, l = f->text; *l; l++) {
|
|
|
|
if (*l == '\n') {
|
2007-04-28 01:40:08 +00:00
|
|
|
for (p = l; p > f->lines[f->num_lines].text && isspace(p[-1]); p--)
|
|
|
|
;
|
|
|
|
f->lines[f->num_lines].len = p - f->lines[f->num_lines].text;
|
2001-07-14 23:53:59 +00:00
|
|
|
f->lines[++f->num_lines].text = l + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f->lines[f->num_lines++].len = l - f->lines[f->num_lines].text;
|
2002-06-11 17:24:37 +00:00
|
|
|
f->pr = pr;
|
2001-07-14 23:53:59 +00:00
|
|
|
Hash_Add (file_hash, f);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_LoadDebug (progs_t *pr)
|
|
|
|
{
|
2007-04-04 12:30:49 +00:00
|
|
|
char *sym_path;
|
|
|
|
const char *path_end, *sym_file;
|
|
|
|
pr_uint_t i;
|
2001-09-10 12:56:23 +00:00
|
|
|
ddef_t *def;
|
2001-07-15 02:05:29 +00:00
|
|
|
pr_type_t *str = 0;
|
|
|
|
|
2004-01-08 04:04:55 +00:00
|
|
|
if (pr->debug)
|
|
|
|
pr->free_progs_mem (pr, pr->debug);
|
2001-07-19 07:27:14 +00:00
|
|
|
pr->debug = 0;
|
|
|
|
pr->auxfunctions = 0;
|
2004-01-08 04:04:55 +00:00
|
|
|
if (pr->auxfunction_map)
|
|
|
|
pr->free_progs_mem (pr, pr->auxfunction_map);
|
2001-07-19 07:27:14 +00:00
|
|
|
pr->auxfunction_map = 0;
|
|
|
|
pr->linenos = 0;
|
|
|
|
pr->local_defs = 0;
|
|
|
|
|
|
|
|
if (!pr_debug->int_val)
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-19 07:27:14 +00:00
|
|
|
|
2001-07-15 02:05:29 +00:00
|
|
|
def = PR_FindGlobal (pr, ".debug_file");
|
|
|
|
if (def)
|
|
|
|
str = &pr->pr_globals[def->ofs];
|
2001-07-14 23:53:59 +00:00
|
|
|
|
|
|
|
Hash_FlushTable (file_hash);
|
|
|
|
if (!str)
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-14 23:53:59 +00:00
|
|
|
pr->debugfile = PR_GetString (pr, str->string_var);
|
2003-02-14 19:46:07 +00:00
|
|
|
sym_file = QFS_SkipPath (pr->debugfile);
|
|
|
|
path_end = QFS_SkipPath (pr->progs_name);
|
2004-11-02 04:59:00 +00:00
|
|
|
sym_path = malloc (strlen (sym_file) + (path_end - pr->progs_name) + 1);
|
2001-07-14 23:53:59 +00:00
|
|
|
strncpy (sym_path, pr->progs_name, path_end - pr->progs_name);
|
|
|
|
strcpy (sym_path + (path_end - pr->progs_name), sym_file);
|
2002-06-11 17:24:37 +00:00
|
|
|
pr->debug = pr->load_file (pr, sym_path);
|
2001-07-14 23:53:59 +00:00
|
|
|
if (!pr->debug) {
|
|
|
|
Sys_Printf ("can't load %s for debug info\n", sym_path);
|
2004-11-02 04:59:00 +00:00
|
|
|
free (sym_path);
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
pr->debug->version = LittleLong (pr->debug->version);
|
|
|
|
if (pr->debug->version != PROG_DEBUG_VERSION) {
|
|
|
|
Sys_Printf ("ignoring %s with unsupported version %x.%03x.%03x\n",
|
|
|
|
sym_path,
|
|
|
|
(pr->debug->version >> 24) & 0xff,
|
|
|
|
(pr->debug->version >> 12) & 0xfff,
|
|
|
|
pr->debug->version & 0xfff);
|
|
|
|
pr->debug = 0;
|
2004-11-02 04:59:00 +00:00
|
|
|
free (sym_path);
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
pr->debug->crc = LittleShort (pr->debug->crc);
|
|
|
|
if (pr->debug->crc != pr->crc) {
|
2001-09-10 12:56:23 +00:00
|
|
|
Sys_Printf ("ignoring %s that doesn't match %s. (CRCs: "
|
|
|
|
"sym:%d dat:%d)\n",
|
2001-07-14 23:53:59 +00:00
|
|
|
sym_path,
|
|
|
|
pr->progs_name,
|
|
|
|
pr->debug->crc,
|
|
|
|
pr->crc);
|
|
|
|
pr->debug = 0;
|
2004-11-02 04:59:00 +00:00
|
|
|
free (sym_path);
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
2004-11-02 04:59:00 +00:00
|
|
|
free (sym_path);
|
2001-09-10 12:56:23 +00:00
|
|
|
pr->debug->you_tell_me_and_we_will_both_know = LittleShort
|
|
|
|
(pr->debug->you_tell_me_and_we_will_both_know);
|
2001-07-14 23:53:59 +00:00
|
|
|
pr->debug->auxfunctions = LittleLong (pr->debug->auxfunctions);
|
|
|
|
pr->debug->num_auxfunctions = LittleLong (pr->debug->num_auxfunctions);
|
|
|
|
pr->debug->linenos = LittleLong (pr->debug->linenos);
|
|
|
|
pr->debug->num_linenos = LittleLong (pr->debug->num_linenos);
|
|
|
|
pr->debug->locals = LittleLong (pr->debug->locals);
|
|
|
|
pr->debug->num_locals = LittleLong (pr->debug->num_locals);
|
|
|
|
|
2001-09-10 12:56:23 +00:00
|
|
|
pr->auxfunctions = (pr_auxfunction_t*)((char*)pr->debug +
|
|
|
|
pr->debug->auxfunctions);
|
2001-07-14 23:53:59 +00:00
|
|
|
pr->linenos = (pr_lineno_t*)((char*)pr->debug + pr->debug->linenos);
|
|
|
|
pr->local_defs = (ddef_t*)((char*)pr->debug + pr->debug->locals);
|
|
|
|
|
2004-01-08 04:04:55 +00:00
|
|
|
i = pr->progs->numfunctions * sizeof (pr_auxfunction_t *);
|
|
|
|
pr->auxfunction_map = pr->allocate_progs_mem (pr, i);
|
2001-07-19 07:27:14 +00:00
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
for (i = 0; i < pr->debug->num_auxfunctions; i++) {
|
2001-09-10 12:56:23 +00:00
|
|
|
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];
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < pr->debug->num_linenos; i++) {
|
|
|
|
pr->linenos[i].fa.func = LittleLong (pr->linenos[i].fa.func);
|
|
|
|
pr->linenos[i].line = LittleLong (pr->linenos[i].line);
|
|
|
|
}
|
|
|
|
for (i = 0; i < pr->debug->num_locals; i++) {
|
|
|
|
pr->local_defs[i].type = LittleShort (pr->local_defs[i].type);
|
|
|
|
pr->local_defs[i].ofs = LittleShort (pr->local_defs[i].ofs);
|
|
|
|
pr->local_defs[i].s_name = LittleLong (pr->local_defs[i].s_name);
|
|
|
|
}
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pr_auxfunction_t *
|
|
|
|
PR_Get_Lineno_Func (progs_t *pr, pr_lineno_t *lineno)
|
|
|
|
{
|
|
|
|
while (lineno > pr->linenos && lineno->line)
|
|
|
|
lineno--;
|
|
|
|
if (lineno->line)
|
|
|
|
return 0;
|
|
|
|
return &pr->auxfunctions[lineno->fa.func];
|
|
|
|
}
|
|
|
|
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_Get_Lineno_Addr (progs_t *pr, pr_lineno_t *lineno)
|
|
|
|
{
|
|
|
|
pr_auxfunction_t *f;
|
|
|
|
|
|
|
|
if (lineno->line)
|
|
|
|
return lineno->fa.addr;
|
|
|
|
f = &pr->auxfunctions[lineno->fa.func];
|
|
|
|
return pr->pr_functions[f->function].first_statement;
|
|
|
|
}
|
|
|
|
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_Get_Lineno_Line (progs_t *pr, pr_lineno_t *lineno)
|
|
|
|
{
|
|
|
|
if (lineno->line)
|
|
|
|
return lineno->line;
|
2004-02-10 04:42:17 +00:00
|
|
|
return 0;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pr_lineno_t *
|
2007-04-04 12:30:49 +00:00
|
|
|
PR_Find_Lineno (progs_t *pr, pr_uint_t addr)
|
2001-07-14 23:53:59 +00:00
|
|
|
{
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t i;
|
|
|
|
pr_lineno_t *lineno = 0;
|
2001-07-14 23:53:59 +00:00
|
|
|
|
|
|
|
if (!pr->debug)
|
|
|
|
return 0;
|
|
|
|
if (!pr->debug->num_linenos)
|
|
|
|
return 0;
|
2007-04-04 12:30:49 +00:00
|
|
|
for (i = pr->debug->num_linenos; i > 0; i--) {
|
|
|
|
if (PR_Get_Lineno_Addr (pr, &pr->linenos[i - 1]) <= addr) {
|
|
|
|
lineno = &pr->linenos[i - 1];
|
2001-07-14 23:53:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lineno;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
PR_Get_Source_File (progs_t *pr, pr_lineno_t *lineno)
|
|
|
|
{
|
|
|
|
pr_auxfunction_t *f;
|
|
|
|
|
|
|
|
f = PR_Get_Lineno_Func (pr, lineno);
|
|
|
|
return PR_GetString(pr, pr->pr_functions[f->function].s_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2007-04-04 12:30:49 +00:00
|
|
|
PR_Get_Source_Line (progs_t *pr, pr_uint_t addr)
|
2001-07-14 23:53:59 +00:00
|
|
|
{
|
2007-04-04 12:30:49 +00:00
|
|
|
const char *fname;
|
|
|
|
pr_uint_t line;
|
|
|
|
file_t *file;
|
|
|
|
pr_auxfunction_t *func;
|
|
|
|
pr_lineno_t *lineno;
|
2003-02-24 03:34:11 +00:00
|
|
|
|
|
|
|
lineno = PR_Find_Lineno (pr, addr);
|
2001-07-14 23:53:59 +00:00
|
|
|
if (!lineno || PR_Get_Lineno_Addr (pr, lineno) != addr)
|
|
|
|
return 0;
|
|
|
|
func = PR_Get_Lineno_Func (pr, lineno);
|
|
|
|
fname = PR_Get_Source_File (pr, lineno);
|
|
|
|
if (!func || !fname)
|
|
|
|
return 0;
|
|
|
|
line = PR_Get_Lineno_Line (pr, lineno);
|
2004-02-10 04:42:17 +00:00
|
|
|
line += func->source_line;
|
2001-07-14 23:53:59 +00:00
|
|
|
|
2001-07-15 02:57:36 +00:00
|
|
|
file = PR_Load_Source_File (pr, fname);
|
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
if (!file || line > file->num_lines)
|
2007-04-06 00:47:41 +00:00
|
|
|
return va ("%s:%u", fname, line);
|
2001-07-14 23:53:59 +00:00
|
|
|
|
2007-04-06 00:47:41 +00:00
|
|
|
return va ("%s:%u:%.*s", fname, line, (int)file->lines[line - 1].len,
|
2004-11-02 04:59:00 +00:00
|
|
|
file->lines[line - 1].text);
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
|
2007-04-09 06:16:03 +00:00
|
|
|
ddef_t *
|
|
|
|
PR_Get_Param_Def (progs_t *pr, dfunction_t *func, unsigned parm)
|
|
|
|
{
|
|
|
|
pr_uint_t i;
|
|
|
|
pr_auxfunction_t *aux_func;
|
|
|
|
ddef_t *ddef = 0;
|
2007-04-09 06:18:14 +00:00
|
|
|
|
2007-05-07 23:10:54 +00:00
|
|
|
if (!pr->debug)
|
|
|
|
return 0;
|
2007-04-09 06:16:03 +00:00
|
|
|
if (!func)
|
|
|
|
return 0;
|
2007-04-09 06:18:14 +00:00
|
|
|
|
2007-04-09 06:16:03 +00:00
|
|
|
if (func->numparms >= 0 && parm >= (unsigned) func->numparms)
|
|
|
|
return 0;
|
|
|
|
if (func->numparms < 0 && parm >= (unsigned) -func->numparms)
|
|
|
|
return 0;
|
2007-04-09 06:18:14 +00:00
|
|
|
|
2007-04-09 06:16:03 +00:00
|
|
|
aux_func = pr->auxfunction_map[func - pr->pr_functions];
|
|
|
|
if (!aux_func)
|
|
|
|
return 0;
|
2007-04-09 06:18:14 +00:00
|
|
|
|
2007-04-09 06:16:03 +00:00
|
|
|
for (i = 0; i < aux_func->num_locals; i++) {
|
|
|
|
ddef = &pr->local_defs[aux_func->local_defs + i];
|
|
|
|
if (!parm--)
|
|
|
|
break;
|
|
|
|
if (ddef->type == ev_vector)
|
|
|
|
i += 3; // skip over component defs
|
|
|
|
}
|
|
|
|
return ddef;
|
|
|
|
}
|
|
|
|
|
2001-07-19 07:27:14 +00:00
|
|
|
ddef_t *
|
2007-04-04 12:30:49 +00:00
|
|
|
PR_Get_Local_Def (progs_t *pr, pr_int_t offs)
|
2001-07-19 07:27:14 +00:00
|
|
|
{
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t i;
|
2007-04-07 01:41:23 +00:00
|
|
|
dfunction_t *func;
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_auxfunction_t *aux_func;
|
2001-07-19 07:27:14 +00:00
|
|
|
|
2007-04-07 01:41:23 +00:00
|
|
|
if (!pr->pr_xfunction)
|
2001-07-19 07:27:14 +00:00
|
|
|
return 0;
|
2007-04-07 01:41:23 +00:00
|
|
|
func = pr->pr_xfunction->descriptor;
|
2001-07-19 07:27:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-10-08 03:46:44 +00:00
|
|
|
PR_DumpState (progs_t *pr)
|
2001-07-14 23:53:59 +00:00
|
|
|
{
|
2003-08-24 05:08:47 +00:00
|
|
|
if (pr->pr_xfunction) {
|
|
|
|
if (pr_debug->int_val && pr->debug) {
|
|
|
|
pr_lineno_t *lineno;
|
|
|
|
pr_auxfunction_t *func = 0;
|
2007-04-07 01:41:23 +00:00
|
|
|
dfunction_t *descriptor = pr->pr_xfunction->descriptor;
|
2007-04-06 00:47:41 +00:00
|
|
|
pr_int_t addr = pr->pr_xstatement;
|
2003-08-24 05:08:47 +00:00
|
|
|
|
|
|
|
lineno = PR_Find_Lineno (pr, addr);
|
|
|
|
if (lineno)
|
|
|
|
func = PR_Get_Lineno_Func (pr, lineno);
|
2007-04-07 01:41:23 +00:00
|
|
|
if (func && descriptor == pr->pr_functions + func->function)
|
2003-08-24 05:08:47 +00:00
|
|
|
addr = PR_Get_Lineno_Addr (pr, lineno);
|
|
|
|
else
|
2007-04-07 01:41:23 +00:00
|
|
|
addr = max (descriptor->first_statement, addr - 5);
|
2003-08-24 05:08:47 +00:00
|
|
|
|
|
|
|
while (addr != pr->pr_xstatement)
|
2007-04-09 06:16:03 +00:00
|
|
|
PR_PrintStatement (pr, pr->pr_statements + addr++, 3);
|
2003-08-24 05:08:47 +00:00
|
|
|
}
|
2007-04-09 06:16:03 +00:00
|
|
|
PR_PrintStatement (pr, pr->pr_statements + pr->pr_xstatement, 3);
|
2001-10-08 03:46:44 +00:00
|
|
|
}
|
|
|
|
PR_StackTrace (pr);
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
2002-10-23 20:42:02 +00:00
|
|
|
|
2004-01-31 04:26:01 +00:00
|
|
|
static const char *
|
|
|
|
value_string (progs_t *pr, etype_t type, pr_type_t *val)
|
|
|
|
{
|
|
|
|
static dstring_t *line;
|
2004-01-31 08:34:01 +00:00
|
|
|
ddef_t *def;
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_int_t ofs;
|
2004-01-31 08:34:01 +00:00
|
|
|
edict_t *edict;
|
2004-01-31 04:26:01 +00:00
|
|
|
dfunction_t *f;
|
2004-01-31 08:34:01 +00:00
|
|
|
const char *str;
|
2004-01-31 04:26:01 +00:00
|
|
|
|
|
|
|
if (!line)
|
|
|
|
line = dstring_new ();
|
|
|
|
|
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ev_string:
|
|
|
|
if (!PR_StringValid (pr, val->string_var))
|
|
|
|
return "*** invalid ***";
|
2004-01-31 08:34:01 +00:00
|
|
|
str = PR_GetString (pr, val->string_var);
|
|
|
|
dstring_copystr (line, "\"");
|
|
|
|
while (*str) {
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
for (s = str; *s && !strchr ("\"\n\t", *s); s++)
|
|
|
|
;
|
|
|
|
if (s != str)
|
|
|
|
dstring_appendsubstr (line, str, s - str);
|
|
|
|
if (*s) {
|
|
|
|
switch (*s) {
|
|
|
|
case '\"':
|
|
|
|
dstring_appendstr (line, "\\\"");
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
dstring_appendstr (line, "\\n");
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
dstring_appendstr (line, "\\t");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dasprintf (line, "\\x%02x", *s & 0xff);
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
str = s;
|
|
|
|
}
|
|
|
|
dstring_appendstr (line, "\"");
|
2004-01-31 04:26:01 +00:00
|
|
|
break;
|
|
|
|
case ev_entity:
|
2004-01-31 08:34:01 +00:00
|
|
|
edict = PROG_TO_EDICT (pr, val->entity_var);
|
2007-04-09 08:55:24 +00:00
|
|
|
dsprintf (line, "entity %d", NUM_FOR_BAD_EDICT (pr, edict));
|
2004-01-31 04:26:01 +00:00
|
|
|
break;
|
|
|
|
case ev_func:
|
|
|
|
if (val->func_var < 0 || val->func_var >= pr->progs->numfunctions)
|
|
|
|
dsprintf (line, "INVALID:%d", val->func_var);
|
|
|
|
else if (!val->func_var)
|
|
|
|
return "NULL";
|
|
|
|
else {
|
|
|
|
f = pr->pr_functions + val->func_var;
|
|
|
|
dsprintf (line, "%s()", PR_GetString (pr, f->s_name));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ev_field:
|
2004-11-05 11:49:00 +00:00
|
|
|
def = PR_FieldAtOfs (pr, val->integer_var);
|
2004-02-07 01:57:31 +00:00
|
|
|
if (def)
|
|
|
|
dsprintf (line, ".%s", PR_GetString (pr, def->s_name));
|
|
|
|
else
|
|
|
|
dsprintf (line, ".<$%04x>", val->integer_var);
|
2004-01-31 04:26:01 +00:00
|
|
|
break;
|
|
|
|
case ev_void:
|
|
|
|
return "void";
|
|
|
|
case ev_float:
|
|
|
|
dsprintf (line, "%g", val->float_var);
|
|
|
|
break;
|
|
|
|
case ev_vector:
|
|
|
|
dsprintf (line, "'%g %g %g'",
|
|
|
|
val->vector_var[0], val->vector_var[1],
|
|
|
|
val->vector_var[2]);
|
|
|
|
break;
|
|
|
|
case ev_pointer:
|
|
|
|
def = 0;
|
|
|
|
ofs = val->integer_var;
|
|
|
|
if (pr_debug->int_val && pr->debug)
|
|
|
|
def = PR_Get_Local_Def (pr, ofs);
|
|
|
|
if (!def)
|
2004-11-05 11:49:00 +00:00
|
|
|
def = PR_GlobalAtOfs (pr, ofs);
|
2004-01-31 04:26:01 +00:00
|
|
|
if (def && def->s_name)
|
|
|
|
dsprintf (line, "&%s", PR_GetString (pr, def->s_name));
|
|
|
|
else
|
|
|
|
dsprintf (line, "[$%x]", ofs);
|
|
|
|
break;
|
2004-04-08 02:33:20 +00:00
|
|
|
case ev_quat:
|
2004-01-31 04:26:01 +00:00
|
|
|
dsprintf (line, "'%g %g %g %g'",
|
|
|
|
val->vector_var[0], val->vector_var[1],
|
|
|
|
val->vector_var[2], val->vector_var[3]);
|
|
|
|
break;
|
|
|
|
case ev_integer:
|
|
|
|
dsprintf (line, "%d", val->integer_var);
|
|
|
|
break;
|
|
|
|
case ev_uinteger:
|
|
|
|
dsprintf (line, "$%08x", val->uinteger_var);
|
|
|
|
break;
|
|
|
|
case ev_sel:
|
|
|
|
dsprintf (line, "(SEL) %s", PR_GetString (pr, val->string_var));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dsprintf (line, "bad type %i", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return line->str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ddef_t *
|
2007-04-04 12:30:49 +00:00
|
|
|
def_string (progs_t *pr, pr_int_t ofs, dstring_t *dstr)
|
2004-01-31 04:26:01 +00:00
|
|
|
{
|
2004-01-31 07:29:11 +00:00
|
|
|
ddef_t *def = 0;
|
2004-01-31 04:26:01 +00:00
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (pr_debug->int_val && pr->debug)
|
|
|
|
def = PR_Get_Local_Def (pr, ofs);
|
|
|
|
if (!def)
|
2004-11-05 11:49:00 +00:00
|
|
|
def = PR_GlobalAtOfs (pr, ofs);
|
2004-01-31 04:26:01 +00:00
|
|
|
if (!def || !*(name = PR_GetString (pr, def->s_name)))
|
|
|
|
dsprintf (dstr, "[$%x]", ofs);
|
|
|
|
else
|
|
|
|
dsprintf (dstr, "%s", name);
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2007-04-04 12:30:49 +00:00
|
|
|
global_string (progs_t *pr, pr_int_t ofs, etype_t type, int contents)
|
2004-01-31 04:26:01 +00:00
|
|
|
{
|
2007-04-04 12:30:49 +00:00
|
|
|
static dstring_t *line = NULL;
|
|
|
|
ddef_t *def = NULL;
|
|
|
|
const char *s;
|
2004-01-31 04:26:01 +00:00
|
|
|
|
|
|
|
if (!line)
|
|
|
|
line = dstring_newstr();
|
|
|
|
|
|
|
|
if (type == ev_short) {
|
|
|
|
dsprintf (line, "%04x", (short) ofs);
|
|
|
|
return line->str;
|
|
|
|
}
|
|
|
|
|
|
|
|
def = def_string (pr, ofs, line);
|
|
|
|
|
|
|
|
if (def || type != ev_void) {
|
|
|
|
const char *oi = "";
|
|
|
|
if (def) {
|
|
|
|
if (type == ev_void)
|
|
|
|
type = def->type;
|
|
|
|
if (type != (etype_t) (def->type & ~DEF_SAVEGLOBAL))
|
|
|
|
oi = "?";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ofs > pr->globals_size)
|
|
|
|
s = "Out of bounds";
|
|
|
|
else
|
|
|
|
s = value_string (pr, type, &pr->pr_globals[ofs]);
|
|
|
|
|
|
|
|
if (strequal(line->str, "IMMEDIATE") || strequal(line->str, ".imm")) {
|
|
|
|
dsprintf (line, "%s", s);
|
|
|
|
} else {
|
2004-02-06 08:03:22 +00:00
|
|
|
if (contents)
|
2004-01-31 04:26:01 +00:00
|
|
|
dasprintf (line, "%s(%s)", oi, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return line->str;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2007-04-04 12:30:49 +00:00
|
|
|
PR_PrintStatement (progs_t *pr, dstatement_t *s, int contents)
|
2002-10-23 20:42:02 +00:00
|
|
|
{
|
2007-04-04 12:30:49 +00:00
|
|
|
int addr = s - pr->pr_statements;
|
2007-04-09 06:16:03 +00:00
|
|
|
int dump_code = contents & 2;
|
2003-07-30 22:24:16 +00:00
|
|
|
const char *fmt;
|
2007-04-04 12:30:49 +00:00
|
|
|
opcode_t *op;
|
2003-07-30 22:24:16 +00:00
|
|
|
static dstring_t *line;
|
2007-04-09 06:16:03 +00:00
|
|
|
dfunction_t *call_func = 0;
|
|
|
|
ddef_t *parm_def = 0;
|
2003-07-30 22:24:16 +00:00
|
|
|
|
|
|
|
if (!line)
|
|
|
|
line = dstring_new ();
|
|
|
|
|
|
|
|
dstring_clearstr (line);
|
2002-10-23 20:42:02 +00:00
|
|
|
|
2007-04-09 06:16:03 +00:00
|
|
|
if (pr_debug->int_val > 1)
|
|
|
|
dump_code = 1;
|
|
|
|
|
2002-10-23 20:42:02 +00:00
|
|
|
if (pr_debug->int_val && pr->debug) {
|
|
|
|
const char *source_line = PR_Get_Source_Line (pr, addr);
|
|
|
|
|
2007-04-09 06:16:03 +00:00
|
|
|
if (source_line) {
|
|
|
|
dasprintf (line, "%s%s", source_line, dump_code ? "\n" : "");
|
|
|
|
if (!dump_code)
|
|
|
|
goto do_print;
|
|
|
|
}
|
|
|
|
if (!dump_code)
|
|
|
|
return;
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
op = PR_Opcode (s->op);
|
|
|
|
if (!op) {
|
2003-07-30 22:24:16 +00:00
|
|
|
Sys_Printf ("%sUnknown instruction %d\n", line->str, s->op);
|
2002-10-23 20:42:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-07-30 22:24:16 +00:00
|
|
|
if (!(fmt = op->fmt))
|
2003-07-30 22:24:44 +00:00
|
|
|
fmt = "%Ga, %Gb, %gc";
|
2003-07-30 22:24:16 +00:00
|
|
|
|
|
|
|
dasprintf (line, "%04x ", addr);
|
2007-04-09 06:16:03 +00:00
|
|
|
if (pr_debug->int_val > 2)
|
2003-07-30 22:24:16 +00:00
|
|
|
dasprintf (line, "%02x %04x(%8s) %04x(%8s) %04x(%8s)\t",
|
2002-10-23 20:42:02 +00:00
|
|
|
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]);
|
|
|
|
|
2003-07-30 22:24:16 +00:00
|
|
|
dasprintf (line, "%s ", op->opname);
|
|
|
|
|
|
|
|
while (*fmt) {
|
|
|
|
if (*fmt == '%') {
|
|
|
|
if (fmt[1] == '%') {
|
|
|
|
dstring_appendsubstr (line, fmt + 1, 1);
|
|
|
|
fmt += 2;
|
|
|
|
} else {
|
2004-01-30 07:55:32 +00:00
|
|
|
const char *str;
|
2005-01-02 14:23:20 +00:00
|
|
|
char mode = fmt[1], opchar = fmt[2];
|
2007-04-09 06:16:03 +00:00
|
|
|
unsigned parm_ind = 0;
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_int_t opval;
|
2007-04-10 08:32:58 +00:00
|
|
|
etype_t optype = ev_void;
|
2003-07-30 22:24:16 +00:00
|
|
|
|
2007-04-09 06:16:03 +00:00
|
|
|
if (mode == 'P') {
|
|
|
|
opchar = fmt[3];
|
|
|
|
parm_ind = fmt[2] - '0';
|
|
|
|
fmt++; // P has one extra item
|
|
|
|
if (parm_ind >= MAX_PARMS)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2003-07-30 22:24:16 +00:00
|
|
|
switch (opchar) {
|
|
|
|
case 'a':
|
|
|
|
opval = s->a;
|
|
|
|
optype = op->type_a;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
opval = s->b;
|
|
|
|
optype = op->type_b;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
opval = s->c;
|
|
|
|
optype = op->type_c;
|
|
|
|
break;
|
2007-04-09 06:16:03 +00:00
|
|
|
case 'x':
|
|
|
|
if (mode == 'P') {
|
|
|
|
opval = pr->pr_real_params[parm_ind]
|
|
|
|
- pr->pr_globals;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-30 22:24:16 +00:00
|
|
|
default:
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
switch (mode) {
|
2007-04-09 06:16:03 +00:00
|
|
|
case 'F':
|
|
|
|
str = global_string (pr, opval, optype, contents & 1);
|
|
|
|
call_func = pr->pr_functions + G_FUNCTION (pr, opval);
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
parm_def = PR_Get_Param_Def (pr, call_func, parm_ind);
|
|
|
|
optype = ev_void;
|
|
|
|
if (parm_def)
|
|
|
|
optype = parm_def->type;
|
|
|
|
str = global_string (pr, opval, optype, contents & 1);
|
|
|
|
break;
|
2003-07-30 22:24:16 +00:00
|
|
|
case 'V':
|
2007-04-09 06:16:03 +00:00
|
|
|
str = global_string (pr, opval, ev_void, contents & 1);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
case 'G':
|
2007-04-09 06:16:03 +00:00
|
|
|
str = global_string (pr, opval, optype, contents & 1);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
case 'g':
|
2004-01-31 04:26:01 +00:00
|
|
|
str = global_string (pr, opval, optype, 0);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
case 's':
|
2004-01-30 07:55:32 +00:00
|
|
|
str = va ("%d", (short) opval);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
case 'O':
|
2004-01-30 07:55:32 +00:00
|
|
|
str = va ("%04x", addr + (short) opval);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto err;
|
|
|
|
}
|
2004-01-30 07:55:32 +00:00
|
|
|
dstring_appendstr (line, str);
|
2003-07-30 22:24:16 +00:00
|
|
|
fmt += 3;
|
|
|
|
continue;
|
|
|
|
err:
|
|
|
|
dstring_appendstr (line, fmt);
|
|
|
|
break;
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
2003-07-30 22:24:16 +00:00
|
|
|
} else {
|
|
|
|
dstring_appendsubstr (line, fmt++, 1);
|
|
|
|
}
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
2007-04-09 06:16:03 +00:00
|
|
|
do_print:
|
2003-07-30 22:24:16 +00:00
|
|
|
Sys_Printf ("%s\n", line->str);
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
2004-01-05 07:10:32 +00:00
|
|
|
static void
|
|
|
|
dump_frame (progs_t *pr, prstack_t *frame)
|
|
|
|
{
|
2007-04-08 00:56:35 +00:00
|
|
|
dfunction_t *f = frame->f ? frame->f->descriptor : 0;
|
2004-01-05 07:10:32 +00:00
|
|
|
|
|
|
|
if (!f) {
|
|
|
|
Sys_Printf ("<NO FUNCTION>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pr_debug->int_val && pr->debug) {
|
|
|
|
pr_lineno_t *lineno = PR_Find_Lineno (pr, frame->s);
|
|
|
|
pr_auxfunction_t *func = PR_Get_Lineno_Func (pr, lineno);
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t line = PR_Get_Lineno_Line (pr, lineno);
|
|
|
|
pr_int_t addr = PR_Get_Lineno_Addr (pr, lineno);
|
2004-01-05 07:10:32 +00:00
|
|
|
|
|
|
|
line += func->source_line;
|
|
|
|
if (addr == frame->s) {
|
2007-04-06 00:47:41 +00:00
|
|
|
Sys_Printf ("%12s:%u : %s: %x\n",
|
2004-01-05 07:10:32 +00:00
|
|
|
PR_GetString (pr, f->s_file),
|
|
|
|
line,
|
|
|
|
PR_GetString (pr, f->s_name),
|
|
|
|
frame->s);
|
|
|
|
} else {
|
2007-04-06 00:47:41 +00:00
|
|
|
Sys_Printf ("%12s:%u+%d : %s: %x\n",
|
2004-01-05 07:10:32 +00:00
|
|
|
PR_GetString (pr, f->s_file),
|
|
|
|
line, frame->s - addr,
|
|
|
|
PR_GetString (pr, f->s_name),
|
|
|
|
frame->s);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Sys_Printf ("%12s : %s: %x\n", PR_GetString (pr, f->s_file),
|
|
|
|
PR_GetString (pr, f->s_name), frame->s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-10 09:45:57 +00:00
|
|
|
VISIBLE void
|
2004-01-05 07:10:32 +00:00
|
|
|
PR_StackTrace (progs_t *pr)
|
2002-10-23 20:42:02 +00:00
|
|
|
{
|
2007-04-04 12:30:49 +00:00
|
|
|
int i;
|
|
|
|
prstack_t top;
|
2002-10-23 20:42:02 +00:00
|
|
|
|
|
|
|
if (pr->pr_depth == 0) {
|
|
|
|
Sys_Printf ("<NO STACK>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-01-05 07:10:32 +00:00
|
|
|
top.s = pr->pr_xstatement;
|
|
|
|
top.f = pr->pr_xfunction;
|
|
|
|
dump_frame (pr, &top);
|
|
|
|
for (i = pr->pr_depth - 1; i >= 0; i--)
|
|
|
|
dump_frame (pr, pr->pr_stack + i);
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-10-23 20:42:02 +00:00
|
|
|
PR_Profile (progs_t * pr)
|
|
|
|
{
|
2007-04-06 00:47:41 +00:00
|
|
|
pr_int_t max, num, i;
|
2007-04-04 12:30:49 +00:00
|
|
|
dfunction_t *best, *f;
|
2002-10-23 20:42:02 +00:00
|
|
|
|
|
|
|
num = 0;
|
|
|
|
do {
|
|
|
|
max = 0;
|
|
|
|
best = NULL;
|
|
|
|
for (i = 0; i < pr->progs->numfunctions; i++) {
|
|
|
|
f = &pr->pr_functions[i];
|
|
|
|
if (f->profile > max) {
|
|
|
|
max = f->profile;
|
|
|
|
best = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (best) {
|
|
|
|
if (num < 10)
|
|
|
|
Sys_Printf ("%7i %s\n", best->profile,
|
|
|
|
PR_GetString (pr, best->s_name));
|
|
|
|
num++;
|
|
|
|
best->profile = 0;
|
|
|
|
}
|
|
|
|
} while (best);
|
|
|
|
}
|
2004-01-30 08:46:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
ED_Print
|
|
|
|
|
|
|
|
For debugging
|
|
|
|
*/
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2004-01-30 08:46:14 +00:00
|
|
|
ED_Print (progs_t *pr, edict_t *ed)
|
|
|
|
{
|
2005-01-02 14:23:20 +00:00
|
|
|
int type, l;
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t i;
|
2004-01-30 08:46:14 +00:00
|
|
|
const char *name;
|
|
|
|
ddef_t *d;
|
|
|
|
pr_type_t *v;
|
|
|
|
|
|
|
|
if (ed->free) {
|
|
|
|
Sys_Printf ("FREE\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-09 08:55:24 +00:00
|
|
|
Sys_Printf ("\nEDICT %d:\n", NUM_FOR_BAD_EDICT (pr, ed));
|
2004-01-30 08:46:14 +00:00
|
|
|
for (i = 0; i < pr->progs->numfielddefs; i++) {
|
|
|
|
d = &pr->pr_fielddefs[i];
|
|
|
|
if (!d->s_name) // null field def (probably 1st)
|
|
|
|
continue;
|
|
|
|
name = PR_GetString (pr, d->s_name);
|
|
|
|
if (name[strlen (name) - 2] == '_')
|
|
|
|
continue; // skip _x, _y, _z vars
|
|
|
|
|
|
|
|
v = ed->v + d->ofs;
|
|
|
|
|
|
|
|
// if the value is still all 0, skip the field
|
|
|
|
type = d->type & ~DEF_SAVEGLOBAL;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ev_entity:
|
|
|
|
case ev_integer:
|
|
|
|
case ev_uinteger:
|
|
|
|
case ev_pointer:
|
|
|
|
case ev_func:
|
|
|
|
case ev_field:
|
|
|
|
if (!v->integer_var)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case ev_sel:
|
|
|
|
if (!v[0].integer_var
|
|
|
|
&& !PR_GetString (pr, v[1].string_var)[0])
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case ev_string:
|
|
|
|
if (PR_StringValid (pr, v->string_var))
|
|
|
|
if (!PR_GetString (pr, v->string_var)[0])
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case ev_float:
|
|
|
|
if (!v->float_var)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case ev_vector:
|
|
|
|
if (!v[0].float_var && !v[1].float_var && !v[2].float_var)
|
|
|
|
continue;
|
|
|
|
break;
|
2004-11-12 11:12:00 +00:00
|
|
|
case ev_void:
|
|
|
|
break;
|
2004-01-30 08:46:14 +00:00
|
|
|
default:
|
|
|
|
PR_Error (pr, "ED_Print: Unhandled type %d", type);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Printf ("%s", name);
|
|
|
|
l = strlen (name);
|
|
|
|
while (l++ < 15)
|
|
|
|
Sys_Printf (" ");
|
|
|
|
|
|
|
|
Sys_Printf ("%s\n", value_string (pr, d->type, v));
|
|
|
|
}
|
|
|
|
}
|