From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CXcqM0csoWp9XDkAWB0awg (envelope-from ) for ; Wed, 09 Sep 2026 05:52:07 -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=NTYKaXnC; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=jNrnO+FI; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=CSQebDmq; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ZWMwmIhj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CC8B21E091; Wed, 09 Sep 2026 05:52:07 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.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 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 EE47A1E091 for ; Wed, 09 Sep 2026 05:52:06 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D6E94BA23F8 for ; Wed, 9 Sep 2026 09:52:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D6E94BA23F8 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=NTYKaXnC; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=jNrnO+FI; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=CSQebDmq; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ZWMwmIhj Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 7F2624BB1C22 for ; Wed, 9 Sep 2026 09:49:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F2624BB1C22 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 7F2624BB1C22 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788947348; cv=none; b=x+qDWqLj5arrJuSve/pMNUcVaKLWVhpWGY3VNfa8pHcmt6CognSze9INRydj4Rxozw1lD4AZ/AC6bRwWMeTxDRHNpb3dgdn7dtNaGojF7tlBXgWsj16gyWCnPMKGph5uCNijRotzuhFni7J/aYCCeGq2GQZHi0VBTap7OHighCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788947348; c=relaxed/simple; bh=sJGX0FTJ0c9Q0msMrP+aRDGlwTkphPsSIz8YeYMPJoU=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=YKMCYSHfDb8XaJaOtMwsQmBYFnDvtEJAtndETOYT9OS91gJNx7NCsQvoXCvGLpelsGkv1ECiEGcI6OMHGwsS4ZamdufAyjMVB5tXwKnYfYiAm6sNp8N3EzIKXb5XD/Ho4ezs5GDcB1nSNf/h5PszHeXKvZ3F7RrZON3pbIitwfs= 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=NTYKaXnC; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=jNrnO+FI; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=CSQebDmq; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ZWMwmIhj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F2624BB1C22 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 3B0FC1FB08 for ; Wed, 9 Sep 2026 09:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788947343; 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: in-reply-to:in-reply-to:references:references; bh=VrSJPMOUHN/e99bNrrOUaxZONsX6uW19+rNAtDZqsHE=; b=NTYKaXnCtsECBB+T54JlAt271bqcUmjKWm+oSiXCnEQ7HGtaMYMWi0ONB2HlxAIzJF4eYf R/bdILhMrglMDZuFBfGjv+YG2etWs4aJDbw36MVxQhaqUixGoDmpe3u9gogpIGsGK3/HKJ Hcb33DpcPEnJK2H8pA5b48YY3DXHsUU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788947343; 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: in-reply-to:in-reply-to:references:references; bh=VrSJPMOUHN/e99bNrrOUaxZONsX6uW19+rNAtDZqsHE=; b=jNrnO+FIGbphCgqW31FisarXB9/VbVXVR7KcOTTb8T3m3QYqPRlXC1rYOJVyCxzwElEu0y tMSuN/HFksChhLBA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=CSQebDmq; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ZWMwmIhj DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788947339; 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: in-reply-to:in-reply-to:references:references; bh=VrSJPMOUHN/e99bNrrOUaxZONsX6uW19+rNAtDZqsHE=; b=CSQebDmqHIZMFfburcfqQ9FhS3h7WAPpw1b995RyGBK9AFw0Bnbh/COsjZaTP8UiAZBLtR iMRSm+v+u+u5Oth03nSRuZ/etKBiRBzVzZo8pigIAwJK0Tnhk8hjO4pTy3CaJF09PGcu85 PVfEO5xE8JWo+4UQv8UpUzOAwfXDlXc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788947339; 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: in-reply-to:in-reply-to:references:references; bh=VrSJPMOUHN/e99bNrrOUaxZONsX6uW19+rNAtDZqsHE=; b=ZWMwmIhjJpZCyxqjf7gkwANu+KQsobrB5MOZ+VgISo5BoHrAXXeLjYRK3OZIUerH5JVsa+ yELCYz3qAfRLGZCQ== 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 3A48A138D2 for ; Wed, 9 Sep 2026 09:48:51 +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 CD/KDIMroWpJBAAAD6G6ig (envelope-from ) for ; Wed, 09 Sep 2026 09:48:51 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 7/7] [gdb/tui] Handle section holes when backward disassembling Date: Wed, 9 Sep 2026 11:48:49 +0200 Message-ID: <20260909094849.2745086-8-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260909094849.2745086-1-tdevries@suse.de> References: <20260909094849.2745086-1-tdevries@suse.de> 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: 3B0FC1FB08 X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_LOW(-1.00)[suse.de:dkim]; 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)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; 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)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(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)[sourceware.org:url,suse.de:dkim,suse.de:mid,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,gdb.tui:url,plt:email]; 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 -q a.out -ex "layout asm" -ex "disassemble 0x401020,0x401040" ... which gives us the following asm window: ... ┌─────────────────────────────────────────────────────────────────────┐ │ 0x401020 push 0x2fca(%rip) # 0x403ff0 │ │ 0x401026 jmp *0x2fcc(%rip) # 0x403ff8 │ │ 0x40102c nopl 0x0(%rax) │ │ 0x401030 jmp *0x2fca(%rip) # 0x404000 push $0x0 │ │ 0x40103b jmp 0x401020 │ │ 0x401040 <_start> endbr64 │ │ 0x401044 <_start+4> xor %ebp,%ebp │ │ 0x401046 <_start+6> mov %rdx,%r9 │ │ 0x401049 <_start+9> pop %rsi │ └─────────────────────────────────────────────────────────────────────┘ ... We can't scroll back from the plt section into the init section, because there's a section hole. Unlike the previous commit, that doesn't improve if we use start. The problem is that tui_find_backward_disassembly_start_address is not able move past section holes. Fix this by using the prev section returned by find_pc_section. This also fixes the paradoxical situation reported in PR34399 where it's possible to scroll forward into a section hole, but not back out of it. This also break gdb.tui/tui-layout-asm-short-prog.exp test-case, because it expects not being able to disassemble instructions before .text. It's easy enough to fix that using: ... -Term::command "- 15" +Term::command "- 4" ... but AFAIU, that breaks the purpose of the test-case. So instead, I've used objcopy --remove-section=.note.* to strip the sections before .text. I fear this may be fragile though. The patch caused a regression in this unit test: ... SELF_CHECK (tui_find_disassembly_address (gdbarch, 0, -1) == 0); ... because this assert got triggered: ... /* When scrolling backward the addresses should move backward, or at the very least stay the same if we are at the first address that can be disassembled. */ gdb_assert (new_low <= pc); ... I wrote two fixes for this in tui_find_disassembly_address. Each fix on its own fixes the regression, but ISTM both make sense, so I included both. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34399 --- .../gdb.tui/tui-layout-asm-short-prog.exp | 25 +++++++++++++++ gdb/tui/tui-disasm.c | 31 +++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp index b3dd72ce1ce..0fad6613e23 100644 --- a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp +++ b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp @@ -30,6 +30,31 @@ if { [build_executable "failed to prepare" $testfile $srcfile $opts] == -1 } { return } +# This test-case relies on not being able to scroll to before _start. That +# used to be the case because there's a section hole in between +# .note.gnu.build-id and .text: +# +# [Nr] Name Type Address Off Size ES Flg Lk Inf Al +# [ 0] NULL 00000000 000000 000000 00 0 0 0 +# [ 1] .note.gnu.property NOTE 00400190 000190 000030 00 A 0 0 8 +# [ 2] .note.gnu.build-id NOTE 004001c0 0001c0 000024 00 A 0 0 4 +# [ 3] .text PROGBITS 00401000 001000 000005 00 AX 0 0 1 +# +# Now that section holes no longer stop scrolling, strip the notes to get: +# +# [Nr] Name Type Address Off Size ES Flg Lk Inf Al +# [ 0] NULL 00000000 000000 000000 00 0 0 0 +# [ 1] .text PROGBITS 00401000 001000 000005 00 AX 0 0 1 + +set objcopy_program [gdb_find_objcopy] +set res \ + [remote_exec host \ + "$objcopy_program --remove-section=.note.* $binfile"] +if {[lindex $res 0] != 0} { + unsupported "Couldn't strip notes" + return +} + Term::clean_restart 24 80 $testfile if {![Term::prepare_for_tui]} { unsupported "TUI not supported" diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index d96048dc1de..bbb447fcf0f 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -201,10 +201,10 @@ tui_find_backward_disassembly_start_address (CORE_ADDR addr) /* Find the first section with start address before ADDR, and use its start address. The found section may be the one containing ADDR, or the one before it. */ - struct obj_section *section; + struct obj_section *section, *prev; for (int offset = 0; offset <= 1; ++offset) { - section = find_pc_section (addr - offset); + section = find_pc_section (addr - offset, &prev); if (offset == 0 && section != nullptr && section->addr () == addr) { /* If ADDR is the start of its section, use ADDR - 1. */ @@ -217,6 +217,20 @@ tui_find_backward_disassembly_start_address (CORE_ADDR addr) if (section != NULL) return section->addr (); + if (prev != nullptr + && (bfd_section_flags (prev->the_bfd_section) & SEC_ALLOC) != 0) + { + /* Skip over section hole and use previous section. */ + + /* If not causing infinite recursion, self-recurse to possibly use + minimal symbols in the previous section. */ + if (prev->endaddr () < addr) + return tui_find_backward_disassembly_start_address (prev->endaddr ()); + + /* Fallback: simply use start of previous section. */ + return prev->addr (); + } + return addr; } @@ -282,6 +296,12 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from) /* Find an address from which we can start disassembling. */ prev_low = new_low; new_low = tui_find_backward_disassembly_start_address (new_low); + if (new_low == prev_low) + { + /* No backward progress made, bail out. */ + next_addr = new_low; + break; + } /* Disassemble forward. */ next_addr = tui_disassemble (gdbarch, asm_lines, new_low, max_lines); @@ -321,6 +341,13 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from) MAX_LINES entries. */ gdb_assert (asm_lines.size () == max_lines); + if (next_addr > pc) + { + /* We're about to scan forward starting at next_addr to reach pc. + No need to do that if next_addr is already past pc. */ + return new_low; + } + /* Scan forward disassembling one instruction at a time until the last visible instruction of the window matches the pc. We keep the disassembled instructions in the 'lines' window -- 2.51.0