From: Abdul Basit Ijaz <abdul.b.ijaz@intel.com>
To: gdb-patches@sourceware.org
Cc: abdul.b.ijaz@intel.com, JiniSusan.George@amd.com, tom@tromey.com,
eliz@gnu.org,
Nils-Christian Kempke <nils-christian.kempke@intel.com>
Subject: [PATCH v6 02/10] gdb/symtab: add lookup for trampoline functions
Date: Thu, 28 Mar 2024 13:05:20 +0100 [thread overview]
Message-ID: <20240328120528.30382-3-abdul.b.ijaz@intel.com> (raw)
In-Reply-To: <20240328120528.30382-1-abdul.b.ijaz@intel.com>
From: Nils-Christian Kempke <nils-christian.kempke@intel.com>
In order to query 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.
2024-03-28 Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
gdb/symtab.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/symtab.h | 14 +++++++++++
2 files changed, 83 insertions(+)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 86603dfebc3..831a58a9aff 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -73,6 +73,7 @@
#include "gdbsupport/pathstuff.h"
#include "gdbsupport/common-utils.h"
#include <optional>
+#include "gdbsupport/symbol.h"
/* Forward declarations for local functions. */
@@ -4205,6 +4206,74 @@ 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_NAME)
+ {
+ /* Handle both the mangled and demangled PHYSNAME. */
+ const char *physname = trampoline->target_name ();
+
+ /* First, check whether there exists a symbol matching the
+ physname. If we cannot find one also check for minimal
+ symbols. */
+ const block *blk = block_for_pc (pc);
+ struct block_symbol bs = lookup_symbol (physname, blk,
+ SEARCH_VAR_DOMAIN, 0);
+ if (bs.symbol != nullptr)
+ {
+ const struct block *block = bs.symbol->value_block ();
+ gdb_assert (block != nullptr);
+ target_address = block->start ();
+ }
+ else
+ {
+ if (find_minimal_symbol_address (physname, &target_address,
+ nullptr) != 0)
+ target_address = 0;
+ }
+ }
+ else if (trampoline->target_kind () == TRAMPOLINE_TARGET_ADDR)
+ {
+ /* 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 = \
+ ( (CORE_ADDR) trampoline->target_addr ()
+ + 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 bf9a3cfb79f..c60485dc6d3 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2354,6 +2354,20 @@ extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p;
extern CORE_ADDR find_solib_trampoline_target (const frame_info_ptr &, CORE_ADDR);
+/* Return whether 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.34.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
next prev parent reply other threads:[~2024-03-28 12:06 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-28 12:05 [PATCH v6 00/10] GDB support for DW_AT_trampoline Abdul Basit Ijaz
2024-03-28 12:05 ` [PATCH v6 01/10] gdb, dwarf: add support for DW_AT_trampoline in DWARF reader Abdul Basit Ijaz
2024-03-28 12:05 ` Abdul Basit Ijaz [this message]
2024-03-28 12:05 ` [PATCH v6 03/10] gdb: handle stepping through functions with DW_AT_trampoline Abdul Basit Ijaz
2024-03-28 13:58 ` Eli Zaretskii
2024-03-28 14:31 ` Ijaz, Abdul B
2024-03-28 12:05 ` [PATCH v6 04/10] gdb: Skip trampoline frames for the backtrace command Abdul Basit Ijaz
2024-03-28 12:05 ` [PATCH v6 05/10] gdb: Skip trampoline functions for the finish and reverse-finish commands Abdul Basit Ijaz
2024-03-28 13:59 ` Eli Zaretskii
2024-03-28 12:05 ` [PATCH v6 06/10] gdb: Skip trampoline functions for the up command Abdul Basit Ijaz
2024-03-28 14:01 ` Eli Zaretskii
2024-03-28 12:05 ` [PATCH v6 07/10] gdb: Skip trampoline functions for the return command Abdul Basit Ijaz
2024-03-28 14:01 ` Eli Zaretskii
2024-03-28 12:05 ` [PATCH v6 08/10] gdb, mi: Skip trampoline functions for the -stack-list-frames command Abdul Basit Ijaz
2024-03-28 14:02 ` Eli Zaretskii
2024-03-28 12:05 ` [PATCH v6 09/10] gdb, mi: Skip trampoline functions for the -stack-list-arguments command Abdul Basit Ijaz
2024-03-28 14:03 ` Eli Zaretskii
2024-03-28 12:05 ` [PATCH v6 10/10] gdb: Filter trampoline frames in backtrace when using Python frame-filters Abdul Basit Ijaz
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=20240328120528.30382-3-abdul.b.ijaz@intel.com \
--to=abdul.b.ijaz@intel.com \
--cc=JiniSusan.George@amd.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=nils-christian.kempke@intel.com \
--cc=tom@tromey.com \
/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