From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SQIIIScsoWp9XDkAWB0awg (envelope-from ) for ; Wed, 09 Sep 2026 05:51:35 -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=NQGB8XOR; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=xc75MEWd; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ruKaMPlf; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=VSMurERJ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 821091E09E; Wed, 09 Sep 2026 05:51:35 -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 E4EF91E091 for ; Wed, 09 Sep 2026 05:51:34 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 189174BA79BB for ; Wed, 9 Sep 2026 09:51:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 189174BA79BB 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=NQGB8XOR; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=xc75MEWd; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ruKaMPlf; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=VSMurERJ Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 25CB04BA23E6 for ; Wed, 9 Sep 2026 09:49:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25CB04BA23E6 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 25CB04BA23E6 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788947340; cv=none; b=pNLJu6FbOu9japXLrY6X34moaXdljumuYDGbR6vHRO0FOttt+y5XDGKNOL10kDIQB+6E0zlrtyx8D/x1ikBWT7JUxuNQeJuBZVRgkm9eUue2nNZEirK0WPiLGpc954/5LPEA5Lw9e+Q7YoYe/i5GjtXAiBqwllkmzSY294uRJqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788947340; c=relaxed/simple; bh=sMYtTcR4V9wTWi/a03D7+yYK6Lqa3DEPXY/3HgbQs4Q=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=H1R3VEG9OUrnawZnZJkD7Tpg7jHn9ozH006Kap4CNSqgskVI7+qZA4hmJmx8E21pUB9em9/jSatcxvpegdQYoBJzRirtj1joZ14T7JCD+R/kg6iS9FuHJyH1bML0WXifXOC53jY7YC6yGHw10AoM5Cz9Gl8U5Qy5GZdKSFEo1w8= 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=NQGB8XOR; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=xc75MEWd; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ruKaMPlf; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=VSMurERJ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25CB04BA23E6 Received: from imap1.dmz-prg2.suse.org (unknown [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 E79B121B25 for ; Wed, 9 Sep 2026 09:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788947335; 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=UWjWR960iTV8R1alUxt6/BoMlmrx2ZCzrXSz3m3UFCM=; b=NQGB8XORR+RdEk/2Vno7WNLIivOTe5XHOpdVrPPNPftM/SynD0Ce4n04EerHVQ5Jm5+Y0T W8btgfmCnIBGrBYCF7/1E+R8a3C3GfpzPzXWtDperp3dMFLbsJUdCJEZ/j1UswkDsVEEDH bdKbpISgG5hlqJmFzwYQNIDe4wKMDCg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788947335; 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=UWjWR960iTV8R1alUxt6/BoMlmrx2ZCzrXSz3m3UFCM=; b=xc75MEWd1NHuM8NnPAIUzgi1fZSAbVr+MIAFTHyalXuIBG58AqZbP06/Na17AXRbzcWqVL p11m7WdKvF+jcVAA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788947330; 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=UWjWR960iTV8R1alUxt6/BoMlmrx2ZCzrXSz3m3UFCM=; b=ruKaMPlfLs6Mhwx/DxC/oVJUyUU1PO6ALPvVsj7kWVIjXffN2vqQ2Ll5SwK74K8/MXrIZf xnVDeskNdOLvXy7K1JJOTiNxvh/PBXXoU4RBvlvvPn3uoSZs5MODHJHhnbjuNCgMUpVyAO nL4fvp0DR3OBOdw+MEgBpKXI1fjrcas= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788947330; 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=UWjWR960iTV8R1alUxt6/BoMlmrx2ZCzrXSz3m3UFCM=; b=VSMurERJg5EuZeJaY0POIVjfRRJaXT0s/5uoL2HjIsdwN9bAqE+/GRWfam1NxSo2j8ZjAr 664doygJAnsbkfAw== 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 B9BD11365E for ; Wed, 9 Sep 2026 09:48:50 +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 MIPGK4IroWpJBAAAD6G6ig (envelope-from ) for ; Wed, 09 Sep 2026 09:48:50 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 3/7] [gdb/tui] Improve section handling in tui_find_backward_disassembly_start_address Date: Wed, 9 Sep 2026 11:48:45 +0200 Message-ID: <20260909094849.2745086-4-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-Spamd-Result: default: False [-3.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.996]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,imap1.dmz-prg2.suse.org:helo] 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 has two types of information it uses: 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 detecting this case and using the previous section instead: ... if (section != nullptr && section->addr () == addr) section = find_pc_section (addr - 1); ... This happens to work because there's no section hole between sections plt and text. --- gdb/tui/tui-disasm.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index 7dcb59e6264..3e525000efd 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -177,9 +177,22 @@ 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. The found section may be the one containing ADDR, or the one + before it. */ + struct obj_section *section; + for (int offset = 0; offset <= 1; ++offset) + { + section = find_pc_section (addr - offset); + if (offset == 0 && section != nullptr && section->addr () == addr) + { + /* If ADDR is the start of its section, use ADDR - 1. */ + continue; + } + + break; + } + if (section != NULL) return section->addr (); -- 2.51.0