From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by sourceware.org (Postfix) with ESMTPS id 044B03858426 for ; Mon, 7 Mar 2022 16:03:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 044B03858426 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f52.google.com with SMTP id q7-20020a7bce87000000b00382255f4ca9so11122740wmj.2 for ; Mon, 07 Mar 2022 08:03:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=CF9e4RElVkVobgTQ+LLKIpTGEKFfDcN09EL5amNigM8=; b=Kkf8ohwB9Dlj5L+60yU3q9Z57D/8vX1ii1HOZHL6UDiRegEW6dzhmcDb31FMdgMNLj B6VgEyTZ3CPF31KvtuHfUl30DUDai1VEw/mpjbLitGXpNJLLoB7l/OxnByKV2969Tzg1 An050tkKsr6M6S55+0Rj86f7W7GUNCGVwwm+NlAcN/0G1zqcLLePDHWj1Bqay4pscLkS E245FwmwKPdHXYh3akVunkrH2UetOlDFqywbruM0e0HnnTx1vw4VFWEuUfZ/GmIRgHHN 20FEX5i+Sq9CtRTIwB1MhhuBOBYzrA3O7X6IvnisNoXvZKtajtAoULn3b7dXtJuXGAXQ cnYw== X-Gm-Message-State: AOAM5316ifh1wG1PggNZtZlvG7RjuPfLzmNIW67v+0gA+8sckTgxQ/Vt cO18lHbcDCg5F/g/TG4Ia530WClnQd4= X-Google-Smtp-Source: ABdhPJwoAUJ6g/uuur++m63WoUU+LLcY2iv4KAFEza5Z4TqkNT2uLUQo+wjhq3Kf30diDeT1+jBx9g== X-Received: by 2002:a1c:7708:0:b0:381:f18b:29ca with SMTP id t8-20020a1c7708000000b00381f18b29camr9663838wmi.140.1646669023849; Mon, 07 Mar 2022 08:03:43 -0800 (PST) Received: from ?IPV6:2001:8a0:f924:2600:209d:85e2:409e:8726? ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id p2-20020a1c7402000000b0038159076d30sm20178553wmc.22.2022.03.07.08.03.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Mar 2022 08:03:42 -0800 (PST) Message-ID: Date: Mon, 7 Mar 2022 16:03:41 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH] gdb/remote: use current_inferior in read_ptid if multi-process not supported Content-Language: en-US To: Tankut Baris Aktemur , gdb-patches@sourceware.org References: <20220209075824.3070-1-tankut.baris.aktemur@intel.com> From: Pedro Alves In-Reply-To: <20220209075824.3070-1-tankut.baris.aktemur@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Mar 2022 16:03:46 -0000 On 2022-02-09 07:58, Tankut Baris Aktemur via Gdb-patches wrote: > --- a/gdb/remote.c > +++ b/gdb/remote.c > @@ -3145,14 +3145,15 @@ read_ptid (const char *buf, const char **obuf) > return null_ptid; > } > > - /* Since the stub is not sending a process id, then default to > - what's in inferior_ptid, unless it's null at this point. If so, > + /* Since the stub is not sending a process id, default to > + what's current_inferior, unless it's null at this point. If so, > then since there's no way to know the pid of the reported > threads, use the magic number. */ > - if (inferior_ptid == null_ptid) > + inferior *inf = current_inferior (); > + if (inf == nullptr || inf->pid == 0) How can current_inferior() ever by nullptr here? That should not be possible, unless you're in some very early _initialize_foo routine, before the initial inferior was created. There's is always an inferior selected, there's no way to select "no inferior". > pid = magic_null_ptid.pid (); > else > - pid = inferior_ptid.pid (); > + pid = inf->pid; > > if (obuf) > *obuf = pp; > diff --git a/gdb/testsuite/gdb.multi/attach-no-multi-process.c b/gdb/testsuite/gdb.multi/attach-no-multi-process.c > new file mode 100644 > index 00000000000..df09dd69ccc > --- /dev/null > +++ b/gdb/testsuite/gdb.multi/attach-no-multi-process.c > @@ -0,0 +1,34 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2020-2022 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 . */ > + > +/* This program is intended to be started outside of gdb, and then > + attached to by GDB. */ gdb vs GDB. Use uppercase in both cases. > + > +#include > + > +int > +main () > +{ > + /* Don't run forever in case GDB crashes and DejaGNU fails to kill > + this program. */ > + alarm (10); > + > + while (1) > + ; Please add some "usleep (1);" or some such in the loop to avoid hogging the CPU. > + > +# The plain remote target can't do multiple inferiors. Extended-remote can. And, you start a separate gdbserver anyhow. What happens if you remove this check? You'd need to pass "set remote multiprocess-feature-packet off" and "maint set target-non-stop" via GDBFLAGS instead of as separate commands after starting gdb, but is there anything else?