From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uY1bCSuD0mimLA8AWB0awg (envelope-from ) for ; Tue, 23 Sep 2025 07:23:23 -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=cyK+eJqu; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1F6231E0BA; Tue, 23 Sep 2025 07:23:23 -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 001E01E047 for ; Tue, 23 Sep 2025 07:23:21 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8EF6A3858408 for ; Tue, 23 Sep 2025 11:23:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EF6A3858408 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=cyK+eJqu Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by sourceware.org (Postfix) with ESMTPS id 14DBE3858C41 for ; Tue, 23 Sep 2025 11:19:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14DBE3858C41 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 14DBE3858C41 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=1758626374; cv=none; b=hhsJDTwgpFUIjdlPvLN6fy0VmxSCJw+BN5cwjq13v4JvSB14iWCBW+IeCFKzAPWYArCZmsAr9qhWJCZec5ERLJKeMSDvMgUeNYdUSW+iSX9CIlORmfz4XSI1i8aDAmYmVTjc+PR7GACgMybYH0T8wtTsqLa5MuJM4fGB7yshAJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758626374; c=relaxed/simple; bh=HjaNULAjkQXNtR2DmToUCqo9sCsVb2Eq3eGCRQ3J4xc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=lYaFFYbx0cZ61XPJscYjeZfHJbKUtLZLS2VPXw1fAnDwrAFOyAa/OC8E/Li45kVY6S4glGD7Z/b6JYc95Jb3RUo1YyGaLkZZrMj6lBpM0oTnYJIAaZSjh2oFNV3uWWMR8DTARv7F85Kz+vKmOGTySxjE83jFYUhpYpqkH1tAHqU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14DBE3858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758626374; x=1790162374; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=HjaNULAjkQXNtR2DmToUCqo9sCsVb2Eq3eGCRQ3J4xc=; b=cyK+eJqufoKToLC+P+tskw7W1Gs6LpT1ThWtfUJxcZptZNtfGZgE+mxB rgKZbm8LY56+G8r9UuC8al04KHBxqFysu7LkFPe3nROnF/V9ajCRT80ez +8jsbXy3BXac4gQ5G0GyELVasUMKMeJv5SN7klPy+plKx8q2/ijgvp2Xb 06PvoEZGbk28wRWqm/M0eWwCCgNnfy6bbvr/xPkvZylSe1DsjGAf8XDxx ExXY389S9JD+HZKdAQ7SV36x6ewi+PmUBycdDaaymOdUPQqi4/jPAlGJu /7EMxoHP2HpFO3y5Z3eyev1aJzN3xGIawkRCiinNu3zJRAaDsrm5ooGEc g==; X-CSE-ConnectionGUID: wBi0Q7WGSt2eRdnwsEnIQA== X-CSE-MsgGUID: 5AuC/5ZGSVyAaoCQr1+cjQ== X-IronPort-AV: E=McAfee;i="6800,10657,11561"; a="60827550" X-IronPort-AV: E=Sophos;i="6.18,287,1751266800"; d="scan'208";a="60827550" 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:34 -0700 X-CSE-ConnectionGUID: kUQS0kyORSm+gLRJEJCN2Q== X-CSE-MsgGUID: xz7n1+ZKRSC6CKotZjSX4w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,287,1751266800"; d="scan'208";a="177118739" 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:33 -0700 From: Christina Schimpe To: gdb-patches@sourceware.org Subject: [PATCH 5/9] gdb: Refactor 'stack.c:print_frame_info'. Date: Tue, 23 Sep 2025 11:18:38 +0000 Message-Id: <20250923111842.4091694-6-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 This patch restructures the 'stack.c:print_frame_info' function by introducing two new functions in stack.c. The new functions will also be called in a later patch "gdb: Implement 'bt shadow' subcommand to print the shadow stack backtrace." --- gdb/stack.c | 159 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 94 insertions(+), 65 deletions(-) diff --git a/gdb/stack.c b/gdb/stack.c index 91ae4046ad6..40756f74a00 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1013,6 +1013,86 @@ get_user_print_what_frame_info (std::optional *what) (user_frame_print_options.print_frame_info); } +/* Return true if PRINT_WHAT is configured to print the location of a + frame. */ + +static bool +should_print_location (print_what print_what) +{ + return (print_what == LOCATION + || print_what == SRC_AND_LOC + || print_what == LOC_AND_ADDRESS + || print_what == SHORT_LOCATION); +} + +/* Print the source information for PC and SAL to UIOUT. Based on the + user-defined configuration disassemble-next-line, display disassembly + of the next source line, in addition to displaying the source line + itself. Print annotations describing source file and and line number + based on MID_STATEMENT information. If SHOW_ADDRESS is true, print the + program counter PC including, if non-empty, PC_ADDRESS_FLAGS. */ + +static void +print_source (ui_out *uiout, gdbarch *gdbarch, CORE_ADDR pc, + symtab_and_line sal, bool show_address, int mid_statement, + const std::string &pc_address_flags) +{ + if (sal.symtab == nullptr) + { + /* If disassemble-next-line is set to auto or on and doesn't have + the line debug messages for $pc, output the next instruction. */ + if (disassemble_next_line == AUTO_BOOLEAN_AUTO + || disassemble_next_line == AUTO_BOOLEAN_TRUE) + do_gdb_disassembly (gdbarch, 1, pc, pc + 1); + + /* If we do not have symtab information, we cannot print any source + line and must return here. */ + return; + } + + if (annotation_level > 0 + && annotate_source_line (sal.symtab, sal.line, mid_statement, pc)) + { + /* The call to ANNOTATE_SOURCE_LINE already printed the annotation + for this source line, so we avoid the two cases below and do not + print the actual source line. The documentation for annotations + makes it clear that the source line annotation is printed + __instead__ of printing the source line, not as well as. + + However, if we fail to print the source line, which usually means + either the source file is missing, or the requested line is out + of range of the file, then we don't print the source annotation, + and will pass through the "normal" print source line code below, + the expectation is that this code will print an appropriate + error. */ + } + else if (deprecated_print_frame_info_listing_hook) + deprecated_print_frame_info_listing_hook (sal.symtab, sal.line, + sal.line + 1, 0); + else + { + /* We used to do this earlier, but that is clearly wrong. This + function is used by many different parts of gdb, including + normal_stop in infrun.c, which uses this to print out the current + PC when we stepi/nexti into the middle of a source line. Only + the command line really wants this behavior. Other UIs probably + would like the ability to decide for themselves if it is + desired. */ + if (show_address) + { + print_pc (uiout, gdbarch, pc_address_flags, pc); + uiout->text ("\t"); + } + + print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); + } + + /* If disassemble-next-line is set to on and there is line debug + messages, output assembly codes for next line. */ + if (disassemble_next_line == AUTO_BOOLEAN_TRUE) + do_gdb_disassembly (gdbarch, -1, sal.pc, sal.end); +} + /* Print information about frame FRAME. The output is format according to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS. For the meaning of PRINT_WHAT, see enum print_what comments in frame.h. @@ -1029,8 +1109,6 @@ do_print_frame_info (struct ui_out *uiout, const frame_print_options &fp_opts, int set_current_sal) { struct gdbarch *gdbarch = get_frame_arch (frame); - int source_print; - int location_print; if (!current_uiout->is_mi_like_p () && fp_opts.print_frame_info != print_frame_info_auto) @@ -1101,75 +1179,26 @@ do_print_frame_info (struct ui_out *uiout, const frame_print_options &fp_opts, to get the line containing FRAME->pc. */ symtab_and_line sal = find_frame_sal (frame); - location_print = (print_what == LOCATION - || print_what == SRC_AND_LOC - || print_what == LOC_AND_ADDRESS - || print_what == SHORT_LOCATION); - if (location_print || !sal.symtab) - print_frame (uiout, fp_opts, frame, print_level, - print_what, print_args, sal); - - source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC); + if (should_print_location (print_what) || sal.symtab == nullptr) + print_frame (uiout, fp_opts, frame, print_level, print_what, + print_args, sal); - /* If disassemble-next-line is set to auto or on and doesn't have - the line debug messages for $pc, output the next instruction. */ - if ((disassemble_next_line == AUTO_BOOLEAN_AUTO - || disassemble_next_line == AUTO_BOOLEAN_TRUE) - && source_print && !sal.symtab) - do_gdb_disassembly (get_frame_arch (frame), 1, - get_frame_pc (frame), get_frame_pc (frame) + 1); - - if (source_print && sal.symtab) + if (print_what == SRC_LINE || print_what == SRC_AND_LOC) { int mid_statement = ((print_what == SRC_LINE) && frame_show_address (frame, sal)); - if (annotation_level > 0 - && annotate_source_line (sal.symtab, sal.line, mid_statement, - get_frame_pc (frame))) - { - /* The call to ANNOTATE_SOURCE_LINE already printed the - annotation for this source line, so we avoid the two cases - below and do not print the actual source line. The - documentation for annotations makes it clear that the source - line annotation is printed __instead__ of printing the source - line, not as well as. - - However, if we fail to print the source line, which usually - means either the source file is missing, or the requested - line is out of range of the file, then we don't print the - source annotation, and will pass through the "normal" print - source line code below, the expectation is that this code - will print an appropriate error. */ - } - else if (deprecated_print_frame_info_listing_hook) - deprecated_print_frame_info_listing_hook (sal.symtab, sal.line, - sal.line + 1, 0); - else - { - struct value_print_options opts; - - get_user_print_options (&opts); - /* We used to do this earlier, but that is clearly - wrong. This function is used by many different - parts of gdb, including normal_stop in infrun.c, - which uses this to print out the current PC - when we stepi/nexti into the middle of a source - line. Only the command line really wants this - behavior. Other UIs probably would like the - ability to decide for themselves if it is desired. */ - if (opts.addressprint && mid_statement) - { - print_pc (uiout, gdbarch, frame, get_frame_pc (frame)); - uiout->text ("\t"); - } - print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); - } + value_print_options opts; + get_user_print_options (&opts); + + const bool print_address = opts.addressprint && mid_statement; + + std::string pc_address_flags + = gdbarch_get_pc_address_flags (gdbarch, frame, get_frame_pc (frame)); + + print_source (uiout, gdbarch, get_frame_pc (frame), sal, + print_address, mid_statement, pc_address_flags); - /* If disassemble-next-line is set to on and there is line debug - messages, output assembly codes for next line. */ - if (disassemble_next_line == AUTO_BOOLEAN_TRUE) - do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end); } if (set_current_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: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928