mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
qfprogs can now read the debug data
This commit is contained in:
parent
7985deefb8
commit
0b1d1ade73
5 changed files with 68 additions and 35 deletions
|
@ -332,6 +332,7 @@ struct progs_s {
|
|||
int (*prune_edict)(progs_t *pr, edict_t *ent);
|
||||
void (*free_edict)(progs_t *pr, edict_t *ent);
|
||||
|
||||
void *(*load_file)(progs_t *pr, const char *path);
|
||||
void *(*allocate_progs_mem)(progs_t *pr, int size);
|
||||
void (*free_progs_mem)(progs_t *pr, void *mem);
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ typedef struct {
|
|||
char *text;
|
||||
line_t *lines;
|
||||
int num_lines;
|
||||
progs_t *pr;
|
||||
} file_t;
|
||||
|
||||
cvar_t *pr_debug;
|
||||
|
@ -77,9 +78,11 @@ file_get_key (void *_f, void *unused)
|
|||
static void
|
||||
file_free (void *_f, void *unused)
|
||||
{
|
||||
file_t *f = (file_t*)_f;
|
||||
file_t *f = (file_t*)_f;
|
||||
progs_t *pr = f->pr;
|
||||
|
||||
free (f->lines);
|
||||
free (f->text);
|
||||
((progs_t *) pr)->free_progs_mem (pr, f->text);
|
||||
free (f->name);
|
||||
free (f);
|
||||
}
|
||||
|
@ -113,7 +116,7 @@ PR_Load_Source_File (progs_t *pr, const char *fname)
|
|||
path = Hunk_TempAlloc (strlen (pr_source_path->string) + strlen (fname) +
|
||||
2);
|
||||
sprintf (path, "%s/%s", pr_source_path->string, fname);
|
||||
f->text = COM_LoadFile (path, 0);
|
||||
f->text = pr->load_file (pr, path);
|
||||
if (!f->text) {
|
||||
free (f);
|
||||
return 0;
|
||||
|
@ -123,14 +126,14 @@ PR_Load_Source_File (progs_t *pr, const char *fname)
|
|||
f->num_lines++;
|
||||
f->name = strdup (fname);
|
||||
if (!f->name) {
|
||||
free (f->text);
|
||||
pr->free_progs_mem (pr, f->text);
|
||||
free (f);
|
||||
return 0;
|
||||
}
|
||||
f->lines = malloc (f->num_lines * sizeof (line_t));
|
||||
if (!f->lines) {
|
||||
free (f->name);
|
||||
free (f->text);
|
||||
pr->free_progs_mem (pr, f->text);
|
||||
free (f);
|
||||
return 0;
|
||||
}
|
||||
|
@ -142,6 +145,7 @@ PR_Load_Source_File (progs_t *pr, const char *fname)
|
|||
}
|
||||
}
|
||||
f->lines[f->num_lines++].len = l - f->lines[f->num_lines].text;
|
||||
f->pr = pr;
|
||||
Hash_Add (file_hash, f);
|
||||
return f;
|
||||
}
|
||||
|
@ -179,7 +183,7 @@ PR_LoadDebug (progs_t *pr)
|
|||
+ 1);
|
||||
strncpy (sym_path, pr->progs_name, path_end - pr->progs_name);
|
||||
strcpy (sym_path + (path_end - pr->progs_name), sym_file);
|
||||
pr->debug = (pr_debug_header_t*)COM_LoadHunkFile (sym_path);
|
||||
pr->debug = pr->load_file (pr, sym_path);
|
||||
if (!pr->debug) {
|
||||
Sys_Printf ("can't load %s for debug info\n", sym_path);
|
||||
return;
|
||||
|
|
|
@ -69,6 +69,12 @@ var_get_key (void *d, void *_pr)
|
|||
return PR_GetString (pr, def->s_name);
|
||||
}
|
||||
|
||||
static void *
|
||||
load_file (progs_t *pr, const char *path)
|
||||
{
|
||||
return COM_LoadHunkFile (path);
|
||||
}
|
||||
|
||||
static void *
|
||||
allocate_progs_mem (progs_t *pr, int size)
|
||||
{
|
||||
|
@ -146,6 +152,8 @@ PR_LoadProgsFile (progs_t * pr, VFile *file, int size, int edicts, int zone)
|
|||
pr->pr_edict_size &= ~(sizeof (void*) - 1);
|
||||
pr->pr_edictareasize = edicts * pr->pr_edict_size;
|
||||
|
||||
if (!pr->load_file)
|
||||
pr->load_file = load_file;
|
||||
if (!pr->allocate_progs_mem)
|
||||
pr->allocate_progs_mem = allocate_progs_mem;
|
||||
if (!pr->free_progs_mem)
|
||||
|
|
|
@ -64,8 +64,10 @@ disassemble_progs (progs_t *pr)
|
|||
|
||||
for (i = 0; i < pr->progs->numstatements; i++) {
|
||||
dfunction_t *f = func_find (i);
|
||||
if (f)
|
||||
if (f) {
|
||||
Sys_Printf ("%s:\n", PR_GetString (pr, f->s_name));
|
||||
pr->pr_xfunction = f;
|
||||
}
|
||||
PR_PrintStatement (pr, &pr->pr_statements[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,50 @@ static int memsize = 1024*1024;
|
|||
|
||||
static hashtab_t *func_tab;
|
||||
|
||||
static VFile *
|
||||
open_file (const char *path, int *len)
|
||||
{
|
||||
int fd = open (path, O_RDONLY);
|
||||
unsigned char id[2];
|
||||
unsigned char len_bytes[4];
|
||||
|
||||
if (fd == -1) {
|
||||
perror (path);
|
||||
return 0;
|
||||
}
|
||||
read (fd, id, 2);
|
||||
if (id[0] == 0x1f && id[1] == 0x8b) {
|
||||
lseek (fd, -4, SEEK_END);
|
||||
read (fd, len_bytes, 4);
|
||||
*len = ((len_bytes[3] << 24)
|
||||
| (len_bytes[2] << 16)
|
||||
| (len_bytes[1] << 8)
|
||||
| (len_bytes[0]));
|
||||
} else {
|
||||
*len = lseek (fd, 0, SEEK_END);
|
||||
}
|
||||
lseek (fd, 0, SEEK_SET);
|
||||
|
||||
return Qdopen (fd, "rbz");
|
||||
}
|
||||
|
||||
static void *
|
||||
load_file (progs_t *pr, const char *name)
|
||||
{
|
||||
VFile *file;
|
||||
int size;
|
||||
void *sym;
|
||||
|
||||
file = open_file (name, &size);
|
||||
if (!file) {
|
||||
perror (name);
|
||||
return 0;
|
||||
}
|
||||
sym = malloc (size);
|
||||
Qread (file, sym, size);
|
||||
return sym;
|
||||
}
|
||||
|
||||
static void *
|
||||
allocate_progs_mem (progs_t *pr, int size)
|
||||
{
|
||||
|
@ -133,6 +177,7 @@ init_qf (void)
|
|||
pr.edicts = &edicts;
|
||||
pr.num_edicts = &num_edicts;
|
||||
pr.reserved_edicts = &reserved_edicts;
|
||||
pr.load_file = load_file;
|
||||
pr.allocate_progs_mem = allocate_progs_mem;
|
||||
pr.free_progs_mem = free_progs_mem;
|
||||
|
||||
|
@ -140,33 +185,6 @@ init_qf (void)
|
|||
Hash_SetHashCompare (func_tab, func_hash, func_compare);
|
||||
}
|
||||
|
||||
static VFile *
|
||||
open_file (const char *path, int *len)
|
||||
{
|
||||
int fd = open (path, O_RDONLY);
|
||||
unsigned char id[2];
|
||||
unsigned char len_bytes[4];
|
||||
|
||||
if (fd == -1) {
|
||||
perror (path);
|
||||
return 0;
|
||||
}
|
||||
read (fd, id, 2);
|
||||
if (id[0] == 0x1f && id[1] == 0x8b) {
|
||||
lseek (fd, -4, SEEK_END);
|
||||
read (fd, len_bytes, 4);
|
||||
*len = ((len_bytes[3] << 24)
|
||||
| (len_bytes[2] << 16)
|
||||
| (len_bytes[1] << 8)
|
||||
| (len_bytes[0]));
|
||||
} else {
|
||||
*len = lseek (fd, 0, SEEK_END);
|
||||
}
|
||||
lseek (fd, 0, SEEK_SET);
|
||||
|
||||
return Qdopen (fd, "rbz");
|
||||
}
|
||||
|
||||
int
|
||||
load_progs (const char *name)
|
||||
{
|
||||
|
@ -190,7 +208,7 @@ load_progs (const char *name)
|
|||
if (pr.pr_functions[i].first_statement > 0)// don't bother with builtins
|
||||
Hash_AddElement (func_tab, &pr.pr_functions[i]);
|
||||
}
|
||||
//PR_LoadDebug (&pr);
|
||||
PR_LoadDebug (&pr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue