From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 4E1713858D28 for ; Fri, 6 Jan 2023 21:27:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E1713858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [172.16.0.64] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id E8AB41E110; Fri, 6 Jan 2023 16:27:22 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1673040443; bh=DVonZJizdPjewsPKan9a77w7pzNA7ywRzpsVSPVm+8c=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=dqMwlE37AU5/05jhI6MUyOcQtY0L4Db3hnzHl5jlPav/mS2bpseM9KLtjvZ4ZY6DQ POIXxAgvcqVpwrlecst6xi8HemvJP7fONZAca0joQc7EwIKFu6QPVUfMiZRenLEIjn m9Nxz0WrD4917CTt9aJef5fUa7IconSdNGm5W/t0= Message-ID: <9c70aa6a-2a00-a985-c080-33d086597ee7@simark.ca> Date: Fri, 6 Jan 2023 16:27:22 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v4] gdb/gcore: interrupt all threads before generating the corefile Content-Language: fr To: Lancelot SIX , gdb-patches@sourceware.org Cc: lsix@lancelotsix.com References: <20221206141248.2485033-1-lancelot.six@amd.com> From: Simon Marchi In-Reply-To: <20221206141248.2485033-1-lancelot.six@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP 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: > @@ -131,6 +132,28 @@ gcore_command (const char *args, int from_tty) > if (!target_has_execution ()) > noprocess (); > > + scoped_restore_current_thread restore_current_thread; > + scoped_disable_commit_resumed disable_commit_resume ("generating coredump"); > + struct inferior *inf = current_inferior (); > + scoped_finish_thread_state finish_state (inf->process_target (), > + ptid_t (inf->pid)); > + > + bool all_stop_was_running = false; > + if (exists_non_stop_target ()) > + stop_all_threads ("generating coredump", inf); > + else > + { > + all_stop_was_running = any_thread_of_inferior (inf)->executing (); I'm wondering what happens if you call this while the inferior is doing an in-line step over, with one thread resumed and the others stopped. I think the others will have executing == false, so could you fall on one that isn't executing? What if we are in all-stop, but we resumed with schedlock on? Note that I'd be fine with merging the patch without considering those cases, since it's clearly an improvement already. > diff --git a/gdb/testsuite/gdb.base/gcore-nonstop.exp b/gdb/testsuite/gdb.base/gcore-nonstop.exp > new file mode 100644 > index 00000000000..4a240eb0872 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcore-nonstop.exp > @@ -0,0 +1,77 @@ > +# Copyright 2022 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# This testcase checks that when in non-stop mode with some threads running > +# the gcore command can interrupt all threads, generate a core dump and > +# restart threads as required. > + Please add a short comment explaining the goal of this test. > +standard_testfile > + > +if { [prepare_for_testing "failed to prepare" \ > + ${testfile} ${srcfile} {pthreads debug}] } { > + return > +} prepare_for_testing starts GDB, but it gets restarted below anyway. Use build_executable to avoid the unnecessary spawn. > + > +save_vars { GDBFLAGS } { > + append GDBFLAGS " -ex \"set non-stop on\"" > + clean_restart ${binfile} > +} > + > +set lineno [gdb_get_line_number "Break here"] > +if { ![runto $lineno] } { > + return > +} > + > +# We should be stopped in thread 1 while thread 2 is running. > +gdb_test_sequence "info threads" "info threads" { > + {Id\s+Target Id\s+Frame} > + {\*\s+1[^\n]*\n} > + {\s+2\s+[^\n]*\(running\)[^\n]*\n} > +} > + > +set th1_pc "" > +gdb_test_multiple "p/x \$pc" "fetch thread 1 PC" { > + -wrap -re "$::decimal = ($::hex)" { > + set th1_pc $expect_out(1,string) > + pass $gdb_test_name > + } Could that use get_hexadecimal_valueof? Simon