public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Nils-Christian Kempke <nils-christian.kempke@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/3] gdb/symtab: add lookup for trampoline functions
Date: Thu,  7 Jul 2022 14:15:37 +0200	[thread overview]
Message-ID: <20220707121538.1317473-3-nils-christian.kempke@intel.com> (raw)
In-Reply-To: <20220707121538.1317473-2-nils-christian.kempke@intel.com>

In order to queriy information about the DW_AT_trampoline tag for
subroutines and inlined subroutines two function were added to symtab.

First, a routine for querying whether the given pc belongs to a block
that is associated with a function (maybe inlined) marked
DW_AT_trampoline.

Second, a routine for querying a trampoline function's target.
Subroutines and inlined subroutines marked with DW_AT_trampoline usually
contain information about the target subroutine they are 'wrapping'/
passing control to.

gdb/ChangeLog:
2022-05-30  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* symtab.h (in_trampoline_function): New function
	(find_function_trampoline_target): New function.
	* symtab.c (in_trampoline_function): New function implementation.
	(find_function_trampoline_target): New implementation of
	trampoline target lookup.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/symtab.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/symtab.h | 14 ++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 03aa2a96b87..a7ea928623b 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -72,6 +72,7 @@
 #include "gdbsupport/gdb_string_view.h"
 #include "gdbsupport/pathstuff.h"
 #include "gdbsupport/common-utils.h"
+#include "gdbsupport/symbol.h"
 
 /* Forward declarations for local functions.  */
 
@@ -4144,6 +4145,58 @@ find_function_alias_target (bound_minimal_symbol msymbol)
   return NULL;
 }
 
+/* See symtab.h.  */
+
+bool
+in_trampoline_function (CORE_ADDR pc)
+{
+  /* Find the innermost function containing pc.  This might be an inlined
+     function.  */
+  symbol *sym = find_pc_sect_containing_function (pc,
+						  find_pc_mapped_section (pc));
+  return sym != nullptr && TYPE_IS_TRAMPOLINE (sym->type ());
+}
+
+/* See symtab.h.  */
+
+CORE_ADDR
+find_function_trampoline_target (CORE_ADDR pc)
+{
+  /* Find the innermost function containing pc.  This might be an inlined
+     function.  */
+  symbol *sym = find_pc_sect_containing_function (pc,
+						  find_pc_mapped_section (pc));
+  CORE_ADDR target_address = 0;
+
+  if (sym != nullptr && TYPE_IS_TRAMPOLINE (sym->type ()))
+    {
+      trampoline_target *trampoline = TYPE_TRAMPOLINE_TARGET (sym->type ());
+
+      /* DW_AT_trampoline can be given as an address, name, or flag here (die
+	 references have been resolved as names at this point.  In the case
+	 where DW_AT_trampoline contains a flag we do not know the target
+	 address and return 0.  */
+      if (trampoline->target_kind () == TRAMPOLINE_TARGET_PHYSNAME)
+	{
+	  /* Handle both the mangled and demangled PHYSNAME.  */
+	  const char *physname = trampoline->target_physname ();
+
+	  if (find_minimal_symbol_address (physname, &target_address, nullptr)
+	      != 0)
+	    target_address = 0;
+	}
+      else if (trampoline->target_kind () == TRAMPOLINE_TARGET_PHYSADDR)
+	{
+	  /* If the function symbol containing this trampoline target has
+	     been relocated we assume the target_address also needs relocation.
+	     If it has not been relocated the offset should be zero.  */
+	  target_address = trampoline->target_physaddr ()
+	    + sym->objfile ()->section_offsets[sym->section_index ()];
+	}
+    }
+
+  return target_address;
+}
 \f
 /* If P is of the form "operator[ \t]+..." where `...' is
    some legitimate operator text, return a pointer to the
diff --git a/gdb/symtab.h b/gdb/symtab.h
index ac902a4cbbe..7dad0ddba9f 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2244,6 +2244,20 @@ extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p;
 
 extern CORE_ADDR find_solib_trampoline_target (struct frame_info *, CORE_ADDR);
 
+/* Return wether or not the current pc is within a block that belongs to a
+   function that is marked as a trampoline by the compiler.  */
+
+extern bool in_trampoline_function (CORE_ADDR pc);
+
+/* Find the target of a trampoline function marked via the DW_AT_trampoline
+   attribute and return its address.  Returns 0 if the pc is not contained
+   in a trampoline function (inlined or not).  If DW_AT_trampoline
+   is given as a flag, the target is unknown and the function will still return
+   0.  One has to additionally query in_trampoline_function to cover this
+   case.  */
+
+extern CORE_ADDR find_function_trampoline_target (CORE_ADDR pc);
+
 struct symtab_and_line
 {
   /* The program space of this sal.  */
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  reply	other threads:[~2022-07-07 12:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07 12:15 [PATCH 1/3] gdb: add support for DW_AT_trampoline in DWARF reader Nils-Christian Kempke
2022-07-07 12:15 ` Nils-Christian Kempke [this message]
2022-07-15 20:13   ` [PATCH 2/3] gdb/symtab: add lookup for trampoline functions Tom Tromey
2022-07-07 12:15 ` [PATCH 3/3] gdb/infrun: handle stepping through functions with DW_AT_trampoline Nils-Christian Kempke
2022-07-15 20:20   ` Tom Tromey
2022-07-13  7:39 ` [PATCH 1/3] gdb: add support for DW_AT_trampoline in DWARF reader George, Jini Susan
2022-07-13 11:59   ` Kempke, Nils-Christian
2022-07-17 12:57     ` George, Jini Susan
2022-07-18 16:11       ` Tom Tromey
2022-07-15 20:05 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220707121538.1317473-3-nils-christian.kempke@intel.com \
    --to=nils-christian.kempke@intel.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).