From patchwork Mon Jun 5 11:04:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ijaz, Abdul B" X-Patchwork-Id: 70597 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BDC54384D1BC for ; Mon, 5 Jun 2023 11:05:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BDC54384D1BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685963140; bh=Zl1cUUw/UFcqceoYuoDJUusHd5Rx2acF+1+2arq2Pyc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=XK/9eyw/JyLQmL0ye9/vqyLL5iWKmx8Q2H3tmuD8ts7gnj6znOKBl+8ZRRvXoQs6y XJ0iXmvM891NE8hnRh7CTUwA7qVSQRhsMFY6GTPlA5t/ECOaKMjdiOAk35ZPJ0KQH5 Rc/ZpOZPxsjiSuX9c86mKgTZGGSZUBwtVPtRea18= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by sourceware.org (Postfix) with ESMTPS id B9939384645F for ; Mon, 5 Jun 2023 11:04:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9939384645F X-IronPort-AV: E=McAfee;i="6600,9927,10731"; a="335957705" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="335957705" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 04:04:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10731"; a="821147473" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="821147473" Received: from labpc2030.iul.intel.com (HELO localhost) ([172.28.48.46]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 04:04:51 -0700 To: gdb-patches@sourceware.org Cc: abdul.b.ijaz@intel.com, JiniSusan.George@amd.com, tom@tromey.com, Nils-Christian Kempke Subject: [PATCH v2 2/4] gdb/symtab: add lookup for trampoline functions Date: Mon, 5 Jun 2023 13:04:08 +0200 Message-Id: <20230605110410.3078-3-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230605110410.3078-1-abdul.b.ijaz@intel.com> References: <20230605110410.3078-1-abdul.b.ijaz@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Abdul Basit Ijaz via Gdb-patches From: "Ijaz, Abdul B" Reply-To: Abdul Basit Ijaz Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Nils-Christian Kempke 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. 2023-06-05 Nils-Christian Kempke --- gdb/symtab.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/symtab.h | 14 +++++++++++ 2 files changed, 82 insertions(+) diff --git a/gdb/symtab.c b/gdb/symtab.c index b3445133c8c..1f59a5da54e 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. */ @@ -4067,6 +4068,73 @@ 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 (); + + /* 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, 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_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; +} /* 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 ae3a81991df..328400fea04 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2255,6 +2255,20 @@ extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p; extern CORE_ADDR find_solib_trampoline_target (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. */