From patchwork Wed Oct 16 19:13:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 35058 Received: (qmail 6612 invoked by alias); 16 Oct 2019 19:14:06 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 6602 invoked by uid 89); 16 Oct 2019 19:14:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy=connecting X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Oct 2019 19:13:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571253238; 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=BqmXZOoTERmBpiOfTl+XdmNPamlNLZH5rctGyTNBLCo=; b=a2Bgzb+oft1OrXtEEqWqDjuwEMsAVTyPw8bR/uS4yHnGXa8fLYQIiWDMPoOqM8wj7gNsmW gGsuZPsPFY6sdqqrGmHxdlgoFWuw27aPe88FAl8uDd6DF3ZPiS1JXIi3PqnmYtYusr/FJb SoKKVAzFdtEwxKTkT1EIfGx19JLhrVg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-324-ZFQ1IrbIN6SaXUqINt1jGQ-1; Wed, 16 Oct 2019 15:13:56 -0400 Received: by mail-wm1-f70.google.com with SMTP id c188so1348268wmd.9 for ; Wed, 16 Oct 2019 12:13:55 -0700 (PDT) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id f9sm28778650wre.74.2019.10.16.12.13.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Oct 2019 12:13:53 -0700 (PDT) Subject: [PATCH] Avoid inferior_ptid reference in gdb/remote.c (Re: [PATCH 00/23] Multi-target support) To: Philippe Waroquiers , gdb-patches@sourceware.org References: <20190906232807.6191-1-palves@redhat.com> <2802fb1954a3756ec7e507141652b8d92127424a.camel@skynet.be> <6bed10d6-482f-917d-54f5-34c079ee9547@redhat.com> <6c1828abbbfda76da123926fda8b37816132075a.camel@skynet.be> From: Pedro Alves Message-ID: <9f323dab-8f2a-50e3-1de6-647910b31a78@redhat.com> Date: Wed, 16 Oct 2019 20:13:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <6c1828abbbfda76da123926fda8b37816132075a.camel@skynet.be> X-Mimecast-Spam-Score: 0 Pedro Alves wrote: On 9/8/19 9:50 PM, Philippe Waroquiers wrote: >> Then when stopping this gdb (which automatically continues the valgrind executables >> till valgrind reports the next error), launching a new gdb, and only connecting to the 32 >> bits valgrind gdbserver, here is what I see. >> >> (gdb) tar rem|lvgdb --pid=16727 >> Remote debugging using |lvgdb >> ... >> 0x04001092 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2 >> (gdb) bt >> #0 0x04001092 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2 >> #1 0x0495fd27 in syscall () at ../sysdeps/unix/sysv/linux/i386/syscall.S:29 >> #2 0x0010922c in main () at scalar_exit_group.c:14 >> (gdb) c >> Continuing. >> ../../multi-target-v1/gdb/inferior.c:285: internal-error: inferior* >> find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed. >> A problem internal to GDB has been detected, >> further debugging may prove unreliable. >> Quit this debugging session? (y or n) >> >> So, that looks to be a regression with the valgrind gdbserver. > Thanks. I'll have to try reproducing this. Thanks for spotting this. It was a regression against any remote target that does not support the remote protocol multi-process extensions. This patch fixes it. From cd7e386563fcdb43d647ce499c5e05b85d44ba68 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 15 Oct 2019 20:01:55 +0100 Subject: [PATCH] Avoid inferior_ptid reference in gdb/remote.c 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 Pedro Alves * remote.c (remote_target::remote_parse_stop_reply) : If no process is specified, assume remote's current process instead of inferior_ptid. gdb/testsuite/ChangeLog: yyyy-mm-dd Pedro Alves * gdb.server/no-multi-process.exp: New file. --- gdb/remote.c | 6 ++-- gdb/testsuite/gdb.server/no-multi-process.exp | 40 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.server/no-multi-process.exp diff --git a/gdb/remote.c b/gdb/remote.c index b6d7bb0a6d..05c8b336f2 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -7511,7 +7511,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 @@ -7535,8 +7534,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, assume the remote's current + process. */ + int pid = get_remote_state ()->general_thread.pid (); if (*p == '\0') ; else if (*p == ';') diff --git a/gdb/testsuite/gdb.server/no-multi-process.exp b/gdb/testsuite/gdb.server/no-multi-process.exp new file mode 100644 index 0000000000..0e946dba6f --- /dev/null +++ b/gdb/testsuite/gdb.server/no-multi-process.exp @@ -0,0 +1,40 @@ +# Copyright (C) 2019 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Smoke tests for debugging against a remote target with no +# multi-process extensions support. + +load_lib gdbserver-support.exp + +if {[skip_gdbserver_tests]} { + return +} + +standard_testfile server.c +if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] { + return -1 +} + +# Make sure we're disconnected, in case we're testing with an +# extended-remote board, therefore already connected. +gdb_test "disconnect" ".*" + +gdb_test_no_output "set remote multiprocess-feature-packet off" +gdbserver_run "" + +# 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 "" continue 1