From: Andi Kleen Date: Tue, 21 Mar 2017 13:05:19 +0000 (+0000) Subject: Add --inlines option to objdump to include scope backtrace of inlined functions when... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4a14e306468af630a27302d68b8d4c59733141b4;p=binutils-gdb.git Add --inlines option to objdump to include scope backtrace of inlined functions when generating source line number information. * objdump.c (unwind_inlines): Add. (option_values): Add OPTION_INLINES. (show_line): Unwind inlines if requested. (main): Parse OPTION_INLINES. (usage): Document --inlines. * doc/binutils.texi: Document --inlines. * NEWS: Likewise. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index dea3e3647d1..5ee8073f057 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,13 @@ +2017-03-21 Andi Kleen + + * objdump.c (unwind_inlines): Add. + (option_values): Add OPTION_INLINES. + (show_line): Unwind inlines if requested. + (main): Parse OPTION_INLINES. + (usage): Document --inlines. + * doc/binutils.texi: Document --inlines. + * NEWS: Likewise. + 2017-03-21 Nick Clifton * readelf.c (print_gnu_build_attribute_name): Allow stack diff --git a/binutils/NEWS b/binutils/NEWS index 3d1576514cc..c98908a0613 100644 --- a/binutils/NEWS +++ b/binutils/NEWS @@ -1,5 +1,8 @@ -*- text -*- +* Add --inlines option to objdump, which extends the --line-numbers option + so that inlined functions will display their nesting information. + * Add --merge-notes options to objcopy to reduce the size of notes in a binary file by merging and deleting redundant notes. diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index 8fe4d3bce8f..ffa7dfd9092 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -761,7 +761,8 @@ nm [@option{-A}|@option{-o}|@option{--print-file-name}] [@option{-a}|@option{--d [@option{-B}|@option{--format=bsd}] [@option{-C}|@option{--demangle}[=@var{style}]] [@option{-D}|@option{--dynamic}] [@option{-f}@var{format}|@option{--format=}@var{format}] [@option{-g}|@option{--extern-only}] [@option{-h}|@option{--help}] - [@option{-l}|@option{--line-numbers}] [@option{-n}|@option{-v}|@option{--numeric-sort}] + [@option{-l}|@option{--line-numbers}] [@option{--inlines}] + [@option{-n}|@option{-v}|@option{--numeric-sort}] [@option{-P}|@option{--portability}] [@option{-p}|@option{--no-sort}] [@option{-r}|@option{--reverse-sort}] [@option{-S}|@option{--print-size}] [@option{-s}|@option{--print-armap}] [@option{-t} @var{radix}|@option{--radix=}@var{radix}] @@ -968,6 +969,16 @@ address of the symbol. For an undefined symbol, look for the line number of a relocation entry which refers to the symbol. If line number information can be found, print it after the other symbol information. +@item --inlines +@cindex objdump inlines +When option @option{-l} is active, if the address belongs to a +function that was inlined, then this option causes the source +information for all enclosing scopes back to the first non-inlined +function to be printed as well. For example, if @code{main} inlines +@code{callee1} which inlines @code{callee2}, and address is from +@code{callee2}, the source information for @code{callee1} and @code{main} +will also be printed. + @item -n @itemx -v @itemx --numeric-sort diff --git a/binutils/objdump.c b/binutils/objdump.c index 6cd8d0becac..58521dd8453 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -117,6 +117,7 @@ static bfd_boolean 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. */ /* A structure to record the sections mentioned in -j switches. */ struct only @@ -257,6 +258,7 @@ usage (FILE *stream, int status) --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\ --prefix-strip=LEVEL Strip initial directory names for -S\n")); fprintf (stream, _("\ @@ -296,7 +298,8 @@ enum option_values OPTION_ADJUST_VMA, OPTION_DWARF_DEPTH, OPTION_DWARF_CHECK, - OPTION_DWARF_START + OPTION_DWARF_START, + OPTION_INLINES }; static struct option long_options[]= @@ -348,6 +351,7 @@ static struct option long_options[]= {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH}, {"dwarf-start", required_argument, 0, OPTION_DWARF_START}, {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK}, + {"inlines", no_argument, 0, OPTION_INLINES}, {0, no_argument, 0, 0} }; @@ -1543,6 +1547,17 @@ show_line (bfd *abfd, asection *section, bfd_vma addr_offset) else printf ("%s:%u\n", filename == NULL ? "???" : filename, linenumber); } + if (unwind_inlines) + { + const char *filename2; + const char *functionname2; + unsigned line2; + + while (bfd_find_inliner_info (abfd, &filename2, &functionname2, + &line2)) + printf ("inlined by %s:%u (%s)\n", filename2, line2, + functionname2); + } } if (with_source_code @@ -3808,6 +3823,9 @@ main (int argc, char **argv) if (insn_width <= 0) fatal (_("error: instruction width must be positive")); break; + case OPTION_INLINES: + unwind_inlines = TRUE; + break; case 'E': if (strcmp (optarg, "B") == 0) endian = BFD_ENDIAN_BIG;