2002-07-12 06:19:02 +00:00
|
|
|
/*
|
2002-10-22 14:53:18 +00:00
|
|
|
qfodump.c
|
2002-07-12 06:19:02 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
qfcc object file dumping
|
2002-07-12 06:19:02 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
Copyright (C) 2002 Bill Currie <bill@taniwha.org>
|
2002-07-12 06:19:02 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2002/07/12
|
2002-07-12 06:19:02 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
# include <io.h>
|
|
|
|
#endif
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
|
|
#include "QF/dstring.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakeio.h"
|
2002-07-12 06:19:02 +00:00
|
|
|
|
|
|
|
#include "class.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "emit.h"
|
|
|
|
#include "function.h"
|
|
|
|
#include "obj_file.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "qfcc.h"
|
|
|
|
#include "type.h"
|
|
|
|
|
|
|
|
int num_linenos;
|
|
|
|
pr_lineno_t *linenos;
|
|
|
|
pr_info_t pr;
|
|
|
|
defspace_t *new_defspace (void) {return 0;}
|
|
|
|
scope_t *new_scope (scope_type type, defspace_t *space, scope_t *parent) {return 0;}
|
|
|
|
string_t ReuseString (const char *str) {return 0;}
|
|
|
|
void encode_type (dstring_t *str, type_t *type) {}
|
|
|
|
codespace_t *codespace_new (void) {return 0;}
|
|
|
|
void codespace_addcode (codespace_t *codespace, struct statement_s *code, int size) {}
|
|
|
|
type_t *parse_type (const char *str) {return 0;}
|
|
|
|
int function_parms (function_t *f, byte *parm_size) {return 0;}
|
|
|
|
pr_auxfunction_t *new_auxfunction (void) {return 0;}
|
2002-07-17 15:40:08 +00:00
|
|
|
ddef_t *new_local (void) {return 0;}
|
|
|
|
void def_to_ddef (def_t *def, ddef_t *ddef, int aux) {}
|
2002-07-12 06:19:02 +00:00
|
|
|
|
|
|
|
static const struct option long_options[] = {
|
|
|
|
{NULL, 0, NULL, 0},
|
|
|
|
};
|
|
|
|
|
2002-07-12 20:22:06 +00:00
|
|
|
void
|
|
|
|
dump_defs (qfo_t *qfo)
|
|
|
|
{
|
|
|
|
qfo_def_t *def;
|
2002-07-15 21:58:39 +00:00
|
|
|
qfo_func_t *func;
|
2002-07-12 20:22:06 +00:00
|
|
|
|
|
|
|
for (def = qfo->defs; def - qfo->defs < qfo->num_defs; def++) {
|
2002-07-16 06:40:34 +00:00
|
|
|
printf ("%5d %4d %4x %d %s %s %d %d %s:%d\n",
|
|
|
|
def - qfo->defs,
|
2002-07-12 20:22:06 +00:00
|
|
|
def->ofs,
|
|
|
|
def->flags,
|
|
|
|
def->basic_type,
|
|
|
|
qfo->types + def->full_type,
|
|
|
|
qfo->strings + def->name,
|
|
|
|
def->relocs, def->num_relocs,
|
|
|
|
qfo->strings + def->file, def->line);
|
|
|
|
if (def->flags & (QFOD_LOCAL | QFOD_EXTERNAL))
|
|
|
|
continue;
|
|
|
|
#if 1
|
|
|
|
if (def->basic_type == ev_string) {
|
2002-07-16 04:38:17 +00:00
|
|
|
printf (" %4d %s\n", qfo->data[def->ofs].string_var,
|
|
|
|
qfo->strings + qfo->data[def->ofs].string_var);
|
2002-07-12 20:22:06 +00:00
|
|
|
} else if (def->basic_type == ev_func) {
|
2002-07-15 21:58:39 +00:00
|
|
|
if (qfo->data[def->ofs].func_var < 1
|
|
|
|
|| qfo->data[def->ofs].func_var - 1 > qfo->num_funcs)
|
|
|
|
func = 0;
|
|
|
|
else
|
|
|
|
func = qfo->funcs + qfo->data[def->ofs].func_var - 1;
|
2002-07-12 20:22:06 +00:00
|
|
|
printf (" %4d %s\n", qfo->data[def->ofs].func_var,
|
2002-07-15 21:58:39 +00:00
|
|
|
func ? qfo->strings + func->name : "BORKAGE");
|
2002-07-16 21:59:47 +00:00
|
|
|
} else if (def->basic_type == ev_field) {
|
|
|
|
printf (" %4d\n", qfo->data[def->ofs].integer_var);
|
2002-07-12 20:22:06 +00:00
|
|
|
} else {
|
|
|
|
// printf (" %4d\n", qfo->data[def->ofs].integer_var);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-15 21:37:52 +00:00
|
|
|
dump_funcs (qfo_t *qfo)
|
2002-07-12 20:22:06 +00:00
|
|
|
{
|
2002-07-15 21:37:52 +00:00
|
|
|
qfo_func_t *func;
|
2002-07-12 20:22:06 +00:00
|
|
|
int i;
|
|
|
|
const char *str = qfo->strings;
|
|
|
|
|
2002-07-15 21:37:52 +00:00
|
|
|
for (i = 0; i < qfo->num_funcs; i++) {
|
|
|
|
func = qfo->funcs + i;
|
2002-07-16 06:40:34 +00:00
|
|
|
printf ("%5d %s %s:%d %d?%d %d %d,%d\n", i,
|
2002-07-12 20:22:06 +00:00
|
|
|
str + func->name, str + func->file, func->line,
|
2002-07-16 04:38:17 +00:00
|
|
|
func->builtin, func->code, func->def,
|
|
|
|
func->relocs, func->num_relocs);
|
2002-07-12 20:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *reloc_names[] = {
|
|
|
|
"none",
|
|
|
|
"op_a_def",
|
|
|
|
"op_b_def",
|
|
|
|
"op_c_def",
|
|
|
|
"op_a_op",
|
|
|
|
"op_b_op",
|
|
|
|
"op_c_op",
|
|
|
|
"def_op",
|
|
|
|
"def_def",
|
|
|
|
"def_func",
|
|
|
|
"def_string",
|
2002-07-16 21:59:47 +00:00
|
|
|
"def_field",
|
2002-07-12 20:22:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
dump_relocs (qfo_t *qfo)
|
|
|
|
{
|
|
|
|
qfo_reloc_t *reloc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < qfo->num_relocs; i++) {
|
|
|
|
reloc = qfo->relocs + i;
|
2002-07-16 06:40:34 +00:00
|
|
|
printf ("%5d %5d %-10s %d\n", i, reloc->ofs, reloc_names[reloc->type],
|
2002-07-12 20:22:06 +00:00
|
|
|
reloc->def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-17 14:19:30 +00:00
|
|
|
void
|
|
|
|
dump_lines (qfo_t *qfo)
|
|
|
|
{
|
|
|
|
pr_lineno_t *line;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < qfo->num_lines; i++) {
|
|
|
|
line = qfo->lines + i;
|
|
|
|
printf ("%5d %5d %d\n", i, line->fa.addr, line->line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-12 06:19:02 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
qfo_t *qfo;
|
|
|
|
|
|
|
|
while ((c = getopt_long (argc, argv, "", long_options, 0)) != EOF) {
|
|
|
|
switch (c) {
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (optind < argc) {
|
2002-07-21 07:12:17 +00:00
|
|
|
qfo = qfo_open (argv[optind++]);
|
2002-07-12 06:19:02 +00:00
|
|
|
if (!qfo)
|
|
|
|
return 1;
|
2002-07-12 20:22:06 +00:00
|
|
|
dump_defs (qfo);
|
2002-07-15 21:37:52 +00:00
|
|
|
dump_funcs (qfo);
|
2002-07-12 20:22:06 +00:00
|
|
|
dump_relocs (qfo);
|
2002-07-17 14:19:30 +00:00
|
|
|
dump_lines (qfo);
|
2002-07-12 06:19:02 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|