From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id aakfMwlhTmpBcSwAWB0awg (envelope-from ) for ; Wed, 08 Jul 2026 10:39:05 -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=JpOHatox; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CD55A1E098; Wed, 08 Jul 2026 10:39:05 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 100E41E024 for ; Wed, 08 Jul 2026 10:39:05 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 408E84BA2E26 for ; Wed, 8 Jul 2026 14:39:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 408E84BA2E26 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=JpOHatox Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by sourceware.org (Postfix) with ESMTPS id 67F474BA2E24 for ; Wed, 8 Jul 2026 14:37:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67F474BA2E24 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 67F474BA2E24 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783521466; cv=none; b=xwu713J1B6P1BB6HYx4ieTXbaSJUyWLnQ4YBVEah5mLTwAulONmFo2Bq8g0cPwo6KpL231HXdQ9t8KDHEgKWYu+ApptfkDcO6VMANX9SCDCKMJ8ls6kkl7qNg25Z6tdXAOSHIYSLx7ktiSrGxx1Yxm+Xl/hWoulSrOkq07Ws23o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783521466; c=relaxed/simple; bh=r33CEqC2Cd+nmoL/h3p9nhbx1puvP5fCBs/dbFmDYhw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=BmJcOrnaVN78zboGiNtmEWfAEnkt3dm1C1RLwvnChgUc/CsE24Nx98lYoHgTtMfBNFcR+HzmrA/hQBU6/Qbhc0pdlDTeLS9W2wfu7rPjx440VRXyg/u52k3wkz0UaiaD6h9JZYU430mXox1IPYna8uZDwoUFoSwN0EZ/rSAKEL0= 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=JpOHatox DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67F474BA2E24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783521467; x=1815057467; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r33CEqC2Cd+nmoL/h3p9nhbx1puvP5fCBs/dbFmDYhw=; b=JpOHatox6RaAwtcmE6fVmF66YSnhC6OlVrUPm3L3jFUxasyximNZd40L StezEQlhfCUNGTdvwqsGA3cRxbnQ4LuzlRD/eJHQEvl1BRBqOYTYnQ1MH 6K5bknqtj67v46f9mFplmdhjNrBfOIzhsR8UUDA/mXWABIiSYtzak/IDv R/mlifBamLexOrT7k0zN060uCB4t07K+i8rqafdGQuYmLD9g+w+OAyug8 UfYF3DDxMlGjb6k+GX2088ls4y7r/H3haxmUd5JKkuuIMdHporcgk0QzZ VF9IbMIACZIEi7naOBUQ/46tFY64MiMgsdsCOG2FgOQhUql/jMjnAs88O A==; X-CSE-ConnectionGUID: zIF4RCFWQXSg5W3t1/S+SA== X-CSE-MsgGUID: HpmxY3hfQUS0jODpZ8ZZhg== X-IronPort-AV: E=McAfee;i="6800,10657,11841"; a="84375456" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84375456" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 07:37:46 -0700 X-CSE-ConnectionGUID: yaSaImSkS5eDSfoeFXecrA== X-CSE-MsgGUID: VqRRHDCSRmmhle1h595L1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="249864316" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 07:37:45 -0700 From: Christina Schimpe To: gdb-patches@sourceware.org Cc: tom@tromey.com, thiago.bauermann@linaro.org Subject: [PATCH v4 07/13] gdb: Refactor 'stack.c:print_frame_info'. Date: Wed, 8 Jul 2026 14:36:33 +0000 Message-Id: <20260708143639.2214689-8-christina.schimpe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708143639.2214689-1-christina.schimpe@intel.com> References: <20260708143639.2214689-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." Approved-By: Tom Tromey --- gdb/stack.c | 159 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 94 insertions(+), 65 deletions(-) diff --git a/gdb/stack.c b/gdb/stack.c index f5196c384fd..7df1d6e33da 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -957,6 +957,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. @@ -973,8 +1053,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) @@ -1045,75 +1123,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: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 89 991 430, www.intel.de Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell Chairperson of the Supervisory Board: Nicole Lau Registered Seat: Munich Commercial Register: Amtsgericht Muenchen HRB 186928