From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 107486 invoked by alias); 17 Oct 2019 22:50:45 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 107304 invoked by uid 89); 17 Oct 2019 22:50:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 Oct 2019 22:50:42 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71DF43091761 for ; Thu, 17 Oct 2019 22:50:41 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00A671001DC0 for ; Thu, 17 Oct 2019 22:50:40 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 15/24] Avoid another inferior_ptid reference in gdb/remote.c Date: Thu, 17 Oct 2019 22:50:00 -0000 Message-Id: <20191017225026.30496-16-palves@redhat.com> In-Reply-To: <20191017225026.30496-1-palves@redhat.com> References: <20191017225026.30496-1-palves@redhat.com> X-SW-Source: 2019-10/txt/msg00599.txt.bz2 From: Tankut Baris Aktemur The multi-target patch makes inferior_ptid point to null_ptid before calling into target_wait, which catches bad uses of inferior_ptid, since the current selected thread in gdb shouldn't have much relation to the thread that reports an event. One such bad use is found in remote_target::remote_parse_stop_reply, where we handle the 'W' or 'X' packets (process exit), and the remote target does not support the multi-process extensions, i.e., it does not report the PID of the process that exited. With the multi-target patch, that would result in a failed assertion, trying to find the inferior for process pid 0. gdb/ChangeLog: yyyy-mm-dd Tankut Baris Aktemur Pedro Alves * remote.c (remote_target::remote_parse_stop_reply) : If no process is specified, return null_ptid instead of inferior_ptid. (remote_target::wait_as): Handle TARGET_WAITKIND_EXITED / TARGET_WAITKIND_SIGNALLED with no pid. gdb/testsuite/ChangeLog: yyyy-mm-dd Tankut Baris Aktemur Pedro Alves * gdb.server/connect-without-multi-process.exp: Also test continuing to end. --- gdb/remote.c | 18 +++++++++++++----- .../gdb.server/connect-without-multi-process.exp | 7 ++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 553f09a6e0..e33dedae26 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -7446,7 +7446,6 @@ Packet: '%s'\n"), case 'W': /* Target exited. */ case 'X': { - int pid; ULONGEST value; /* GDB used to accept only 2 hex chars here. Stubs should @@ -7470,8 +7469,9 @@ Packet: '%s'\n"), event->ws.value.sig = GDB_SIGNAL_UNKNOWN; } - /* If no process is specified, assume inferior_ptid. */ - pid = inferior_ptid.pid (); + /* If no process is specified, return null_ptid, and let the + caller figure out the right process to use. */ + int pid = 0; if (*p == '\0') ; else if (*p == ';') @@ -7847,8 +7847,16 @@ remote_target::wait_as (ptid_t ptid, target_waitstatus *status, int options) event_ptid = first_remote_resumed_thread (); } else - /* A process exit. Invalidate our notion of current thread. */ - record_currthread (rs, minus_one_ptid); + { + /* A process exit. Invalidate our notion of current thread. */ + record_currthread (rs, minus_one_ptid); + /* It's possible that the packet did not include a pid. */ + if (event_ptid == null_ptid) + event_ptid = first_remote_resumed_thread (); + /* EVENT_PTID could still be NULL_PTID. Double-check. */ + if (event_ptid == null_ptid) + event_ptid = magic_null_ptid; + } return event_ptid; } diff --git a/gdb/testsuite/gdb.server/connect-without-multi-process.exp b/gdb/testsuite/gdb.server/connect-without-multi-process.exp index fba20a6a0b..6ba35bf508 100644 --- a/gdb/testsuite/gdb.server/connect-without-multi-process.exp +++ b/gdb/testsuite/gdb.server/connect-without-multi-process.exp @@ -14,7 +14,7 @@ # along with this program. If not, see . */ # Check that we can connect to GDBserver with the multiprocess -# extensions disabled, and run to main. +# extensions disabled, run to main, and finish the process. load_lib gdbserver-support.exp @@ -52,6 +52,11 @@ proc do_test {multiprocess} { "target $gdbserver_protocol" gdb_test "continue" "main .*" "continue to main" + + # The W/X packets do not include the PID of the exiting process + # without the multi-process extensions. Check that we handle + # process exit correctly in that case. + gdb_continue_to_end } foreach multiprocess { "off" "auto" } { -- 2.14.5