From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by sourceware.org (Postfix) with ESMTPS id 0A5633858C74 for ; Thu, 11 Aug 2022 15:00:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0A5633858C74 Received: by mail-io1-xd30.google.com with SMTP id v185so14805708ioe.11 for ; Thu, 11 Aug 2022 08:00:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=25Vq4GUfUDyZlwCJTUomYJCb9n/UFnLgyrqGfs0pubw=; b=w5YFIGSgbbRFx+5CBjNPYqfdLyJDQO7InlvhjPgnpYIkkCZ3ofc876f41n+thRjq/L 8Y+/YmN0hAYIKrfDPIEq8qYoOksF+douSJim0vkzG9F3/tit7Z1xFmGoknNldu1y8lJk b5Eep6k/A1ConxDVjthrVzU3G0C+67Ab1HtT88mjIyUlX2MLUzbLYB8arb5dyl77sPnb x9OaVrMccpTp7vLYQMxR/TUZXfjwsyGepT0PDqX74z7w4+L5gbXZlcqSXDIv2w8cx8Ji j7Xz7Dz+bks5Y9QBTvrRWmNEymPQxnhdoRfJxBSnTyxbk70M/Qx9wUcEsAJir6Cd2KBf wwQw== X-Gm-Message-State: ACgBeo0lqTZQiMjpS2vqYPx+kYNO4TZuYr36N3OteH+sOlvzvWLFvd3+ jFwlAGmYE0rL4pGp3UH9Iww3mChrQO8qHg== X-Google-Smtp-Source: AA6agR7gSOJPA3L/noTHLj/uDJa7ezfXWxQfOa7crw7nX0DlFlX3rcPZb6nA4kwFylWFpWpfCMQuaw== X-Received: by 2002:a02:9714:0:b0:343:5c61:8409 with SMTP id x20-20020a029714000000b003435c618409mr469539jai.277.1660230013196; Thu, 11 Aug 2022 08:00:13 -0700 (PDT) Received: from murgatroyd.Home (71-211-185-228.hlrn.qwest.net. [71.211.185.228]) by smtp.gmail.com with ESMTPSA id r20-20020a028814000000b00342919722e7sm8741996jai.174.2022.08.11.08.00.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 08:00:12 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Avoid crash with Ravenscar tasks Date: Thu, 11 Aug 2022 09:00:10 -0600 Message-Id: <20220811150010.991599-1-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 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: Thu, 11 Aug 2022 15:00:17 -0000 When using Ravenscar, gdb can crash if the user sets a breakpoint very early in task startup. This happens because gdb thinks the runtime is initialized, but in practice the particular task isn't sufficiently initialized. This patch avoids the issue by turning an assertion into an early return. I tested this using the AdaCore internal test suite. I don't know how to test Ravenscar using the FSF test suite. --- gdb/ravenscar-thread.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c index 1718c367ff6..fd4bf453cac 100644 --- a/gdb/ravenscar-thread.c +++ b/gdb/ravenscar-thread.c @@ -302,10 +302,12 @@ ravenscar_thread_target::add_active_thread () if (!runtime_initialized ()) return nullptr; - /* Make sure we set m_base_ptid before calling active_task - as the latter relies on it. */ + /* It's possible for runtime_initialized to return true but for it + not to be fully initialized. For example, this can happen for a + breakpoint placed at the task's beginning. */ ptid_t active_ptid = active_task (base_cpu); - gdb_assert (active_ptid != null_ptid); + if (active_ptid == null_ptid) + return nullptr; /* The running thread may not have been added to system.tasking.debug's list yet; so ravenscar_update_thread_list @@ -437,7 +439,9 @@ ravenscar_thread_target::wait (ptid_t ptid, { m_base_ptid = event_ptid; this->update_thread_list (); - return this->add_active_thread ()->ptid; + thread_info *thr = this->add_active_thread (); + if (thr != nullptr) + return thr->ptid; } return event_ptid; } -- 2.34.1