From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 40629 invoked by alias); 20 Dec 2019 18:50:24 -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 40618 invoked by uid 89); 20 Dec 2019 18:50:24 -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,SPF_PASS autolearn=ham version=3.3.1 spammy=program_space, wow, packet, H*r:sk:mail-ed X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Dec 2019 18:50:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576867820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PVdY2t7CaqzI98+FKH+XtUm2UfrhrdHKZuMJLWndM9I=; b=DhMhATQDrtWVOn9dNxysZKz0tcVk9fhMb8FVcRrGW6il5SBx5TRDLeGxuX35TNUF9wqIX6 uNGBswgdbWVniuUFqaD6GQcj3LoXye8z1LPdYHkOt661nZuQM0x2l1+x8Ej5pCuMA9MESY ag/es7l2oWKX1fpKPzWvKPAqRdDcMXw= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-191--efuP9lXMFSy8riG0_-O4Q-1; Fri, 20 Dec 2019 13:50:18 -0500 Received: by mail-ed1-f70.google.com with SMTP id n63so6360539edc.20 for ; Fri, 20 Dec 2019 10:50:17 -0800 (PST) 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 f18sm1040451edy.91.2019.12.20.10.50.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Dec 2019 10:50:15 -0800 (PST) Subject: Re: [PATCH v2 08/24] Introduce switch_to_inferior_no_thread To: "Paunovic, Aleksandar" References: <20191017225026.30496-1-palves@redhat.com> <20191017225026.30496-9-palves@redhat.com> Cc: "gdb-patches@sourceware.org" From: Pedro Alves Message-ID: Date: Fri, 20 Dec 2019 18:50:00 -0000 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: X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-12/txt/msg00920.txt.bz2 On 11/7/19 9:14 AM, Paunovic, Aleksandar wrote: > Shouldn't there be this change as well: > > diff --git a/gdb/progspace-and-thread.c b/gdb/progspace-and-thread.c > index 3c92b5c8e0..f66aabea40 100644 > --- a/gdb/progspace-and-thread.c > +++ b/gdb/progspace-and-thread.c > @@ -39,6 +39,5 @@ switch_to_program_space_and_thread (program_space *pspace) > } > } > > - switch_to_no_thread (); > - set_current_program_space (pspace); > + switch_to_inferior_no_thread (inf); > } > > This fixes the case when an inferior has PID = 0. > The problem is that in the current state GDB would switch to no_thread and also set the program space > but because the inferior is not switched, potentially an incorrect target would remain. > > Here is a sample scenario that exploits this flow: > > # On terminal 1, start a gdbserver on a program named foo: > $ gdbserver :1234 ./foo > > # On terminal 2, start gdb on a program named bar. Suppose foo and bar are compiled from foo.c and bar.c. > They are completely separate. So, bar.c:2 has no meaning for foo. > > $ gdb -q ./bar > Reading symbols from ./bar... > (gdb) add-inferior > [New inferior 2] > Added inferior 2 > (gdb) inferior 2 > [Switching to inferior 2 [] ()] > (gdb) target remote :1234 > ... > (gdb) set debug remote 2 > (gdb) break bar.c:2 > Sending packet: $Hgp0.0#ad...Packet received: OK > Sending packet: $m5fa,12#f8...Packet received: E01 > Sending packet: $m5fa,1#c6...Packet received: E01 > Sending packet: $m5fb,3#c9...Packet received: E01 > Sending packet: $m5fe,1#ca...Packet received: E01 > Breakpoint 1 at 0x5fe: file bar.c, line 2. > (gdb) > > Here we have an unnecessary sending of the packets to the gdbserver. > But with the proposed change in progspace-and-thread.c there is this > > (gdb) break bar.c:2 > Breakpoint 1 at 0x5fe: file bar.c, line 2. > (gdb) > > Now there is no sending of the packets to the gdbserver. Oh wow, thanks much for this. You're right. I'm working on converting your example above to a testsuite testcase. Thanks, Pedro Alves