From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by sourceware.org (Postfix) with ESMTPS id 86DEA3858C52 for ; Mon, 4 Apr 2022 14:37:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 86DEA3858C52 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-wr1-f52.google.com with SMTP id h4so14770862wrc.13 for ; Mon, 04 Apr 2022 07:37:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SdhArl5qdT6JJOov6dxrfUmw/pFVRyWKZ2Zsaz3bs8E=; b=ksXoIxMye3nMnvjBzlbr85gJvV0puNVwUfxOwUjv3AhTQ385hJlUPrmWL2YIjwQSEs ureCD3PbEKLLNZqUOI2UsqMbs/CNYag714f1hqgjnpwv2tZTUAJrzX1Ih8xwc3Kei5d8 QHAM7cbWRPzzrZ8GJ0lICi7EIDxbk9QT2L0jMItP6UKSeN1MNcvhJvbgyTNHOhgLDDxE 8WBs00vA4HRdClBc6gjqH5gsYwzDxN81+vs8Di3WKniS17y7rQAc3VtYF414zqWcG3RQ 05cnG9If4w7AaEPlV/AF/WPkWU0f7EPDXPGuNzqEkSlTpIK/Il+vQQqhiSaW8NtftHgm mS0g== X-Gm-Message-State: AOAM5302Fqit6tFx/Iza7uYUXU0pWBxYm6AohPYm0BLiqylRVH845DDr M8m5tMeNmPBNeUlDTo7YemJe8o4zSKk= X-Google-Smtp-Source: ABdhPJz5CWJcm6j42QZq8d72Mqca6RmpEltHdxC+N6gheiZ7zdXoBChCevQCRiSCZzu6DQ0Ficmbrg== X-Received: by 2002:a05:6000:15ce:b0:204:1113:b053 with SMTP id y14-20020a05600015ce00b002041113b053mr17348947wry.701.1649083074765; Mon, 04 Apr 2022 07:37:54 -0700 (PDT) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id o9-20020a056000010900b00206186ac25esm1114075wrx.12.2022.04.04.07.37.53 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Apr 2022 07:37:54 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 1/4] gdbserver/qXfer::threads, prepare_to_access_memory=>target_pause_all Date: Mon, 4 Apr 2022 15:37:47 +0100 Message-Id: <20220404143750.758138-2-pedro@palves.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220404143750.758138-1-pedro@palves.net> References: <20220404143750.758138-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.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, 04 Apr 2022 14:37:58 -0000 handle_qxfer_threads_proper needs to pause all threads even if the target can read memory when threads are running, so use target_pause_all instead, which is what the Linux implementation of prepare_to_access_memory uses. (Only Linux implements this hook.) A following patch will make the Linux backend be able to access memory when threads are running, and thus will also make prepare_to_access_memory do nothing, which would cause testsuite regressions without this change. Change-Id: I127fec7246b7c45b60dfa7341e781606bf54b5da --- gdbserver/server.cc | 51 ++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 9f52d6e63fe..e43a40a9b1f 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1691,47 +1691,28 @@ handle_qxfer_threads_worker (thread_info *thread, struct buffer *buffer) static bool handle_qxfer_threads_proper (struct buffer *buffer) { - client_state &cs = get_client_state (); - - scoped_restore_current_thread restore_thread; - scoped_restore save_current_general_thread - = make_scoped_restore (&cs.general_thread); - buffer_grow_str (buffer, "\n"); - process_info *error_proc = find_process ([&] (process_info *process) - { - /* The target may need to access memory and registers (e.g. via - libthread_db) to fetch thread properties. Prepare for memory - access here, so that we potentially pause threads just once - for all accesses. Note that even if someday we stop needing - to pause threads to access memory, we will need to be able to - access registers, or other ptrace accesses like - PTRACE_GET_THREAD_AREA. */ - - /* Need to switch to each process in turn, because - prepare_to_access_memory prepares for an access in the - current process pointed to by general_thread. */ - switch_to_process (process); - cs.general_thread = current_thread->id; - - int res = prepare_to_access_memory (); - if (res == 0) - { - for_each_thread (process->pid, [&] (thread_info *thread) - { - handle_qxfer_threads_worker (thread, buffer); - }); + /* The target may need to access memory and registers (e.g. via + libthread_db) to fetch thread properties. Even if don't need to + stop threads to access memory, we still will need to be able to + access registers, and other ptrace accesses like + PTRACE_GET_THREAD_AREA that require a paused thread. Pause all + threads here, so that we pause each thread at most once for all + accesses. */ + if (non_stop) + target_pause_all (true); - done_accessing_memory (); - return false; - } - else - return true; + for_each_thread ([&] (thread_info *thread) + { + handle_qxfer_threads_worker (thread, buffer); }); + if (non_stop) + target_unpause_all (true); + buffer_grow_str0 (buffer, "\n"); - return error_proc == nullptr; + return true; } /* Handle qXfer:threads:read. */ -- 2.26.2