From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 9BA823858C31 for ; Tue, 5 Sep 2023 15:03:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BA823858C31 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D6E6A1FE80 for ; Tue, 5 Sep 2023 15:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1693926227; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gOC11p+31Z34//iRhZm5uggr0kEsoaEJDdfCcFP3+sU=; b=I9AHE7om8Kwb77QWtR+ROQUeb8HM6EDGaOChoOoPYXG4GqqNhV5Or/aVnvhYrHyrILcjWp zr0JqEoR5by0Do/OMbmuKKViY7I1rG7INrLky32SdlxzuhlIv3uwE7iNllYCZ6H7+0GHrH dQaqN/MnNDbI2mqd/qmSIiehdaydPkc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1693926227; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gOC11p+31Z34//iRhZm5uggr0kEsoaEJDdfCcFP3+sU=; b=HNQpbNuGSJNLXMIsYQWRhOrhttCCTjWjNvBzP54ytQ5373J4S5pFCodnrH94SSZLUGCmbM vStSl99b1wiPbeAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C404113A1B for ; Tue, 5 Sep 2023 15:03:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +Ca3LlND92T2bAAAMHmgww (envelope-from ) for ; Tue, 05 Sep 2023 15:03:47 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 2/2] [gdb/tui] Only handle code sections in tui_find_backward_disassembly_start_address Date: Tue, 5 Sep 2023 17:03:39 +0200 Message-Id: <20230905150339.6452-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230905150339.6452-1-tdevries@suse.de> References: <20230905150339.6452-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: After adding a unit test in gdb/tui/tui-disasm.c excercising tui_find_disassembly_address, I decided to try to extend it using addresses around section borders. The new test was very slow (when using gdb as inferior, as is done in gdb.gdb/unittest.exp), due to disassembling entire non-code sections. Fix this this by limiting tui_find_backward_disassembly_start_address to SEC_CODE sections. FWIW, compared to other self-tests it's still somewhat slow: ... (gdb) maint selftest ... Command execution time: 1.535391 (cpu), 1.571246 (wall) (gdb) maint selftest tui-disasm ... Command execution time: 0.482022 (cpu), 0.482028 (wall) ... This is for calling gdb_print_insn ~550 times. Tested on x86_64-linux. --- gdb/tui/tui-disasm.c | 50 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index 03c78aa1291..c31ab5b0680 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -46,6 +46,8 @@ #include "gdb_curses.h" +#include + struct tui_asm_line { CORE_ADDR addr; @@ -164,6 +166,15 @@ tui_disassemble (struct gdbarch *gdbarch, static CORE_ADDR tui_find_backward_disassembly_start_address (CORE_ADDR addr) { + struct obj_section *section = find_pc_section (addr); + /* Don't handle addresses not in a known section. */ + if (section == nullptr) + return addr; + + /* Only handle sections with only code. */ + if ((section->the_bfd_section->flags & SEC_CODE) == 0) + return addr; + struct bound_minimal_symbol msym, msym_prev; msym = lookup_minimal_symbol_by_pc_section (addr - 1, nullptr, @@ -174,13 +185,8 @@ 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); - if (section != NULL) - return section->addr (); - - return addr; + /* Use the start of the section. */ + return section->addr (); } /* Find the disassembly address that corresponds to FROM lines above @@ -545,6 +551,36 @@ run_tests () being passed a PC for which gdb_print_insn throws a MEMORY_ERROR. */ SELF_CHECK (tui_find_disassembly_address (gdbarch, 0, 1) == 0); SELF_CHECK (tui_find_disassembly_address (gdbarch, 0, -1) == 0); + + /* Poke around the edges of sections. */ + gdbarch_iterate_over_objfiles_in_search_order + (target_gdbarch (), + [gdbarch] (objfile *obj) + { + std::unordered_set visited; + + /* Already done above. */ + visited.insert (0); + + for (obj_section *osect : obj->sections ()) + { + CORE_ADDR first_addr = osect->addr (); + CORE_ADDR last_addr = osect->endaddr () - 1; + + for (auto addr_ : { first_addr, last_addr }) + for (int offset = -1; offset <= 1; ++offset) + { + CORE_ADDR addr = addr_ + offset; + if (visited.find (addr) != visited.end ()) + continue; + + tui_find_disassembly_address (gdbarch, addr, 1); + tui_find_disassembly_address (gdbarch, addr, -1); + visited.insert (addr); + } + } + return false; + }, nullptr); } } -- 2.35.3