From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yRNDDiWummrdMygAWB0awg (envelope-from ) for ; Fri, 04 Sep 2026 07:40:21 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fe4Qm7xC; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 36F4A1E09B; Fri, 04 Sep 2026 07:40:21 -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 E3A511E09B for ; Fri, 04 Sep 2026 07:40:19 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E42146A9CCC for ; Fri, 4 Sep 2026 11:40:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E42146A9CCC Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fe4Qm7xC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 3FD8451A3B9F for ; Fri, 4 Sep 2026 11:39:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FD8451A3B9F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3FD8451A3B9F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788521991; cv=none; b=NcKY8n578vj3DwMeCo/f22+zfwLM9bQeEOFOfbVS3sNxJxLBpns8gX3kWIy03C5lTvl+5VWURSRII6bIljvKIUcA0EDWk22iASprUuaUfXOYf3qlGdRhTZoTOgg3R8iSvK34sUEGuMJT94Gc3NI++lKn7IFiSbibwSqYrib3Huo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788521991; c=relaxed/simple; bh=2NPn/8XFCQa062ISo4dsr8UV9ihy3q/niwnx5Sz+BI8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=EHRYUwFtjp2pcikfOi4J+ubIyTNfricESHgZmdLYjMVwc2n2JiEWxTKekQeAJCMhXN0mo62Vsy6VCwXh/Lj73mAXJMHzwzfBw7XWfX6zJK6c/mhyY3z6vYF6dxpxGaT/ZkiS8Fjdwt8NdMf/n9nj7je1B5TWSRV5TU1aVCmQRSc= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fe4Qm7xC DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FD8451A3B9F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788521990; h=from:from:reply-to:subject:subject: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=q9r7xMb6Pb8iY7VwyH7P/G3BhcNYwzj9QTphtrG/yss=; b=fe4Qm7xCr+TTkH6H0NM2DnKGguvBAObN7vWgZbURfaaIy8jToPGVsyOnwugkFMM1kMXdHX MmLaI0DQLVQ9VNFVGwae+ecWiAj6XA7jKryRKo8Bz67SW3qx20fIzat+HmxIkm6mL9+PzS a0e4ybzvnUWmctVF1+6YqOIxZTlDCF0= Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-IoGWpZ8lO1CUUoJq2y09Ow-1; Fri, 04 Sep 2026 07:39:49 -0400 X-MC-Unique: IoGWpZ8lO1CUUoJq2y09Ow-1 X-Mimecast-MFC-AGG-ID: IoGWpZ8lO1CUUoJq2y09Ow_1788521989 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-822ce245c5aso15617137b3.1 for ; Fri, 04 Sep 2026 04:39:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788521989; x=1789126789; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=q9r7xMb6Pb8iY7VwyH7P/G3BhcNYwzj9QTphtrG/yss=; b=NgkyGPajAS2eDQ0QTDNR1/UTqNu056J9+fzoHhEXp38iIJm8vpL0KQm122uYo7O5xV fXM8N086yiQzWTZYorU5KT5RX5HVDOnMdnMJzWU5lPjPU3b31QbbPSNkWfHja6wl+dDi Gd34dq1FfhEVioldVxDikOc+NavawYwgocBHvx7MYyz5FrCF75ovjgTNY+woZMXeGSYw rvubIVEQmoXpxi6/YLKMbBIaMhKCIHoM6PhDOVdHfhb3wLliR9iDnjXKRWCsEvMZ0Uv3 KLGrknw6xT79j5Z794EuR2dqGD3Blb9lmzzNWG239fBuTGtQS+1xZeVI8a42nK/+ZFxM WANQ== X-Forwarded-Encrypted: i=1; AKwUvByVF8gS2AiQEUTtIv1z+RCN5vhuqI54R1O08Eu+1ISkYXjbXW22/dLtnYyVectmyypSIUe/7xS6Rxn+EQ==@sourceware.org X-Gm-Message-State: AFuF++lRfufkqKSB3mzw+pCPyH9rhKNsu7JHmwRQ5TginSMgxTHZjIt5 5q8R7uza2EPSEB8eCx6sd7o2yJt/A+NhvL50mRpfSiGQFG2XJIGqqR80zcqKGB/wZYYOICAamIJ Fe+EJrDl0s78jvSSOekJRdEj/dHyjJUpJdNCFY312UBDg95tZlldQ+2ylraO52Au8GapX17w= X-Gm-Gg: AYBFou3b9Rus5N16pha+oLQRRAhyuxOJKecKHtStXt5HTkHRizlQmYiPb3q90qsGzrk F7mtNKZt5hwafYZzuSFWFthO4h7enFyBJiiRJJjbrgx0Q8g2h6OFyZiApIHW/A5B5x0CMAF6Sze xbHcQlyaI8NtND4vVmBDPeFPi7WDsJIyBRwHB7bPDbO730vC5EWXBKou30cNtisZvITbKjlJieG aVtumBfzboRb4MynR2RoEFFynmXsMBLby15PB2I4vJ0M18HU5CQ6jlu9zU4hglslr1WxXJ/v5a8 fWD6XUHUYEqk4CRmli35Jvv/Tl8DbD63ky2RcOZkui9cTI0GENlI6EGDCL7M9Uo1llCawm4RUVd d2MDU/ksGxQGlmBxZ3K4Fyx5coxPBrDIobqljZZfXsOqAbj4HiA== X-Received: by 2002:a05:690c:d84:b0:870:96e4:6709 with SMTP id 00721157ae682-87122985ba4mr27717647b3.9.1788521988804; Fri, 04 Sep 2026 04:39:48 -0700 (PDT) X-Received: by 2002:a05:690c:d84:b0:870:96e4:6709 with SMTP id 00721157ae682-87122985ba4mr27717457b3.9.1788521988241; Fri, 04 Sep 2026 04:39:48 -0700 (PDT) Received: from ?IPV6:2804:14d:8084:993e:22e8:4ed1:527a:55c0? ([2804:14d:8084:993e:22e8:4ed1:527a:55c0]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8714b7255fbsm15738437b3.42.2026.09.04.04.39.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Sep 2026 04:39:47 -0700 (PDT) Message-ID: <7c55b686-2067-4dbd-8eaa-c7a77ad11afa@redhat.com> Date: Fri, 4 Sep 2026 08:39:43 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] [gdb/tui] Don't disassemble non-code sections and section holes To: Tom de Vries , gdb-patches@sourceware.org References: <20260819143514.2221499-1-tdevries@suse.de> From: Guinevere Larsen In-Reply-To: <20260819143514.2221499-1-tdevries@suse.de> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: h6T3wK1gB1OmI0jywEdMcHjK5YJXGTK0c57QyanzobA_1788521989 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 On 8/19/26 11:35 AM, Tom de Vries wrote: > I was investigating TUI behaviour on ppc64-linux using the executable from > test-case gdb.tui/basic.exp, and after scrolling in the asm window ended up > with: > ... > +----------------------------------------------------------------------------+ > | 0x920 <__libc_start_main@plt+4> b 0x8f0 <__glink_PLTresolve> | > | 0x924 <__gmon_start__@plt> li r0,1 | > | 0x928 <__gmon_start__@plt+4> b 0x8f0 <__glink_PLTresolve> | > | 0x92c <__cxa_finalize@plt> li r0,2 | > | 0x930 <__cxa_finalize@plt+4> b 0x8f0 <__glink_PLTresolve> | > | 0x934 <._fini> mflr r0 | > | 0x938 <._fini+4> std r0,16(r1) | > | 0x93c <._fini+8> stdu r1,-112(r1) | > | 0x940 <._fini+12> addi r1,r1,112 | > | 0x944 <._fini+16> ld r0,16(r1) | > | 0x948 <._fini+20> mtlr r0 | > | 0x94c <._fini+24> blr | > | 0x950 <_IO_stdin_used> .long 0x20001 | > | 0x954 .long 0x11b033b | > | 0x958 .long 0x18 | > | 0x95c .long 0x2 | > | 0x960 .long 0xffffff60 | > | 0x964 .long 0x48 | > | 0x968 .long 0xffffff9c | > | 0x96c .long 0x30 | > +----------------------------------------------------------------------------+ > exec No process (asm) In: L?? PC: ?? > (gdb) > ... > > The view corresponds to this objdump -D output: > ... > Disassembly of section .text: > > ... > > 000000000000091c <__libc_start_main@plt>: > 91c: 38 00 00 00 li r0,0 > 920: 4b ff ff d0 b 8f0 <__glink_PLTresolve> > > 0000000000000924 <__gmon_start__@plt>: > 924: 38 00 00 01 li r0,1 > 928: 4b ff ff c8 b 8f0 <__glink_PLTresolve> > > 000000000000092c <__cxa_finalize@plt>: > 92c: 38 00 00 02 li r0,2 > 930: 4b ff ff c0 b 8f0 <__glink_PLTresolve> > > Disassembly of section .fini: > > 0000000000000934 <._fini>: > 934: 7c 08 02 a6 mflr r0 > 938: f8 01 00 10 std r0,16(r1) > 93c: f8 21 ff 91 stdu r1,-112(r1) > 940: 38 21 00 70 addi r1,r1,112 > 944: e8 01 00 10 ld r0,16(r1) > 948: 7c 08 03 a6 mtlr r0 > 94c: 4e 80 00 20 blr > > Disassembly of section .rodata: > > 0000000000000950 <_IO_stdin_used>: > 950: 00 02 00 01 .long 0x20001 > > Disassembly of section .eh_frame_hdr: > > 0000000000000954 <__GNU_EH_FRAME_HDR>: > 954: 01 1b 03 3b .long 0x11b033b > 958: 00 00 00 18 .long 0x18 > 95c: 00 00 00 02 .long 0x2 > 960: ff ff ff 60 .long 0xffffff60 > 964: 00 00 00 48 .long 0x48 > 968: ff ff ff 9c .long 0xffffff9c > 96c: 00 00 00 30 .long 0x30 > ... > > ISTM that we should not be disassembling the .rodata section. > > My first thought was to require tui_disassemble to stay in the same section, > but after thinking about it a bit more decided that that was too restrictive, > and instead went for requiring that we stay in code sections. > > So, I came up with this fix: > ... > struct obj_section *section = find_pc_section (pc); > if (section != nullptr > && (bfd_section_flags (section->the_bfd_section) & SEC_CODE) == 0) > return pc; > ... > > Then I stumbled on PR tui/34399, which reports not being able to scroll back > up after scrolling down. The problem there is that we disassemble code from a > section hole (0x401034-0x402000): > ... > Section Headers: > [Nr] Name Type Address Offset > Size EntSize Flags Link Info Align > [ 0] NULL 0000000000000000 00000000 > 0000000000000000 0000000000000000 0 0 0 > [ 1] .note.gnu.pr[...] NOTE 0000000000400190 00000190 > 0000000000000030 0000000000000000 A 0 0 8 > [ 2] .note.gnu.bu[...] NOTE 00000000004001c0 000001c0 > 0000000000000024 0000000000000000 A 0 0 4 > [ 3] .text PROGBITS 0000000000401000 00001000 > 0000000000000034 0000000000000000 AX 0 0 1 > [ 4] .rodata PROGBITS 0000000000402000 00002000 > 0000000000000006 0000000000000000 A 0 0 1 > [ 5] .symtab SYMTAB 0000000000000000 00002008 > 0000000000000078 0000000000000018 6 1 8 > [ 6] .strtab STRTAB 0000000000000000 00002080 > 0000000000000019 0000000000000000 0 0 1 > [ 7] .shstrtab STRTAB 0000000000000000 00002099 > 000000000000004f 0000000000000000 0 0 1 > Key to Flags: > W (write), A (alloc), X (execute), M (merge), S (strings), I (info), > L (link order), O (extra OS processing required), G (group), T (TLS), > C (compressed), x (unknown), o (OS specific), E (exclude), > D (mbind), l (large), p (processor specific) > ... > and once we call tui_find_backward_disassembly_start_address with an address > ADDR for which find_pc_section (ADDR - 1) == nullptr, we are stuck in the > section hole. > > Fix this by not disassembling section holes. > > This is achieved by slightly modifying the earlier fix: > ... > if (section == nullptr > || (bfd_section_flags (section->the_bfd_section) & SEC_CODE) == 0) > return pc; > ... > > Tested on x86_64-linux and ppc64-linux. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34399 > --- Hi! Thank you for working on this! I think your fix makes perfect sense, but I noticed an inaccuracy in the function comment. It predates your change, but I think now would be a reasonable time to fix it. The comment reads:     Function to disassemble up to COUNT instructions starting from address PC     into the ASM_LINES vector (which will be emptied of any previous contents).     Return the address of the COUNT'th instruction after pc. Considering that returning early is possible, I think this comment should say that we return the address right after the last disassembled instruction, or something to that effect. Also, I tried to reproduce this issue in x86 but couldn't. It would be nice if there was a test that exercised this, but it isn't a requirement for me. -- Cheers, Guinevere Larsen it/its she/her (deprecated) > gdb/tui/tui-disasm.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c > index 5c68312a91b..085a6c2903e 100644 > --- a/gdb/tui/tui-disasm.c > +++ b/gdb/tui/tui-disasm.c > @@ -112,6 +112,15 @@ tui_disassemble (struct gdbarch *gdbarch, > { > tui_asm_line tal; > > + /* Don't disassemble: > + - non-code sections (not appropriate for disassembly window), and > + - section holes (otherwise we can get stuck, unable to scroll back to > + the section before the section hole). */ > + struct obj_section *section = find_pc_section (pc); > + if (section == nullptr > + || (bfd_section_flags (section->the_bfd_section) & SEC_CODE) == 0) > + return pc; > + > /* Save the instruction address. */ > tal.addr = pc; > > > base-commit: 4ed310516eb76cbf650523a53f733060d3ae71b9