From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 45D873858000; Thu, 1 Dec 2022 15:07:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45D873858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669907249; bh=SP9aMyXBE2ZSl4jzS+R5DkYrxp0CuVyu6nTt+4T1ccw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GB2OjPFzSsGLNQWrlNOJHqJuAucPCHNC3ajyNroIRWTE/kZ5nmq/Vm6C90rQsY558 ch2G1Uj/OpXHrtQiw6RQZz/C3RALqZKOtU3Iv2Js03VUaBfwE1oMo16TkUdXVE5fwM /J2VyVhAxofG7houvMRbEhvGzT4jAlpfe/A1e7+4= From: "cvs-commit at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug gdb/28275] commit_resumed_state assertion failure when killing running inferior and running again Date: Thu, 01 Dec 2022 15:07:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: 13.1 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=3D28275 --- Comment #16 from cvs-commit at gcc dot gnu.org --- The gdb-12-branch branch has been updated by Simon Marchi : https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D1aefce82fdf8= 834c7440747b80656e0d030aa2fd commit 1aefce82fdf8834c7440747b80656e0d030aa2fd Author: Simon Marchi Date: Mon Nov 21 12:12:13 2022 -0500 gdb: disable commit resumed in target_kill New in this version: - Better comment in target_kill - Uncomment line in test to avoid hanging when exiting, when testing on native-extended-gdbserver PR 28275 shows that doing a sequence of: - Run inferior in background (run &) - kill that inferior - Run again We get into this assertion: /home/smarchi/src/binutils-gdb/gdb/target.c:2590: internal-error: target_wait: Assertion `!proc_target->commit_resumed_state' failed. #0 internal_error_loc (file=3D0x5606b344e740 "/home/smarchi/src/binutils-gdb/gdb/target.c", line=3D2590, fmt=3D0x5606b34= 4d6a0 "%s: Assertion `%s' failed.") at /home/smarchi/src/binutils-gdb/gdbsupport/errors.cc:54 #1 0x00005606b6296475 in target_wait (ptid=3D..., status=3D0x7fffb= 9390630, options=3D...) at /home/smarchi/src/binutils-gdb/gdb/target.c:2590 #2 0x00005606b5767a98 in startup_inferior (proc_target=3D0x5606bfc= cb2a0 , pid=3D3884857, ntraps=3D1, last_waitstatus=3D= 0x0, last_ptid=3D0x0) at /home/smarchi/src/binutils-gdb/gdb/nat/fork-inferior.c:= 482 #3 0x00005606b4e6c9c5 in gdb_startup_inferior (pid=3D3884857, num_traps=3D1) at /home/smarchi/src/binutils-gdb/gdb/fork-child.c:132 #4 0x00005606b50f14a5 in inf_ptrace_target::create_inferior (this=3D0x5606bfccb2a0 , exec_file=3D0x60400003= 9f50 "/home/smarchi/build/binutils-gdb/gdb/test", allargs=3D"", env=3D0x61500000= a580, from_tty=3D1) at /home/smarchi/src/binutils-gdb/gdb/inf-ptrace.c:105 #5 0x00005606b53b6d23 in linux_nat_target::create_inferior (this=3D0x5606bfccb2a0 , exec_file=3D0x60400003= 9f50 "/home/smarchi/build/binutils-gdb/gdb/test", allargs=3D"", env=3D0x61500000= a580, from_tty=3D1) at /home/smarchi/src/binutils-gdb/gdb/linux-nat.c:978 #6 0x00005606b512b79b in run_command_1 (args=3D0x0, from_tty=3D1, run_how=3DRUN_NORMAL) at /home/smarchi/src/binutils-gdb/gdb/infcmd.c:468 #7 0x00005606b512c236 in run_command (args=3D0x0, from_tty=3D1) at /home/smarchi/src/binutils-gdb/gdb/infcmd.c:526 When running the kill command, commit_resumed_state for the process_stratum_target (linux-nat, here) is true. After the kill, when there are no more threads, commit_resumed_state is still true, as nothing touches this flag during the kill operation. During the subsequent run command, run_command_1 does: scoped_disable_commit_resumed disable_commit_resumed ("running"); We would think that this would clear the commit_resumed_state flag of our native target, but that's not the case, because scoped_disable_commit_resumed iterates on non-exited inferiors in order to find active process targets. And after the kill, the inferior is exited, and the native target was unpushed from it anyway. So scoped_disable_commit_resumed doesn't touch the commit_resumed_state flag of the native target, it stays true. When reaching target_wait, in startup_inferior (to consume the initial expect stop events while the inferior is starting up and working its way through the shell), commit_resumed_state is true, breaking the contract saying that commit_resumed_state is always false when calling the targets' wait method. (note: to be correct, I think that startup_inferior should toggle commit_resumed between the target_wait and target_resume calls, but I'll ignore that for now) I can see multiple ways to fix this. In the end, we need commit_resumed_state to be cleared by the time we get to that target_wait. It could be done at the end of the kill command, or at the beginning of the run command. To keep things in a coherent state, I'd like to make it so that after the kill command, when the target is left with no threads, its commit_resumed_state flag is left to false. This way, we can keep working with the assumption that a target with no threads (and therefore no running threads) has commit_resumed_state =3D=3D false. Do this by adding a scoped_disable_commit_resumed in target_kill. It clears the target's commit_resumed_state on entry, and leaves it false if the target does not have any resumed thread on exit. That means, even if the target has another inferior with stopped threads, commit_resumed_state will be left to false, which makes sense. Add a test that tries to cover various combinations of actions done while an inferior is running (and therefore while commit_resumed_state is true on the process target). Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D28275 Change-Id: I8e6fe6dc1f475055921520e58cab68024039a1e9 Approved-By: Andrew Burgess --=20 You are receiving this mail because: You are on the CC list for the bug.=