From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by sourceware.org (Postfix) with ESMTPS id D31913857806 for ; Wed, 16 Aug 2023 21:54:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D31913857806 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692222867; x=1723758867; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y7mqBHItid+L/6JcHnyPCjunq6HSd5Fy+SsnI43C+/4=; b=gvImf+7ec+0BzeDzIA3B4DxzC205qGzB+u/cUfiB5YXU0nG4k/E48cPp or+9U5D8gH7Zc6h+SKnh2GcCe5XstpMNSiZakQqNvvRyenbj87ismS2ZU GKn+E3qu30jiGJn19zkD0ELQIfkewTHl6hJ6XANlSrOstgQVvO/GbLVgL pX4YF4w+tDbHa3mQCogeD5ofvex7pd4EUrWXGoiI/YqklHE7nbgcrVWBi k9Z3f1dvN16f3Zxp/0iFkvyGXexo4N9Lqsn1d2Y0Hn+3ywQgbLjML6Vfl x6KvjrYLvCngR2clBWP5c+0h/qGoeyQFEI+/Sq0gi3ZEQEXtXJEX8t+2a w==; X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="459003171" X-IronPort-AV: E=Sophos;i="6.01,178,1684825200"; d="scan'208";a="459003171" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 14:54:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="857966324" X-IronPort-AV: E=Sophos;i="6.01,178,1684825200"; d="scan'208";a="857966324" Received: from abijaz-mobl2.ger.corp.intel.com (HELO localhost) ([10.249.40.204]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 14:54:25 -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, blarsen@redhat.com Subject: [PATCH v5 2/4] gdb/symtab: add lookup for trampoline functions Date: Wed, 16 Aug 2023 23:53:47 +0200 Message-Id: <20230816215349.6198-3-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816215349.6198-1-abdul.b.ijaz@intel.com> References: <20230816215349.6198-1-abdul.b.ijaz@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.1 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 List-Id: 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-08-16 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 0117a2a59d7..855f9b41ec7 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -73,6 +73,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. */ @@ -4051,6 +4052,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_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, 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 ee4729b14cd..fc2d82e6567 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2312,6 +2312,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. */ -- 2.34.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, 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