From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E38BD3858C62 for ; Thu, 13 Jul 2023 12:22:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E38BD3858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689250921; 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=puVfZCHTwuBShce49Ifm0+qIPKv1OCh6mC2ujnGlD2M=; b=c0sfHUwAAtfFNF0y0C9qN5fjF6tmVo5RYY8brgTjL5t+8LLiwz+q2ilgUhoQ/Ou0roTteW E77nhuTaWxRHMZ2PFOW3ZfAoeCUULUA741vXsP+l6KG77e28DhgEAgZyIaXHyYSi7WM/YR Cz17k/ccclbt7PkZzchl3Ds8Hv1Xoy8= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-439-wBdzg6SGOf-96bCSdS4rOQ-1; Thu, 13 Jul 2023 08:22:00 -0400 X-MC-Unique: wBdzg6SGOf-96bCSdS4rOQ-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-403a435e333so4794631cf.1 for ; Thu, 13 Jul 2023 05:22:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689250919; x=1691842919; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=puVfZCHTwuBShce49Ifm0+qIPKv1OCh6mC2ujnGlD2M=; b=ZVdRdhUPQSk/MziglF3AY0yxLRrrq+kezIt8p1yr5X8GDd1OuczFXEEaDXyIEeMUrH Xz/lazEOCi1HbVDAL/Hvf6nm/BP7FiVTf8wY51wKMh4O/hK+degivgnBH1smBodRAePD VNJEN22eq2kx7JaIxLK+wpejzV8DjVADq9Rpu3mT24uS6rlRy2lxHFbmbHKxr9nncOc4 lgcSuuIYRxRmzYUrQr5mwDTqqAAn/MAPPli4ciRFb85oo2St2cjmHmfp0OCBkdeO8vVq c2Q7m8BPxGVnmJqJDu66ekbgkqQ526AkKWuEBdZIAvU1Bjh4hVo6FfXIsp1jTZECEvco JInQ== X-Gm-Message-State: ABy/qLbU8QXJEFdNyu39KM+Z8kUi7n1c+ZGwY+IIiafkvv9YIvoyn2bX 8cpARty3bCvk9fJV6t85oCakIZZIRlIgaJBvt1S7zlQAbaxQ6O7c4HMfMDRH375bz9OSQla9l3v QEmPMyujlgcNbeKFUZz6so3tmBjkEEA== X-Received: by 2002:a05:622a:1045:b0:3f9:b870:ba13 with SMTP id f5-20020a05622a104500b003f9b870ba13mr1885317qte.24.1689250919501; Thu, 13 Jul 2023 05:21:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlEKHainVYkQS97Msge17IZBM1in6eGCaMtERXNRiuRCafjmtCNJ2i+ZEMJlpuGnMuwII/HBhg== X-Received: by 2002:a05:622a:1045:b0:3f9:b870:ba13 with SMTP id f5-20020a05622a104500b003f9b870ba13mr1885301qte.24.1689250919221; Thu, 13 Jul 2023 05:21:59 -0700 (PDT) Received: from [192.168.0.129] (ip-94-112-225-44.bb.vodafone.cz. [94.112.225.44]) by smtp.gmail.com with ESMTPSA id v26-20020ac8729a000000b004039a43ddbasm3043970qto.53.2023.07.13.05.21.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jul 2023 05:21:58 -0700 (PDT) Message-ID: <8b3ebcfa-1cfa-b5ab-f451-165fd2960112@redhat.com> Date: Thu, 13 Jul 2023 14:21:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v2 1/2] gdb: keep record of thread numbers for reverse execution targets To: Magne Hov , gdb-patches@sourceware.org References: <20230629083651.3145268-1-mhov@undo.io> <20230707162451.3605544-1-mhov@undo.io> <20230707162451.3605544-2-mhov@undo.io> From: Bruno Larsen In-Reply-To: <20230707162451.3605544-2-mhov@undo.io> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 07/07/2023 18:24, Magne Hov via Gdb-patches wrote: > Targets that support reverse execution may report threads that have > previously been seen to exit. Currently, GDB assigns a new thread > number every time it sees the same thread (re)appearing, but this is > problematic because it makes the output of `info threads` inconsistent, > and because thread-specific breakpoints depend on stable thread-numbers > in order to stop on the right thread. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23454 Hi! Thanks for working on this. This looks like a good addition, and introduces no regressions. Reviewed-By: Bruno Larsen I hope a global maintainers or Markus look at it soon! -- Cheers, Bruno > --- > gdb/inferior.c | 1 + > gdb/inferior.h | 7 +++++++ > gdb/thread.c | 38 ++++++++++++++++++++++++++++++++++++-- > 3 files changed, 44 insertions(+), 2 deletions(-) > > diff --git a/gdb/inferior.c b/gdb/inferior.c > index eee4785fbf7..b6323110e69 100644 > --- a/gdb/inferior.c > +++ b/gdb/inferior.c > @@ -258,6 +258,7 @@ inferior::clear_thread_list (bool silent) > delete thr; > }); > ptid_thread_map.clear (); > + ptid_thread_num_map.clear (); > } > > /* Notify interpreters and observers that inferior INF was removed. */ > diff --git a/gdb/inferior.h b/gdb/inferior.h > index caa8e4d494a..33eb857645e 100644 > --- a/gdb/inferior.h > +++ b/gdb/inferior.h > @@ -569,6 +569,13 @@ class inferior : public refcounted_object, > /* The highest thread number this inferior ever had. */ > int highest_thread_num = 0; > > + /* A map of ptid_t to global thread number and per-inferior thread > + number, used for targets that support reverse execution. These > + mappings are maintained for the lifetime of the inferior so that > + thread numbers can be reused for threads that reappear after > + having exited. */ > + std::unordered_map, hash_ptid> ptid_thread_num_map; > + > /* State of GDB control of inferior process execution. > See `struct inferior_control_state'. */ > inferior_control_state control; > diff --git a/gdb/thread.c b/gdb/thread.c > index 7f7f035b5ab..ef3da68fc30 100644 > --- a/gdb/thread.c > +++ b/gdb/thread.c > @@ -290,6 +290,15 @@ add_thread_silent (process_stratum_target *targ, ptid_t ptid) > inf->num, ptid.to_string ().c_str (), > targ->shortname ()); > > + /* Targets that support reverse execution can see the same thread > + being added multiple times. If the state for an exited thread is > + still present in the inferior's thread list it must be cleaned up > + now before we add a new non-exited entry for the same thread. > + Targets without reverse execution are not affected by this because > + they do not reuse thread numbers. */ > + if (target_can_execute_reverse ()) > + delete_exited_threads (); > + > /* We may have an old thread with the same id in the thread list. > If we do, it must be dead, otherwise we wouldn't be adding a new > thread with the same id. The OS is reusing this id --- delete > @@ -332,8 +341,33 @@ thread_info::thread_info (struct inferior *inf_, ptid_t ptid_) > { > gdb_assert (inf_ != NULL); > > - this->global_num = ++highest_thread_num; > - this->per_inf_num = ++inf_->highest_thread_num; > + /* Targets that support reverse execution may see the same thread be > + created multiple times so a historical record must be maintained > + and queried. For targets without reverse execution we don't look > + up historical thread numbers because it leaves us vulnerable to > + collisions between thread identifiers that have been recycled by > + the target operating system. */ > + if (target_can_execute_reverse ()) > + { > + auto pair = inf_->ptid_thread_num_map.find (ptid_); > + if (pair != inf_->ptid_thread_num_map.end ()) > + { > + this->global_num = pair->second.first; > + this->per_inf_num = pair->second.second; > + } > + else > + { > + this->global_num = ++highest_thread_num; > + this->per_inf_num = ++inf_->highest_thread_num; > + inf_->ptid_thread_num_map[ptid_] = std::make_pair (this->global_num, > + this->per_inf_num); > + } > + } > + else > + { > + this->global_num = ++highest_thread_num; > + this->per_inf_num = ++inf_->highest_thread_num; > + } > > /* Nothing to follow yet. */ > this->pending_follow.set_spurious ();