#include "debug.h"
#include "budbg.h"
+#ifdef ANSI_PROTOTYPES
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
/* Internal headers for the ELF .stab-dump code - sorry. */
#define BYTES_IN_WORD 32
#include "aout/aout64.h"
#ifdef NEED_DECLARATION_FPRINTF
/* This is needed by INIT_DISASSEMBLE_INFO. */
-extern int fprintf PARAMS ((FILE *, const char *));
+extern int fprintf PARAMS ((FILE *, const char *, ...));
#endif
char *default_target = NULL; /* default at runtime */
display_bfd PARAMS ((bfd *abfd));
static void
-objdump_print_value PARAMS ((bfd_vma, FILE *));
+objdump_print_value PARAMS ((bfd_vma, struct disassemble_info *));
static void
objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
/* Print VMA to STREAM with no leading zeroes. */
static void
-objdump_print_value (vma, stream)
+objdump_print_value (vma, info)
bfd_vma vma;
- FILE *stream;
+ struct disassemble_info *info;
{
char buf[30];
char *p;
sprintf_vma (buf, vma);
for (p = buf; *p == '0'; ++p)
;
- fprintf (stream, "%s", p);
+ (*info->fprintf_func) (info->stream, "%s", p);
}
/* Print VMA symbolically to INFO if possible. */
bfd_vma vma;
struct disassemble_info *info;
{
+ char buf[30];
+
/* @@ Would it speed things up to cache the last two symbols returned,
and maybe their address ranges? For many processors, only one memory
operand can be present at a time, so the 2-entry cache wouldn't be
long max = sorted_symcount;
long thisplace;
- fprintf_vma (info->stream, vma);
+ sprintf_vma (buf, vma);
+ (*info->fprintf_func) (info->stream, "%s", buf);
if (sorted_symcount < 1)
return;
{
bfd_vma secaddr;
- fprintf (info->stream, " <%s",
- bfd_get_section_name (aux->abfd, aux->sec));
+ (*info->fprintf_func) (info->stream, " <%s",
+ bfd_get_section_name (aux->abfd, aux->sec));
secaddr = bfd_get_section_vma (aux->abfd, aux->sec);
if (vma < secaddr)
{
- fprintf (info->stream, "-");
- objdump_print_value (secaddr - vma, info->stream);
+ (*info->fprintf_func) (info->stream, "-");
+ objdump_print_value (secaddr - vma, info);
}
else if (vma > secaddr)
{
- fprintf (info->stream, "+");
- objdump_print_value (vma - secaddr, info->stream);
+ (*info->fprintf_func) (info->stream, "+");
+ objdump_print_value (vma - secaddr, info);
}
- fprintf (info->stream, ">");
+ (*info->fprintf_func) (info->stream, ">");
return;
}
}
}
- fprintf (info->stream, " <%s", sorted_syms[thisplace]->name);
+ (*info->fprintf_func) (info->stream, " <%s", sorted_syms[thisplace]->name);
if (bfd_asymbol_value (sorted_syms[thisplace]) > vma)
{
- fprintf (info->stream, "-");
+ (*info->fprintf_func) (info->stream, "-");
objdump_print_value (bfd_asymbol_value (sorted_syms[thisplace]) - vma,
- info->stream);
+ info);
}
else if (vma > bfd_asymbol_value (sorted_syms[thisplace]))
{
- fprintf (info->stream, "+");
+ (*info->fprintf_func) (info->stream, "+");
objdump_print_value (vma - bfd_asymbol_value (sorted_syms[thisplace]),
- info->stream);
+ info);
}
- fprintf (info->stream, ">");
+ (*info->fprintf_func) (info->stream, ">");
}
/* Hold the last function name and the last line number we displayed
prev_line = line;
}
+/* Pseudo FILE object for strings. */
+typedef struct {
+ char *buffer;
+ char *current;
+} SFILE;
+
+/* sprintf to a "stream" */
+
+#ifdef ANSI_PROTOTYPES
+static int
+objdump_sprintf (SFILE *f, const char *format, ...)
+{
+ int n;
+ va_list args;
+
+ va_start (args, format);
+ vsprintf (f->current, format, args);
+ f->current += n = strlen (f->current);
+ va_end (args);
+ return n;
+}
+#else
+static int
+objdump_sprintf (va_alist)
+ va_dcl
+{
+ int n;
+ SFILE *f;
+ const char *format;
+ va_list args;
+
+ va_start (args);
+ f = va_arg (args, SFILE *);
+ format = va_arg (args, const char *);
+ vsprintf (f->current, format, args);
+ f->current += n = strlen (f->current);
+ va_end (args);
+ return n;
+}
+#endif
+
void
disassemble_data (abfd)
bfd *abfd;
struct objdump_disasm_info aux;
asection *section;
boolean done_dot = false;
+ char buf[200];
+ SFILE sfile;
print_files = NULL;
prev_functionname = NULL;
disasm_info.application_data = (PTR) &aux;
aux.abfd = abfd;
disasm_info.print_address_func = objdump_print_address;
- if (show_raw_insn)
- disasm_info.flags |= DISASM_RAW_INSN_FLAG;
if (machine != (char *) NULL)
{
aux.require_sec = false;
putchar (' ');
+ sfile.buffer = sfile.current = buf;
+ disasm_info.fprintf_func = (fprintf_ftype) objdump_sprintf;
+ disasm_info.stream = (FILE *) &sfile;
bytes = (*disassemble_fn) (section->vma + i, &disasm_info);
+ disasm_info.fprintf_func = (fprintf_ftype) fprintf;
+ disasm_info.stream = stdout;
if (bytes < 0)
break;
+ if (show_raw_insn)
+ {
+ long j;
+ for (j = i; j < i + bytes; ++j)
+ {
+ printf ("%02x", (unsigned) data[j]);
+ putchar (' ');
+ }
+ /* Separate raw data from instruction by extra space. */
+ putchar (' ');
+ }
+
+ printf ("%s", sfile.buffer);
+
if (!wide_output)
putchar ('\n');
else
could be a direct-mapped table, but instead we build one the first
time we need it. */
-char **stab_name;
-
-struct stab_print {
- int value;
- char *string;
-};
-
-struct stab_print stab_print[] = {
-#define __define_stab(NAME, CODE, STRING) {CODE, STRING},
-#include "aout/stab.def"
-#undef __define_stab
- {0, ""}
-};
-
void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name,
char *strsect_name));
dump_stabs (abfd)
bfd *abfd;
{
- /* Allocate and initialize stab name array if first time. */
- if (stab_name == NULL)
- {
- int i;
-
- stab_name = (char **) xmalloc (256 * sizeof(char *));
- /* Clear the array. */
- for (i = 0; i < 256; i++)
- stab_name[i] = NULL;
- /* Fill in the defined stabs. */
- for (i = 0; *stab_print[i].string; i++)
- stab_name[stab_print[i].value] = stab_print[i].string;
- }
-
dump_section_stabs (abfd, ".stab", ".stabstr");
dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
for (i = -1; stabp < stabs_end; stabp++, i++)
{
+ const char *name;
+
SWAP_SYMBOL (stabp, abfd);
printf ("\n%-6d ", i);
/* Either print the stab name, or, if unnamed, print its number
again (makes consistent formatting for tools like awk). */
- if (stab_name[stabp->n_type])
- printf ("%-6s", stab_name[stabp->n_type]);
+ name = bfd_get_stab_name (stabp->n_type);
+ if (name != NULL)
+ printf ("%-6s", name);
else if (stabp->n_type == N_UNDF)
printf ("HdrSym");
else