From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id w3sADmR1rGaCgTkAWB0awg (envelope-from ) for ; Fri, 02 Aug 2024 01:57:56 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wF1IJws4; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0jJJKcZq; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wF1IJws4; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0jJJKcZq; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 232D41E0D0; Fri, 2 Aug 2024 01:57:56 -0400 (EDT) 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 D822D1E097 for ; Fri, 2 Aug 2024 01:57:53 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A7F0385C6D1 for ; Fri, 2 Aug 2024 05:57:53 +0000 (GMT) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id A1FED385C6D1 for ; Fri, 2 Aug 2024 05:57:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1FED385C6D1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A1FED385C6D1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722578251; cv=none; b=hUUs5QvoEefnMJqQmubPRRdYJsTZb48dVgr3bk83lDvEjM9oqRqGzKEFVrv6NuT/gzS1hOW8vSBy31iuopF68hoZu6GHRjKZT/T52agG8PPoOEqd9e6KV39koebLu4y/6MqlT5XCHNJwlq8ffvS1CVOE3Cc4ERw60A2Bg2MlaUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722578251; c=relaxed/simple; bh=ycxsfeZ5HWS5R/P2vBMjZwj3R0rE5F8o1EUWbYiR4pE=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=tsKZ/GLqUJt8GavPlYydYSAv35JvfAbPf3G3dI/x8cFS8kKldOvkpgG/HUxwLNGipCsb6sTDMYH15mkHx3XLserLhf0ODXZbafSJSOFobgiRrSm/LOu9BvavqZD4/KAmJ4DoBpGXa7JpRJo3s6spErsHQJ5KLg2BzlgGOIAL/kE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6B45621992 for ; Fri, 2 Aug 2024 05:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722578248; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=cfkACAzi9pKDqSK2iOC+FXLQeu5i+kpdJipSLVClya0=; b=wF1IJws4MMWdZs7zR621PIDlODlw5jazaWvPL7TUESrs0y9l2XtPgIB9OfukW06Eg/9XJf kg0cjoffaZykNUwqC+bdtWke8JBhuSa8dzACZlEX6EVXhHPcIg5ILAx9g+UGbZCnXpcNET KxM5bRfXJeVx/5yhpcB1clvY+92C2JA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722578248; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=cfkACAzi9pKDqSK2iOC+FXLQeu5i+kpdJipSLVClya0=; b=0jJJKcZqC6wARzXr9Oeu1hfYDzxLcVleU4sB6nUxug1V6TInChZkars37+T/89ov9NvvAk UGpPtuwNkAB5RFDw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=wF1IJws4; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=0jJJKcZq DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722578248; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=cfkACAzi9pKDqSK2iOC+FXLQeu5i+kpdJipSLVClya0=; b=wF1IJws4MMWdZs7zR621PIDlODlw5jazaWvPL7TUESrs0y9l2XtPgIB9OfukW06Eg/9XJf kg0cjoffaZykNUwqC+bdtWke8JBhuSa8dzACZlEX6EVXhHPcIg5ILAx9g+UGbZCnXpcNET KxM5bRfXJeVx/5yhpcB1clvY+92C2JA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722578248; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=cfkACAzi9pKDqSK2iOC+FXLQeu5i+kpdJipSLVClya0=; b=0jJJKcZqC6wARzXr9Oeu1hfYDzxLcVleU4sB6nUxug1V6TInChZkars37+T/89ov9NvvAk UGpPtuwNkAB5RFDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 531DC1388E for ; Fri, 2 Aug 2024 05:57:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id tg/TEkh1rGafbQAAD6G6ig (envelope-from ) for ; Fri, 02 Aug 2024 05:57:28 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb] Notice when stepping into different file Date: Fri, 2 Aug 2024 07:57:30 +0200 Message-Id: <20240802055730.11865-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Rspamd-Queue-Id: 6B45621992 X-Spam-Score: -4.81 X-Spam-Level: X-Spamd-Result: default: False [-4.81 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[gnu.org:url,suse.de:dkim]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, 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 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 Consider the following test-case: ... $ cat test.c int var; int foo (void) { var = 1; } int main () { return foo (); } $ cat test.h return 1; $ gcc test.c -g ... When stepping through the test-case, gdb doesn't make it explicit that line 1 is not in test.c: ... Temporary breakpoint 1, main () at test.c:13 13 return foo (); (gdb) step foo () at test.c:6 6 var = 1; (gdb) n 1 return 1; (gdb) 8 } (gdb) ... which makes it easy to misinterpret the output. This is with the default "print frame-info" == auto, with documented behaviour [1]: ... stepi will switch between source-line and source-and-location depending on the program counter. ... What is actually implemented is that source-line is used unless stepping into or out of a function. The problem can be worked around by using "set print frame-info source-and-location", but that's a bit verbose. Instead, change the behaviour of "print frame-info" == auto to also use source-and-location when stepping into another file, which gets us: ... (gdb) n foo () at test.h:1 1 return 1; ... Tested on x86_64-linux. PR gdb/32011 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32011 [1] https://sourceware.org/gdb/current/onlinedocs/gdb.html/Print-Settings.html#index-set-print-frame_002dinfo --- gdb/infrun.c | 18 ++++++++-- gdb/testsuite/gdb.base/step-into-other-file.c | 31 ++++++++++++++++ .../gdb.base/step-into-other-file.exp | 36 +++++++++++++++++++ gdb/testsuite/gdb.base/step-into-other-file.h | 18 ++++++++++ 4 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.base/step-into-other-file.c create mode 100644 gdb/testsuite/gdb.base/step-into-other-file.exp create mode 100644 gdb/testsuite/gdb.base/step-into-other-file.h diff --git a/gdb/infrun.c b/gdb/infrun.c index 06b454bf78f..05e81a08e03 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -9296,12 +9296,24 @@ print_stop_location (const target_waitstatus &ws) && (tp->control.step_start_function == find_pc_function (tp->stop_pc ()))) { - /* Finished step, just print source line. */ - source_flag = SRC_LINE; + symtab_and_line sal = find_frame_sal (get_selected_frame (nullptr)); + if (sal.symtab != tp->current_symtab) + { + /* Finished step in same frame but into different file, print + location and source line. */ + source_flag = SRC_AND_LOC; + } + else + { + /* Finished step in same frame and same file, just print source + line. */ + source_flag = SRC_LINE; + } } else { - /* Print location and source line. */ + /* Finished step into different frame, print location and source + line. */ source_flag = SRC_AND_LOC; } break; diff --git a/gdb/testsuite/gdb.base/step-into-other-file.c b/gdb/testsuite/gdb.base/step-into-other-file.c new file mode 100644 index 00000000000..5ec7c332739 --- /dev/null +++ b/gdb/testsuite/gdb.base/step-into-other-file.c @@ -0,0 +1,31 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int var; + +int +foo (void) +{ + var = 1; +#include "step-into-other-file.h" +} + +int +main () +{ + return foo (); +} diff --git a/gdb/testsuite/gdb.base/step-into-other-file.exp b/gdb/testsuite/gdb.base/step-into-other-file.exp new file mode 100644 index 00000000000..f0e8c3f0870 --- /dev/null +++ b/gdb/testsuite/gdb.base/step-into-other-file.exp @@ -0,0 +1,36 @@ +# Copyright (C) 2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that when stepping into another file, the file is shown. + +standard_testfile .c .h + +set flags {} +lappend flags debug +lappend_include_file flags $srcdir/$subdir/$srcfile2 + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \ + $flags] == -1 } { + return -1 +} + +if ![runto_main] { + return -1 +} + +gdb_test step $srcfile:$decimal\r\n.* + +# Regression test for PR32011. +gdb_test next $srcfile2:$decimal\r\n.* diff --git a/gdb/testsuite/gdb.base/step-into-other-file.h b/gdb/testsuite/gdb.base/step-into-other-file.h new file mode 100644 index 00000000000..60b481670f7 --- /dev/null +++ b/gdb/testsuite/gdb.base/step-into-other-file.h @@ -0,0 +1,18 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + return 1; base-commit: 94223333026f06dc5d78266dd9b6082544641f07 -- 2.35.3