mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
break out the backtrace code from PR_RunError into PR_DumpState and use
PR_DumpState instead of PR_RunError in seg_fault_handler so we get both a progs trace /and/ a core file (ulimit allowing)
This commit is contained in:
parent
c7d1f961c3
commit
3a366f4f7e
5 changed files with 49 additions and 39 deletions
|
@ -187,6 +187,8 @@ 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);
|
||||
void PR_DumpState (progs_t *pr);
|
||||
void PR_StackTrace (progs_t * pr);
|
||||
|
||||
extern struct cvar_s *pr_debug;
|
||||
|
||||
|
|
|
@ -68,6 +68,37 @@ cvar_t *pr_source_path;
|
|||
static hashtab_t *file_hash;
|
||||
|
||||
|
||||
static const char *
|
||||
file_get_key (void *_f, void *unused)
|
||||
{
|
||||
return ((file_t*)_f)->name;
|
||||
}
|
||||
|
||||
static void
|
||||
file_free (void *_f, void *unused)
|
||||
{
|
||||
file_t *f = (file_t*)_f;
|
||||
free (f->lines);
|
||||
free (f->text);
|
||||
free (f->name);
|
||||
free (f);
|
||||
}
|
||||
|
||||
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");
|
||||
pr_source_path = Cvar_Get ("pr_source_path", ".", CVAR_NONE, NULL, "where "
|
||||
"to look (within gamedir) for source files");
|
||||
}
|
||||
|
||||
file_t *
|
||||
PR_Load_Source_File (progs_t *pr, const char *fname)
|
||||
{
|
||||
|
@ -333,33 +364,17 @@ PR_Get_Local_Def (progs_t *pr, int offs)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char *
|
||||
file_get_key (void *_f, void *unused)
|
||||
{
|
||||
return ((file_t*)_f)->name;
|
||||
}
|
||||
|
||||
static void
|
||||
file_free (void *_f, void *unused)
|
||||
{
|
||||
file_t *f = (file_t*)_f;
|
||||
free (f->lines);
|
||||
free (f->text);
|
||||
free (f->name);
|
||||
free (f);
|
||||
}
|
||||
|
||||
void
|
||||
PR_Debug_Init (void)
|
||||
PR_DumpState (progs_t *pr)
|
||||
{
|
||||
file_hash = Hash_NewTable (1024, file_get_key, file_free, 0);
|
||||
}
|
||||
if (pr_debug->int_val && pr->debug) {
|
||||
int addr = pr->pr_xstatement;
|
||||
|
||||
void
|
||||
PR_Debug_Init_Cvars (void)
|
||||
{
|
||||
pr_debug = Cvar_Get ("pr_debug", "0", CVAR_NONE, NULL,
|
||||
"enable progs debugging");
|
||||
pr_source_path = Cvar_Get ("pr_source_path", ".", CVAR_NONE, NULL, "where "
|
||||
"to look (within gamedir) for source files");
|
||||
while (!PR_Get_Source_Line (pr, addr))
|
||||
addr--;
|
||||
while (addr != pr->pr_xstatement)
|
||||
PR_PrintStatement (pr, pr->pr_statements + addr++);
|
||||
}
|
||||
PR_PrintStatement (pr, pr->pr_statements + pr->pr_xstatement);
|
||||
PR_StackTrace (pr);
|
||||
}
|
||||
|
|
|
@ -1461,6 +1461,7 @@ EDICT_NUM (progs_t * pr, int n)
|
|||
int offs = n * pr->pr_edict_size;
|
||||
if (offs < 0 || n >= pr->pr_edictareasize)
|
||||
PR_RunError (pr, "EDICT_NUM: bad number %i", n);
|
||||
|
||||
return PROG_TO_EDICT (pr, offs);
|
||||
}
|
||||
|
||||
|
|
|
@ -157,20 +157,12 @@ PR_RunError (progs_t * pr, const char *error, ...)
|
|||
vsnprintf (string, sizeof (string), error, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
if (pr_debug->int_val && pr->debug) {
|
||||
int addr = pr->pr_xstatement;
|
||||
|
||||
while (!PR_Get_Source_Line (pr, addr))
|
||||
addr--;
|
||||
while (addr != pr->pr_xstatement)
|
||||
PR_PrintStatement (pr, pr->pr_statements + addr++);
|
||||
}
|
||||
PR_PrintStatement (pr, pr->pr_statements + pr->pr_xstatement);
|
||||
PR_StackTrace (pr);
|
||||
PR_DumpState (pr);
|
||||
|
||||
Sys_Printf ("%s\n", string);
|
||||
|
||||
pr->pr_depth = 0; // dump the stack so PR_Error can
|
||||
// shutdown functions
|
||||
// dump the stack so PR_Error can shutdown functions
|
||||
pr->pr_depth = 0;
|
||||
|
||||
PR_Error (pr, "Program error");
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ static void
|
|||
seg_fault_handler(int whatever)
|
||||
{
|
||||
if (sv_pr_state.pr_xfunction)
|
||||
PR_RunError (&sv_pr_state, "Segmentation Fault\n");
|
||||
PR_DumpState (&sv_pr_state);
|
||||
signal (SIGSEGV, old_seg_handler);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue