From patchwork Sun Nov 24 22:03:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ijaz, Abdul B" X-Patchwork-Id: 101803 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 2EC9B3858C33 for ; Sun, 24 Nov 2024 22:06:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2EC9B3858C33 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=IQ915h0p X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by sourceware.org (Postfix) with ESMTPS id 165B83858C54 for ; Sun, 24 Nov 2024 22:04:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 165B83858C54 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 165B83858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732485870; cv=none; b=QzmXrr1tkpGbYVkdU5fDIMuarwNHs/5bY4ny4WUSJvc380ODZ4K9UsYakfzCtn3+BEL0HLF6Oj4x/pL54aClTWG1RZJzMIPLq0vktT15Ye7AL01YKLlPCmV7/WxCnI503tZFXE28uTpT8DGyxNtoPwJlchYUewp1n12/7emZj0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732485870; c=relaxed/simple; bh=3S/bvfdZQdjGEn+C1I4JsA6bT9lEHOz4jhKvkB2/S6A=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=XI50bLxFHnmX6TNuJEdKNXGSH/rpRrAedfYKL9sSvLuwlp5cJVItRQLmqIR2cw21m9E8O7MfZlvNZOwrEp3lAiVHQT4yAUal0n0VyMcNr1Ld3KmGyAAR9h9XyKBGHo+tuCKyLJDOo6QV9r9qdjinxYNo4zdMMMmroVDGbfT2ESw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 165B83858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732485870; x=1764021870; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3S/bvfdZQdjGEn+C1I4JsA6bT9lEHOz4jhKvkB2/S6A=; b=IQ915h0pzsg/sRGjLhTzQTOc4k3G2WVghgpyXZFtzM9tY392xFBL/kj7 /6lKUB747+EKvU93w7OmVlQdsYd0t8WgwyfN2TYLBbc4rozEVyye1TQbM i/PpmhF2AfJG9FQ882vPNIc8ebCcJ4ERdKsXlpiSLf0T2O+XesWVHIjWR qk0DIeINQpSG3EGs6EGQLRxO8k/346G+byjJvz93cZQrW54mjStlXN20y 8Vc6CbuOI8THTOQH+aoYN/z7U/W73cze02p7eEcHa9+ZlpTkQLuNt20+d d6JEady9MMGiaMsAD7KeuEj7wzNk2wERCOeLYcAu4m2UIVvZ/KdVXLWv+ Q==; X-CSE-ConnectionGUID: hNCaxbBtSSO49NchKckdkA== X-CSE-MsgGUID: LAH4bkjGRzCTIHSR/02U9Q== X-IronPort-AV: E=McAfee;i="6700,10204,11266"; a="32315652" X-IronPort-AV: E=Sophos;i="6.12,181,1728975600"; d="scan'208";a="32315652" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2024 14:04:29 -0800 X-CSE-ConnectionGUID: KAEA9nyuSbGHAZsyFt2Y5w== X-CSE-MsgGUID: DCHDlUvUSRyXr/0C6G1dAw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,181,1728975600"; d="scan'208";a="91270572" Received: from abijaz-mobl2.ger.corp.intel.com (HELO localhost) ([10.245.166.144]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2024 14:04:26 -0800 From: Abdul Basit Ijaz To: gdb-patches@sourceware.org Cc: abdul.b.ijaz@intel.com, JiniSusan.George@amd.com, tom@tromey.com, eliz@gnu.org, Nils-Christian Kempke Subject: [PATCH v9 02/10] gdb/symtab: add lookup for trampoline functions Date: Sun, 24 Nov 2024 23:03:45 +0100 Message-Id: <20241124220353.3465-3-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241124220353.3465-1-abdul.b.ijaz@intel.com> References: <20241124220353.3465-1-abdul.b.ijaz@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org 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. 2024-11-24 Nils-Christian Kempke --- gdb/symtab.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/symtab.h | 14 ++++++++++ 2 files changed, 91 insertions(+) diff --git a/gdb/symtab.c b/gdb/symtab.c index 63d2a0e99d0..5e1c790a76e 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -73,6 +73,7 @@ #include "gdbsupport/pathstuff.h" #include "gdbsupport/common-utils.h" #include +#include "gdbsupport/symbol.h" /* Forward declarations for local functions. */ @@ -4320,6 +4321,82 @@ 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); + block_symbol bs + = lookup_symbol (physname, blk, SEARCH_VAR_DOMAIN, 0); + if (bs.symbol != nullptr) + { + const block *block = bs.symbol->value_block (); + gdb_assert (block != nullptr); + target_address = block->start (); + } + else + { + /* We normally expect the target symbol to be located in one + objfile only. However, a JIT compiler may have generated + a duplicated symbol that most likely resides in the same + objfile with the trampoline symbol. Give priority to that + objfile in the search. If not found, try all objfiles. + This is a heuristic. */ + if ((find_minimal_symbol_address (physname, &target_address, + sym->objfile ()) != 0) + && (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; +} /* 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 ef2ff5e2ef5..bbfda4c4a8e 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2380,6 +2380,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. */