From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mFgdB6GxrmqybyEAWB0awg (envelope-from ) for ; Sat, 19 Sep 2026 12:00:33 -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=sSAQhl/C; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=V4V3V7OX; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=by4jtniR; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8BNRZrc4; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 0B2EB1E01F; Sat, 19 Sep 2026 12:00:33 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 6ADCE1E01F for ; Sat, 19 Sep 2026 12:00:31 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD7964B99F44 for ; Sat, 19 Sep 2026 16:00:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD7964B99F44 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=sSAQhl/C; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=V4V3V7OX; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=by4jtniR; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8BNRZrc4 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 72CBE4BA2E15 for ; Sat, 19 Sep 2026 15:59:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72CBE4BA2E15 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 72CBE4BA2E15 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789833598; cv=none; b=eCcVUnvMAwVX+QOTi2fXeN+9XvUbmTgxyoOOzkgWbNFgTkuNDBHXAYA7i/Ip0wCu9CPziOILFJQqyoN1HSEkVTOxYnlOk2disBjoR2+5rmYQQkT/phoH2MqYqBTfcOqu/yHa5V+ilS+RL5MseBn33FVOOst5HTSzYs4SRFeYyY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789833598; c=relaxed/simple; bh=hX47CMRMuMbn/C9kuNngUCmf4/0BUaSXJH072fHkrgI=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=PX2oQbaUtnJKcqNSFvYwW66SoqejHw8YijCN3dDlhiU0B8DarxoOk9F0QIgVCt3mGHes5hhfXXS4ciDhihd7FvmXZVO100riHLjRSfXzoSZT4yoYRY9iF2tbhdjLYicA7z6tiSgnUern9Gk+OtNUcFzfVlIHzdCTdaQ3KHYgRto= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=sSAQhl/C; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=V4V3V7OX; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=by4jtniR; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8BNRZrc4 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72CBE4BA2E15 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-out2.suse.de (Postfix) with ESMTPS id E85701F451 for ; Sat, 19 Sep 2026 15:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1789833593; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TzswP75d4NKA+p8tVovnc1KwZDFjOgrmm54Ex6TbsqI=; b=sSAQhl/CGPI8LceQa/ZLJGjUhjuF6tSjfsxjJxN10ytsRicDnOlaRhAWnzzcUUbm6il/dl 3x2RSDle/Y8rN/Er8SB1XCSPzxCTMBCjmRbijqA5Ru0f7AwgDB0PrM+kR/kyHlVqRaX8fM XG5eMaG2HSY4lC4bUbv48wpCl79ZMtU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1789833593; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TzswP75d4NKA+p8tVovnc1KwZDFjOgrmm54Ex6TbsqI=; b=V4V3V7OXt4mG914yFUIR65Pc+3LyNa5D5qvh8e+WVT3fNvCc0DjoTEIbaDvQLmpCGjk/qd j7qHcDq6nXbnIZDg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=by4jtniR; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=8BNRZrc4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1789833589; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TzswP75d4NKA+p8tVovnc1KwZDFjOgrmm54Ex6TbsqI=; b=by4jtniRLPpOFJOQLb/a2yx3VNWweKjlWnBR48yO3NeP3qu/sbFOlDF1BYQxZZYed3lFqU 4zJ/+pZOEB75wgJLzNxNFFJOBDLJD93lhbcV0ZmGYTZCDVUtQxTctsrbBDLLP2+FsU42FX j0FtigtQYTKxSqrR+IXtmnaSkK6I8aU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1789833589; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TzswP75d4NKA+p8tVovnc1KwZDFjOgrmm54Ex6TbsqI=; b=8BNRZrc4fbpPJDGcXnN8q6UzE6IMqSXdy9Fmc3P8xaGf2kTm4AFggEe2hfSLPn8Zhw2ttL GdoIhyoeoxVDisCA== 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 9254D133CF for ; Sat, 19 Sep 2026 15:59:48 +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 tdWDF3SxrmrsHgAAD6G6ig (envelope-from ) for ; Sat, 19 Sep 2026 15:59:48 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [pushed] [gdb/tui] Improve section handling in tui_find_backward_disassembly_start_address Date: Sat, 19 Sep 2026 17:59:48 +0200 Message-ID: <20260919155948.1356120-1-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: E85701F451 X-Spamd-Result: default: False [-3.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_TLS_ALL(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.de:dkim,suse.de:mid,gnu.org:url]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] 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 a hello world: ... $ gcc hello.c -g ... and gdb setup like this: ... $ gdb a.out -ex "layout asm" -ex "disassemble _start" ... which gives us the following asm window: ... ┌─────────────────────────────────────────────────────────────────────┐ │ 0x401040 <_start> endbr64 │ │ 0x401044 <_start+4> xor %ebp,%ebp │ │ 0x401046 <_start+6> mov %rdx,%r9 │ │ 0x401049 <_start+9> pop %rsi │ │ 0x40104a <_start+10> mov %rsp,%rdx │ │ 0x40104d <_start+13> and $0xfffffffffffffff0,%rsp │ │ 0x401051 <_start+17> push %rax │ │ 0x401052 <_start+18> push %rsp │ │ 0x401053 <_start+19> xor %r8d,%r8d │ │ 0x401056 <_start+22> xor %ecx,%ecx │ └─────────────────────────────────────────────────────────────────────┘ ... The _start function sits at the start of the text section: ... Disassembly of section .plt: ... 0000000000401030 : 401030: ff 25 ca 2f 00 00 jmp *0x2fca(%rip) 401036: 68 00 00 00 00 push $0x0 40103b: e9 e0 ff ff ff jmp 401020 <_init+0x20> Disassembly of section .text: 0000000000401040 <_start>: ... and using we can scroll to the last instruction of the plt section, at 0x40103b. To make this happen: - tui_find_backward_disassembly_start_address is called with addr == 0x401040 - lookup_minimal_symbol_by_pc_section is called with addr - 1 - minimal symbol puts@plt is found - its address is returned and used as starting point for disassembly However, tui_find_backward_disassembly_start_address uses two types of information: minimal symbols, and sections. If we disable the minimal symbol handling in tui_find_backward_disassembly_start_address, we're no longer able to scroll to the instruction at 0x40103b. The section handling code: .... /* Find the section that ADDR is in, and look for the start of the section. */ struct obj_section *section = find_pc_section (addr); if (section != NULL) return section->addr (); ... looks up the section for 0x401040, which is .text, and it returns its start address, which is also 0x401040, signalling that we cannot scroll to before that address. Fix this by using addr - 1. This happens to work because there's no section hole between sections plt and text. --- gdb/testsuite/gdb.tui/scroll-back.S | 52 ++++++++++++++++ gdb/testsuite/gdb.tui/scroll-back.exp | 89 +++++++++++++++++++++++++++ gdb/tui/tui-disasm.c | 6 +- 3 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.tui/scroll-back.S create mode 100644 gdb/testsuite/gdb.tui/scroll-back.exp diff --git a/gdb/testsuite/gdb.tui/scroll-back.S b/gdb/testsuite/gdb.tui/scroll-back.S new file mode 100644 index 00000000000..0ee1067ad2c --- /dev/null +++ b/gdb/testsuite/gdb.tui/scroll-back.S @@ -0,0 +1,52 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2026 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 . */ + + .section .text + .global main +main: + nop + +#ifdef __arm__ + .section .text_1,"ax",%progbits +#else + .section .text_1,"ax",@progbits +#endif + + # This is foo, but we don't use a symbol. We use a repetition of 8 to + # get the end of the section to be 8-byte aligned, to increase the + # chances of avoiding a section hole in between .text_1 and .text_2. + .rept 8 + nop + .endr + + .align 1 + +#ifdef __arm__ + .section .text_2,"ax",%progbits +#else + .section .text_2,"ax",@progbits +#endif + + .global bar +bar: + nop + +#ifdef __arm__ + .section .note.GNU-stack,"",%progbits +#else + .section .note.GNU-stack,"",@progbits +#endif diff --git a/gdb/testsuite/gdb.tui/scroll-back.exp b/gdb/testsuite/gdb.tui/scroll-back.exp new file mode 100644 index 00000000000..76eb66eafca --- /dev/null +++ b/gdb/testsuite/gdb.tui/scroll-back.exp @@ -0,0 +1,89 @@ +# Copyright 2026 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 . + +# Setup TUI such that the first instruction in the disassembly window is the +# start of a section. Then scroll back to the last instruction of the +# previous section. ATM this won't work if there's a section hole. +# +# The .S file tries to make sure that there's no section hole, but AFAIU that +# can't be guaranteed. If this test-case detects a section hole, it bails +# out with unsupported. +# +# The .S file is odd in the sense that the "previous section" doesn't contain +# any symbols. This is done to trigger a different path in +# tui_find_backward_disassembly_start_address. + +# This test-case uses two extra text sections. This is not supported on cygwin. +require {!istarget *-*-cygwin*} + +tuiterm_env + +standard_testfile scroll-back.S + +if {[build_executable "failed to prepare" $testfile $srcfile \ + {nodebug}] == -1} { + return +} + +Term::clean_restart 24 80 $testfile +if {![Term::prepare_for_tui]} { + unsupported "TUI not supported" + return +} + +set re_no_hole \ + [subst_vars \ + {$hex:\s+$hex}] +set re_hole \ + [subst_vars \ + {$hex:\s+Cannot access memory at address $hex}] + +set section_hole -1 +gdb_test_multiple "x /cx bar-1" "" { + -re -wrap $re_no_hole { + set section_hole 0 + } + -re -wrap $re_hole { + set section_hole 1 + } +} + +if {$section_hole != 0} { + unsupported "require no section hole between .text_1 and .text_2" + return +} + +gdb_assert {[Term::command_no_prompt_prefix "layout asm"] == 1} +gdb_assert {[Term::command "disassemble bar"] == 1} + +set first_line_asm {1 1 78 1} +Term::check_region_contents "first insn bar" {*}$first_line_asm \ + [subst_vars \ + {$hex\s+\s+nop}] + +# Send an up arrow. +set esc "\033" +set left_square_bracket "\[" +set csi "$esc$left_square_bracket" +set cursor_up "${csi}A" +send_gdb $cursor_up + +Term::dump_screen + +gdb_assert \ + {[Term::wait_for_region_contents {*}$first_line_asm \ + [subst_vars \ + {$hex\s+nop}]]} \ + "last insn foo" diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index 7dcb59e6264..1a1866003dd 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -177,9 +177,9 @@ tui_find_backward_disassembly_start_address (CORE_ADDR addr) else if (msym_prev.minsym != nullptr) return msym_prev.value_address (); - /* Find the section that ADDR is in, and look for the start of the - section. */ - struct obj_section *section = find_pc_section (addr); + /* Find the first section with start address before ADDR, and use its start + address. */ + struct obj_section *section = find_pc_section (addr - 1); if (section != NULL) return section->addr (); base-commit: dd41575147933228c3996204b68c6c6e6ed3d9e8 -- 2.51.0