From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YRrBMrmC0mimLA8AWB0awg (envelope-from ) for ; Tue, 23 Sep 2025 07:21:29 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=NsHtYugX; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C958A1E0BA; Tue, 23 Sep 2025 07:21:29 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 3D2091E047 for ; Tue, 23 Sep 2025 07:21:29 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C93AE3858406 for ; Tue, 23 Sep 2025 11:21:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C93AE3858406 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=NsHtYugX Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by sourceware.org (Postfix) with ESMTPS id D9CCB3858D26 for ; Tue, 23 Sep 2025 11:19:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9CCB3858D26 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 D9CCB3858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758626367; cv=none; b=VPl2rtxS2PdC68pIzMkBHAnQQtoC79F124K8PldSbuBnG+X4Mfvz+UmBrhFAq22353Zu7tURVcFJMQ/lRwEKrft2seoGMZIsliwk0p3nIuJ2AFfLyAjK+RLf/JJz59tqkNbrSDsM7DfBOQ3iWqv9lmOxZXUXDJcDnpzD5y3Tnp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758626367; c=relaxed/simple; bh=4sMXrEV9MHutd5HzjAaaqvpvc8Uue5mJu3nEL6oPrWo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=lcvGm3xFSJuP/VyEgVbwCFPYnK8bYiycMHom9AQbjHzt2kfBTM9Rq0y4SLOINuavYDkvCTDVY5eUCFrv6jVZezZ6gc6KIBRXWyln+rJN8kzX6/nBj0iJWjylOpoiOK5D+bkwXe7Cnhf8uKxbbsxMVVv/1bzG7tI7NiHUj/eeXMQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9CCB3858D26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758626367; x=1790162367; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=4sMXrEV9MHutd5HzjAaaqvpvc8Uue5mJu3nEL6oPrWo=; b=NsHtYugXpn2ZVQi0vesWLmBkUsa9UK/umkYVdRmTypTPtie8Valz2OS7 0b+FYG2yJxvcO7wVZEnt9rLTxaLjqyTxdX42SsVIqwMXz9sTdAqberHEx 0OTMJeVnZl7g5Bfdu4mQXr4mgEsxgVDPLb5eVTP907o5K5WT1BE/g3m34 gK8WxayRkqrIG7zGFfUg0t/zMUiJf9BhC1H6nDwxmX4twTw6vhBEotXX0 HkffBTDwviKrSCP2PDZ7UAHWVoH3UZ/z+d6xyehFgCCdaz2B/77UdhwAc pw58njtKclPkQqm0g3gR0KW7mrmYgLgHK/8/QaemRSXVfGYkVlf76Vzeq g==; X-CSE-ConnectionGUID: OF45ZkaWQDyWXZnla8t1tQ== X-CSE-MsgGUID: O9gvGbmZSE+7TEy2pTj/2w== X-IronPort-AV: E=McAfee;i="6800,10657,11561"; a="60827538" X-IronPort-AV: E=Sophos;i="6.18,287,1751266800"; d="scan'208";a="60827538" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2025 04:19:27 -0700 X-CSE-ConnectionGUID: YAgv9GkGRRi8qf/VVzSZ6w== X-CSE-MsgGUID: ENnmEsjrQ3+IHjX/QpoH9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,287,1751266800"; d="scan'208";a="177118705" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2025 04:19:26 -0700 From: Christina Schimpe To: gdb-patches@sourceware.org Subject: [PATCH 4/9] gdb: Refactor 'find_symbol_funname' and 'info_frame_command_core' in stack.c. Date: Tue, 23 Sep 2025 11:18:37 +0000 Message-Id: <20250923111842.4091694-5-christina.schimpe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250923111842.4091694-1-christina.schimpe@intel.com> References: <20250923111842.4091694-1-christina.schimpe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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~public-inbox=simark.ca@sourceware.org To avoid code duplication, create a new function 'stack.c:find_symbol_funname', which will be used in 'stack.c:find_frame_funname' and 'stack.c:info_frame_command_core'. The function will also be used in a following commit. --- gdb/stack.c | 72 ++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/gdb/stack.c b/gdb/stack.c index 1c84b17bc14..91ae4046ad6 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1267,6 +1267,33 @@ get_last_displayed_sal () return sal; } +/* Find the function name for the symbol SYM. */ + +static gdb::unique_xmalloc_ptr +find_symbol_funname (const symbol *sym) +{ + gdb::unique_xmalloc_ptr funname; + const char *print_name = sym->print_name (); + + if (sym->language () == language_cplus) + { + /* It seems appropriate to use print_name () here, + to display the demangled name that we already have + stored in the symbol table, but we stored a version + with DMGL_PARAMS turned on, and here we don't want to + display parameters. So remove the parameters. */ + funname = cp_remove_params (print_name); + } + + if (funname == nullptr) + { + /* If we didn't hit the C++ case above, set *funname here. */ + funname.reset (xstrdup (print_name)); + } + + return funname; +} + /* Attempt to obtain the name, FUNLANG and optionally FUNCP of the function corresponding to FRAME. */ @@ -1285,25 +1312,10 @@ find_frame_funname (const frame_info_ptr &frame, enum language *funlang, func = get_frame_function (frame); if (func) { - const char *print_name = func->print_name (); - *funlang = func->language (); if (funcp) *funcp = func; - if (*funlang == language_cplus) - { - /* It seems appropriate to use print_name() here, - to display the demangled name that we already have - stored in the symbol table, but we stored a version - with DMGL_PARAMS turned on, and here we don't want to - display parameters. So remove the parameters. */ - funname = cp_remove_params (print_name); - } - - /* If we didn't hit the C++ case above, set *funname - here. */ - if (funname == NULL) - funname.reset (xstrdup (print_name)); + funname = find_symbol_funname (func); } else { @@ -1509,8 +1521,7 @@ info_frame_command_core (const frame_info_ptr &fi, bool selected_frame_p) struct symtab *s; frame_info_ptr calling_frame_info; int numregs; - const char *funname = 0; - enum language funlang = language_unknown; + gdb::unique_xmalloc_ptr funname; const char *pc_regname; struct gdbarch *gdbarch; std::optional frame_pc; @@ -1538,32 +1549,13 @@ info_frame_command_core (const frame_info_ptr &fi, bool selected_frame_p) func = get_frame_function (fi); symtab_and_line sal = find_frame_sal (fi); s = sal.symtab; - gdb::unique_xmalloc_ptr func_only; if (func) - { - funname = func->print_name (); - funlang = func->language (); - if (funlang == language_cplus) - { - /* It seems appropriate to use print_name() here, - to display the demangled name that we already have - stored in the symbol table, but we stored a version - with DMGL_PARAMS turned on, and here we don't want to - display parameters. So remove the parameters. */ - func_only = cp_remove_params (funname); - - if (func_only) - funname = func_only.get (); - } - } + funname = find_symbol_funname (func); else if (frame_pc.has_value ()) { bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (*frame_pc); if (msymbol.minsym != NULL) - { - funname = msymbol.minsym->print_name (); - funlang = msymbol.minsym->language (); - } + funname.reset (xstrdup (msymbol.minsym->print_name ())); } calling_frame_info = get_prev_frame (fi); @@ -1588,7 +1580,7 @@ info_frame_command_core (const frame_info_ptr &fi, bool selected_frame_p) if (funname) { gdb_printf (" in "); - gdb_puts (funname); + gdb_puts (funname.get ()); } gdb_stdout->wrap_here (3); if (sal.symtab) -- 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: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928