From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by sourceware.org (Postfix) with ESMTPS id 6F4B73858002 for ; Mon, 13 Nov 2023 14:11:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F4B73858002 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6F4B73858002 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699884720; cv=none; b=N35Oo2KTAJ1kF75W+DfzrwynibsBIqiS+4k6ONPXmOh15USNRz1IfSfQSyQ3JtFIpSUGWWYS9osgBejR5vZPskdJLRDAaL4L09yEtyvuam10ygs+6V+bwEkbP/TCuKAZS/4t9TQa0/e7+CNIxshlPGl8ysYRMKWVqdBg4pA6zJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699884720; c=relaxed/simple; bh=WtpWTzslxrXAd9xk0epItfMbnBE0PeISFt/AaH1g+fg=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=SjF5sHdwZXLFSjaXcaHcU0FPiU9PHv4STIXzPnyERlPIYqpNi2cZQqlb+/CszFLcu+OBzXEfQy9mSJXfcttaDqrOj97jDJgsc4MGvfZiz2jCPIWZ9kgi1yZajOS3+jQtAveupQUeVCBv8uqle2QQTNzxmdt+NxiyvNfbXzKcaLU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-40806e4106dso25972785e9.1 for ; Mon, 13 Nov 2023 06:11:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699884716; x=1700489516; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ffwps48WbXHeYE0Nr/IwB4GTt1Qu3oa7lW4EXPZ17gQ=; b=KkboIFK29DCjjRZ6OkFeSL4KG5V9IhqibYx5Eskk9HRTLAe35TCLyigD2I2V2Xfrbo K3yRa08RwZc2c/RqBdA/ROvsQT4LHHMOdBzNrJFMXcbmAq9dH2JzyHfstXVOfFgvsj7B 97x1ayZqw2P7t82hsySYWlm1RkQkexm/mP76decmpM8ax966p51iyxSLZS4KWXA2b1bz V9JNFy9l5mW7DRQFmibd7iCXb88vvUN1wN7q+3ItL1B/lXkNIv5R9rGob2zsdehbtzLk UKYoLkfCLbYPJ6x1KZpUOgXJtDcv6Nmjj2usvPFOrcS1MUbKYBt/HW9+Jnml3ygWOYwC t7fw== X-Gm-Message-State: AOJu0Ywx56C2KCPv3Id7FM6G2EFWIFrUQOeAdjvQFXxjTtwBXgCuoRjs G2V4mjTvsP2a63aF0YVhjtZCGFbzNSk= X-Google-Smtp-Source: AGHT+IFPWFqySjspF61s/J4LnKqNV/lZpZt5ixJXBZXkJ3WmVF0Is4Y8++wcEf0IhUfI0OMGP4WLDw== X-Received: by 2002:a05:600c:1c05:b0:402:ebe1:7960 with SMTP id j5-20020a05600c1c0500b00402ebe17960mr5697425wms.2.1699884715133; Mon, 13 Nov 2023 06:11:55 -0800 (PST) Received: from ?IPV6:2001:8a0:f91e:1a00:8060:1e54:fb28:9635? ([2001:8a0:f91e:1a00:8060:1e54:fb28:9635]) by smtp.gmail.com with ESMTPSA id he9-20020a05600c540900b0040a48430837sm9830701wmb.13.2023.11.13.06.11.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Nov 2023 06:11:54 -0800 (PST) Message-ID: <12c28313-3dac-46d5-b536-d71d5c9c7bbc@palves.net> Date: Mon, 13 Nov 2023 14:11:51 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 14/31] all-stop/synchronous RSP support thread-exit events Content-Language: en-US To: Andrew Burgess , gdb-patches@sourceware.org References: <20221212203101.1034916-1-pedro@palves.net> <20221212203101.1034916-15-pedro@palves.net> <87zg5byxal.fsf@redhat.com> From: Pedro Alves In-Reply-To: <87zg5byxal.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-06-07 18:52, Andrew Burgess wrote: > Pedro Alves writes: > >> Currently, GDB does not understand the THREAD_EXITED stop reply in >> remote all-stop mode. There's no good reason for this, it just >> happened that THREAD_EXITED was only ever reported in non-stop mode so >> far. This patch teaches GDB to parse that event in all-stop RSP too. >> There is no need to add a qSupported feature for this, because the >> server won't send a THREAD_EXITED event unless GDB explicitly asks for >> it, with QThreadEvents, or with the GDB_THREAD_OPTION_EXIT >> QThreadOptions option added in the next patch. >> >> Change-Id: Ide5d12391adf432779fe4c79526801c4a5630966 >> --- >> gdb/remote.c | 5 +++-- >> gdbserver/server.cc | 1 + >> 2 files changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/gdb/remote.c b/gdb/remote.c >> index 9de8ed8a068..f7ab8523fd5 100644 >> --- a/gdb/remote.c >> +++ b/gdb/remote.c >> @@ -8172,7 +8172,8 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply, >> && status->kind () != TARGET_WAITKIND_NO_RESUMED) >> { >> /* Expedited registers. */ >> - if (!stop_reply->regcache.empty ()) >> + if (status->kind () != TARGET_WAITKIND_THREAD_EXITED >> + && !stop_reply->regcache.empty ()) > > I haven't investigated if this crops up, but, inside the if block we > call xfree to release some of the regcache data. > > If it was ever the case the status->kind() was THREAD_EXITED, and the > regcache was not empty, would we then leak memory? THREAD_EXITED stop replies can't carry expedited registers, they're not a kind of T stop reply, they're their own stop reply kind. They're just: @anchor{thread exit event} @cindex thread exit event, remote reply @item w @var{AA} ; @var{tid} The thread exited, and @var{AA} is the exit status. This response should not be sent by default; @value{GDBN} requests it with the @ref{QThreadEvents} packet. See also @ref{thread create event} above. @var{AA} is formatted as a big-endian hex string. But even if a remote server included them somehow, we wouldn't parse them: case 'w': /* Thread exited. */ { ULONGEST value; p = unpack_varlen_hex (&buf[1], &value); event->ws.set_thread_exited (value); if (*p != ';') error (_("stop reply packet badly formatted: %s"), buf); event->ptid = read_ptid (++p, NULL); break; } I don't remember exactly why I added the "status->kind () != TARGET_WAITKIND_THREAD_EXITED" check, I think it was just because I was reading the code and noticed it doesn't make sense to process expected registers for that event. > > If THREAD_EXITED implies that the regcache is empty could we use an > assert here instead of adding the kind check to the if? Maybe: > > if (!stop_reply->regcache.empty ()) > { > gdb_assert (status->kind () != TARGET_WAITKIND_THREAD_EXITED); > > ... > Makes sense, I did this. > But maybe that's bad because we'd be making assert based on state that > arrives from gdbserver. As explained above, that can't happen, so an assertion is fine. > In which case, should we perform some action to > ensure that the regcache data is correctly freed? I wrote a couple patches to improve ownership around this, using unique_ptr more. I will post them after this series (need to write commit logs, etc.)