From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id p7HEEmtD92QyfBEAWB0awg (envelope-from ) for ; Tue, 05 Sep 2023 11:04:11 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=OrAvXvtc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3B42E1E0C2; Tue, 5 Sep 2023 11:04:11 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 25B211E098 for ; Tue, 5 Sep 2023 11:04:09 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95F4C385770A for ; Tue, 5 Sep 2023 15:04:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95F4C385770A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693926248; bh=gOC11p+31Z34//iRhZm5uggr0kEsoaEJDdfCcFP3+sU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=OrAvXvtccb8ozyn24kjDwmx3E9IcS5/mV2CDlNXOcMvGVEH0Zgo1S9denl1PI15zG QNg9iBYVQKOJ0iMWB13wagoU8Wf3STNEGqWmCI6uDEhkOCHOpk58mN+eaGuKWDJi+V aBej/jIJqfkCeE3qo0IVeB+gXaTOXKZVFw8UKGjk= 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 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) 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 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 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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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