From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sdCFKwLhtGqL3zsAWB0awg (envelope-from ) for ; Thu, 24 Sep 2026 04:36:18 -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=AlFpHFbo; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id AE4CF1E033; Thu, 24 Sep 2026 04:36:18 -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 vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 A2B9E1E033 for ; Thu, 24 Sep 2026 04:36:17 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CCC824BB3BF9 for ; Thu, 24 Sep 2026 08:36:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCC824BB3BF9 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=AlFpHFbo Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by sourceware.org (Postfix) with ESMTPS id 108224BB3BBB for ; Thu, 24 Sep 2026 08:34:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 108224BB3BBB 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 108224BB3BBB Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790238879; cv=none; b=xGXnxlGvSiWUtQe+vULfreY+kHnP3HB/6f+XBYBuSXK/UQbidZ5eQj4LEF8kr2nn8Te92k2QcW+iThxaneljS1QTG24JuzQ5SlFHiuxTDjemZwRaXcuBQvq585xuESLTF2c1rdtwUoftcN1Al3CifFQ3Uowpun8jjRDpNcbahXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790238879; c=relaxed/simple; bh=hxQaD4liH19DdSISegL6/k6D9eXtDzR381wFaYvDXm4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JIK5LTEs0FWqNOD9B+FrpUMGRzSxKdb6ofpHWMC0wsUmbGSeUyGuoS4HbGMHqfmN3ntMWMK1H7TJOGBnVooREBxkFZ2OsFmziG6/43UesOupQA5RzWJIdfVapeGzIOR7+diZw4j7bayaS3TElbw5T7KYkI6ypSWuwjD7tizIhnQ= ARC-Authentication-Results: i=1; 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=AlFpHFbo DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 108224BB3BBB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790238879; x=1821774879; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hxQaD4liH19DdSISegL6/k6D9eXtDzR381wFaYvDXm4=; b=AlFpHFboXf/x7iFiFkouHy+LxXGH+/vMo3BHwjSUuFixHBq5+Id8z5ZI 1ZfwRNf7fv46MobwvKa7gvdumUgSYBcQzdZVwCzu037zDHpQMNCafIlTO ZReGzBk4NbQApQKX5/TQq3S8PKuYs6JB5/K1yYsp5k8qxn5cvmgJrl1s4 Hddl7j85LVzynp28TueC3sDtNzjNB5OWkR6LAOnTkr0hyRKmP6Z9oeVBI p2+o6vpZOXQd3/ITZZqvwOWkmu2UkUDlHS6NdQfEZNNaKKAegi+vCtVMe ZqDvlWXjiIHkCkreR9psnlhX/amQdG/Xegb4RbhWMRd8ca4WxeiQ06vy6 A==; X-CSE-ConnectionGUID: a5L2UqnqQleteOUMmXQfLA== X-CSE-MsgGUID: feyOuL8URbe19Gpgz835wg== X-IronPort-AV: E=McAfee;i="6800,10657,11914"; a="91021354" X-IronPort-AV: E=Sophos;i="6.27,120,1787036400"; d="scan'208";a="91021354" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2026 01:34:38 -0700 X-CSE-ConnectionGUID: zjf8lJ9XSGyZW/M0WiAfLw== X-CSE-MsgGUID: Z2q+GuWzQKaMJSrnIDo73g== X-ExtLoop1: 1 Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2026 01:34:37 -0700 From: Christina Joos To: gdb-patches@sourceware.org Cc: thiago.bauermann@linaro.org, tom@tromey.com, luis.machado.foss@gmail.com Subject: [PATCH v5 07/13] gdb: Refactor 'stack.c:print_frame_info'. Date: Thu, 24 Sep 2026 10:33:04 +0200 Message-ID: <20260924083311.1961530-8-christina.joos@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260924083311.1961530-1-christina.joos@intel.com> References: <20260924083311.1961530-1-christina.joos@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." Approved-By: Tom Tromey --- gdb/stack.c | 156 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 93 insertions(+), 63 deletions(-) diff --git a/gdb/stack.c b/gdb/stack.c index 958db4dfe12..fda20904029 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -996,6 +996,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. @@ -1012,8 +1092,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) @@ -1084,73 +1162,25 @@ 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 - { - const value_print_options &opts = get_user_print_options (); - /* 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); - } + const value_print_options &opts = get_user_print_options (); + + 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.53.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.