From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 8D67C385840B for ; Fri, 29 Sep 2023 10:07:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D67C385840B 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 C6DB81F45E for ; Fri, 29 Sep 2023 10:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695982041; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=r05I+4fiRMqh1NlFVzYJFzxsFCz4mj0YtQ5h8BtSsuI=; b=NdXCUL3ChTOed59t49z2arPhjNA9R38FhAbxG2ZhS5xVXjsLAKeFU36vKw8PdafjdcTWtY qWGDHjmSNSXATwPWJjPmQXftdNUhTcBjfz6YiFHtgg1FappxT/PK/mlQqr2Kqp9GRcnGwY YE9oKmlkKV9rhlep8fy6/qHK8nJH0YA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695982041; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=r05I+4fiRMqh1NlFVzYJFzxsFCz4mj0YtQ5h8BtSsuI=; b=CBREr9dj7HpvNYZGI8IQ/dlyG76xwkECAkw/diWPs83cC02sIAf/0ezSwF/1ZLt7ehM0Tt 7h1XsamztfxrBOCg== 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 B2E991390A for ; Fri, 29 Sep 2023 10:07:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ppSjKtmhFmU5HQAAMHmgww (envelope-from ) for ; Fri, 29 Sep 2023 10:07:21 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 1/2] [gdb/tui] Make assert in tui_find_disassembly_address more strict Date: Fri, 29 Sep 2023 12:07:27 +0200 Message-Id: <20230929100728.27029-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 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: In tui_find_disassembly_address we find an assert: ... if (asm_lines.size () < max_lines) { if (!possible_new_low.has_value ()) return new_low; /* Take the best possible match we have. */ new_low = *possible_new_low; next_addr = tui_disassemble (gdbarch, asm_lines, new_low, max_lines); last_addr = asm_lines.back ().addr; gdb_assert (asm_lines.size () >= max_lines); } ... The comment right above: ... /* If we failed to disassemble the required number of lines then the following walk forward is not going to work, it assumes that ASM_LINES contains exactly MAX_LINES entries. Instead we should consider falling back to a previous possible start address in POSSIBLE_NEW_LOW. */ ... claims that the more strict asm_lines.size () == max_line is required. Update the assert to reflect this, and move it to after the if because it's supposed to hold in general, not just when entering the if. Tested on x86_64-linux. --- gdb/tui/tui-disasm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index 03c78aa1291..e6d4ee6a7ef 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -268,11 +268,8 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from) || (last_addr == pc && asm_lines.size () < max_lines)) && new_low != prev_low); - /* If we failed to disassemble the required number of lines then the - following walk forward is not going to work, it assumes that - ASM_LINES contains exactly MAX_LINES entries. Instead we should - consider falling back to a previous possible start address in - POSSIBLE_NEW_LOW. */ + /* If we failed to disassemble the required number of lines, try to fall + back to a previous possible start address in POSSIBLE_NEW_LOW. */ if (asm_lines.size () < max_lines) { if (!possible_new_low.has_value ()) @@ -282,9 +279,12 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from) new_low = *possible_new_low; next_addr = tui_disassemble (gdbarch, asm_lines, new_low, max_lines); last_addr = asm_lines.back ().addr; - gdb_assert (asm_lines.size () >= max_lines); } + /* The following walk forward assumes that ASM_LINES contains exactly + MAX_LINES entries. */ + gdb_assert (asm_lines.size () == max_lines); + /* Scan forward disassembling one instruction at a time until the last visible instruction of the window matches the pc. We keep the disassembled instructions in the 'lines' window base-commit: 17827f6183550bdaaa8c0a1f82482b7bc88bab41 -- 2.35.3