/* objdump.c -- dump information about an object file.
- Copyright (C) 1990-2019 Free Software Foundation, Inc.
+ Copyright (C) 1990-2021 Free Software Foundation, Inc.
This file is part of GNU Binutils.
static int show_version = 0; /* Show the version number. */
static int dump_section_contents; /* -s */
static int dump_section_headers; /* -h */
-static bfd_boolean dump_file_header; /* -f */
+static bool dump_file_header; /* -f */
static int dump_symtab; /* -t */
static int dump_dynamic_symtab; /* -T */
static int dump_reloc_info; /* -r */
static int dump_ar_hdrs; /* -a */
static int dump_private_headers; /* -p */
static char *dump_private_options; /* -P */
+static int no_addresses; /* --no-addresses */
static int prefix_addresses; /* --prefix-addresses */
static int with_line_numbers; /* -l */
-static bfd_boolean with_source_code; /* -S */
+static bool with_source_code; /* -S */
static int show_raw_insn; /* --show-raw-insn */
static int dump_dwarf_section_info; /* --dwarf */
static int dump_stab_section_info; /* --stabs */
static char *dump_ctf_section_name;
static char *dump_ctf_parent_name; /* --ctf-parent */
static int do_demangle; /* -C, --demangle */
-static bfd_boolean disassemble; /* -d */
-static bfd_boolean disassemble_all; /* -D */
+static bool disassemble; /* -d */
+static bool disassemble_all; /* -D */
static int disassemble_zeroes; /* --disassemble-zeroes */
-static bfd_boolean formats_info; /* -i */
+static bool formats_info; /* -i */
static int wide_output; /* -w */
static int insn_width; /* --insn-width */
static bfd_vma start_address = (bfd_vma) -1; /* --start-address */
static int dump_special_syms = 0; /* --special-syms */
static bfd_vma adjust_section_vma = 0; /* --adjust-vma */
static int file_start_context = 0; /* --file-start-context */
-static bfd_boolean display_file_offsets;/* -F */
+static bool display_file_offsets; /* -F */
static const char *prefix; /* --prefix */
static int prefix_strip; /* --prefix-strip */
static size_t prefix_length;
-static bfd_boolean unwind_inlines; /* --inlines. */
+static bool unwind_inlines; /* --inlines. */
static const char * disasm_sym; /* Disassembly start symbol. */
static const char * source_comment; /* --source_comment. */
+static bool visualize_jumps = false; /* --visualize-jumps. */
+static bool color_output = false; /* --visualize-jumps=color. */
+static bool extended_color_output = false; /* --visualize-jumps=extended-color. */
+static int process_links = false; /* --process-links. */
static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
/* A structure to record the sections mentioned in -j switches. */
struct only
{
- const char * name; /* The name of the section. */
- bfd_boolean seen; /* A flag to indicate that the section has been found in one or more input files. */
- struct only * next; /* Pointer to the next structure in the list. */
+ const char *name; /* The name of the section. */
+ bool seen; /* A flag to indicate that the section has been found in one or more input files. */
+ struct only *next; /* Pointer to the next structure in the list. */
};
/* Pointer to an array of 'only' structures.
This pointer is NULL if the -j switch has not been used. */
function. */
struct objdump_disasm_info
{
- bfd * abfd;
- asection * sec;
- bfd_boolean require_sec;
- arelent ** dynrelbuf;
- long dynrelcount;
+ bfd *abfd;
+ bool require_sec;
disassembler_ftype disassemble_fn;
- arelent * reloc;
- const char * symbol;
+ arelent *reloc;
+ const char *symbol;
};
/* Architecture to disassemble for, or default if NULL. */
OBJDUMP_PRIVATE_VECTORS
NULL
};
+
+/* The list of detected jumps inside a function. */
+static struct jump_info *detected_jumps = NULL;
\f
static void usage (FILE *, int) ATTRIBUTE_NORETURN;
static void
fprintf (stream, _(" Display information from object <file(s)>.\n"));
fprintf (stream, _(" At least one of the following switches must be given:\n"));
fprintf (stream, _("\
- -a, --archive-headers Display archive header information\n\
- -f, --file-headers Display the contents of the overall file header\n\
- -p, --private-headers Display object format specific file header contents\n\
- -P, --private=OPT,OPT... Display object format specific contents\n\
- -h, --[section-]headers Display the contents of the section headers\n\
- -x, --all-headers Display the contents of all headers\n\
- -d, --disassemble Display assembler contents of executable sections\n\
- -D, --disassemble-all Display assembler contents of all sections\n\
- --disassemble=<sym> Display assembler contents from <sym>\n\
- -S, --source Intermix source code with disassembly\n\
- --source-comment[=<txt>] Prefix lines of source code with <txt>\n\
- -s, --full-contents Display the full contents of all sections requested\n\
- -g, --debugging Display debug information in object file\n\
- -e, --debugging-tags Display debug information using ctags style\n\
- -G, --stabs Display (in raw form) any STABS info in the file\n\
- -W[lLiaprmfFsoRtUuTgAckK] or\n\
- --dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
- =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
- =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
- =addr,=cu_index,=links,=follow-links]\n\
- Display DWARF info in the file\n\
- --ctf=SECTION Display CTF info from SECTION\n\
- -t, --syms Display the contents of the symbol table(s)\n\
- -T, --dynamic-syms Display the contents of the dynamic symbol table\n\
- -r, --reloc Display the relocation entries in the file\n\
- -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
- @<file> Read options from <file>\n\
- -v, --version Display this program's version number\n\
- -i, --info List object formats and architectures supported\n\
- -H, --help Display this information\n\
-"));
+ -a, --archive-headers Display archive header information\n"));
+ fprintf (stream, _("\
+ -f, --file-headers Display the contents of the overall file header\n"));
+ fprintf (stream, _("\
+ -p, --private-headers Display object format specific file header contents\n"));
+ fprintf (stream, _("\
+ -P, --private=OPT,OPT... Display object format specific contents\n"));
+ fprintf (stream, _("\
+ -h, --[section-]headers Display the contents of the section headers\n"));
+ fprintf (stream, _("\
+ -x, --all-headers Display the contents of all headers\n"));
+ fprintf (stream, _("\
+ -d, --disassemble Display assembler contents of executable sections\n"));
+ fprintf (stream, _("\
+ -D, --disassemble-all Display assembler contents of all sections\n"));
+ fprintf (stream, _("\
+ --disassemble=<sym> Display assembler contents from <sym>\n"));
+ fprintf (stream, _("\
+ -S, --source Intermix source code with disassembly\n"));
+ fprintf (stream, _("\
+ --source-comment[=<txt>] Prefix lines of source code with <txt>\n"));
+ fprintf (stream, _("\
+ -s, --full-contents Display the full contents of all sections requested\n"));
+ fprintf (stream, _("\
+ -g, --debugging Display debug information in object file\n"));
+ fprintf (stream, _("\
+ -e, --debugging-tags Display debug information using ctags style\n"));
+ fprintf (stream, _("\
+ -G, --stabs Display (in raw form) any STABS info in the file\n"));
+ fprintf (stream, _("\
+ -W, --dwarf[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
+ f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
+ m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
+ s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
+ U/=trace_info]\n\
+ Display the contents of DWARF debug sections\n"));
+ fprintf (stream, _("\
+ -Wk,--dwarf=links Display the contents of sections that link to\n\
+ separate debuginfo files\n"));
+#if DEFAULT_FOR_FOLLOW_LINKS
+ fprintf (stream, _("\
+ -WK,--dwarf=follow-links\n\
+ Follow links to separate debug info files (default)\n"));
+ fprintf (stream, _("\
+ -WN,--dwarf=no-follow-links\n\
+ Do not follow links to separate debug info files\n"));
+#else
+ fprintf (stream, _("\
+ -WK,--dwarf=follow-links\n\
+ Follow links to separate debug info files\n"));
+ fprintf (stream, _("\
+ -WN,--dwarf=no-follow-links\n\
+ Do not follow links to separate debug info files\n\
+ (default)\n"));
+#endif
+ fprintf (stream, _("\
+ -L, --process-links Display the contents of non-debug sections in\n\
+ separate debuginfo files. (Implies -WK)\n"));
+#ifdef ENABLE_LIBCTF
+ fprintf (stream, _("\
+ --ctf=SECTION Display CTF info from SECTION\n"));
+#endif
+ fprintf (stream, _("\
+ -t, --syms Display the contents of the symbol table(s)\n"));
+ fprintf (stream, _("\
+ -T, --dynamic-syms Display the contents of the dynamic symbol table\n"));
+ fprintf (stream, _("\
+ -r, --reloc Display the relocation entries in the file\n"));
+ fprintf (stream, _("\
+ -R, --dynamic-reloc Display the dynamic relocation entries in the file\n"));
+ fprintf (stream, _("\
+ @<file> Read options from <file>\n"));
+ fprintf (stream, _("\
+ -v, --version Display this program's version number\n"));
+ fprintf (stream, _("\
+ -i, --info List object formats and architectures supported\n"));
+ fprintf (stream, _("\
+ -H, --help Display this information\n"));
+
if (status != 2)
{
const struct objdump_private_desc * const *desc;
fprintf (stream, _("\n The following switches are optional:\n"));
fprintf (stream, _("\
- -b, --target=BFDNAME Specify the target object format as BFDNAME\n\
- -m, --architecture=MACHINE Specify the target architecture as MACHINE\n\
- -j, --section=NAME Only display information for section NAME\n\
- -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
- -EB --endian=big Assume big endian format when disassembling\n\
- -EL --endian=little Assume little endian format when disassembling\n\
- --file-start-context Include context from start of file (with -S)\n\
- -I, --include=DIR Add DIR to search list for source files\n\
- -l, --line-numbers Include line numbers and filenames in output\n\
- -F, --file-offsets Include file offsets when displaying information\n\
+ -b, --target=BFDNAME Specify the target object format as BFDNAME\n"));
+ fprintf (stream, _("\
+ -m, --architecture=MACHINE Specify the target architecture as MACHINE\n"));
+ fprintf (stream, _("\
+ -j, --section=NAME Only display information for section NAME\n"));
+ fprintf (stream, _("\
+ -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n"));
+ fprintf (stream, _("\
+ -EB --endian=big Assume big endian format when disassembling\n"));
+ fprintf (stream, _("\
+ -EL --endian=little Assume little endian format when disassembling\n"));
+ fprintf (stream, _("\
+ --file-start-context Include context from start of file (with -S)\n"));
+ fprintf (stream, _("\
+ -I, --include=DIR Add DIR to search list for source files\n"));
+ fprintf (stream, _("\
+ -l, --line-numbers Include line numbers and filenames in output\n"));
+ fprintf (stream, _("\
+ -F, --file-offsets Include file offsets when displaying information\n"));
+ fprintf (stream, _("\
-C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
The STYLE, if specified, can be `auto', `gnu',\n\
`lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
- or `gnat'\n\
- --recurse-limit Enable a limit on recursion whilst demangling. [Default]\n\
- --no-recurse-limit Disable a limit on recursion whilst demangling\n\
- -w, --wide Format output for more than 80 columns\n\
- -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\
- --start-address=ADDR Only process data whose address is >= ADDR\n\
- --stop-address=ADDR Only process data whose address is < ADDR\n\
- --prefix-addresses Print complete address alongside disassembly\n\
- --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\
- --insn-width=WIDTH Display WIDTH bytes on a single line for -d\n\
- --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
- --special-syms Include special symbols in symbol dumps\n\
- --inlines Print all inlines for source line (with -l)\n\
- --prefix=PREFIX Add PREFIX to absolute paths for -S\n\
+ or `gnat'\n"));
+ fprintf (stream, _("\
+ --recurse-limit Enable a limit on recursion whilst demangling\n\
+ (default)\n"));
+ fprintf (stream, _("\
+ --no-recurse-limit Disable a limit on recursion whilst demangling\n"));
+ fprintf (stream, _("\
+ -w, --wide Format output for more than 80 columns\n"));
+ fprintf (stream, _("\
+ -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n"));
+ fprintf (stream, _("\
+ --start-address=ADDR Only process data whose address is >= ADDR\n"));
+ fprintf (stream, _("\
+ --stop-address=ADDR Only process data whose address is < ADDR\n"));
+ fprintf (stream, _("\
+ --no-addresses Do not print address alongside disassembly\n"));
+ fprintf (stream, _("\
+ --prefix-addresses Print complete address alongside disassembly\n"));
+ fprintf (stream, _("\
+ --[no-]show-raw-insn Display hex alongside symbolic disassembly\n"));
+ fprintf (stream, _("\
+ --insn-width=WIDTH Display WIDTH bytes on a single line for -d\n"));
+ fprintf (stream, _("\
+ --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n"));
+ fprintf (stream, _("\
+ --special-syms Include special symbols in symbol dumps\n"));
+ fprintf (stream, _("\
+ --inlines Print all inlines for source line (with -l)\n"));
+ fprintf (stream, _("\
+ --prefix=PREFIX Add PREFIX to absolute paths for -S\n"));
+ fprintf (stream, _("\
--prefix-strip=LEVEL Strip initial directory names for -S\n"));
fprintf (stream, _("\
- --dwarf-depth=N Do not display DIEs at depth N or greater\n\
- --dwarf-start=N Display DIEs starting with N, at the same depth\n\
- or deeper\n\
- --dwarf-check Make additional dwarf internal consistency checks.\
- \n\
- --ctf-parent=SECTION Use SECTION as the CTF parent\n\n"));
+ --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
+ fprintf (stream, _("\
+ --dwarf-start=N Display DIEs starting at offset N\n"));
+ fprintf (stream, _("\
+ --dwarf-check Make additional dwarf consistency checks.\n"));
+#ifdef ENABLE_LIBCTF
+ fprintf (stream, _("\
+ --ctf-parent=SECTION Use SECTION as the CTF parent\n"));
+#endif
+ fprintf (stream, _("\
+ --visualize-jumps Visualize jumps by drawing ASCII art lines\n"));
+ fprintf (stream, _("\
+ --visualize-jumps=color Use colors in the ASCII art\n"));
+ fprintf (stream, _("\
+ --visualize-jumps=extended-color\n\
+ Use extended 8-bit color codes\n"));
+ fprintf (stream, _("\
+ --visualize-jumps=off Disable jump visualization\n\n"));
+
list_supported_targets (program_name, stream);
list_supported_architectures (program_name, stream);
OPTION_NO_RECURSE_LIMIT,
OPTION_INLINES,
OPTION_SOURCE_COMMENT,
+#ifdef ENABLE_LIBCTF
OPTION_CTF,
- OPTION_CTF_PARENT
+ OPTION_CTF_PARENT,
+#endif
+ OPTION_VISUALIZE_JUMPS
};
static struct option long_options[]=
{"info", no_argument, NULL, 'i'},
{"line-numbers", no_argument, NULL, 'l'},
{"no-show-raw-insn", no_argument, &show_raw_insn, -1},
+ {"no-addresses", no_argument, &no_addresses, 1},
+ {"process-links", no_argument, &process_links, true},
{"prefix-addresses", no_argument, &prefix_addresses, 1},
{"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT},
{"recursion-limit", no_argument, NULL, OPTION_RECURSE_LIMIT},
{"special-syms", no_argument, &dump_special_syms, 1},
{"include", required_argument, NULL, 'I'},
{"dwarf", optional_argument, NULL, OPTION_DWARF},
+#ifdef ENABLE_LIBCTF
{"ctf", required_argument, NULL, OPTION_CTF},
{"ctf-parent", required_argument, NULL, OPTION_CTF_PARENT},
+#endif
{"stabs", no_argument, NULL, 'G'},
{"start-address", required_argument, NULL, OPTION_START_ADDRESS},
{"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
{"dwarf-start", required_argument, 0, OPTION_DWARF_START},
{"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
{"inlines", no_argument, 0, OPTION_INLINES},
+ {"visualize-jumps", optional_argument, 0, OPTION_VISUALIZE_JUMPS},
{0, no_argument, 0, 0}
};
\f
\f
/* Returns TRUE if the specified section should be dumped. */
-static bfd_boolean
+static bool
process_section_p (asection * section)
{
struct only * only;
if (only_list == NULL)
- return TRUE;
+ return true;
for (only = only_list; only; only = only->next)
if (strcmp (only->name, section->name) == 0)
{
- only->seen = TRUE;
- return TRUE;
+ only->seen = true;
+ return true;
}
- return FALSE;
+ return false;
}
/* Add an entry to the 'only' list. */
only = xmalloc (sizeof * only);
only->name = name;
- only->seen = FALSE;
+ only->seen = false;
only->next = only_list;
only_list = only;
}
static void
free_only_list (void)
{
- bfd_boolean at_least_one_seen = FALSE;
+ bool at_least_one_seen = false;
struct only * only;
struct only * next;
for (only = only_list; only; only = only->next)
if (only->seen)
{
- at_least_one_seen = TRUE;
+ at_least_one_seen = true;
break;
}
non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd));
bfd_fatal (_("error message was"));
}
+
if (storage)
{
off_t filesize = bfd_get_file_size (abfd);
&& filesize < storage
/* The MMO file format supports its own special compression
technique, so its sections can be larger than the file size. */
- && bfd_get_flavour (abfd) != bfd_target_mmo_flavour)
+ && bfd_get_flavour (abfd) != bfd_target_mmo_flavour)
{
bfd_nonfatal_message (bfd_get_filename (abfd), abfd, NULL,
- _("error: symbol table size (%#lx) is larger than filesize (%#lx)"),
- storage, (long) filesize);
+ _("error: symbol table size (%#lx) "
+ "is larger than filesize (%#lx)"),
+ storage, (long) filesize);
exit_status = 1;
symcount = 0;
return NULL;
bfd_fatal (bfd_get_filename (abfd));
}
+
if (storage)
sy = (asymbol **) xmalloc (storage);
table of sorted symbol names, even if they are marked as
debugging/section symbols. */
-static bfd_boolean
+static bool
is_significant_symbol_name (const char * name)
{
- return strncmp (name, ".plt", 4) == 0 || strcmp (name, ".got") == 0;
+ return startswith (name, ".plt") || startswith (name, ".got");
}
/* Filter out (in place) symbols that are useless for disassembly.
return out_ptr - symbols;
}
+static const asection *compare_section;
+
/* Sort symbols into value order. */
static int
const char *bn;
size_t anl;
size_t bnl;
- bfd_boolean af;
- bfd_boolean bf;
+ bool as, af, bs, bf;
flagword aflags;
flagword bflags;
else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
return -1;
- if (a->section > b->section)
- return 1;
- else if (a->section < b->section)
+ /* Prefer symbols from the section currently being disassembled.
+ Don't sort symbols from other sections by section, since there
+ isn't much reason to prefer one section over another otherwise.
+ See sym_ok comment for why we compare by section name. */
+ as = strcmp (compare_section->name, a->section->name) == 0;
+ bs = strcmp (compare_section->name, b->section->name) == 0;
+ if (as && !bs)
return -1;
+ if (!as && bs)
+ return 1;
an = bfd_asymbol_name (a);
bn = bfd_asymbol_name (b);
#define file_symbol(s, sn, snl) \
(((s)->flags & BSF_FILE) != 0 \
- || ((sn)[(snl) - 2] == '.' \
+ || ((snl) > 2 \
+ && (sn)[(snl) - 2] == '.' \
&& ((sn)[(snl) - 1] == 'o' \
|| (sn)[(snl) - 1] == 'a')))
if (! af && bf)
return -1;
- /* Try to sort global symbols before local symbols before function
- symbols before debugging symbols. */
+ /* Sort function and object symbols before global symbols before
+ local symbols before section symbols before debugging symbols. */
aflags = a->flags;
bflags = b->flags;
else
return -1;
}
+ if ((aflags & BSF_SECTION_SYM) != (bflags & BSF_SECTION_SYM))
+ {
+ if ((aflags & BSF_SECTION_SYM) != 0)
+ return 1;
+ else
+ return -1;
+ }
if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
{
if ((aflags & BSF_FUNCTION) != 0)
else
return 1;
}
+ if ((aflags & BSF_OBJECT) != (bflags & BSF_OBJECT))
+ {
+ if ((aflags & BSF_OBJECT) != 0)
+ return -1;
+ else
+ return 1;
+ }
if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
{
if ((aflags & BSF_LOCAL) != 0)
static void
objdump_print_value (bfd_vma vma, struct disassemble_info *inf,
- bfd_boolean skip_zeroes)
+ bool skip_zeroes)
{
char buf[30];
char *p;
{
char *alloc;
const char *name, *version_string = NULL;
- bfd_boolean hidden = FALSE;
+ bool hidden = false;
alloc = NULL;
name = bfd_asymbol_name (sym);
}
if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0)
- version_string = bfd_get_symbol_version_string (abfd, sym, &hidden);
+ version_string = bfd_get_symbol_version_string (abfd, sym, true,
+ &hidden);
if (bfd_is_und_section (bfd_asymbol_section (sym)))
- hidden = TRUE;
+ hidden = true;
name = sanitize_string (name);
free (alloc);
}
-static inline bfd_boolean
-sym_ok (bfd_boolean want_section,
- bfd * abfd ATTRIBUTE_UNUSED,
- long place,
- asection * sec,
- struct disassemble_info * inf)
+static inline bool
+sym_ok (bool want_section,
+ bfd *abfd ATTRIBUTE_UNUSED,
+ long place,
+ asection *sec,
+ struct disassemble_info *inf)
{
if (want_section)
{
+ /* NB: An object file can have different sections with the same
+ section name. Compare compare section pointers if they have
+ the same owner. */
+ if (sorted_syms[place]->section->owner == sec->owner
+ && sorted_syms[place]->section != sec)
+ return false;
+
/* Note - we cannot just compare section pointers because they could
be different, but the same... Ie the symbol that we are trying to
find could have come from a separate debug info file. Under such
will be the same. */
if (strcmp (bfd_section_name (sorted_syms[place]->section),
bfd_section_name (sec)) != 0)
- return FALSE;
+ return false;
}
return inf->symbol_is_valid (sorted_syms[place], inf);
bfd *abfd;
asection *sec;
unsigned int opb;
- bfd_boolean want_section;
+ bool want_section;
long rel_count;
if (sorted_symcount < 1)
aux = (struct objdump_disasm_info *) inf->application_data;
abfd = aux->abfd;
- sec = aux->sec;
+ sec = inf->section;
opb = inf->octets_per_byte;
/* Perform a binary search looking for the closest symbol to the
/* The symbol we want is now in min, the low end of the range we
were searching. If there are several symbols with the same
- value, we want the first (non-section/non-debugging) one. */
+ value, we want the first one. */
thisplace = min;
while (thisplace > 0
&& (bfd_asymbol_value (sorted_syms[thisplace])
- == bfd_asymbol_value (sorted_syms[thisplace - 1]))
- && ((sorted_syms[thisplace - 1]->flags
- & (BSF_SECTION_SYM | BSF_DEBUGGING)) == 0)
- )
+ == bfd_asymbol_value (sorted_syms[thisplace - 1])))
--thisplace;
/* Prefer a symbol in the current section if we have multple symbols
&& (bfd_asymbol_value (sorted_syms[min])
== bfd_asymbol_value (sorted_syms[thisplace])))
{
- if (sym_ok (TRUE, abfd, min, sec, inf))
+ if (sym_ok (true, abfd, min, sec, inf))
{
thisplace = min;
and we have dynamic relocations available, then we can produce
a better result by matching a relocation to the address and
using the symbol associated with that relocation. */
- rel_count = aux->dynrelcount;
+ rel_count = inf->dynrelcount;
if (!want_section
&& sorted_syms[thisplace]->value != vma
&& rel_count > 0
- && aux->dynrelbuf != NULL
- && aux->dynrelbuf[0]->address <= vma
- && aux->dynrelbuf[rel_count - 1]->address >= vma
+ && inf->dynrelbuf != NULL
+ && inf->dynrelbuf[0]->address <= vma
+ && inf->dynrelbuf[rel_count - 1]->address >= vma
/* If we have matched a synthetic symbol, then stick with that. */
&& (sorted_syms[thisplace]->flags & BSF_SYNTHETIC) == 0)
{
arelent ** rel_low;
arelent ** rel_high;
- rel_low = aux->dynrelbuf;
+ rel_low = inf->dynrelbuf;
rel_high = rel_low + rel_count - 1;
while (rel_low <= rel_high)
{
static void
objdump_print_addr_with_sym (bfd *abfd, asection *sec, asymbol *sym,
bfd_vma vma, struct disassemble_info *inf,
- bfd_boolean skip_zeroes)
+ bool skip_zeroes)
{
- objdump_print_value (vma, inf, skip_zeroes);
+ if (!no_addresses)
+ {
+ objdump_print_value (vma, inf, skip_zeroes);
+ (*inf->fprintf_func) (inf->stream, " ");
+ }
if (sym == NULL)
{
bfd_vma secaddr;
- (*inf->fprintf_func) (inf->stream, " <%s",
+ (*inf->fprintf_func) (inf->stream, "<%s",
sanitize_string (bfd_section_name (sec)));
secaddr = bfd_section_vma (sec);
if (vma < secaddr)
{
(*inf->fprintf_func) (inf->stream, "-0x");
- objdump_print_value (secaddr - vma, inf, TRUE);
+ objdump_print_value (secaddr - vma, inf, true);
}
else if (vma > secaddr)
{
(*inf->fprintf_func) (inf->stream, "+0x");
- objdump_print_value (vma - secaddr, inf, TRUE);
+ objdump_print_value (vma - secaddr, inf, true);
}
(*inf->fprintf_func) (inf->stream, ">");
}
else
{
- (*inf->fprintf_func) (inf->stream, " <");
+ (*inf->fprintf_func) (inf->stream, "<");
objdump_print_symname (abfd, inf, sym);
else if (bfd_asymbol_value (sym) > vma)
{
(*inf->fprintf_func) (inf->stream, "-0x");
- objdump_print_value (bfd_asymbol_value (sym) - vma, inf, TRUE);
+ objdump_print_value (bfd_asymbol_value (sym) - vma, inf, true);
}
else if (vma > bfd_asymbol_value (sym))
{
(*inf->fprintf_func) (inf->stream, "+0x");
- objdump_print_value (vma - bfd_asymbol_value (sym), inf, TRUE);
+ objdump_print_value (vma - bfd_asymbol_value (sym), inf, true);
}
(*inf->fprintf_func) (inf->stream, ">");
static void
objdump_print_addr (bfd_vma vma,
struct disassemble_info *inf,
- bfd_boolean skip_zeroes)
+ bool skip_zeroes)
{
struct objdump_disasm_info *aux;
asymbol *sym = NULL;
- bfd_boolean skip_find = FALSE;
+ bool skip_find = false;
aux = (struct objdump_disasm_info *) inf->application_data;
if (sorted_symcount < 1)
{
- (*inf->fprintf_func) (inf->stream, "0x");
- objdump_print_value (vma, inf, skip_zeroes);
+ if (!no_addresses)
+ {
+ (*inf->fprintf_func) (inf->stream, "0x");
+ objdump_print_value (vma, inf, skip_zeroes);
+ }
if (display_file_offsets)
inf->fprintf_func (inf->stream, _(" (File Offset: 0x%lx)"),
- (long int)(aux->sec->filepos + (vma - aux->sec->vma)));
+ (long int) (inf->section->filepos
+ + (vma - inf->section->vma)));
return;
}
vma += bfd_asymbol_value (sym);
if (bfd_is_und_section (bfd_asymbol_section (sym)))
- skip_find = TRUE;
+ skip_find = true;
}
if (!skip_find)
sym = find_symbol_for_address (vma, inf, NULL);
- objdump_print_addr_with_sym (aux->abfd, aux->sec, sym, vma, inf,
+ objdump_print_addr_with_sym (aux->abfd, inf->section, sym, vma, inf,
skip_zeroes);
}
/* Determine if the given address has a symbol associated with it. */
-static int
+static asymbol *
objdump_symbol_at_address (bfd_vma vma, struct disassemble_info * inf)
{
asymbol * sym;
sym = find_symbol_for_address (vma, inf, NULL);
+ if (sym != NULL && bfd_asymbol_value (sym) == vma)
+ return sym;
- return (sym != NULL && (bfd_asymbol_value (sym) == vma));
+ return NULL;
}
/* Hold the last function name and the last line number we displayed
const char *functionname;
unsigned int linenumber;
unsigned int discriminator;
- bfd_boolean reloc;
+ bool reloc;
char *path = NULL;
if (! with_line_numbers && ! with_source_code)
char *path_up;
const char *fname = filename;
- path = xmalloc (prefix_length + PATH_MAX + 1);
+ path = xmalloc (prefix_length + 1 + strlen (filename));
if (prefix_length)
memcpy (path, prefix, prefix_length);
/* Skip selected directory levels. */
for (s = fname + 1; *s != '\0' && level < prefix_strip; s++)
- if (IS_DIR_SEPARATOR(*s))
+ if (IS_DIR_SEPARATOR (*s))
{
fname = s;
level++;
}
/* Update complete filename. */
- strncpy (path_up, fname, PATH_MAX);
- path_up[PATH_MAX] = '\0';
+ strcpy (path_up, fname);
filename = path;
- reloc = TRUE;
+ reloc = true;
}
else
- reloc = FALSE;
+ reloc = false;
if (with_line_numbers)
{
&& (prev_functionname == NULL
|| strcmp (functionname, prev_functionname) != 0))
{
- printf ("%s():\n", sanitize_string (functionname));
+ char *demangle_alloc = NULL;
+ if (do_demangle && functionname[0] != '\0')
+ {
+ /* Demangle the name. */
+ demangle_alloc = bfd_demangle (abfd, functionname,
+ demangle_flags);
+ }
+
+ /* Demangling adds trailing parens, so don't print those. */
+ if (demangle_alloc != NULL)
+ printf ("%s:\n", sanitize_string (demangle_alloc));
+ else
+ printf ("%s():\n", sanitize_string (functionname));
+
prev_line = -1;
+ free (demangle_alloc);
}
if (linenumber > 0
&& (linenumber != prev_line
return n;
}
+/* Code for generating (colored) diagrams of control flow start and end
+ points. */
+
+/* Structure used to store the properties of a jump. */
+
+struct jump_info
+{
+ /* The next jump, or NULL if this is the last object. */
+ struct jump_info *next;
+ /* The previous jump, or NULL if this is the first object. */
+ struct jump_info *prev;
+ /* The start addresses of the jump. */
+ struct
+ {
+ /* The list of start addresses. */
+ bfd_vma *addresses;
+ /* The number of elements. */
+ size_t count;
+ /* The maximum number of elements that fit into the array. */
+ size_t max_count;
+ } start;
+ /* The end address of the jump. */
+ bfd_vma end;
+ /* The drawing level of the jump. */
+ int level;
+};
+
+/* Construct a jump object for a jump from start
+ to end with the corresponding level. */
+
+static struct jump_info *
+jump_info_new (bfd_vma start, bfd_vma end, int level)
+{
+ struct jump_info *result = xmalloc (sizeof (struct jump_info));
+
+ result->next = NULL;
+ result->prev = NULL;
+ result->start.addresses = xmalloc (sizeof (bfd_vma *) * 2);
+ result->start.addresses[0] = start;
+ result->start.count = 1;
+ result->start.max_count = 2;
+ result->end = end;
+ result->level = level;
+
+ return result;
+}
+
+/* Free a jump object and return the next object
+ or NULL if this was the last one. */
+
+static struct jump_info *
+jump_info_free (struct jump_info *ji)
+{
+ struct jump_info *result = NULL;
+
+ if (ji)
+ {
+ result = ji->next;
+ if (ji->start.addresses)
+ free (ji->start.addresses);
+ free (ji);
+ }
+
+ return result;
+}
+
+/* Get the smallest value of all start and end addresses. */
+
+static bfd_vma
+jump_info_min_address (const struct jump_info *ji)
+{
+ bfd_vma min_address = ji->end;
+ size_t i;
+
+ for (i = ji->start.count; i-- > 0;)
+ if (ji->start.addresses[i] < min_address)
+ min_address = ji->start.addresses[i];
+ return min_address;
+}
+
+/* Get the largest value of all start and end addresses. */
+
+static bfd_vma
+jump_info_max_address (const struct jump_info *ji)
+{
+ bfd_vma max_address = ji->end;
+ size_t i;
+
+ for (i = ji->start.count; i-- > 0;)
+ if (ji->start.addresses[i] > max_address)
+ max_address = ji->start.addresses[i];
+ return max_address;
+}
+
+/* Get the target address of a jump. */
+
+static bfd_vma
+jump_info_end_address (const struct jump_info *ji)
+{
+ return ji->end;
+}
+
+/* Test if an address is one of the start addresses of a jump. */
+
+static bool
+jump_info_is_start_address (const struct jump_info *ji, bfd_vma address)
+{
+ bool result = false;
+ size_t i;
+
+ for (i = ji->start.count; i-- > 0;)
+ if (address == ji->start.addresses[i])
+ {
+ result = true;
+ break;
+ }
+
+ return result;
+}
+
+/* Test if an address is the target address of a jump. */
+
+static bool
+jump_info_is_end_address (const struct jump_info *ji, bfd_vma address)
+{
+ return (address == ji->end);
+}
+
+/* Get the difference between the smallest and largest address of a jump. */
+
+static bfd_vma
+jump_info_size (const struct jump_info *ji)
+{
+ return jump_info_max_address (ji) - jump_info_min_address (ji);
+}
+
+/* Unlink a jump object from a list. */
+
+static void
+jump_info_unlink (struct jump_info *node,
+ struct jump_info **base)
+{
+ if (node->next)
+ node->next->prev = node->prev;
+ if (node->prev)
+ node->prev->next = node->next;
+ else
+ *base = node->next;
+ node->next = NULL;
+ node->prev = NULL;
+}
+
+/* Insert unlinked jump info node into a list. */
+
+static void
+jump_info_insert (struct jump_info *node,
+ struct jump_info *target,
+ struct jump_info **base)
+{
+ node->next = target;
+ node->prev = target->prev;
+ target->prev = node;
+ if (node->prev)
+ node->prev->next = node;
+ else
+ *base = node;
+}
+
+/* Add unlinked node to the front of a list. */
+
+static void
+jump_info_add_front (struct jump_info *node,
+ struct jump_info **base)
+{
+ node->next = *base;
+ if (node->next)
+ node->next->prev = node;
+ node->prev = NULL;
+ *base = node;
+}
+
+/* Move linked node to target position. */
+
+static void
+jump_info_move_linked (struct jump_info *node,
+ struct jump_info *target,
+ struct jump_info **base)
+{
+ /* Unlink node. */
+ jump_info_unlink (node, base);
+ /* Insert node at target position. */
+ jump_info_insert (node, target, base);
+}
+
+/* Test if two jumps intersect. */
+
+static bool
+jump_info_intersect (const struct jump_info *a,
+ const struct jump_info *b)
+{
+ return ((jump_info_max_address (a) >= jump_info_min_address (b))
+ && (jump_info_min_address (a) <= jump_info_max_address (b)));
+}
+
+/* Merge two compatible jump info objects. */
+
+static void
+jump_info_merge (struct jump_info **base)
+{
+ struct jump_info *a;
+
+ for (a = *base; a; a = a->next)
+ {
+ struct jump_info *b;
+
+ for (b = a->next; b; b = b->next)
+ {
+ /* Merge both jumps into one. */
+ if (a->end == b->end)
+ {
+ /* Reallocate addresses. */
+ size_t needed_size = a->start.count + b->start.count;
+ size_t i;
+
+ if (needed_size > a->start.max_count)
+ {
+ a->start.max_count += b->start.max_count;
+ a->start.addresses =
+ xrealloc (a->start.addresses,
+ a->start.max_count * sizeof (bfd_vma *));
+ }
+
+ /* Append start addresses. */
+ for (i = 0; i < b->start.count; ++i)
+ a->start.addresses[a->start.count++] =
+ b->start.addresses[i];
+
+ /* Remove and delete jump. */
+ struct jump_info *tmp = b->prev;
+ jump_info_unlink (b, base);
+ jump_info_free (b);
+ b = tmp;
+ }
+ }
+ }
+}
+
+/* Sort jumps by their size and starting point using a stable
+ minsort. This could be improved if sorting performance is
+ an issue, for example by using mergesort. */
+
+static void
+jump_info_sort (struct jump_info **base)
+{
+ struct jump_info *current_element = *base;
+
+ while (current_element)
+ {
+ struct jump_info *best_match = current_element;
+ struct jump_info *runner = current_element->next;
+ bfd_vma best_size = jump_info_size (best_match);
+
+ while (runner)
+ {
+ bfd_vma runner_size = jump_info_size (runner);
+
+ if ((runner_size < best_size)
+ || ((runner_size == best_size)
+ && (jump_info_min_address (runner)
+ < jump_info_min_address (best_match))))
+ {
+ best_match = runner;
+ best_size = runner_size;
+ }
+
+ runner = runner->next;
+ }
+
+ if (best_match == current_element)
+ current_element = current_element->next;
+ else
+ jump_info_move_linked (best_match, current_element, base);
+ }
+}
+
+/* Visualize all jumps at a given address. */
+
+static void
+jump_info_visualize_address (bfd_vma address,
+ int max_level,
+ char *line_buffer,
+ uint8_t *color_buffer)
+{
+ struct jump_info *ji = detected_jumps;
+ size_t len = (max_level + 1) * 3;
+
+ /* Clear line buffer. */
+ memset (line_buffer, ' ', len);
+ memset (color_buffer, 0, len);
+
+ /* Iterate over jumps and add their ASCII art. */
+ while (ji)
+ {
+ /* Discard jumps that are never needed again. */
+ if (jump_info_max_address (ji) < address)
+ {
+ struct jump_info *tmp = ji;
+
+ ji = ji->next;
+ jump_info_unlink (tmp, &detected_jumps);
+ jump_info_free (tmp);
+ continue;
+ }
+
+ /* This jump intersects with the current address. */
+ if (jump_info_min_address (ji) <= address)
+ {
+ /* Hash target address to get an even
+ distribution between all values. */
+ bfd_vma hash_address = jump_info_end_address (ji);
+ uint8_t color = iterative_hash_object (hash_address, 0);
+ /* Fetch line offset. */
+ int offset = (max_level - ji->level) * 3;
+
+ /* Draw start line. */
+ if (jump_info_is_start_address (ji, address))
+ {
+ size_t i = offset + 1;
+
+ for (; i < len - 1; ++i)
+ if (line_buffer[i] == ' ')
+ {
+ line_buffer[i] = '-';
+ color_buffer[i] = color;
+ }
+
+ if (line_buffer[i] == ' ')
+ {
+ line_buffer[i] = '-';
+ color_buffer[i] = color;
+ }
+ else if (line_buffer[i] == '>')
+ {
+ line_buffer[i] = 'X';
+ color_buffer[i] = color;
+ }
+
+ if (line_buffer[offset] == ' ')
+ {
+ if (address <= ji->end)
+ line_buffer[offset] =
+ (jump_info_min_address (ji) == address) ? '/': '+';
+ else
+ line_buffer[offset] =
+ (jump_info_max_address (ji) == address) ? '\\': '+';
+ color_buffer[offset] = color;
+ }
+ }
+ /* Draw jump target. */
+ else if (jump_info_is_end_address (ji, address))
+ {
+ size_t i = offset + 1;
+
+ for (; i < len - 1; ++i)
+ if (line_buffer[i] == ' ')
+ {
+ line_buffer[i] = '-';
+ color_buffer[i] = color;
+ }
+
+ if (line_buffer[i] == ' ')
+ {
+ line_buffer[i] = '>';
+ color_buffer[i] = color;
+ }
+ else if (line_buffer[i] == '-')
+ {
+ line_buffer[i] = 'X';
+ color_buffer[i] = color;
+ }
+
+ if (line_buffer[offset] == ' ')
+ {
+ if (jump_info_min_address (ji) < address)
+ line_buffer[offset] =
+ (jump_info_max_address (ji) > address) ? '>' : '\\';
+ else
+ line_buffer[offset] = '/';
+ color_buffer[offset] = color;
+ }
+ }
+ /* Draw intermediate line segment. */
+ else if (line_buffer[offset] == ' ')
+ {
+ line_buffer[offset] = '|';
+ color_buffer[offset] = color;
+ }
+ }
+
+ ji = ji->next;
+ }
+}
+
+/* Clone of disassemble_bytes to detect jumps inside a function. */
+/* FIXME: is this correct? Can we strip it down even further? */
+
+static struct jump_info *
+disassemble_jumps (struct disassemble_info * inf,
+ disassembler_ftype disassemble_fn,
+ bfd_vma start_offset,
+ bfd_vma stop_offset,
+ bfd_vma rel_offset,
+ arelent *** relppp,
+ arelent ** relppend)
+{
+ struct objdump_disasm_info *aux;
+ struct jump_info *jumps = NULL;
+ asection *section;
+ bfd_vma addr_offset;
+ unsigned int opb = inf->octets_per_byte;
+ int octets = opb;
+ SFILE sfile;
+
+ aux = (struct objdump_disasm_info *) inf->application_data;
+ section = inf->section;
+
+ sfile.alloc = 120;
+ sfile.buffer = (char *) xmalloc (sfile.alloc);
+ sfile.pos = 0;
+
+ inf->insn_info_valid = 0;
+ inf->fprintf_func = (fprintf_ftype) objdump_sprintf;
+ inf->stream = &sfile;
+
+ addr_offset = start_offset;
+ while (addr_offset < stop_offset)
+ {
+ int previous_octets;
+
+ /* Remember the length of the previous instruction. */
+ previous_octets = octets;
+ octets = 0;
+
+ sfile.pos = 0;
+ inf->bytes_per_line = 0;
+ inf->bytes_per_chunk = 0;
+ inf->flags = ((disassemble_all ? DISASSEMBLE_DATA : 0)
+ | (wide_output ? WIDE_OUTPUT : 0));
+ if (machine)
+ inf->flags |= USER_SPECIFIED_MACHINE_TYPE;
+
+ if (inf->disassembler_needs_relocs
+ && (bfd_get_file_flags (aux->abfd) & EXEC_P) == 0
+ && (bfd_get_file_flags (aux->abfd) & DYNAMIC) == 0
+ && *relppp < relppend)
+ {
+ bfd_signed_vma distance_to_rel;
+
+ distance_to_rel = (**relppp)->address - (rel_offset + addr_offset);
+
+ /* Check to see if the current reloc is associated with
+ the instruction that we are about to disassemble. */
+ if (distance_to_rel == 0
+ /* FIXME: This is wrong. We are trying to catch
+ relocs that are addressed part way through the
+ current instruction, as might happen with a packed
+ VLIW instruction. Unfortunately we do not know the
+ length of the current instruction since we have not
+ disassembled it yet. Instead we take a guess based
+ upon the length of the previous instruction. The
+ proper solution is to have a new target-specific
+ disassembler function which just returns the length
+ of an instruction at a given address without trying
+ to display its disassembly. */
+ || (distance_to_rel > 0
+ && distance_to_rel < (bfd_signed_vma) (previous_octets/ opb)))
+ {
+ inf->flags |= INSN_HAS_RELOC;
+ }
+ }
+
+ if (! disassemble_all
+ && (section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
+ == (SEC_CODE | SEC_HAS_CONTENTS))
+ /* Set a stop_vma so that the disassembler will not read
+ beyond the next symbol. We assume that symbols appear on
+ the boundaries between instructions. We only do this when
+ disassembling code of course, and when -D is in effect. */
+ inf->stop_vma = section->vma + stop_offset;
+
+ inf->stop_offset = stop_offset;
+
+ /* Extract jump information. */
+ inf->insn_info_valid = 0;
+ octets = (*disassemble_fn) (section->vma + addr_offset, inf);
+ /* Test if a jump was detected. */
+ if (inf->insn_info_valid
+ && ((inf->insn_type == dis_branch)
+ || (inf->insn_type == dis_condbranch)
+ || (inf->insn_type == dis_jsr)
+ || (inf->insn_type == dis_condjsr))
+ && (inf->target >= section->vma + start_offset)
+ && (inf->target < section->vma + stop_offset))
+ {
+ struct jump_info *ji =
+ jump_info_new (section->vma + addr_offset, inf->target, -1);
+ jump_info_add_front (ji, &jumps);
+ }
+
+ inf->stop_vma = 0;
+
+ addr_offset += octets / opb;
+ }
+
+ inf->fprintf_func = (fprintf_ftype) fprintf;
+ inf->stream = stdout;
+
+ free (sfile.buffer);
+
+ /* Merge jumps. */
+ jump_info_merge (&jumps);
+ /* Process jumps. */
+ jump_info_sort (&jumps);
+
+ /* Group jumps by level. */
+ struct jump_info *last_jump = jumps;
+ int max_level = -1;
+
+ while (last_jump)
+ {
+ /* The last jump is part of the next group. */
+ struct jump_info *base = last_jump;
+ /* Increment level. */
+ base->level = ++max_level;
+
+ /* Find jumps that can be combined on the same
+ level, with the largest jumps tested first.
+ This has the advantage that large jumps are on
+ lower levels and do not intersect with small
+ jumps that get grouped on higher levels. */
+ struct jump_info *exchange_item = last_jump->next;
+ struct jump_info *it = exchange_item;
+
+ for (; it; it = it->next)
+ {
+ /* Test if the jump intersects with any
+ jump from current group. */
+ bool ok = true;
+ struct jump_info *it_collision;
+
+ for (it_collision = base;
+ it_collision != exchange_item;
+ it_collision = it_collision->next)
+ {
+ /* This jump intersects so we leave it out. */
+ if (jump_info_intersect (it_collision, it))
+ {
+ ok = false;
+ break;
+ }
+ }
+
+ /* Add jump to group. */
+ if (ok)
+ {
+ /* Move current element to the front. */
+ if (it != exchange_item)
+ {
+ struct jump_info *save = it->prev;
+ jump_info_move_linked (it, exchange_item, &jumps);
+ last_jump = it;
+ it = save;
+ }
+ else
+ {
+ last_jump = exchange_item;
+ exchange_item = exchange_item->next;
+ }
+ last_jump->level = max_level;
+ }
+ }
+
+ /* Move to next group. */
+ last_jump = exchange_item;
+ }
+
+ return jumps;
+}
+
/* The number of zeroes we want to see before we start skipping them.
The number is arbitrarily chosen. */
return 1;
}
+/* Print out jump visualization. */
+
+static void
+print_jump_visualisation (bfd_vma addr, int max_level, char *line_buffer,
+ uint8_t *color_buffer)
+{
+ if (!line_buffer)
+ return;
+
+ jump_info_visualize_address (addr, max_level, line_buffer, color_buffer);
+
+ size_t line_buffer_size = strlen (line_buffer);
+ char last_color = 0;
+ size_t i;
+
+ for (i = 0; i <= line_buffer_size; ++i)
+ {
+ if (color_output)
+ {
+ uint8_t color = (i < line_buffer_size) ? color_buffer[i]: 0;
+
+ if (color != last_color)
+ {
+ if (color)
+ if (extended_color_output)
+ /* Use extended 8bit color, but
+ do not choose dark colors. */
+ printf ("\033[38;5;%dm", 124 + (color % 108));
+ else
+ /* Use simple terminal colors. */
+ printf ("\033[%dm", 31 + (color % 7));
+ else
+ /* Clear color. */
+ printf ("\033[0m");
+ last_color = color;
+ }
+ }
+ putchar ((i < line_buffer_size) ? line_buffer[i]: ' ');
+ }
+}
+
/* Disassemble some data in memory between given values. */
static void
-disassemble_bytes (struct disassemble_info * inf,
- disassembler_ftype disassemble_fn,
- bfd_boolean insns,
- bfd_byte * data,
- bfd_vma start_offset,
- bfd_vma stop_offset,
- bfd_vma rel_offset,
- arelent *** relppp,
- arelent ** relppend)
+disassemble_bytes (struct disassemble_info *inf,
+ disassembler_ftype disassemble_fn,
+ bool insns,
+ bfd_byte *data,
+ bfd_vma start_offset,
+ bfd_vma stop_offset,
+ bfd_vma rel_offset,
+ arelent ***relppp,
+ arelent **relppend)
{
struct objdump_disasm_info *aux;
asection *section;
- int octets_per_line;
- int skip_addr_chars;
+ unsigned int octets_per_line;
+ unsigned int skip_addr_chars;
bfd_vma addr_offset;
unsigned int opb = inf->octets_per_byte;
unsigned int skip_zeroes = inf->skip_zeroes;
unsigned int skip_zeroes_at_end = inf->skip_zeroes_at_end;
- int octets = opb;
+ size_t octets;
SFILE sfile;
aux = (struct objdump_disasm_info *) inf->application_data;
- section = aux->sec;
+ section = inf->section;
sfile.alloc = 120;
sfile.buffer = (char *) xmalloc (sfile.alloc);
zeroes in chunks of 4, ensuring that there is always a leading
zero remaining. */
skip_addr_chars = 0;
- if (! prefix_addresses)
+ if (!no_addresses && !prefix_addresses)
{
char buf[30];
inf->insn_info_valid = 0;
+ /* Determine maximum level. */
+ uint8_t *color_buffer = NULL;
+ char *line_buffer = NULL;
+ int max_level = -1;
+
+ /* Some jumps were detected. */
+ if (detected_jumps)
+ {
+ struct jump_info *ji;
+
+ /* Find maximum jump level. */
+ for (ji = detected_jumps; ji; ji = ji->next)
+ {
+ if (ji->level > max_level)
+ max_level = ji->level;
+ }
+
+ /* Allocate buffers. */
+ size_t len = (max_level + 1) * 3 + 1;
+ line_buffer = xmalloc (len);
+ line_buffer[len - 1] = 0;
+ color_buffer = xmalloc (len);
+ color_buffer[len - 1] = 0;
+ }
+
addr_offset = start_offset;
while (addr_offset < stop_offset)
{
- bfd_vma z;
- bfd_boolean need_nl = FALSE;
+ bool need_nl = false;
octets = 0;
/* If we see more than SKIP_ZEROES octets of zeroes, we just
print `...'. */
- for (z = addr_offset * opb; z < stop_offset * opb; z++)
- if (data[z] != 0)
- break;
+ if (! disassemble_zeroes)
+ for (; addr_offset * opb + octets < stop_offset * opb; octets++)
+ if (data[addr_offset * opb + octets] != 0)
+ break;
if (! disassemble_zeroes
&& (inf->insn_info_valid == 0
|| inf->branch_delay_insns == 0)
- && (z - addr_offset * opb >= skip_zeroes
- || (z == stop_offset * opb &&
- z - addr_offset * opb < skip_zeroes_at_end)))
+ && (octets >= skip_zeroes
+ || (addr_offset * opb + octets == stop_offset * opb
+ && octets < skip_zeroes_at_end)))
{
/* If there are more nonzero octets 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_offset * opb)
- z = addr_offset * opb + ((z - addr_offset * opb) &~ 3);
-
- octets = z - addr_offset * opb;
+ if (addr_offset * opb + octets != stop_offset * opb)
+ octets &= ~3;
/* If we are going to display more data, and we are displaying
file offsets, then tell the user how many zeroes we skip
and the file offset from where we resume dumping. */
- if (display_file_offsets && ((addr_offset + (octets / opb)) < stop_offset))
- printf ("\t... (skipping %d zeroes, resuming at file offset: 0x%lx)\n",
- octets / opb,
+ if (display_file_offsets
+ && addr_offset + octets / opb < stop_offset)
+ printf (_("\t... (skipping %lu zeroes, "
+ "resuming at file offset: 0x%lx)\n"),
+ (unsigned long) (octets / opb),
(unsigned long) (section->filepos
- + (addr_offset + (octets / opb))));
+ + addr_offset + octets / opb));
else
printf ("\t...\n");
}
else
{
char buf[50];
- int bpc = 0;
- int pb = 0;
+ unsigned int bpc = 0;
+ unsigned int pb = 0;
if (with_line_numbers || with_source_code)
show_line (aux->abfd, section, addr_offset);
- if (! prefix_addresses)
+ if (no_addresses)
+ printf ("\t");
+ else if (!prefix_addresses)
{
char *s;
}
else
{
- aux->require_sec = TRUE;
+ aux->require_sec = true;
objdump_print_address (section->vma + addr_offset, inf);
- aux->require_sec = FALSE;
+ aux->require_sec = false;
putchar (' ');
}
+ print_jump_visualisation (section->vma + addr_offset,
+ max_level, line_buffer,
+ color_buffer);
+
if (insns)
{
+ int insn_size;
+
sfile.pos = 0;
inf->fprintf_func = (fprintf_ftype) objdump_sprintf;
inf->stream = &sfile;
&& *relppp < relppend)
{
bfd_signed_vma distance_to_rel;
- int insn_size = 0;
int max_reloc_offset
= aux->abfd->arch_info->max_reloc_offset_into_insn;
distance_to_rel = ((**relppp)->address - rel_offset
- addr_offset);
+ insn_size = 0;
if (distance_to_rel > 0
&& (max_reloc_offset < 0
|| distance_to_rel <= max_reloc_offset))
}
if (! disassemble_all
- && (section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
- == (SEC_CODE | SEC_HAS_CONTENTS))
+ && ((section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
+ == (SEC_CODE | SEC_HAS_CONTENTS)))
/* Set a stop_vma so that the disassembler will not read
beyond the next symbol. We assume that symbols appear on
the boundaries between instructions. We only do this when
inf->stop_vma = section->vma + stop_offset;
inf->stop_offset = stop_offset;
- octets = (*disassemble_fn) (section->vma + addr_offset, inf);
+ insn_size = (*disassemble_fn) (section->vma + addr_offset, inf);
+ octets = insn_size;
inf->stop_vma = 0;
inf->fprintf_func = (fprintf_ftype) fprintf;
inf->stream = stdout;
if (insn_width == 0 && inf->bytes_per_line != 0)
octets_per_line = inf->bytes_per_line;
- if (octets < (int) opb)
+ if (insn_size < (int) opb)
{
if (sfile.pos)
printf ("%s\n", sfile.buffer);
- if (octets >= 0)
+ if (insn_size >= 0)
{
non_fatal (_("disassemble_fn returned length %d"),
- octets);
+ insn_size);
exit_status = 1;
}
break;
/* PR 21580: Check for a buffer ending early. */
if (j + bpc <= stop_offset * opb)
{
- int k;
+ unsigned int k;
if (inf->display_endian == BFD_ENDIAN_LITTLE)
{
- for (k = bpc - 1; k >= 0; k--)
+ for (k = bpc; k-- != 0; )
printf ("%02x", (unsigned) data[j + k]);
}
else
for (; pb < octets_per_line; pb += bpc)
{
- int k;
+ unsigned int k;
for (k = 0; k < bpc; k++)
printf (" ");
putchar ('\n');
j = addr_offset * opb + pb;
- bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb);
- for (s = buf + skip_addr_chars; *s == '0'; s++)
- *s = ' ';
- if (*s == '\0')
- *--s = '0';
- printf ("%s:\t", buf + skip_addr_chars);
+ if (no_addresses)
+ printf ("\t");
+ else
+ {
+ bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb);
+ for (s = buf + skip_addr_chars; *s == '0'; s++)
+ *s = ' ';
+ if (*s == '\0')
+ *--s = '0';
+ printf ("%s:\t", buf + skip_addr_chars);
+ }
+
+ print_jump_visualisation (section->vma + j / opb,
+ max_level, line_buffer,
+ color_buffer);
pb += octets_per_line;
if (pb > octets)
/* PR 21619: Check for a buffer ending early. */
if (j + bpc <= stop_offset * opb)
{
- int k;
+ unsigned int k;
if (inf->display_endian == BFD_ENDIAN_LITTLE)
{
- for (k = bpc - 1; k >= 0; k--)
+ for (k = bpc; k-- != 0; )
printf ("%02x", (unsigned) data[j + k]);
}
else
if (!wide_output)
putchar ('\n');
else
- need_nl = TRUE;
+ need_nl = true;
}
while ((*relppp) < relppend
else
printf ("\t\t\t");
- objdump_print_value (section->vma - rel_offset + q->address,
- inf, TRUE);
+ if (!no_addresses)
+ {
+ objdump_print_value (section->vma - rel_offset + q->address,
+ inf, true);
+ printf (": ");
+ }
if (q->howto == NULL)
- printf (": *unknown*\t");
+ printf ("*unknown*\t");
else if (q->howto->name)
- printf (": %s\t", q->howto->name);
+ printf ("%s\t", q->howto->name);
else
- printf (": %d\t", q->howto->type);
+ printf ("%d\t", q->howto->type);
if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL)
printf ("*unknown*");
if (q->addend)
{
- bfd_signed_vma addend = q->addend;
- if (addend < 0)
+ bfd_vma addend = q->addend;
+ if ((bfd_signed_vma) addend < 0)
{
printf ("-0x");
addend = -addend;
}
else
printf ("+0x");
- objdump_print_value (addend, inf, TRUE);
+ objdump_print_value (addend, inf, true);
}
printf ("\n");
- need_nl = FALSE;
+ need_nl = false;
}
++(*relppp);
}
}
free (sfile.buffer);
+ free (line_buffer);
+ free (color_buffer);
}
static void
disassemble_section (bfd *abfd, asection *section, void *inf)
{
- const struct elf_backend_data * bed;
- bfd_vma sign_adjust = 0;
- struct disassemble_info * pinfo = (struct disassemble_info *) inf;
- struct objdump_disasm_info * paux;
- unsigned int opb = pinfo->octets_per_byte;
- bfd_byte * data = NULL;
- bfd_size_type datasize = 0;
- arelent ** rel_pp = NULL;
- arelent ** rel_ppstart = NULL;
- arelent ** rel_ppend;
- bfd_vma stop_offset;
- asymbol * sym = NULL;
- long place = 0;
- long rel_count;
- bfd_vma rel_offset;
- unsigned long addr_offset;
- bfd_boolean do_print;
+ const struct elf_backend_data *bed;
+ bfd_vma sign_adjust = 0;
+ struct disassemble_info *pinfo = (struct disassemble_info *) inf;
+ struct objdump_disasm_info *paux;
+ unsigned int opb = pinfo->octets_per_byte;
+ bfd_byte *data = NULL;
+ bfd_size_type datasize = 0;
+ arelent **rel_pp = NULL;
+ arelent **rel_ppstart = NULL;
+ arelent **rel_ppend;
+ bfd_vma stop_offset;
+ asymbol *sym = NULL;
+ long place = 0;
+ long rel_count;
+ bfd_vma rel_offset;
+ unsigned long addr_offset;
+ bool do_print;
enum loop_control
{
stop_offset_reached,
/* Decide which set of relocs to use. Load them if necessary. */
paux = (struct objdump_disasm_info *) pinfo->application_data;
- if (paux->dynrelbuf && dump_dynamic_reloc_info)
+ if (pinfo->dynrelbuf && dump_dynamic_reloc_info)
{
- rel_pp = paux->dynrelbuf;
- rel_count = paux->dynrelcount;
+ rel_pp = pinfo->dynrelbuf;
+ rel_count = pinfo->dynrelcount;
/* Dynamic reloc addresses are absolute, non-dynamic are section
relative. REL_OFFSET specifies the reloc address corresponding
to the start of this section. */
return;
}
- paux->sec = section;
pinfo->buffer = data;
pinfo->buffer_vma = section->vma;
pinfo->buffer_length = datasize;
pinfo->section = section;
+ /* Sort the symbols into value and section order. */
+ compare_section = section;
+ if (sorted_symcount > 1)
+ qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
+
/* Skip over the relocs belonging to addresses below the
start address. */
while (rel_pp < rel_ppend
printf (_("\nDisassembly of section %s:\n"), sanitize_string (section->name));
/* Find the nearest symbol forwards from our current position. */
- paux->require_sec = TRUE;
+ paux->require_sec = true;
sym = (asymbol *) find_symbol_for_address (section->vma + addr_offset,
(struct disassemble_info *) inf,
&place);
- paux->require_sec = FALSE;
+ paux->require_sec = false;
/* PR 9774: If the target used signed addresses then we must make
sure that we sign extend the value that we calculate for 'addr'
bfd_vma addr;
asymbol *nextsym;
bfd_vma nextstop_offset;
- bfd_boolean insns;
+ bool insns;
addr = section->vma + addr_offset;
addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust;
{
case function_sym:
if (sym->flags & BSF_FUNCTION)
- do_print = FALSE;
+ do_print = false;
break;
case stop_offset_reached:
that the name of sym is different from
paux->symbol. */
if (! bfd_is_local_label (abfd, sym))
- do_print = FALSE;
+ do_print = false;
break;
}
}
if the current symbol matches the requested symbol. */
if (streq (name, paux->symbol))
{
- do_print = TRUE;
+ do_print = true;
if (sym->flags & BSF_FUNCTION)
{
{
pinfo->fprintf_func (pinfo->stream, "\n");
objdump_print_addr_with_sym (abfd, section, sym, addr,
- pinfo, FALSE);
+ pinfo, false);
pinfo->fprintf_func (pinfo->stream, ":\n");
}
&& (strstr (bfd_asymbol_name (sym), "gcc2_compiled")
== NULL))
|| (sym->flags & BSF_FUNCTION) != 0)
- insns = TRUE;
+ insns = true;
else
- insns = FALSE;
+ insns = false;
if (do_print)
- disassemble_bytes (pinfo, paux->disassemble_fn, insns, data,
- addr_offset, nextstop_offset,
- rel_offset, &rel_pp, rel_ppend);
+ {
+ /* Resolve symbol name. */
+ if (visualize_jumps && abfd && sym && sym->name)
+ {
+ struct disassemble_info di;
+ SFILE sf;
+
+ sf.alloc = strlen (sym->name) + 40;
+ sf.buffer = (char*) xmalloc (sf.alloc);
+ sf.pos = 0;
+ di.fprintf_func = (fprintf_ftype) objdump_sprintf;
+ di.stream = &sf;
+
+ objdump_print_symname (abfd, &di, sym);
+
+ /* Fetch jump information. */
+ detected_jumps = disassemble_jumps
+ (pinfo, paux->disassemble_fn,
+ addr_offset, nextstop_offset,
+ rel_offset, &rel_pp, rel_ppend);
+
+ /* Free symbol name. */
+ free (sf.buffer);
+ }
+
+ /* Add jumps to output. */
+ disassemble_bytes (pinfo, paux->disassemble_fn, insns, data,
+ addr_offset, nextstop_offset,
+ rel_offset, &rel_pp, rel_ppend);
+
+ /* Free jumps. */
+ while (detected_jumps)
+ {
+ detected_jumps = jump_info_free (detected_jumps);
+ }
+ }
addr_offset = nextstop_offset;
sym = nextsym;
sorted_symcount = symcount ? symcount : dynsymcount;
sorted_syms = (asymbol **) xmalloc ((sorted_symcount + synthcount)
* sizeof (asymbol *));
- memcpy (sorted_syms, symcount ? syms : dynsyms,
- sorted_symcount * sizeof (asymbol *));
+ if (sorted_symcount != 0)
+ {
+ memcpy (sorted_syms, symcount ? syms : dynsyms,
+ sorted_symcount * sizeof (asymbol *));
- sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
+ sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
+ }
for (i = 0; i < synthcount; ++i)
{
++sorted_symcount;
}
- /* Sort the symbols into section and symbol order. */
- qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
-
init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf);
disasm_info.application_data = (void *) &aux;
aux.abfd = abfd;
- aux.require_sec = FALSE;
- aux.dynrelbuf = NULL;
- aux.dynrelcount = 0;
+ aux.require_sec = false;
+ disasm_info.dynrelbuf = NULL;
+ disasm_info.dynrelcount = 0;
aux.reloc = NULL;
aux.symbol = disasm_sym;
disasm_info.octets_per_byte = bfd_octets_per_byte (abfd, NULL);
disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES;
disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END;
- disasm_info.disassembler_needs_relocs = FALSE;
+ disasm_info.disassembler_needs_relocs = false;
if (bfd_big_endian (abfd))
disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG;
instead. */
disasm_info.endian = BFD_ENDIAN_UNKNOWN;
+ disasm_info.endian_code = disasm_info.endian;
+
/* Allow the target to customize the info structure. */
disassemble_init_for_target (& disasm_info);
/* Pre-load the dynamic relocs as we may need them during the disassembly. */
- {
- long relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
+ long relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
- if (relsize < 0 && dump_dynamic_reloc_info)
- bfd_fatal (bfd_get_filename (abfd));
+ if (relsize < 0 && dump_dynamic_reloc_info)
+ bfd_fatal (bfd_get_filename (abfd));
- if (relsize > 0)
- {
- aux.dynrelbuf = (arelent **) xmalloc (relsize);
- aux.dynrelcount = bfd_canonicalize_dynamic_reloc (abfd,
- aux.dynrelbuf,
- dynsyms);
- if (aux.dynrelcount < 0)
- bfd_fatal (bfd_get_filename (abfd));
+ if (relsize > 0)
+ {
+ disasm_info.dynrelbuf = (arelent **) xmalloc (relsize);
+ disasm_info.dynrelcount
+ = bfd_canonicalize_dynamic_reloc (abfd, disasm_info.dynrelbuf, dynsyms);
+ if (disasm_info.dynrelcount < 0)
+ bfd_fatal (bfd_get_filename (abfd));
- /* Sort the relocs by address. */
- qsort (aux.dynrelbuf, aux.dynrelcount, sizeof (arelent *),
- compare_relocs);
- }
+ /* Sort the relocs by address. */
+ qsort (disasm_info.dynrelbuf, disasm_info.dynrelcount, sizeof (arelent *),
+ compare_relocs);
}
+
disasm_info.symtab = sorted_syms;
disasm_info.symtab_size = sorted_symcount;
bfd_map_over_sections (abfd, disassemble_section, & disasm_info);
- if (aux.dynrelbuf != NULL)
- free (aux.dynrelbuf);
+ free (disasm_info.dynrelbuf);
+ disasm_info.dynrelbuf = NULL;
free (sorted_syms);
+ disassemble_free_target (&disasm_info);
}
\f
-static bfd_boolean
+static bool
load_specific_debug_section (enum dwarf_section_display_enum debug,
asection *sec, void *file)
{
bfd_byte *contents;
bfd_size_type amt;
size_t alloced;
+ bool ret;
if (section->start != NULL)
{
/* If it is already loaded, do nothing. */
if (streq (section->filename, bfd_get_filename (abfd)))
- return TRUE;
+ return true;
free (section->start);
}
section->reloc_info = NULL;
section->num_relocs = 0;
section->address = bfd_section_vma (sec);
- section->user_data = sec;
section->size = bfd_section_size (sec);
/* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
alloced = amt = section->size + 1;
printf (_("\nSection '%s' has an invalid size: %#llx.\n"),
sanitize_string (section->name),
(unsigned long long) section->size);
- return FALSE;
- }
- section->start = contents = malloc (alloced);
- if (section->start == NULL
- || !bfd_get_full_section_contents (abfd, sec, &contents))
- {
- free_debug_section (debug);
- printf (_("\nCan't get contents for section '%s'.\n"),
- sanitize_string (section->name));
- return FALSE;
+ return false;
}
+
+ section->start = contents = xmalloc (alloced);
/* Ensure any string section has a terminating NUL. */
section->start[section->size] = 0;
if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0
&& debug_displays [debug].relocate)
{
- long reloc_size;
- bfd_boolean ret;
-
- bfd_cache_section_contents (sec, section->start);
-
ret = bfd_simple_get_relocated_section_contents (abfd,
sec,
section->start,
syms) != NULL;
-
- if (! ret)
- {
- free_debug_section (debug);
- printf (_("\nCan't get contents for section '%s'.\n"),
- sanitize_string (section->name));
- return FALSE;
- }
-
- reloc_size = bfd_get_reloc_upper_bound (abfd, sec);
- if (reloc_size > 0)
+ if (ret)
{
- unsigned long reloc_count;
- arelent **relocs;
-
- relocs = (arelent **) xmalloc (reloc_size);
+ long reloc_size = bfd_get_reloc_upper_bound (abfd, sec);
- reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, NULL);
- if (reloc_count == 0)
- free (relocs);
- else
+ if (reloc_size > 0)
{
- section->reloc_info = relocs;
- section->num_relocs = reloc_count;
+ unsigned long reloc_count;
+ arelent **relocs;
+
+ relocs = (arelent **) xmalloc (reloc_size);
+
+ reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, NULL);
+ if (reloc_count == 0)
+ free (relocs);
+ else
+ {
+ section->reloc_info = relocs;
+ section->num_relocs = reloc_count;
+ }
}
}
}
+ else
+ ret = bfd_get_full_section_contents (abfd, sec, &contents);
+
+ if (!ret)
+ {
+ free_debug_section (debug);
+ printf (_("\nCan't get contents for section '%s'.\n"),
+ sanitize_string (section->name));
+ return false;
+ }
- return TRUE;
+ return true;
}
-bfd_boolean
+bool
reloc_at (struct dwarf_section * dsec, dwarf_vma offset)
{
arelent ** relocs;
arelent * rp;
if (dsec == NULL || dsec->reloc_info == NULL)
- return FALSE;
+ return false;
relocs = (arelent **) dsec->reloc_info;
for (; (rp = * relocs) != NULL; ++ relocs)
if (rp->address == offset)
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
-bfd_boolean
+bool
load_debug_section (enum dwarf_section_display_enum debug, void *file)
{
struct dwarf_section *section = &debug_displays [debug].section;
if (section->start != NULL)
{
if (streq (section->filename, bfd_get_filename (abfd)))
- return TRUE;
+ return true;
}
/* Locate the debug section. */
section->name = section->compressed_name;
}
if (sec == NULL)
- return FALSE;
+ return false;
return load_specific_debug_section (debug, sec, file);
}
{
struct dwarf_section *section = &debug_displays [debug].section;
- if (section->start == NULL)
- return;
-
- /* PR 17512: file: 0f67f69d. */
- if (section->user_data != NULL)
- {
- asection * sec = (asection *) section->user_data;
-
- /* If we are freeing contents that are also pointed to by the BFD
- library's section structure then make sure to update those pointers
- too. Otherwise, the next time we try to load data for this section
- we can end up using a stale pointer. */
- if (section->start == sec->contents)
- {
- sec->contents = NULL;
- sec->flags &= ~ SEC_IN_MEMORY;
- sec->compress_status = COMPRESS_SECTION_NONE;
- }
- }
-
free ((char *) section->start);
section->start = NULL;
section->address = 0;
return data;
}
+#if HAVE_LIBDEBUGINFOD
+/* Return a hex string represention of the build-id. */
+
+unsigned char *
+get_build_id (void * data)
+{
+ unsigned i;
+ char * build_id_str;
+ bfd * abfd = (bfd *) data;
+ const struct bfd_build_id * build_id;
+
+ build_id = abfd->build_id;
+ if (build_id == NULL)
+ return NULL;
+
+ build_id_str = malloc (build_id->size * 2 + 1);
+ if (build_id_str == NULL)
+ return NULL;
+
+ for (i = 0; i < build_id->size; i++)
+ sprintf (build_id_str + (i * 2), "%02x", build_id->data[i]);
+ build_id_str[build_id->size * 2] = '\0';
+
+ return (unsigned char *)build_id_str;
+}
+#endif /* HAVE_LIBDEBUGINFOD */
+
static void
dump_dwarf_section (bfd *abfd, asection *section,
void *arg ATTRIBUTE_UNUSED)
const char *match;
int i;
- if (CONST_STRNEQ (name, ".gnu.linkonce.wi."))
+ if (startswith (name, ".gnu.linkonce.wi."))
match = ".debug_info";
else
match = name;
return;
}
- eh_addr_size = bfd_arch_bits_per_address (abfd) / 8;
-
switch (bfd_get_arch (abfd))
{
- case bfd_arch_i386:
- switch (bfd_get_mach (abfd))
- {
- case bfd_mach_x86_64:
- case bfd_mach_x86_64_intel_syntax:
- case bfd_mach_x86_64_nacl:
- case bfd_mach_x64_32:
- case bfd_mach_x64_32_intel_syntax:
- case bfd_mach_x64_32_nacl:
- init_dwarf_regnames_x86_64 ();
- break;
-
- default:
- init_dwarf_regnames_i386 ();
- break;
- }
- break;
-
- case bfd_arch_iamcu:
- init_dwarf_regnames_iamcu ();
- break;
-
- case bfd_arch_aarch64:
- init_dwarf_regnames_aarch64();
- break;
-
- case bfd_arch_s390:
- init_dwarf_regnames_s390 ();
- break;
-
- case bfd_arch_riscv:
- init_dwarf_regnames_riscv ();
- break;
-
case bfd_arch_s12z:
/* S12Z has a 24 bit address space. But the only known
producer of dwarf_info encodes addresses into 32 bits. */
break;
default:
+ eh_addr_size = bfd_arch_bits_per_address (abfd) / 8;
break;
}
+ init_dwarf_regnames_by_bfd_arch_and_mach (bfd_get_arch (abfd),
+ bfd_get_mach (abfd));
+
bfd_map_over_sections (abfd, dump_dwarf_section, NULL);
}
\f
{
printf (_("No %s section present\n\n"),
sanitize_string (sect_name));
- return FALSE;
+ return false;
}
if (!bfd_malloc_and_get_section (abfd, stabsect, &contents))
bfd_get_mach (abfd)));
printf (_("flags 0x%08x:\n"), abfd->flags & ~BFD_FLAGS_FOR_BFD_USE_MASK);
-#define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
+#define PF(x, y) if (abfd->flags & x) {printf ("%s%s", comma, y); comma=", ";}
PF (HAS_RELOC, "HAS_RELOC");
PF (EXEC_P, "EXEC_P");
PF (HAS_LINENO, "HAS_LINENO");
}
\f
+#ifdef ENABLE_LIBCTF
/* Formatting callback function passed to ctf_dump. Returns either the pointer
it is passed, or a pointer to newly-allocated storage, in which case
dump_ctf() will free it when it no longer needs it. */
return ctfsect;
}
+/* Dump CTF errors/warnings. */
+static void
+dump_ctf_errs (ctf_dict_t *fp)
+{
+ ctf_next_t *it = NULL;
+ char *errtext;
+ int is_warning;
+ int err;
+
+ /* Dump accumulated errors and warnings. */
+ while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL)
+ {
+ non_fatal (_("%s: %s"), is_warning ? _("warning"): _("error"),
+ errtext);
+ free (errtext);
+ }
+ if (err != ECTF_NEXT_END)
+ {
+ non_fatal (_("CTF error: cannot get CTF errors: `%s'"),
+ ctf_errmsg (err));
+ }
+}
+
/* Dump one CTF archive member. */
static int
-dump_ctf_archive_member (ctf_file_t *ctf, const char *name, void *arg)
+dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, void *arg)
{
- ctf_file_t *parent = (ctf_file_t *) arg;
+ ctf_dict_t *parent = (ctf_dict_t *) arg;
const char *things[] = {"Header", "Labels", "Data objects",
"Function objects", "Variables", "Types", "Strings",
""};
if (ctf_errno (ctf))
{
- non_fatal (_("Iteration failed: %s, %s\n"), *thing,
+ non_fatal (_("Iteration failed: %s, %s"), *thing,
ctf_errmsg (ctf_errno (ctf)));
break;
}
}
+
+ dump_ctf_errs (ctf);
+
return 0;
}
bfd_byte *ctfdata, *parentdata = NULL;
bfd_size_type ctfsize, parentsize;
ctf_sect_t ctfsect;
- ctf_file_t *parent = NULL;
+ ctf_dict_t *parent = NULL;
int err;
if ((ctfdata = read_section_stabs (abfd, sect_name, &ctfsize, NULL)) == NULL)
ctfsect = make_ctfsect (sect_name, ctfdata, ctfsize);
if ((ctfa = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL)
{
- non_fatal (_("CTF open failure: %s\n"), ctf_errmsg (err));
+ dump_ctf_errs (NULL);
+ non_fatal (_("CTF open failure: %s"), ctf_errmsg (err));
bfd_fatal (bfd_get_filename (abfd));
}
ctfsect = make_ctfsect (parent_name, parentdata, parentsize);
if ((parenta = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL)
{
- non_fatal (_("CTF open failure: %s\n"), ctf_errmsg (err));
+ dump_ctf_errs (NULL);
+ non_fatal (_("CTF open failure: %s"), ctf_errmsg (err));
bfd_fatal (bfd_get_filename (abfd));
}
/* Assume that the applicable parent archive member is the default one.
(This is what all known implementations are expected to do, if they
put CTFs and their parents in archives together.) */
- if ((parent = ctf_arc_open_by_name (lookparent, NULL, &err)) == NULL)
+ if ((parent = ctf_dict_open (lookparent, NULL, &err)) == NULL)
{
- non_fatal (_("CTF open failure: %s\n"), ctf_errmsg (err));
+ dump_ctf_errs (NULL);
+ non_fatal (_("CTF open failure: %s"), ctf_errmsg (err));
bfd_fatal (bfd_get_filename (abfd));
}
printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name));
- ctf_archive_iter (ctfa, dump_ctf_archive_member, parent);
- ctf_file_close (parent);
+ if ((err = ctf_archive_iter (ctfa, dump_ctf_archive_member, parent)) != 0)
+ {
+ dump_ctf_errs (NULL);
+ non_fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err));
+ bfd_fatal (bfd_get_filename (abfd));
+ }
+ ctf_dict_close (parent);
ctf_close (ctfa);
ctf_close (parenta);
free (parentdata);
free (ctfdata);
}
+#else
+static void
+dump_ctf (bfd *abfd ATTRIBUTE_UNUSED, const char *sect_name ATTRIBUTE_UNUSED,
+ const char *parent_name ATTRIBUTE_UNUSED) {}
+#endif
\f
static void
/* Clear all options. */
for (opt = (*desc)->options; opt->name; opt++)
- opt->selected = FALSE;
+ opt->selected = false;
/* Decode options. */
b = dump_private_options;
for (opt = (*desc)->options; opt->name; opt++)
if (strcmp (opt->name, b) == 0)
{
- opt->selected = TRUE;
+ opt->selected = true;
break;
}
if (opt->name == NULL)
int count;
int width;
- if ((section->flags & SEC_HAS_CONTENTS) == 0)
+ if (! process_section_p (section))
return;
- if (! process_section_p (section))
+ if ((section->flags & SEC_HAS_CONTENTS) == 0)
return;
if ((datasize = bfd_section_size (section)) == 0)
/* Should perhaps share code and display with nm? */
static void
-dump_symbols (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean dynamic)
+dump_symbols (bfd *abfd ATTRIBUTE_UNUSED, bool dynamic)
{
asymbol **current;
long max_count;
Undo this transformation, otherwise the output
will be confusing. */
if (abfd->xvec->flavour == bfd_target_elf_flavour
- && elf_tdata(abfd)->elf_header->e_machine == EM_SPARCV9
+ && elf_tdata (abfd)->elf_header->e_machine == EM_SPARCV9
&& relcount > 1
&& !strcmp (q->howto->name, "R_SPARC_LO10"))
{
{
if ((section->flags & SEC_DEBUGGING) == 0)
{
- bfd_boolean *has_reloc_p = (bfd_boolean *) arg;
+ bool *has_reloc_p = (bool *) arg;
section->vma += adjust_section_vma;
if (*has_reloc_p)
section->lma += adjust_section_vma;
/* Dump selected contents of ABFD. */
static void
-dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
+dump_bfd (bfd *abfd, bool is_mainfile)
{
const struct elf_backend_data * bed;
separate_info * i;
for (i = first_separate_info; i != NULL; i = i->next)
- dump_bfd (i->handle, FALSE);
+ dump_bfd (i->handle, false);
}
}
bfd_find_nearest_line will not do the right thing. */
if (adjust_section_vma != 0)
{
- bfd_boolean has_reloc = (abfd->flags & HAS_RELOC);
+ bool has_reloc = (abfd->flags & HAS_RELOC);
bfd_map_over_sections (abfd, adjust_addresses, &has_reloc);
}
+ if (! is_mainfile && ! process_links)
+ return;
+
if (! dump_debugging_tags && ! suppress_bfd_header)
printf (_("\n%s: file format %s\n"),
sanitize_string (bfd_get_filename (abfd)),
abfd->xvec->name);
if (dump_ar_hdrs)
- print_arelt_descr (stdout, abfd, TRUE, FALSE);
+ print_arelt_descr (stdout, abfd, true, false);
if (dump_file_header)
dump_bfd_header (abfd);
if (dump_private_headers)
}
else
{
- syms = xrealloc (syms, (symcount + old_symcount) * sizeof (asymbol *));
+ syms = xrealloc (syms, ((symcount + old_symcount + 1)
+ * sizeof (asymbol *)));
memcpy (syms + old_symcount,
extra_syms,
- symcount * sizeof (asymbol *));
+ (symcount + 1) * sizeof (asymbol *));
}
}
}
if (dump_symtab)
- dump_symbols (abfd, FALSE);
+ dump_symbols (abfd, false);
if (dump_dynamic_symtab)
- dump_symbols (abfd, TRUE);
+ dump_symbols (abfd, true);
if (dump_dwarf_section_info)
dump_dwarf (abfd);
if (dump_ctf_section_info)
{
void *dhandle;
- dhandle = read_debugging_info (abfd, syms, symcount, TRUE);
+ dhandle = read_debugging_info (abfd, syms, symcount, true);
if (dhandle != NULL)
{
if (!print_debugging_info (stdout, dhandle, abfd, syms,
bfd_demangle,
- dump_debugging_tags ? TRUE : FALSE))
+ dump_debugging_tags != 0))
{
non_fatal (_("%s: printing debugging information failed"),
bfd_get_filename (abfd));
if (bfd_check_format_matches (abfd, bfd_object, &matching))
{
- dump_bfd (abfd, TRUE);
+ dump_bfd (abfd, true);
return;
}
if (bfd_check_format_matches (abfd, bfd_core, &matching))
{
- dump_bfd (abfd, TRUE);
+ dump_bfd (abfd, true);
return;
}
}
static void
-display_file (char *filename, char *target, bfd_boolean last_file)
+display_file (char *filename, char *target, bool last_file)
{
bfd *file;
{
int c;
char *target = default_target;
- bfd_boolean seenflag = FALSE;
+ bool seenflag = false;
-#if defined (HAVE_SETLOCALE)
-#if defined (HAVE_LC_MESSAGES)
+#ifdef HAVE_LC_MESSAGES
setlocale (LC_MESSAGES, "");
#endif
setlocale (LC_CTYPE, "");
-#endif
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
add_only (optarg);
break;
case 'F':
- display_file_offsets = TRUE;
+ display_file_offsets = true;
break;
case 'l':
- with_line_numbers = TRUE;
+ with_line_numbers = true;
break;
case 'b':
target = optarg;
break;
case 'C':
- do_demangle = TRUE;
+ do_demangle = true;
if (optarg != NULL)
{
enum demangling_styles style;
demangle_flags |= DMGL_NO_RECURSE_LIMIT;
break;
case 'w':
- do_wide = wide_output = TRUE;
+ do_wide = wide_output = true;
break;
case OPTION_ADJUST_VMA:
adjust_section_vma = parse_vma (optarg, "--adjust-vma");
fatal (_("error: instruction width must be positive"));
break;
case OPTION_INLINES:
- unwind_inlines = TRUE;
+ unwind_inlines = true;
+ break;
+ case OPTION_VISUALIZE_JUMPS:
+ visualize_jumps = true;
+ color_output = false;
+ extended_color_output = false;
+ if (optarg != NULL)
+ {
+ if (streq (optarg, "color"))
+ color_output = true;
+ else if (streq (optarg, "extended-color"))
+ {
+ color_output = true;
+ extended_color_output = true;
+ }
+ else if (streq (optarg, "off"))
+ visualize_jumps = false;
+ else
+ nonfatal (_("unrecognized argument to --visualize-option"));
+ }
break;
case 'E':
if (strcmp (optarg, "B") == 0)
break;
case 'f':
- dump_file_header = TRUE;
- seenflag = TRUE;
+ dump_file_header = true;
+ seenflag = true;
break;
case 'i':
- formats_info = TRUE;
- seenflag = TRUE;
+ formats_info = true;
+ seenflag = true;
break;
case 'I':
add_include_path (optarg);
break;
case 'p':
- dump_private_headers = TRUE;
- seenflag = TRUE;
+ dump_private_headers = true;
+ seenflag = true;
break;
case 'P':
dump_private_options = optarg;
- seenflag = TRUE;
+ seenflag = true;
break;
case 'x':
- dump_private_headers = TRUE;
- dump_symtab = TRUE;
- dump_reloc_info = TRUE;
- dump_file_header = TRUE;
- dump_ar_hdrs = TRUE;
- dump_section_headers = TRUE;
- seenflag = TRUE;
+ dump_private_headers = true;
+ dump_symtab = true;
+ dump_reloc_info = true;
+ dump_file_header = true;
+ dump_ar_hdrs = true;
+ dump_section_headers = true;
+ seenflag = true;
break;
case 't':
- dump_symtab = TRUE;
- seenflag = TRUE;
+ dump_symtab = true;
+ seenflag = true;
break;
case 'T':
- dump_dynamic_symtab = TRUE;
- seenflag = TRUE;
+ dump_dynamic_symtab = true;
+ seenflag = true;
break;
case 'd':
- disassemble = TRUE;
- seenflag = TRUE;
+ disassemble = true;
+ seenflag = true;
disasm_sym = optarg;
break;
case 'z':
- disassemble_zeroes = TRUE;
+ disassemble_zeroes = true;
break;
case 'D':
- disassemble = TRUE;
- disassemble_all = TRUE;
- seenflag = TRUE;
+ disassemble = true;
+ disassemble_all = true;
+ seenflag = true;
break;
case 'S':
- disassemble = TRUE;
- with_source_code = TRUE;
- seenflag = TRUE;
+ disassemble = true;
+ with_source_code = true;
+ seenflag = true;
break;
case OPTION_SOURCE_COMMENT:
- disassemble = TRUE;
- with_source_code = TRUE;
- seenflag = TRUE;
+ disassemble = true;
+ with_source_code = true;
+ seenflag = true;
if (optarg)
source_comment = xstrdup (sanitize_string (optarg));
else
break;
case 'g':
dump_debugging = 1;
- seenflag = TRUE;
+ seenflag = true;
break;
case 'e':
dump_debugging = 1;
dump_debugging_tags = 1;
- do_demangle = TRUE;
- seenflag = TRUE;
+ do_demangle = true;
+ seenflag = true;
+ break;
+ case 'L':
+ process_links = true;
+ do_follow_links = true;
break;
case 'W':
- dump_dwarf_section_info = TRUE;
- seenflag = TRUE;
+ dump_dwarf_section_info = true;
+ seenflag = true;
if (optarg)
dwarf_select_sections_by_letters (optarg);
else
dwarf_select_sections_all ();
break;
case OPTION_DWARF:
- dump_dwarf_section_info = TRUE;
- seenflag = TRUE;
+ dump_dwarf_section_info = true;
+ seenflag = true;
if (optarg)
dwarf_select_sections_by_names (optarg);
else
}
break;
case OPTION_DWARF_CHECK:
- dwarf_check = TRUE;
+ dwarf_check = true;
break;
+#ifdef ENABLE_LIBCTF
case OPTION_CTF:
- dump_ctf_section_info = TRUE;
+ dump_ctf_section_info = true;
dump_ctf_section_name = xstrdup (optarg);
- seenflag = TRUE;
+ seenflag = true;
break;
case OPTION_CTF_PARENT:
dump_ctf_parent_name = xstrdup (optarg);
break;
+#endif
case 'G':
- dump_stab_section_info = TRUE;
- seenflag = TRUE;
+ dump_stab_section_info = true;
+ seenflag = true;
break;
case 's':
- dump_section_contents = TRUE;
- seenflag = TRUE;
+ dump_section_contents = true;
+ seenflag = true;
break;
case 'r':
- dump_reloc_info = TRUE;
- seenflag = TRUE;
+ dump_reloc_info = true;
+ seenflag = true;
break;
case 'R':
- dump_dynamic_reloc_info = TRUE;
- seenflag = TRUE;
+ dump_dynamic_reloc_info = true;
+ seenflag = true;
break;
case 'a':
- dump_ar_hdrs = TRUE;
- seenflag = TRUE;
+ dump_ar_hdrs = true;
+ seenflag = true;
break;
case 'h':
- dump_section_headers = TRUE;
- seenflag = TRUE;
+ dump_section_headers = true;
+ seenflag = true;
break;
case 'v':
case 'V':
- show_version = TRUE;
- seenflag = TRUE;
+ show_version = true;
+ seenflag = true;
break;
case 'H':
else
{
if (optind == argc)
- display_file ("a.out", target, TRUE);
+ display_file ("a.out", target, true);
else
for (; optind < argc;)
{