From patchwork Fri May 24 09:16:05 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: 90788 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 17F3D3858410 for ; Fri, 24 May 2024 09:17:29 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by sourceware.org (Postfix) with ESMTPS id AC0663858410 for ; Fri, 24 May 2024 09:16:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC0663858410 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 AC0663858410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716542209; cv=none; b=LkKB1r5jGqpuIcYnq4J/NpXYNldFrVV2oMiJG4mIhAYo3TFrhpS3lDRp8sH90P4fh/KwYBbKHFN5xqEFQmpsBiDCNVFEppFZfGxcHQ5nIK8WDXDgJA/EC7mcy8F2T0lBDkT1i8OkiUg5gzJQ5mPyjEyQO0PSGooqQQn4BjahEkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716542209; c=relaxed/simple; bh=0wPTDcxnFGXAJnm4xY33FAyqrLrlV8V4CyRpK6bnLtg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=CxL/3RwVWHUKjzEkv8iDUzI0QGaSIzi5aeO0HQ8wkJONCPf4+w3XdiRS/PGVhr8W96MOL9D6KFBBjBEj28+ojTW5zcAvQHML9FYhAlrFJgvs4jDWcPgKh8OKqIL07kZuo+53AErgdVeDwZGfPDure4eSAv0fTdc885aWvCBkUdw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716542203; x=1748078203; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0wPTDcxnFGXAJnm4xY33FAyqrLrlV8V4CyRpK6bnLtg=; b=LDqf9rFTAbwiWo+VIVWjiRiPh7x8YLEtnw5v9BrthV+Z4sgBBuEs2PfP VjQ8+f6OkJ+5vhvan6wcSeOwW3Rlm/sIBR7gYAwk/KuwZw00DhhmoqeNN y3W5AMQlrBo3p/+mUhuJfojfcyz1iW8nnwaIIdzBK7GPDOhxYhGf1QznJ 2IitcOeDrrQp2gQJs4jSI8tl5Cw8ny8mJB8vfieTxqr6Vvaroj52cjVBE 4gtVd6moQTM0YILDTe2yCDkGMgjHHc+FrnwQcTNAY9RhG5TfwT4gNnc6E yBBn6GLTLne0F3aGCwGTK4aB0Sb/SoQfxcnbKiCV5jU6thy2KaDjC1px+ w==; X-CSE-ConnectionGUID: zjZUpcjQToCk6gpvMv74+w== X-CSE-MsgGUID: olrIJFPRSnKjoQ0LcOHmzQ== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="30417576" X-IronPort-AV: E=Sophos;i="6.08,185,1712646000"; d="scan'208";a="30417576" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2024 02:16:42 -0700 X-CSE-ConnectionGUID: MkNKGwElQtOOQRPKP8gxMg== X-CSE-MsgGUID: Y/U1jqsyTFykXxC9J/KgdQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,185,1712646000"; d="scan'208";a="38542811" Received: from abijaz-mobl2.ger.corp.intel.com (HELO localhost) ([10.94.253.168]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2024 02:16:40 -0700 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 v7 02/10] gdb/symtab: add lookup for trampoline functions Date: Fri, 24 May 2024 11:16:05 +0200 Message-Id: <20240524091613.11377-3-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240524091613.11377-1-abdul.b.ijaz@intel.com> References: <20240524091613.11377-1-abdul.b.ijaz@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 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-05-24 Nils-Christian Kempke --- gdb/symtab.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/symtab.h | 14 +++++++++++ 2 files changed, 83 insertions(+) diff --git a/gdb/symtab.c b/gdb/symtab.c index 58648a8779d..5eac2ee8535 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. */ @@ -4286,6 +4287,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; +} /* 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. */