From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BBCB83861849; Thu, 28 Sep 2023 18:17:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBCB83861849 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695925055; bh=+gVA43qsPDxdymFV8/PFwpy5lS8iI5KmW9eLT7vnp/U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Mop27g1H9iThNnU8Mc6yz7fnAcUXu2FDNlkY3020nROzRN97rCKXglMqxMNsxO5YG oItHeaYAnA4m8znYr8D1AElknQ4KTylMdYtovzisX4UndviCwvwJsQaMTvM+DfUwP6 PIIFdkBmqks28db3eZXZKJNwrQshwHK3Nd22dtLk= From: "cvs-commit at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug tui/30823] [gdb/tui] segfault in tui_find_disassembly_address Date: Thu, 28 Sep 2023 18:17:33 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: tui X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30823 --- Comment #3 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by Tom de Vries : https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D72535eb14bda= 8ea61d801f007c4d38533c727832 commit 72535eb14bda8ea61d801f007c4d38533c727832 Author: Tom de Vries Date: Thu Sep 28 20:17:33 2023 +0200 [gdb/tui] Fix segfault in tui_find_disassembly_address PR29040 describes a FAIL for test-case gdb.threads/next-fork-other-thread.exp and target board unix/-m32. The FAIL happens due to the test executable running into an assert, whi= ch is caused by a forked child segfaulting, like so: ... Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00000000 in ?? () ... I tried to reproduce the segfault with exec next-fork-other-thread-fork, using TUI layout asm. I set a breakpoint at fork and ran to the breakpoint, and somewhere dur= ing the following session I ran into a gdb segfault here in tui_find_disassembly_address: ... /* Disassemble forward. */ next_addr =3D tui_disassemble (gdbarch, asm_lines, new_low, max_lines); last_addr =3D asm_lines.back ().addr; ... due to asm_lines being empty after the call to tui_disassemble, while asm_lines.back () assumes that it's not empty. I have not been able to reproduce that segfault in that original settin= g, I'm not sure of the exact scenario (though looking back it probably involved "set detach-on-fork off"). What likely happened is that I managed to reproduce PR29040, and TUI (attempted to) display the disassembly for address 0, which led to the gdb segfaul= t. When gdb_print_insn encounters an insn it cannot print because it can't read the memory, it throws a MEMORY_ERROR that is caught by tui_disassemble. The specific bit that causes the gdb segfault is that if gdb_print_insn throws a MEMORY_ERROR for the first insn in tui_disassemble, it returns an emp= ty asm_lines. FWIW, I did manage to reproduce the gdb segfault as follows: ... $ gdb -q \ -iex "set pagination off" \ /usr/bin/rustc \ -ex "set breakpoint pending on" \ -ex "b dl_main" \ -ex run \ -ex "up 4" \ -ex "layout asm" \ -ex "print \$pc" ... ... $1 =3D (void (*)()) 0x1 (gdb) ... Now press , and the segfault triggers. Fix the segfault by handling asm_lines.empty () results of tui_disassem= ble in tui_find_disassembly_address. I've written a unit test that exercises this scenario. Tested on x86_64-linux. Reviewed-by: Kevin Buettner PR tui/30823 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30823 --=20 You are receiving this mail because: You are on the CC list for the bug.=