public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] addr2line: Iterate scopes for inline's parent function
@ 2014-12-10 19:41 Josh Stone
  0 siblings, 0 replies; 2+ messages in thread
From: Josh Stone @ 2014-12-10 19:41 UTC (permalink / raw)
  To: elfutils-devel

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

The function which contains an inline might not be the immediate next
die scope.  For instance, there may be a lexical scope in between.
Instead, iterate the remaining scopes until an appropriate tag is found.

Signed-off-by: Josh Stone <jistone@redhat.com>
---
 src/ChangeLog   |  4 ++++
 src/addr2line.c | 17 ++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index c149a9c67bf3..484cb53d892f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2014-12-10  Josh Stone  <jistone@redhat.com>
+
+	* addr2line.c (handle_address): Find the proper inline parents.
+
 2014-12-04  Mark Wielaard  <mjw@redhat.com>
 
 	* objdump.c (show_relocs_x): Make sure destshdr exists.
diff --git a/src/addr2line.c b/src/addr2line.c
index 50fc2b38c367..eea39da97e2c 100644
--- a/src/addr2line.c
+++ b/src/addr2line.c
@@ -672,7 +672,22 @@ handle_address (const char *string, Dwfl *dwfl)
 			continue;
 
 		      if (show_functions)
-			print_diesym (&scopes[i + 1]);
+			{
+			  /* Search for the parent inline or function.  It
+			     might not be directly above this inline -- e.g.
+			     there could be a lexical_block in between.  */
+			  for (int j = i + 1; j < nscopes; j++)
+			    {
+			      Dwarf_Die *parent = &scopes[j];
+			      int tag = dwarf_tag (parent);
+			      if (tag == DW_TAG_inlined_subroutine
+				  || tag == DW_TAG_subprogram)
+				{
+				  print_diesym (parent);
+				  break;
+				}
+			    }
+			}
 
 		      src = NULL;
 		      lineno = 0;
-- 
2.1.0


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

* Re: [PATCH 1/2] addr2line: Iterate scopes for inline's parent function
@ 2014-12-11 10:33 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2014-12-11 10:33 UTC (permalink / raw)
  To: elfutils-devel

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

On Wed, 2014-12-10 at 11:41 -0800, Josh Stone wrote:
> The function which contains an inline might not be the immediate next
> die scope.  For instance, there may be a lexical scope in between.
> Instead, iterate the remaining scopes until an appropriate tag is found.
>
> +2014-12-10  Josh Stone  <jistone@redhat.com>
> +
> +	* addr2line.c (handle_address): Find the proper inline parents.
>
> --- a/src/addr2line.c
> +++ b/src/addr2line.c
> @@ -672,7 +672,22 @@ handle_address (const char *string, Dwfl *dwfl)
>  			continue;
>  
>  		      if (show_functions)
> -			print_diesym (&scopes[i + 1]);
> +			{
> +			  /* Search for the parent inline or function.  It
> +			     might not be directly above this inline -- e.g.
> +			     there could be a lexical_block in between.  */
> +			  for (int j = i + 1; j < nscopes; j++)
> +			    {
> +			      Dwarf_Die *parent = &scopes[j];
> +			      int tag = dwarf_tag (parent);
> +			      if (tag == DW_TAG_inlined_subroutine
> +				  || tag == DW_TAG_subprogram)

I believe technically you also want to match DW_TAG_entry_point. That
would match what eu-stack does. Admittedly GCC doesn't emit
DW_TAG_entry_point (the code is commented out in dwarf2out.c), but other
(fortran) compilers might. DWARF describes subprograms and entry_points
almost identically, both have a name and possibly a linkage_name, which
is what we care about here.

> +				{
> +				  print_diesym (parent);
> +				  break;
> +				}
> +			    }
> +			}
>  
>  		      src = NULL;
>  		      lineno = 0;

Looks good, but please add DW_TAG_entry_point above before pushing this
commit.

Thanks,

Mark

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

end of thread, other threads:[~2014-12-11 10:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-10 19:41 [PATCH 1/2] addr2line: Iterate scopes for inline's parent function Josh Stone
2014-12-11 10:33 Mark Wielaard

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).