From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id P4V6NrkroWrcWzkAWB0awg (envelope-from ) for ; Wed, 09 Sep 2026 05:49:45 -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=tUf3d0ek; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=wjL2GBOt; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=j7VoNTbp; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=HlqNyKAG; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C3D151E091; Wed, 09 Sep 2026 05:49:45 -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 5CB661E091 for ; Wed, 09 Sep 2026 05:49:44 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C1214BB58AF for ; Wed, 9 Sep 2026 09:49:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C1214BB58AF 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=tUf3d0ek; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=wjL2GBOt; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=j7VoNTbp; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=HlqNyKAG Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 3F6044BB58E4 for ; Wed, 9 Sep 2026 09:49:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F6044BB58E4 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 3F6044BB58E4 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=1788947348; cv=none; b=R3Jrl2hK5PZktbb2yVY+bFy8poBvGSD0U/CB3HvGaXAcUgdFPZXQBI2UAdmqXpetWSYdWs4Mm83siIY2rmLrme12SMLBlTU8I/WzEtjyydUXv+p5AWXZ/FdTuE0hFMSbZoP9am5yBAZfYxVs8pSxygdAVU/EEUruR3jpqFqR8cU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788947348; c=relaxed/simple; bh=DwpDTLJBxVKxxtwe2NWvHEV2SWLfwDceVypdyt0ORQo=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=XFMYi61ijz/750uuv4IKmL6llHU9x9w0/EhHFenLm0lYQRIRUDQDKeYQ3sVrX9erXOdFsezq0ALES8KQLKE2ePO8+LhM9dccmn4/CzzS3lA4Kygjth47rr/pWYn+MUq7AeZRheyi3CmOBD9i5MnZkhYW9Ui7q8w471tavFxPILw= 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=tUf3d0ek; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=wjL2GBOt; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=j7VoNTbp; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=HlqNyKAG DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F6044BB58E4 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 1A2EE21B20 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=s1n/DBayEi8pyeeaCvF6sJe1ZgYZQQ3ZKW2z3ylNNFQ=; b=tUf3d0ekXwHAEQdP9g+DECszhafQwNDwTC3evYgT5vz4Kzd4oIjDMgp2cBcePJPOW+zf6H bLcIVhumwGPDC1jtAPE99BLXbosXJnxYOGFDPk4c+cNf01N1vwzKSBMWe8vpWHB1nNOX1M gVbC+x9lmi29qGitGCczBsTOk6Rx44U= 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=s1n/DBayEi8pyeeaCvF6sJe1ZgYZQQ3ZKW2z3ylNNFQ=; b=wjL2GBOtbNo3bopuShDRmHYR+hmORmlenl24CZuGfYs0wACGDR1GaTbuE3imlQ6f1m352+ zSUn9KWbQRhNXODA== Authentication-Results: smtp-out1.suse.de; none 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=s1n/DBayEi8pyeeaCvF6sJe1ZgYZQQ3ZKW2z3ylNNFQ=; b=j7VoNTbpuQ9eYrN3C0F/Agd/RpYLJN2adQtzk3E8Vqwku4y03KgsNzoa9HWOI3BRuWCU8r BL7IZhmKugCSIwT4tLwL7ftlVSwHKroKjkk70ErJxIWdry2zLOlxuXTYRAHVPtS17wjEz7 GaT/FdHBJ8ZWjAfpTuGhFB/J/zc02Mo= 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=s1n/DBayEi8pyeeaCvF6sJe1ZgYZQQ3ZKW2z3ylNNFQ=; b=HlqNyKAGo6UqucuqQGqgcGReNfXBDjVXGNCx9/vQD4CWkbgWzCpOuoVP12O2STEfw2B2es drUWPQ3Z1G7ZfmBw== 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 1DB121388B 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 8G7DBYMroWpJBAAAD6G6ig (envelope-from ) for ; Wed, 09 Sep 2026 09:48:51 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 6/7] [gdb/tui] Handle section holes when forward disassembling Date: Wed, 9 Sep 2026 11:48:48 +0200 Message-ID: <20260909094849.2745086-7-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.995]; 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)[plt-0x10:email, imap1.dmz-prg2.suse.org:helo, suse.de:mid] 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 _init" ... which gives us the following asm window: ... ┌─────────────────────────────────────────────────────────────────────┐ │ 0x401000 <_init> endbr64 │ │ 0x401004 <_init+4> sub $0x8,%rsp │ │ 0x401008 <_init+8> mov 0x2fd1(%rip),%rax # 0x403fe0│ │ 0x40100f <_init+15> test %rax,%rax │ │ 0x401012 <_init+18> je 0x401016 <_init+22> │ │ 0x401014 <_init+20> call *%rax │ │ 0x401016 <_init+22> add $0x8,%rsp │ │ 0x40101a <_init+26> ret │ │ │ │ │ └─────────────────────────────────────────────────────────────────────┘ ... We cannot scroll from the init section to the plt section, because there's a section hole in between: ... Disassembly of section .init: 0000000000401000 <_init>: ... 40101a: c3 ret Disassembly of section .plt: 0000000000401020 : 401020: ff 35 ca 2f 00 00 push 0x2fca(%rip) ... and the section hole is causing MEMORY_ERRORs in tui_disassemble. However, that all changes if instead we do: ... $ gdb -q a.out -ex start -ex "layout asm" -ex "disassemble _init" ... and get: ... ┌─────────────────────────────────────────────────────────────────────┐ │ 0x401000 <_init> endbr64 │ │ 0x401004 <_init+4> sub $0x8,%rsp │ │ 0x401008 <_init+8> mov 0x2fd1(%rip),%rax # 0x403fe0│ │ 0x40100f <_init+15> test %rax,%rax │ │ 0x401012 <_init+18> je 0x401016 <_init+22> │ │ 0x401014 <_init+20> call *%rax │ │ 0x401016 <_init+22> add $0x8,%rsp │ │ 0x40101a <_init+26> ret │ │ 0x40101b add %al,(%rax) │ │ 0x40101d add %al,(%rax) │ └─────────────────────────────────────────────────────────────────────┘ ... The section hole is no longer causing MEMORY_ERRORs, and we can scroll past it into the plt section. Achieve something similar in the initial setup (without start) by skipping over the section hole, getting us: ... ┌─────────────────────────────────────────────────────────────────────┐ │ 0x401000 <_init> endbr64 │ │ 0x401004 <_init+4> sub $0x8,%rsp │ │ 0x401008 <_init+8> mov 0x2fd1(%rip),%rax # 0x403fe0│ │ 0x40100f <_init+15> test %rax,%rax │ │ 0x401012 <_init+18> je 0x401016 <_init+22> │ │ 0x401014 <_init+20> call *%rax │ │ 0x401016 <_init+22> add $0x8,%rsp │ │ 0x40101a <_init+26> ret │ │ 0x401020 push 0x2fca(%rip) # 0x403ff0 │ │ 0x401026 jmp *0x2fcc(%rip) # 0x403ff8 │ └─────────────────────────────────────────────────────────────────────┘ ... allowing to scroll (further) into the plt section. --- gdb/tui/tui-disasm.c | 51 +++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index 3e525000efd..d96048dc1de 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -112,22 +112,43 @@ tui_disassemble (struct gdbarch *gdbarch, { tui_asm_line tal; - /* Save the instruction address. */ - tal.addr = pc; - - try - { - pc += gdb_print_insn (gdbarch, pc, stream, NULL); - } - catch (const gdb_exception_error &except) + bool retry; + do { - /* If PC points to an invalid address then we'll catch a - MEMORY_ERROR here, this should stop the disassembly, but - otherwise is fine. */ - if (except.error != MEMORY_ERROR) - throw; - return pc; + retry = false; + + /* Save the instruction address. */ + tal.addr = pc; + + try + { + pc += gdb_print_insn (gdbarch, pc, stream, NULL); + } + catch (const gdb_exception_error &except) + { + /* If PC points to an invalid address then we'll catch a + MEMORY_ERROR here, this should stop the disassembly, but + otherwise is fine. */ + if (except.error != MEMORY_ERROR) + throw; + + struct obj_section *next; + struct obj_section *section + = find_pc_section (pc, nullptr, &next); + if (section == nullptr + && next != nullptr + && ((bfd_section_flags (next->the_bfd_section) & SEC_ALLOC) + != 0)) + { + /* Skip over section hole. */ + pc = next->addr (); + retry = true; + } + else + return pc; + } } + while (retry); /* If that's all we need, continue. */ if (addr_size == nullptr) @@ -563,7 +584,7 @@ run_tests () /* Check that tui_find_disassembly_address robustly handles the case of being passed a PC for which gdb_print_insn throws a MEMORY_ERROR. */ - SELF_CHECK (tui_find_disassembly_address (gdbarch, 0, 1) == 0); + tui_find_disassembly_address (gdbarch, 0, 1); SELF_CHECK (tui_find_disassembly_address (gdbarch, 0, -1) == 0); } } -- 2.51.0