/* objdump.c -- dump information about an object file.
- Copyright 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
+ Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
This file is part of GNU Binutils.
static char *default_target = NULL; /* default at runtime */
-extern char *program_version;
-
static int show_version = 0; /* show the version number */
static int dump_section_contents; /* -s */
static int dump_section_headers; /* -h */
static int dump_dynamic_reloc_info; /* -R */
static int dump_ar_hdrs; /* -a */
static int dump_private_headers; /* -p */
+static int prefix_addresses; /* --prefix-addresses */
static int with_line_numbers; /* -l */
static boolean with_source_code; /* -S */
static int show_raw_insn; /* --show-raw-insn */
static int dump_stab_section_info; /* --stabs */
static boolean disassemble; /* -d */
static boolean disassemble_all; /* -D */
+static int disassemble_zeroes; /* --disassemble-zeroes */
static boolean formats_info; /* -i */
static char *only; /* -j secname */
static int wide_output; /* -w */
display_bfd PARAMS ((bfd *abfd));
static void
-objdump_print_value PARAMS ((bfd_vma, struct disassemble_info *));
+objdump_print_value PARAMS ((bfd_vma, struct disassemble_info *, boolean));
+
+static asymbol *
+find_symbol_for_address PARAMS ((bfd *, asection *, bfd_vma, boolean, long *));
+
+static void
+objdump_print_addr_with_sym PARAMS ((bfd *, asection *, asymbol *, bfd_vma,
+ struct disassemble_info *, boolean));
+
+static void
+objdump_print_addr PARAMS ((bfd_vma, struct disassemble_info *, boolean));
static void
objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
static void
show_line PARAMS ((bfd *, asection *, bfd_vma));
+static void
+disassemble_bytes PARAMS ((struct disassemble_info *, disassembler_ftype,
+ boolean, bfd_byte *, long, long, arelent ***,
+ arelent **));
+
+static void
+disassemble_data PARAMS ((bfd *));
+
static const char *
endian_string PARAMS ((enum bfd_endian));
\f
fprintf (stream, "\
Usage: %s [-ahifdDprRtTxsSlw] [-b bfdname] [-m machine] [-j section-name]\n\
[--archive-headers] [--target=bfdname] [--debugging] [--disassemble]\n\
- [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
+ [--disassemble-all] [--disassemble-zeroes] [--file-headers]\n\
+ [--section-headers] [--headers]\n\
[--info] [--section=section-name] [--line-numbers] [--source]\n",
program_name);
fprintf (stream, "\
[--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
[--wide] [--version] [--help] [--private-headers]\n\
[--start-address=addr] [--stop-address=addr]\n\
- [--show-raw-insn] [-EB|-EL] [--endian={big|little}] objfile...\n\
+ [--prefix-addresses] [--show-raw-insn]\n\
+ [-EB|-EL] [--endian={big|little}] objfile...\n\
at least one option besides -l (--line-numbers) must be given\n");
list_supported_targets (program_name, stream);
+ if (status == 0)
exit (status);
}
{"debugging", no_argument, &dump_debugging, 1},
{"disassemble", no_argument, NULL, 'd'},
{"disassemble-all", no_argument, NULL, 'D'},
+ {"disassemble-zeroes", no_argument, &disassemble_zeroes, 1},
{"dynamic-reloc", no_argument, NULL, 'R'},
{"dynamic-syms", no_argument, NULL, 'T'},
{"endian", required_argument, NULL, OPTION_ENDIAN},
{"help", no_argument, NULL, 'H'},
{"info", no_argument, NULL, 'i'},
{"line-numbers", no_argument, NULL, 'l'},
+ {"prefix-addresses", no_argument, &prefix_addresses, 1},
{"reloc", no_argument, NULL, 'r'},
{"section", required_argument, NULL, 'j'},
{"section-headers", no_argument, NULL, 'h'},
if (! af && bf)
return -1;
- /* Try to sort global symbols before local symbols before debugging
- symbols. */
+ /* Try to sort global symbols before local symbols before function
+ symbols before debugging symbols. */
aflags = a->flags;
bflags = b->flags;
else
return -1;
}
+ if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
+ {
+ if ((aflags & BSF_FUNCTION) != 0)
+ return -1;
+ else
+ return 1;
+ }
if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
{
if ((aflags & BSF_LOCAL) != 0)
return 0;
}
-/* Print VMA to STREAM with no leading zeroes. */
+/* Print VMA to STREAM. If SKIP_ZEROES is true, omit leading zeroes. */
static void
-objdump_print_value (vma, info)
+objdump_print_value (vma, info, skip_zeroes)
bfd_vma vma;
struct disassemble_info *info;
+ boolean skip_zeroes;
{
char buf[30];
char *p;
sprintf_vma (buf, vma);
- for (p = buf; *p == '0'; ++p)
- ;
+ if (! skip_zeroes)
+ p = buf;
+ else
+ {
+ for (p = buf; *p == '0'; ++p)
+ ;
+ if (*p == '\0')
+ --p;
+ }
(*info->fprintf_func) (info->stream, "%s", p);
}
-/* Print VMA symbolically to INFO if possible. */
+/* Locate a symbol given a bfd, a section, and a VMA. If REQUIRE_SEC
+ is true, then always require the symbol to be in the section. This
+ returns NULL if there is no suitable symbol. If PLACE is not NULL,
+ then *PLACE is set to the index of the symbol in sorted_syms. */
-static void
-objdump_print_address (vma, info)
+static asymbol *
+find_symbol_for_address (abfd, sec, vma, require_sec, place)
+ bfd *abfd;
+ asection *sec;
bfd_vma vma;
- struct disassemble_info *info;
+ boolean require_sec;
+ long *place;
{
- 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;
- sprintf_vma (buf, vma);
- (*info->fprintf_func) (info->stream, "%s", buf);
-
if (sorted_symcount < 1)
- return;
+ return NULL;
/* Perform a binary search looking for the closest symbol to the
required value. We are searching the range (min, max]. */
== bfd_asymbol_value (sorted_syms[thisplace - 1])))
--thisplace;
- {
- /* If the file is relocateable, and the symbol could be from this
- section, prefer a symbol from this section over symbols from
- others, even if the other symbol's value might be closer.
+ /* If the file is relocateable, and the symbol could be from this
+ section, prefer a symbol from this section over symbols from
+ others, even if the other symbol's value might be closer.
- Note that this may be wrong for some symbol references if the
- sections have overlapping memory ranges, but in that case there's
- no way to tell what's desired without looking at the relocation
- table. */
- struct objdump_disasm_info *aux;
- long i;
-
- aux = (struct objdump_disasm_info *) info->application_data;
- if (sorted_syms[thisplace]->section != aux->sec
- && (aux->require_sec
- || ((aux->abfd->flags & HAS_RELOC) != 0
- && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
- && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
- + bfd_section_size (aux->abfd, aux->sec)))))
- {
- for (i = thisplace + 1; i < sorted_symcount; i++)
- {
- if (bfd_asymbol_value (sorted_syms[i])
- != bfd_asymbol_value (sorted_syms[thisplace]))
+ Note that this may be wrong for some symbol references if the
+ sections have overlapping memory ranges, but in that case there's
+ no way to tell what's desired without looking at the relocation
+ table. */
+
+ if (sorted_syms[thisplace]->section != sec
+ && (require_sec
+ || ((abfd->flags & HAS_RELOC) != 0
+ && vma >= bfd_get_section_vma (abfd, sec)
+ && vma < (bfd_get_section_vma (abfd, sec)
+ + bfd_section_size (abfd, sec)))))
+ {
+ long i;
+
+ for (i = thisplace + 1; i < sorted_symcount; i++)
+ {
+ if (bfd_asymbol_value (sorted_syms[i])
+ != bfd_asymbol_value (sorted_syms[thisplace]))
+ break;
+ }
+ --i;
+ for (; i >= 0; i--)
+ {
+ if (sorted_syms[i]->section == sec
+ && (i == 0
+ || sorted_syms[i - 1]->section != sec
+ || (bfd_asymbol_value (sorted_syms[i])
+ != bfd_asymbol_value (sorted_syms[i - 1]))))
+ {
+ thisplace = i;
break;
- }
- --i;
- for (; i >= 0; i--)
- {
- if (sorted_syms[i]->section == aux->sec
- && (i == 0
- || sorted_syms[i - 1]->section != aux->sec
- || (bfd_asymbol_value (sorted_syms[i])
- != bfd_asymbol_value (sorted_syms[i - 1]))))
- {
- thisplace = i;
- break;
- }
- }
+ }
+ }
- if (sorted_syms[thisplace]->section != aux->sec)
- {
- /* We didn't find a good symbol with a smaller value.
- Look for one with a larger value. */
- for (i = thisplace + 1; i < sorted_symcount; i++)
- {
- if (sorted_syms[i]->section == aux->sec)
- {
- thisplace = i;
- break;
- }
- }
- }
+ if (sorted_syms[thisplace]->section != sec)
+ {
+ /* We didn't find a good symbol with a smaller value.
+ Look for one with a larger value. */
+ for (i = thisplace + 1; i < sorted_symcount; i++)
+ {
+ if (sorted_syms[i]->section == sec)
+ {
+ thisplace = i;
+ break;
+ }
+ }
+ }
- if (sorted_syms[thisplace]->section != aux->sec
- && (aux->require_sec
- || ((aux->abfd->flags & HAS_RELOC) != 0
- && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
- && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
- + bfd_section_size (aux->abfd, aux->sec)))))
- {
- bfd_vma secaddr;
+ if (sorted_syms[thisplace]->section != sec
+ && (require_sec
+ || ((abfd->flags & HAS_RELOC) != 0
+ && vma >= bfd_get_section_vma (abfd, sec)
+ && vma < (bfd_get_section_vma (abfd, sec)
+ + bfd_section_size (abfd, sec)))))
+ {
+ /* There is no suitable symbol. */
+ return NULL;
+ }
+ }
- (*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)
- {
- (*info->fprintf_func) (info->stream, "-");
- objdump_print_value (secaddr - vma, info);
- }
- else if (vma > secaddr)
- {
- (*info->fprintf_func) (info->stream, "+");
- objdump_print_value (vma - secaddr, info);
- }
- (*info->fprintf_func) (info->stream, ">");
- return;
- }
- }
- }
+ if (place != NULL)
+ *place = thisplace;
+
+ return sorted_syms[thisplace];
+}
+
+/* Print an address to INFO symbolically. */
+
+static void
+objdump_print_addr_with_sym (abfd, sec, sym, vma, info, skip_zeroes)
+ bfd *abfd;
+ asection *sec;
+ asymbol *sym;
+ bfd_vma vma;
+ struct disassemble_info *info;
+ boolean skip_zeroes;
+{
+ objdump_print_value (vma, info, skip_zeroes);
- (*info->fprintf_func) (info->stream, " <%s", sorted_syms[thisplace]->name);
- if (bfd_asymbol_value (sorted_syms[thisplace]) > vma)
+ if (sym == NULL)
{
- (*info->fprintf_func) (info->stream, "-");
- objdump_print_value (bfd_asymbol_value (sorted_syms[thisplace]) - vma,
- info);
+ bfd_vma secaddr;
+
+ (*info->fprintf_func) (info->stream, " <%s",
+ bfd_get_section_name (abfd, sec));
+ secaddr = bfd_get_section_vma (abfd, sec);
+ if (vma < secaddr)
+ {
+ (*info->fprintf_func) (info->stream, "-");
+ objdump_print_value (secaddr - vma, info, true);
+ }
+ else if (vma > secaddr)
+ {
+ (*info->fprintf_func) (info->stream, "+");
+ objdump_print_value (vma - secaddr, info, true);
+ }
+ (*info->fprintf_func) (info->stream, ">");
+ }
+ else
+ {
+ (*info->fprintf_func) (info->stream, " <%s", sym->name);
+ if (bfd_asymbol_value (sym) > vma)
+ {
+ (*info->fprintf_func) (info->stream, "-");
+ objdump_print_value (bfd_asymbol_value (sym) - vma, info, true);
+ }
+ else if (vma > bfd_asymbol_value (sym))
+ {
+ (*info->fprintf_func) (info->stream, "+");
+ objdump_print_value (vma - bfd_asymbol_value (sym), info, true);
+ }
+ (*info->fprintf_func) (info->stream, ">");
}
- else if (vma > bfd_asymbol_value (sorted_syms[thisplace]))
+}
+
+/* Print VMA to INFO, symbolically if possible. If SKIP_ZEROES is
+ true, don't output leading zeroes. */
+
+static void
+objdump_print_addr (vma, info, skip_zeroes)
+ bfd_vma vma;
+ struct disassemble_info *info;
+ boolean skip_zeroes;
+{
+ struct objdump_disasm_info *aux;
+ asymbol *sym;
+
+ if (sorted_symcount < 1)
{
- (*info->fprintf_func) (info->stream, "+");
- objdump_print_value (vma - bfd_asymbol_value (sorted_syms[thisplace]),
- info);
+ objdump_print_value (vma, info, skip_zeroes);
+ return;
}
- (*info->fprintf_func) (info->stream, ">");
+
+ aux = (struct objdump_disasm_info *) info->application_data;
+ sym = find_symbol_for_address (aux->abfd, aux->sec, vma, aux->require_sec,
+ (long *) NULL);
+ objdump_print_addr_with_sym (aux->abfd, aux->sec, sym, vma, info,
+ skip_zeroes);
+}
+
+/* Print VMA to INFO. This function is passed to the disassembler
+ routine. */
+
+static void
+objdump_print_address (vma, info)
+ bfd_vma vma;
+ struct disassemble_info *info;
+{
+ objdump_print_addr (vma, info, ! prefix_addresses);
}
/* Hold the last function name and the last line number we displayed
}
#endif
+/* The number of zeroes we want to see before we start skipping them.
+ The number is arbitrarily chosen. */
+
+#define SKIP_ZEROES (8)
+
+/* The number of zeroes to skip at the end of a section. If the
+ number of zeroes at the end is between SKIP_ZEROES_AT_END and
+ SKIP_ZEROES, they will be disassembled. If there are fewer than
+ SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
+ attempt to avoid disassembling zeroes inserted by section
+ alignment. */
+
+#define SKIP_ZEROES_AT_END (3)
+
+/* Disassemble some data in memory between given values. */
+
+static void
+disassemble_bytes (info, disassemble_fn, insns, data, start, stop, relppp,
+ relppend)
+ struct disassemble_info *info;
+ disassembler_ftype disassemble_fn;
+ boolean insns;
+ bfd_byte *data;
+ long start;
+ long stop;
+ arelent ***relppp;
+ arelent **relppend;
+{
+ struct objdump_disasm_info *aux;
+ asection *section;
+ int bytes_per_line;
+ boolean done_dot;
+ int skip_addr_chars;
+ long i;
+
+ aux = (struct objdump_disasm_info *) info->application_data;
+ section = aux->sec;
+
+ if (insns)
+ bytes_per_line = 4;
+ else
+ bytes_per_line = 16;
+
+ /* Figure out how many characters to skip at the start of an
+ address, to make the disassembly look nicer. We discard leading
+ zeroes in chunks of 4, ensuring that there is always a leading
+ zero remaining. */
+ skip_addr_chars = 0;
+ if (! prefix_addresses)
+ {
+ char buf[30];
+ char *s;
+
+ sprintf_vma (buf,
+ section->vma + bfd_section_size (section->owner, section));
+ s = buf;
+ while (s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0'
+ && s[4] == '0')
+ {
+ skip_addr_chars += 4;
+ s += 4;
+ }
+ }
+
+ info->insn_info_valid = 0;
+
+ done_dot = false;
+ i = start;
+ while (i < stop)
+ {
+ long z;
+ int bytes;
+ boolean need_nl = false;
+
+ /* If we see more than SKIP_ZEROES bytes of zeroes, we just
+ print `...'. */
+ for (z = i; z < stop; z++)
+ if (data[z] != 0)
+ break;
+ if (! disassemble_zeroes
+ && (info->insn_info_valid == 0
+ || info->branch_delay_insns == 0)
+ && (z - i >= SKIP_ZEROES
+ || (z == stop && z - i < SKIP_ZEROES_AT_END)))
+ {
+ printf ("\t...\n");
+
+ /* If there are more nonzero bytes to follow, we only skip
+ zeroes in multiples of 4, to try to avoid running over
+ the start of an instruction which happens to start with
+ zero. */
+ if (z != stop)
+ z = i + ((z - i) &~ 3);
+
+ bytes = z - i;
+ }
+ else
+ {
+ char buf[1000];
+ SFILE sfile;
+ int bpc, pb = 0;
+
+ done_dot = false;
+
+ if (with_line_numbers || with_source_code)
+ show_line (aux->abfd, section, i);
+
+ if (! prefix_addresses)
+ {
+ char *s;
+
+ sprintf_vma (buf, section->vma + i);
+ for (s = buf + skip_addr_chars; *s == '0'; s++)
+ *s = ' ';
+ if (*s == '\0')
+ *--s = '0';
+ printf ("%s:\t", buf + skip_addr_chars);
+ }
+ else
+ {
+ aux->require_sec = true;
+ objdump_print_address (section->vma + i, info);
+ aux->require_sec = false;
+ putchar (' ');
+ }
+
+ if (insns)
+ {
+ sfile.buffer = sfile.current = buf;
+ info->fprintf_func = (fprintf_ftype) objdump_sprintf;
+ info->stream = (FILE *) &sfile;
+ info->bytes_per_line = 0;
+ info->bytes_per_chunk = 0;
+ bytes = (*disassemble_fn) (section->vma + i, info);
+ info->fprintf_func = (fprintf_ftype) fprintf;
+ info->stream = stdout;
+ if (info->bytes_per_line != 0)
+ bytes_per_line = info->bytes_per_line;
+ if (bytes < 0)
+ break;
+ }
+ else
+ {
+ long j;
+
+ bytes = bytes_per_line;
+ if (i + bytes > stop)
+ bytes = stop - i;
+
+ for (j = i; j < i + bytes; ++j)
+ {
+ if (isprint (data[j]))
+ buf[j - i] = data[j];
+ else
+ buf[j - i] = '.';
+ }
+ buf[j - i] = '\0';
+ }
+
+ if (! prefix_addresses || show_raw_insn)
+ {
+ long j;
+
+ /* If ! prefix_addresses and ! wide_output, we print
+ bytes_per_line bytes per line. */
+ pb = bytes;
+ if (pb > bytes_per_line && ! prefix_addresses && ! wide_output)
+ pb = bytes_per_line;
+
+ if (info->bytes_per_chunk)
+ bpc = info->bytes_per_chunk;
+ else
+ bpc = 1;
+
+ for (j = i; j < i + pb; j += bpc)
+ {
+ int k;
+ if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE)
+ {
+ for (k = bpc - 1; k >= 0; k--)
+ printf ("%02x", (unsigned) data[j + k]);
+ putchar (' ');
+ }
+ else
+ {
+ for (k = 0; k < bpc; k++)
+ printf ("%02x", (unsigned) data[j + k]);
+ putchar (' ');
+ }
+ }
+
+ for (; pb < bytes_per_line; pb += bpc)
+ {
+ int k;
+
+ for (k = 0; k < bpc; k++)
+ printf (" ");
+ putchar (' ');
+ }
+
+ /* Separate raw data from instruction by extra space. */
+ if (insns)
+ putchar ('\t');
+ else
+ printf (" ");
+ }
+
+ printf ("%s", buf);
+
+ if (! prefix_addresses || show_raw_insn)
+ {
+ while (pb < bytes)
+ {
+ long j;
+ char *s;
+
+ putchar ('\n');
+ j = i + pb;
+
+ sprintf_vma (buf, section->vma + j);
+ for (s = buf + skip_addr_chars; *s == '0'; s++)
+ *s = ' ';
+ if (*s == '\0')
+ *--s = '0';
+ printf ("%s:\t", buf + skip_addr_chars);
+
+ pb += bytes_per_line;
+ if (pb > bytes)
+ pb = bytes;
+ for (; j < i + pb; j += bpc)
+ {
+ int k;
+
+ if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE)
+ {
+ for (k = bpc - 1; k >= 0; k--)
+ printf ("%02x", (unsigned) data[j + k]);
+ putchar (' ');
+ }
+ else
+ {
+ for (k = 0; k < bpc; k++)
+ printf ("%02x", (unsigned) data[j + k]);
+ putchar (' ');
+ }
+ }
+ }
+ }
+
+ if (!wide_output)
+ putchar ('\n');
+ else
+ need_nl = true;
+ }
+
+ if (dump_reloc_info
+ && (section->flags & SEC_RELOC) != 0)
+ {
+ while ((*relppp) < relppend
+ && ((**relppp)->address >= (bfd_vma) i
+ && (**relppp)->address < (bfd_vma) i + bytes))
+ {
+ arelent *q;
+ const char *sym_name;
+
+ q = **relppp;
+
+ if (wide_output)
+ putchar ('\t');
+ else
+ printf ("\t\t\t");
+
+ objdump_print_value (section->vma + q->address, info, true);
+
+ printf (": %s\t", q->howto->name);
+
+ if (q->sym_ptr_ptr != NULL
+ && *q->sym_ptr_ptr != NULL)
+ {
+ sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
+ if (sym_name == NULL || *sym_name == '\0')
+ {
+ asection *sym_sec;
+
+ sym_sec = bfd_get_section (*q->sym_ptr_ptr);
+ sym_name = bfd_get_section_name (abfd, sym_sec);
+ if (sym_name == NULL || *sym_name == '\0')
+ sym_name = "*unknown*";
+ }
+ }
+ else
+ sym_name = "*unknown*";
+
+ printf ("%s", sym_name);
+
+ if (q->addend)
+ {
+ printf ("+0x");
+ objdump_print_value (q->addend, info, true);
+ }
+
+ printf ("\n");
+ need_nl = false;
+ ++(*relppp);
+ }
+ }
+
+ if (need_nl)
+ printf ("\n");
+
+ i += bytes;
+ }
+}
+
+/* Disassemble the contents of an object file. */
+
static void
disassemble_data (abfd)
bfd *abfd;
{
long i;
- disassembler_ftype disassemble_fn = 0; /* New style */
+ disassembler_ftype disassemble_fn;
struct disassemble_info disasm_info;
struct objdump_disasm_info aux;
asection *section;
- boolean done_dot = false;
- char buf[200];
- SFILE sfile;
print_files = NULL;
prev_functionname = NULL;
INIT_DISASSEMBLE_INFO(disasm_info, stdout, fprintf);
disasm_info.application_data = (PTR) &aux;
aux.abfd = abfd;
+ aux.require_sec = false;
disasm_info.print_address_func = objdump_print_address;
if (machine != (char *) NULL)
exit (1);
}
+ disasm_info.flavour = bfd_get_flavour (abfd);
disasm_info.arch = bfd_get_arch (abfd);
disasm_info.mach = bfd_get_mach (abfd);
if (bfd_big_endian (abfd))
if (stop > disasm_info.buffer_length)
stop = disasm_info.buffer_length;
}
- while (i < stop)
+
+ if (prefix_addresses)
+ disassemble_bytes (&disasm_info, disassemble_fn, true, data, i, stop,
+ &relpp, relppend);
+ else
{
- int bytes;
- boolean need_nl = false;
-
- if (data[i] == 0
- && (i + 1 >= stop
- || (data[i + 1] == 0
- && (i + 2 >= stop
- || (data[i + 2] == 0
- && (i + 3 >= stop
- || data[i + 3] == 0))))))
- {
- if (done_dot == false)
- {
- printf ("...\n");
- done_dot = true;
- }
- bytes = 4;
- }
- else
+ asymbol *sym;
+ long place;
+
+ sym = find_symbol_for_address (abfd, section, i, true, &place);
+ ++place;
+ while (i < stop)
{
- done_dot = false;
- if (with_line_numbers || with_source_code)
- show_line (abfd, section, i);
- aux.require_sec = true;
- objdump_print_address (section->vma + i, &disasm_info);
- aux.require_sec = false;
- putchar (' ');
+ asymbol *nextsym;
+ long nextstop;
+ boolean insns;
- 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;
+ disasm_info.symbol = sym;
- if (show_raw_insn)
+ printf ("\n");
+ objdump_print_addr_with_sym (abfd, section, sym,
+ section->vma + i,
+ &disasm_info,
+ false);
+ printf (":\n");
+
+ if (sym == NULL)
+ nextsym = NULL;
+ else
{
- long j;
- for (j = i; j < i + bytes; ++j)
- {
- printf ("%02x", (unsigned) data[j]);
- putchar (' ');
- }
- /* Separate raw data from instruction by extra space. */
- putchar (' ');
+ while (place < sorted_symcount
+ && (sorted_syms[place]->section != section
+ || (bfd_asymbol_value (sorted_syms[place])
+ <= bfd_asymbol_value (sym))))
+ ++place;
+ if (place >= sorted_symcount)
+ nextsym = NULL;
+ else
+ nextsym = sorted_syms[place];
}
- printf ("%s", sfile.buffer);
-
- if (!wide_output)
- putchar ('\n');
+ if (nextsym == NULL)
+ nextstop = stop;
else
- need_nl = true;
- }
-
- if (dump_reloc_info
- && (section->flags & SEC_RELOC) != 0)
- {
- while (relpp < relppend
- && ((*relpp)->address >= (bfd_vma) i
- && (*relpp)->address < (bfd_vma) i + bytes))
{
- arelent *q;
- const char *sym_name;
-
- q = *relpp;
-
- printf ("\t\tRELOC: ");
-
- printf_vma (section->vma + q->address);
-
- printf (" %s ", q->howto->name);
-
- if (q->sym_ptr_ptr != NULL
- && *q->sym_ptr_ptr != NULL)
- {
- sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
- if (sym_name == NULL || *sym_name == '\0')
- {
- asection *sym_sec;
+ nextstop = bfd_asymbol_value (nextsym) - section->vma;
+ if (nextstop > stop)
+ nextstop = stop;
+ }
- sym_sec = bfd_get_section (*q->sym_ptr_ptr);
- sym_name = bfd_get_section_name (abfd, sym_sec);
- if (sym_name == NULL || *sym_name == '\0')
- sym_name = "*unknown*";
- }
- }
- else
- sym_name = "*unknown*";
+ /* If a symbol is explicitly marked as being an object
+ rather than a function, just dump the bytes without
+ disassembling them. */
+ if (disassemble_all
+ || sym == NULL
+ || ((sym->flags & BSF_OBJECT) == 0
+ && (strstr (bfd_asymbol_name (sym), "gnu_compiled")
+ == NULL)
+ && (strstr (bfd_asymbol_name (sym), "gcc2_compiled")
+ == NULL))
+ || (sym->flags & BSF_FUNCTION) != 0)
+ insns = true;
+ else
+ insns = false;
- printf ("%s", sym_name);
+ disassemble_bytes (&disasm_info, disassemble_fn, insns, data, i,
+ nextstop, &relpp, relppend);
- if (q->addend)
- {
- printf ("+0x");
- printf_vma (q->addend);
- }
-
- printf ("\n");
- need_nl = false;
- ++relpp;
- }
+ i = nextstop;
+ sym = nextsym;
}
-
- if (need_nl)
- printf ("\n");
-
- i += bytes;
}
free (data);
/* The length of the longest architecture name + 1. */
#define LONGEST_ARCH sizeof("rs6000:6000")
-#ifndef L_tmpnam
-#define L_tmpnam 25
-#endif
-
static const char *
endian_string (endian)
enum bfd_endian endian;
static void
display_target_list ()
{
- extern char *tmpnam ();
extern bfd_target *bfd_target_vector[];
- char tmparg[L_tmpnam];
char *dummy_name;
int t;
- dummy_name = tmpnam (tmparg);
+ dummy_name = choose_temp_base ();
for (t = 0; bfd_target_vector[t]; t++)
{
bfd_target *p = bfd_target_vector[t];
bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
}
unlink (dummy_name);
+ free (dummy_name);
}
/* Print a table showing which architectures are supported for entries
int last;
{
extern bfd_target *bfd_target_vector[];
- extern char *tmpnam ();
- char tmparg[L_tmpnam];
int t, a;
char *dummy_name;
printf ("%s ", bfd_target_vector[t]->name);
putchar ('\n');
- dummy_name = tmpnam (tmparg);
+ dummy_name = choose_temp_base ();
for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
{
putchar ('\n');
}
unlink (dummy_name);
+ free (dummy_name);
}
/* Print tables of all the target-architecture combinations that
}
if (show_version)
- {
- printf ("GNU %s version %s\n", program_name, program_version);
- exit (0);
- }
+ print_version ("objdump");
if (seenflag == false)
usage (stderr, 1);