public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Support inline stacks in objdump
@ 2017-03-20 23:25 Andi Kleen
  2017-03-21 13:08 ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2017-03-20 23:25 UTC (permalink / raw)
  To: binutils; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

For some analysis it is useful to know inline stacks (similar to
addr2line -i) in objdump. This patch adds a new option --inlines
that extends the existing -l output to also display inline stacks
using the already existing BFD support.

There is no attempt to dedup the inline stacks. Each line gets
its own complete inline stack.

v2: Addressed review feedback.
Use bfd_boolean. Use always --inlines correctly. Avoid tabs.
Fix format character.

binutils/:
2017-03-20  Andi Kleen  <ak@linux.intel.com>

	* objdump.c (unwind_inlines): Add.
	(option_values): Add OPTION_INLINES.
	(show_line): Unwind inlines.
	(main): Parse OPTION_INLINES.
	(usage): Document --inlines.
	* doc/binutils.texi: Document --inlines
---
 binutils/doc/binutils.texi | 10 ++++++++++
 binutils/objdump.c         | 23 ++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 8fe4d3bce8f1..6fe9be5b253c 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -762,6 +762,7 @@ nm [@option{-A}|@option{-o}|@option{--print-file-name}] [@option{-a}|@option{--d
    [@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{--inlines}]
    [@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,15 @@ 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
+If the address belongs to a function that was inlined, the source
+information for all enclosing scopes back to the first non-inlined
+function will also be printed.  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 6cd8d0becac5..ce62bdd64a07 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, unwind 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}
 };
 \f
@@ -1543,6 +1547,20 @@ 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);
+	    }
+	  /* Not freeing, as the pointers seem to be owned by BFD?  */
+	}
     }
 
   if (with_source_code
@@ -3808,6 +3826,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;
-- 
2.9.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Support inline stacks in objdump
  2017-03-20 23:25 [PATCH] Support inline stacks in objdump Andi Kleen
@ 2017-03-21 13:08 ` Nick Clifton
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Clifton @ 2017-03-21 13:08 UTC (permalink / raw)
  To: Andi Kleen, binutils; +Cc: Andi Kleen

Hi Andi,

> binutils/:
> 2017-03-20  Andi Kleen  <ak@linux.intel.com>
> 
> 	* objdump.c (unwind_inlines): Add.
> 	(option_values): Add OPTION_INLINES.
> 	(show_line): Unwind inlines.
> 	(main): Parse OPTION_INLINES.
> 	(usage): Document --inlines.
> 	* doc/binutils.texi: Document --inlines

Approved and applied.

Note - I added one small change - an entry in the binutils/NEWS file 
mentioning this new feature.

I did consider asking for a testcase as well.  But when I looked into
this I realised that it would be very hard to do in a generic way.
(Hard, but not impossible, should you feel so inclined).

One day, when I have lots of free time, I will look into creating more
tests for the binutils tools.

Cheers
  Nick



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Support inline stacks in objdump
  2017-03-18 23:36 Andi Kleen
  2017-03-19  8:29 ` Andreas Schwab
@ 2017-03-20  2:50 ` Mike Frysinger
  1 sibling, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2017-03-20  2:50 UTC (permalink / raw)
  To: Andi Kleen; +Cc: binutils, Andi Kleen

[-- Attachment #1: Type: text/plain, Size: 1388 bytes --]

On 18 Mar 2017 16:36, Andi Kleen wrote:
> @@ -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			 Unwind inlines (with -l)\n\

only use spaces for indentation, not tabs

> @@ -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},

please don't use tabs

> +      if (unwind_inlines)
> +	{
> +	  const char *filename2;
> +	  const char *functionname2;
> +	  unsigned line2;
> +
> +	  while (bfd_find_inliner_info (abfd, &filename2, &functionname2,
> +					&line2))
> +	    {
> +	      printf ("inlined by %s:%d (%s)\n", filename2, line2,
> +		      functionname2);

line2 is unsigned, so should use %u instead of %d

> @@ -3808,6 +3826,9 @@ main (int argc, char **argv)
>  	  if (insn_width <= 0)
>  	    fatal (_("error: instruction width must be positive"));
>  	  break;
> +	case OPTION_INLINES:
> +	  unwind_inlines = 1;

use a bfd_boolean, and TRUE/FALSE
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Support inline stacks in objdump
  2017-03-18 23:36 Andi Kleen
@ 2017-03-19  8:29 ` Andreas Schwab
  2017-03-20  2:50 ` Mike Frysinger
  1 sibling, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2017-03-19  8:29 UTC (permalink / raw)
  To: Andi Kleen; +Cc: binutils, Andi Kleen

On Mär 18 2017, Andi Kleen <andi@firstfloor.org> wrote:

> @@ -968,6 +969,10 @@ 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.
>  
> +@itemx --line-numbers

--inlines

> +@cindex inlines
> +Enable printing the inlined function stack when printing line numbers is enabled.
> +

Perhaps copy the doc of addr2line --inlines?

>  @item -n
>  @itemx -v
>  @itemx --numeric-sort
> diff --git a/binutils/objdump.c b/binutils/objdump.c
> index 6cd8d0becac5..83154695f8f2 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 int unwind_inlines;		/* --inline, unwind inlines */

--inlines

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Support inline stacks in objdump
@ 2017-03-18 23:36 Andi Kleen
  2017-03-19  8:29 ` Andreas Schwab
  2017-03-20  2:50 ` Mike Frysinger
  0 siblings, 2 replies; 5+ messages in thread
From: Andi Kleen @ 2017-03-18 23:36 UTC (permalink / raw)
  To: binutils; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

For some analysis it is useful to know inline stacks (similar to
addr2line -i) in objdump. This patch adds a new option --inlines
that extends the existing -l output to also display inline stacks
using the already existing BFD support.

There is no attempt to dedup the inline stacks. Each line gets
its own complete inline stack.

binutils/:
2017-03-17  Andi Kleen  <ak@linux.intel.com>

	* objdump.c (unwind_inlines): Add.
	(option_values): Add OPTION_INLINES.
	(show_line): Unwind inlines.
	(main): Parse OPTION_INLINES.
	(usage): Document --inlines.
	* doc/binutils.texi: Document --inlines
---
 binutils/doc/binutils.texi |  5 +++++
 binutils/objdump.c         | 23 ++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 8fe4d3bce8f1..1775a59002a5 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -762,6 +762,7 @@ nm [@option{-A}|@option{-o}|@option{--print-file-name}] [@option{-a}|@option{--d
    [@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{--inlines}]
    [@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,10 @@ 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.
 
+@itemx --line-numbers
+@cindex inlines
+Enable printing the inlined function stack when printing line numbers is enabled.
+
 @item -n
 @itemx -v
 @itemx --numeric-sort
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 6cd8d0becac5..83154695f8f2 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 int unwind_inlines;		/* --inline, unwind 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			 Unwind inlines (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}
 };
 \f
@@ -1543,6 +1547,20 @@ 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:%d (%s)\n", filename2, line2,
+		      functionname2);
+	    }
+	  /* Not freeing, as the pointers seem to be owned by BFD?  */
+	}
     }
 
   if (with_source_code
@@ -3808,6 +3826,9 @@ main (int argc, char **argv)
 	  if (insn_width <= 0)
 	    fatal (_("error: instruction width must be positive"));
 	  break;
+	case OPTION_INLINES:
+	  unwind_inlines = 1;
+	  break;
 	case 'E':
 	  if (strcmp (optarg, "B") == 0)
 	    endian = BFD_ENDIAN_BIG;
-- 
2.9.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-03-21 13:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-20 23:25 [PATCH] Support inline stacks in objdump Andi Kleen
2017-03-21 13:08 ` Nick Clifton
  -- strict thread matches above, loose matches on Subject: below --
2017-03-18 23:36 Andi Kleen
2017-03-19  8:29 ` Andreas Schwab
2017-03-20  2:50 ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).