2002-05-16 23:44:53 +00:00
|
|
|
/*
|
|
|
|
#FILENAME#
|
|
|
|
|
|
|
|
#DESCRIPTION#
|
|
|
|
|
|
|
|
Copyright (C) 2001 #AUTHOR#
|
|
|
|
|
|
|
|
Author: #AUTHOR#
|
|
|
|
Date: #DATE#
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2002-05-16 23:44:53 +00:00
|
|
|
#include <stdlib.h>
|
2003-04-23 20:10:51 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2002-05-16 23:44:53 +00:00
|
|
|
|
2007-04-09 07:47:51 +00:00
|
|
|
#include "QF/dstring.h"
|
2002-05-16 23:44:53 +00:00
|
|
|
#include "QF/progs.h"
|
2002-05-17 20:03:59 +00:00
|
|
|
#include "QF/va.h"
|
2002-05-16 23:44:53 +00:00
|
|
|
|
2007-04-09 07:47:51 +00:00
|
|
|
#include "obj_file.h"
|
2002-05-16 23:44:53 +00:00
|
|
|
#include "qfprogs.h"
|
2007-04-09 13:33:59 +00:00
|
|
|
#include "reloc.h"
|
2002-05-16 23:44:53 +00:00
|
|
|
|
2003-04-23 20:10:51 +00:00
|
|
|
static int
|
|
|
|
cmp (const void *_a, const void *_b)
|
|
|
|
{
|
|
|
|
const ddef_t *a = (const ddef_t *)_a;
|
|
|
|
const ddef_t *b = (const ddef_t *)_b;
|
|
|
|
|
|
|
|
return a->ofs - b->ofs;
|
|
|
|
}
|
|
|
|
|
2002-05-16 23:44:53 +00:00
|
|
|
void
|
|
|
|
dump_globals (progs_t *pr)
|
|
|
|
{
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int i;
|
2002-05-17 20:03:59 +00:00
|
|
|
const char *name;
|
|
|
|
const char *type;
|
|
|
|
int saveglobal;
|
|
|
|
int offset;
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *comment;
|
2003-04-23 20:10:51 +00:00
|
|
|
ddef_t *global_defs = pr->pr_globaldefs;
|
2002-05-16 23:44:53 +00:00
|
|
|
|
2003-04-23 20:10:51 +00:00
|
|
|
if (sorted) {
|
|
|
|
global_defs = malloc (pr->progs->numglobaldefs * sizeof (ddef_t));
|
|
|
|
memcpy (global_defs, pr->pr_globaldefs,
|
|
|
|
pr->progs->numglobaldefs * sizeof (ddef_t));
|
|
|
|
qsort (global_defs, pr->progs->numglobaldefs, sizeof (ddef_t), cmp);
|
|
|
|
}
|
2002-05-16 23:44:53 +00:00
|
|
|
for (i = 0; i < pr->progs->numglobaldefs; i++) {
|
2003-04-23 20:10:51 +00:00
|
|
|
ddef_t *def = &global_defs[i];
|
2002-05-16 23:44:53 +00:00
|
|
|
|
2003-04-22 05:39:12 +00:00
|
|
|
if (!def->type && !def->ofs && !def->s_name)
|
|
|
|
continue;
|
|
|
|
|
2002-05-17 20:03:59 +00:00
|
|
|
name = PR_GetString (pr, def->s_name);
|
|
|
|
type = pr_type_name[def->type & ~DEF_SAVEGLOBAL];
|
|
|
|
saveglobal = (def->type & DEF_SAVEGLOBAL) != 0;
|
|
|
|
offset = def->ofs;
|
|
|
|
|
2007-04-09 07:47:51 +00:00
|
|
|
comment = "";
|
2002-05-17 20:03:59 +00:00
|
|
|
|
|
|
|
if (def->type == ev_func) {
|
|
|
|
func_t func = G_FUNCTION (pr, offset);
|
2002-06-12 03:01:30 +00:00
|
|
|
int start;
|
|
|
|
if (func >= 0 && func < pr->progs->numfunctions) {
|
|
|
|
start = pr->pr_functions[func].first_statement;
|
|
|
|
if (start > 0)
|
|
|
|
comment = va (" %d @ %d", func, start);
|
|
|
|
else
|
|
|
|
comment = va (" %d = #%d", func, -start);
|
|
|
|
} else {
|
|
|
|
comment = va (" %d = illegal function", func);
|
|
|
|
}
|
2002-05-17 20:03:59 +00:00
|
|
|
}
|
2007-04-09 13:33:59 +00:00
|
|
|
if (def->type == ev_field)
|
|
|
|
comment = va (" %d", G_INT (pr, offset));
|
2002-05-17 20:03:59 +00:00
|
|
|
|
2007-04-09 07:47:51 +00:00
|
|
|
printf ("%d %d %s %s%s\n", offset, saveglobal, name, type, comment);
|
2002-05-16 23:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-09 16:28:19 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
dump_fields (progs_t *pr)
|
|
|
|
{
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int i;
|
2002-06-09 16:28:19 +00:00
|
|
|
const char *name;
|
|
|
|
const char *type;
|
|
|
|
int offset;
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *comment;
|
2002-06-09 16:28:19 +00:00
|
|
|
|
|
|
|
for (i = 0; i < pr->progs->numfielddefs; i++) {
|
|
|
|
ddef_t *def = &pr->pr_fielddefs[i];
|
|
|
|
|
|
|
|
name = PR_GetString (pr, def->s_name);
|
|
|
|
type = pr_type_name[def->type & ~DEF_SAVEGLOBAL];
|
|
|
|
offset = def->ofs;
|
|
|
|
|
2007-04-09 07:47:51 +00:00
|
|
|
comment = "";
|
2002-06-09 16:28:19 +00:00
|
|
|
|
2007-04-09 07:47:51 +00:00
|
|
|
printf ("%d %s %s%s\n", offset, name, type, comment);
|
2002-06-09 16:28:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dump_functions (progs_t *pr)
|
|
|
|
{
|
2002-06-27 22:51:42 +00:00
|
|
|
int i, j;
|
2002-06-09 16:28:19 +00:00
|
|
|
const char *name;
|
2002-06-27 22:51:42 +00:00
|
|
|
int start, count;
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *comment;
|
2002-06-09 16:28:19 +00:00
|
|
|
|
|
|
|
for (i = 0; i < pr->progs->numfunctions; i++) {
|
|
|
|
dfunction_t *func = &pr->pr_functions[i];
|
|
|
|
|
|
|
|
name = PR_GetString (pr, func->s_name);
|
|
|
|
|
2007-04-09 07:47:51 +00:00
|
|
|
comment = "";
|
2002-06-09 16:28:19 +00:00
|
|
|
|
|
|
|
start = func->first_statement;
|
|
|
|
if (start > 0)
|
|
|
|
comment = va (" @ %d", start);
|
|
|
|
else
|
|
|
|
comment = va (" = #%d", -start);
|
|
|
|
|
2007-04-10 14:03:34 +00:00
|
|
|
printf ("%-5d %s%s: %d (", i, name, comment, func->numparms);
|
2002-06-27 22:51:42 +00:00
|
|
|
if (func->numparms < 0)
|
|
|
|
count = -func->numparms - 1;
|
|
|
|
else
|
|
|
|
count = func->numparms;
|
|
|
|
for (j = 0; j < count; j++)
|
|
|
|
printf (" %d", func->parm_size[j]);
|
2007-04-10 14:03:34 +00:00
|
|
|
printf (") %d @ %d", func->locals, func->parm_start);
|
2002-06-27 22:51:42 +00:00
|
|
|
puts ("");
|
2002-06-09 16:28:19 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-09 07:47:51 +00:00
|
|
|
|
|
|
|
static const char *
|
|
|
|
flags_string (pr_uint_t flags)
|
|
|
|
{
|
|
|
|
static dstring_t *str;
|
|
|
|
if (!str)
|
|
|
|
str = dstring_newstr ();
|
|
|
|
dstring_clearstr (str);
|
|
|
|
dstring_appendstr (str, (flags & QFOD_INITIALIZED) ? "I" : "-");
|
|
|
|
dstring_appendstr (str, (flags & QFOD_CONSTANT) ? "C" : "-");
|
|
|
|
dstring_appendstr (str, (flags & QFOD_ABSOLUTE) ? "A" : "-");
|
|
|
|
dstring_appendstr (str, (flags & QFOD_GLOBAL) ? "G" : "-");
|
|
|
|
dstring_appendstr (str, (flags & QFOD_EXTERNAL) ? "E" : "-");
|
|
|
|
dstring_appendstr (str, (flags & QFOD_LOCAL) ? "L" : "-");
|
|
|
|
dstring_appendstr (str, (flags & QFOD_SYSTEM) ? "S" : "-");
|
|
|
|
dstring_appendstr (str, (flags & QFOD_NOSAVE) ? "N" : "-");
|
|
|
|
return str->str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qfo_globals (qfo_t *qfo)
|
|
|
|
{
|
|
|
|
qfo_def_t *def;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < qfo->num_defs; i++) {
|
|
|
|
def = &qfo->defs[i];
|
2007-04-09 08:56:23 +00:00
|
|
|
printf ("%-5d %s %s", def->ofs, flags_string (def->flags),
|
2007-04-09 07:47:51 +00:00
|
|
|
qfo->strings + def->name);
|
2007-04-09 08:56:23 +00:00
|
|
|
if (!(def->flags & QFOD_EXTERNAL))
|
|
|
|
printf (" %d", qfo->data[def->ofs].integer_var);
|
|
|
|
puts ("");
|
2007-04-09 07:47:51 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-09 13:33:59 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
qfo_relocs (qfo_t *qfo)
|
|
|
|
{
|
|
|
|
qfo_reloc_t *reloc;
|
|
|
|
qfo_def_t *def;
|
|
|
|
qfo_func_t *func;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < qfo->num_relocs; i++) {
|
|
|
|
reloc = qfo->relocs + i;
|
|
|
|
if ((unsigned) reloc->type > rel_def_field_ofs) {
|
|
|
|
printf ("%d unknown reloc: %d\n", i, reloc->type);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
printf ("%s", reloc_names[reloc->type]);
|
|
|
|
def = 0;
|
|
|
|
func = 0;
|
|
|
|
switch ((reloc_type) reloc->type) {
|
|
|
|
case rel_none:
|
|
|
|
break;
|
|
|
|
case rel_op_a_def:
|
|
|
|
case rel_op_b_def:
|
|
|
|
case rel_op_c_def:
|
|
|
|
def = qfo->defs + reloc->def;
|
|
|
|
printf (" op.%c %d %d %s", reloc->type - rel_op_a_def + 'a',
|
|
|
|
reloc->ofs, def->ofs, qfo->strings + def->name);
|
|
|
|
break;
|
|
|
|
case rel_op_a_op:
|
|
|
|
case rel_op_b_op:
|
|
|
|
case rel_op_c_op:
|
|
|
|
printf (" op.%c op@%d", reloc->type - rel_op_a_def + 'a',
|
|
|
|
reloc->ofs);
|
|
|
|
break;
|
|
|
|
case rel_def_op:
|
|
|
|
printf (" def@%d op@%d", reloc->ofs, reloc->def);
|
|
|
|
break;
|
|
|
|
case rel_def_def:
|
|
|
|
def = qfo->defs + reloc->def;
|
|
|
|
printf (" def@%d def@%d %s", reloc->ofs, reloc->def,
|
|
|
|
qfo->strings + def->name);
|
|
|
|
break;
|
|
|
|
case rel_def_func:
|
|
|
|
func = qfo->funcs + reloc->def;
|
|
|
|
printf (" def@%d func@%d %s", reloc->ofs, reloc->def,
|
|
|
|
qfo->strings + func->name);
|
|
|
|
break;
|
|
|
|
case rel_def_string:
|
|
|
|
printf (" def@%d string:`%s'", reloc->ofs,
|
|
|
|
qfo->strings + qfo->data[reloc->ofs].string_var);
|
|
|
|
break;
|
|
|
|
case rel_def_field:
|
|
|
|
def = qfo->defs + reloc->def;
|
|
|
|
printf (" def@%d def@%d %s", reloc->ofs, reloc->def,
|
|
|
|
qfo->strings + def->name);
|
|
|
|
break;
|
|
|
|
case rel_op_a_def_ofs:
|
|
|
|
case rel_op_b_def_ofs:
|
|
|
|
case rel_op_c_def_ofs:
|
|
|
|
def = qfo->defs + reloc->def;
|
|
|
|
printf (" op.%c %d %d %s", reloc->type - rel_op_a_def + 'a',
|
|
|
|
reloc->ofs, def->ofs, qfo->strings + def->name);
|
|
|
|
break;
|
|
|
|
case rel_def_def_ofs:
|
|
|
|
def = qfo->defs + reloc->def;
|
|
|
|
printf (" def@%d def@%d+%d %s+%d", reloc->ofs, reloc->def,
|
|
|
|
qfo->data[reloc->ofs].integer_var,
|
|
|
|
qfo->strings + def->name,
|
|
|
|
qfo->data[reloc->ofs].integer_var);
|
|
|
|
break;
|
|
|
|
case rel_def_field_ofs:
|
|
|
|
def = qfo->defs + reloc->def;
|
|
|
|
printf (" def@%d def@%d+%d %s+%d", reloc->ofs, reloc->def,
|
|
|
|
qfo->data[reloc->ofs].integer_var,
|
|
|
|
qfo->strings + def->name,
|
|
|
|
qfo->data[reloc->ofs].integer_var);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (def && def->flags & QFOD_EXTERNAL)
|
|
|
|
printf (" external");
|
|
|
|
if (func && qfo->defs[func->def].flags & QFOD_EXTERNAL)
|
|
|
|
printf (" external");
|
|
|
|
if (def && (i < def->relocs || i >= def->relocs + def->num_relocs))
|
|
|
|
printf (" BOGUS reloc!");
|
|
|
|
if (func && (i < func->relocs || i >= func->relocs + func->num_relocs))
|
|
|
|
printf (" BOGUS reloc!");
|
|
|
|
puts ("");
|
|
|
|
}
|
|
|
|
}
|