public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Lancelot SIX <Lancelot.Six@amd.com>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Cc: lsix@lancelotsix.com
Subject: Re: [PATCH v4] gdb/gcore: interrupt all threads before generating the corefile
Date: Mon, 30 Jan 2023 16:33:06 +0000	[thread overview]
Message-ID: <58e6882d-ef47-ca0a-4233-e4cff650db4d@amd.com> (raw)
In-Reply-To: <9c70aa6a-2a00-a985-c080-33d086597ee7@simark.ca>

Hi,

Further comments below:

On 06/01/2023 21:27, Simon Marchi wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
>> @@ -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.

I'll leave it as is for next revision.  I am happy to update this later 
if it turns out a change makes (more) sense.

> 
>> 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 <https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.gnu.org%2Flicenses%2F&data=05%7C01%7Clancelot.six%40amd.com%7C0c9302e594fb40109eb608daf02ccd10%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C638086372462764298%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FRBRcPMwmRPfLUYdn%2FYsLT5VRlvsDbEZjmhXTFRM7bY%3D&reserved=0>.
>> +
>> +# 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.
> 

I have reworked a bit the description.

>> +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.
> 

Done.

>> +
>> +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?

I do  not think it would add anything.  get_hexadecimal_valueof in the 
end does:

     gdb_test_multiple "print /x ${exp}" $test {
       -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
         set val $expect_out(1,string)
         pass "$test"
       }
     }
     return ${val}

This does not add anything to what the test already does, so it looks to 
me it would be a no-op.

I'll sent an updated version shortly.

Best,
Lancelot.
> 
> Simon
> 

      parent reply	other threads:[~2023-01-30 16:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-06 14:12 Lancelot SIX
2022-12-06 15:03 ` Eli Zaretskii
2023-01-04 11:15 ` [PING] " Lancelot SIX
2023-01-06 21:27 ` Simon Marchi
2023-01-10 14:40   ` Lancelot SIX
2023-01-30 16:33   ` Lancelot SIX [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58e6882d-ef47-ca0a-4233-e4cff650db4d@amd.com \
    --to=lancelot.six@amd.com \
    --cc=gdb-patches@sourceware.org \
    --cc=lsix@lancelotsix.com \
    --cc=simark@simark.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).