From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) by sourceware.org (Postfix) with ESMTPS id 088303858CD1 for ; Wed, 20 Dec 2023 22:00:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 088303858CD1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 088303858CD1 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=96.47.72.81 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1703109624; cv=pass; b=qU8ahAV+0/5qn8cq7T/KM7jDk1EAwqWRCEYYMes5udvSUN0eTxKfK5d3xAhzCvL574LIJPSJIwICiPpa4RMnf/3/tU25sMSUa0fx9Bi4kD1oDCXzZTn07oJSMAr7zWBizTWtJbVHwNEfVMo+2sKL4ncWpijUAaF3zlE+WEoXHIQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1703109624; c=relaxed/simple; bh=hI0Uov4QnGTWXWz7W79UbMQo8OlgopdhgugMifsUvBE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=ugAcEcGLtJFzlmI6I3HCEWmK55ff8giD7Yetwqa5PQxyDUtrCSc7R33rhQYYp0YX2JuawJrnJv+3sAp06quzOceXtbb9uIl83r/jhz6Q6ci8gFtBDBpAn/vVQENlUUraTzMLRRla2SgzF7Gw+Jago1OkcyDejCSrbWoF6Kh3d2Y= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 4SwSCp2JgGz4hmb; Wed, 20 Dec 2023 22:00:06 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SwSCp1VThz3WrF; Wed, 20 Dec 2023 22:00:06 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703109606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WwK+YsBjDHdwTEqzIRzAm5nsRNe5sTbn+lxRO/HaT3M=; b=SsHojBSt1JZkgS+P/X87olD3st70afCWWFcdrLx6tZctCHQd/QUhEx1yNv7shX6vn74Xz5 PnujOMclSlAEywwkoxeRu41y6OlFGnz4pJj8yAitzUz1VSq6aqvDWZSOGE2sqKeZPFKMcG hbyt9HzXUsJ8g3GLQ10FgbAaNEQcigLn0cefpVJY6vgJnAcDhuHMpRLqZiH5zYgRkA/38q dviWzPP4ZXtkAObsI5Y8sxFv6UAc5e4kJyD3SCSlcJMSQNmk/TcYOam9GUUwQb53GZnPcn MGzI4tFlFQs/lcYceM+h4YKm8eM6/mk699n9Etfx4ZhjvWGlIhJdu35mjqusSw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703109606; a=rsa-sha256; cv=none; b=J2gieST5jbZb+yGsfS4rRJTrorC/x28TMCQShrHaSspldI2gLRdfqql20bCc6dWkcEUv4Q Xjj2F8fhM7J/BY8tBWec2PhrF1ZNlsuTrM2SE0Rqz1o29j5ZOoka1eT/4i8bmUbSXU0WhJ hwQUYgV3EoyfoIXHuXGRlt+hA6TQDadrYZW1YGjkhwL8+KX3PV20wHx0PGqPcx1pxnnk6g HfglIKak1pj43PSyTntWhrEaUIbS/C6RXtJRptinTGEFpoVIjqUM+Kl++AfGFfivT+N3+I w4F5mWxkCvGCslJa43+GNljdq0cGd/dba9jmsHFDf2jERA3Vudt+E0yvBK1ZJg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703109606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WwK+YsBjDHdwTEqzIRzAm5nsRNe5sTbn+lxRO/HaT3M=; b=t6TC5c/KHD67LtWaDP4AAtU2YoCSRa7YAxzgr1pXuIFmP1D/67ygIzzkxSWGWt9OqVS56I 90qGDCOLkL8MS8SP6CqcF0Nv6l7Cz9JhZX9FXE/4kSCdX64yzOkSPUOcy0k5t9Z2YtcHMw pYgbHMo22ICMCQ7QWsZqJojAqwFEqseTQKRTLEAqyJYm0PNy9B6Zj1FLJx2PoMyNRt3SbZ ZAV1kUqn0uttB+/C0LrzfD8BZGy/37i5A50mF58brwtk/o9Wyf12pvsbv9qeAMIDIwCfyX 0cyK55j1uSBVRs9eVLhURoOui8JAXkFUWFKKw2wHG7qc+VX26Nz8GIKZ1uwBog== Received: from [IPV6:2601:644:9381:f410:78bc:f512:b288:d2ba] (unknown [IPv6:2601:644:9381:f410:78bc:f512:b288:d2ba]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4SwSCn53jxzpnR; Wed, 20 Dec 2023 22:00:05 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: <1aa5010d-e17c-484b-b0cb-c1bf67b2f71d@FreeBSD.org> Date: Wed, 20 Dec 2023 14:00:03 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 2/2] gdb: raise and handle NOT_AVAILABLE_ERROR when accessing frame PC Content-Language: en-US To: Tankut Baris Aktemur , gdb-patches@sourceware.org References: <6fb2a95f5999118e30ac972503be4bec35b092ac.1702909611.git.tankut.baris.aktemur@intel.com> From: John Baldwin In-Reply-To: <6fb2a95f5999118e30ac972503be4bec35b092ac.1702909611.git.tankut.baris.aktemur@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: On 12/18/23 6:40 AM, Tankut Baris Aktemur wrote: > This patch can be considered a continuation of > > commit 4778a5f87d253399083565b4919816f541ebe414 > Author: Tom de Vries > Date: Tue Apr 21 15:45:57 2020 +0200 > > [gdb] Fix hang after ext sigkill > > and > > commit 47f1aceffa02be4726b854082d7587eb259136e0 > Author: Tankut Baris Aktemur > Date: Thu May 14 13:59:54 2020 +0200 > > gdb/infrun: handle already-exited threads when attempting to stop > > If a process dies before GDB reports the exit error to the user, we > may see the "Couldn't get registers: No such process." error message > in various places. For instance: > > (gdb) start > ... > (gdb) info inferior > Num Description Connection Executable > * 1 process 31943 1 (native) /tmp/a.out > (gdb) shell kill -9 31943 > (gdb) maintenance flush register-cache > Register cache flushed. > Couldn't get registers: No such process. > (gdb) info threads > Id Target Id Frame > * 1 process 31943 "a.out" Couldn't get registers: No such process. > (gdb) backtrace > Python Exception : Couldn't get registers: No such process. > Couldn't get registers: No such process. > (gdb) inferior 1 > Couldn't get registers: No such process. > (gdb) thread > [Current thread is 1 (process 31943)] > Couldn't get registers: No such process. > (gdb) > > The gdb.threads/killed-outside.exp, gdb.multi/multi-kill.exp, and > gdb.multi/multi-exit.exp tests also check related scenarios. > > To improve the situation, > > 1. when printing the frame info, catch and process a NOT_AVAILABLE_ERROR. > > 2. when accessing the target to fetch registers, if the operation > fails, raise a NOT_AVAILABLE_ERROR instead of a generic error, so > that clients can attempt to recover accordingly. This patch updates > the amd64_linux_nat_target and remote_target in this direction. > > With this patch, we obtain the following behavior: > > (gdb) start > ... > (gdb) info inferior > Num Description Connection Executable > * 1 process 748 1 (native) /tmp/a.out > (gdb) shell kill -9 748 > (gdb) maintenance flush register-cache > Register cache flushed. > (gdb) info threads > Id Target Id Frame > * 1 process 748 "a.out" > (gdb) backtrace > #0 > Backtrace stopped: not enough registers or memory available to unwind further > (gdb) inferior 1 > [Switching to inferior 1 [process 748] (/tmp/a.out)] > [Switching to thread 1 (process 748)] > #0 > (gdb) thread > [Current thread is 1 (process 748)] > (gdb) > > Here is another "before/after" case. Suppose we have two inferiors, > each having its own remote target underneath. Before this patch, we > get the following output: > > # Create two inferiors on two remote targets, resume both until > # termination. Exit event from one of them is shown first, but the > # other also exited -- just not yet shown. > (gdb) maint set target-non-stop on > (gdb) target remote | gdbserver - ./a.out > (gdb) add-inferior -no-connection > (gdb) inferior 2 > (gdb) target remote | gdbserver - ./a.out > (gdb) set schedule-multiple on > (gdb) continue > ... > [Inferior 2 (process 22127) exited normally] > (gdb) inferior 1 > [Switching to inferior 1 [process 22111] (target:/tmp/a.out)] > [Switching to thread 1.1 (Thread 22111.22111)] > Could not read registers; remote failure reply 'E01' > (gdb) info threads > Id Target Id Frame > * 1.1 Thread 22111.22111 "a.out" Could not read registers; remote failure reply 'E01' > (gdb) backtrace > Python Exception : Could not read registers; remote failure reply 'E01' > Could not read registers; remote failure reply 'E01' > (gdb) thread > [Current thread is 1.1 (Thread 22111.22111)] > Could not read registers; remote failure reply 'E01' > (gdb) > > With this patch, it becomes: > > ... > [Inferior 1 (process 11759) exited normally] > (gdb) inferior 2 > [Switching to inferior 2 [process 13440] (target:/path/to/a.out)] > [Switching to thread 2.1 (Thread 13440.13440)] > #0 in ?? () > (gdb) info threads > Id Target Id Frame > * 2.1 Thread 13440.13440 "a.out" in ?? () > (gdb) backtrace > #0 in ?? () > Backtrace stopped: not enough registers or memory available to unwind further > (gdb) thread > [Current thread is 2.1 (Thread 13440.13440)] > (gdb) > > Finally, together with its predecessor, this patch also fixes PR gdb/26877. > > Regression-tested on X86_64-Linux. > --- > gdb/amd64-linux-nat.c | 5 +- > gdb/remote.c | 15 ++-- > gdb/stack.c | 33 ++++++- > gdb/testsuite/gdb.threads/killed-outside.exp | 8 +- > .../gdb.tui/multi-exit-remove-inferior.c | 21 +++++ > .../gdb.tui/multi-exit-remove-inferior.exp | 86 +++++++++++++++++++ > 6 files changed, 156 insertions(+), 12 deletions(-) > create mode 100644 gdb/testsuite/gdb.tui/multi-exit-remove-inferior.c > create mode 100644 gdb/testsuite/gdb.tui/multi-exit-remove-inferior.exp > > diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c > index f7f9a483def..aa9b10c52d1 100644 > --- a/gdb/amd64-linux-nat.c > +++ b/gdb/amd64-linux-nat.c > @@ -223,7 +223,10 @@ amd64_linux_nat_target::fetch_registers (struct regcache *regcache, int regnum) > elf_gregset_t regs; > > if (ptrace (PTRACE_GETREGS, tid, 0, (long) ®s) < 0) > - perror_with_name (_("Couldn't get registers")); > + { > + std::string msg = perror_string (_("Couldn't get registers")); > + throw_error (NOT_AVAILABLE_ERROR, "%s", msg.c_str ()); > + } Should other nat backends for other OS's (and other arches) also make this change when failing to fetch registers? -- John Baldwin