public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] linux-nat.c, linux-fork.c: Fix detach bug when lwp has exited/terminated
Date: Mon, 13 Nov 2023 18:36:35 -0700	[thread overview]
Message-ID: <20231113183635.7d5a81ae@f39-zbm-nv> (raw)
In-Reply-To: <87il65sywr.fsf@redhat.com>

Hi Andrew,

I'll make (or at least consider) the changes that you requested, but I
see that you also asked a question.  I'll answer that now...

On Mon, 13 Nov 2023 10:58:12 +0000
Andrew Burgess <aburgess@redhat.com> wrote:

> Kevin Buettner <kevinb@redhat.com> writes:
> > +    }
> > +
> >    if (signo_p == NULL)
> >      {
> >        /* Pass on any pending signal for this LWP.  */
> > @@ -1427,13 +1440,13 @@ linux_nat_target::detach (inferior *inf, int from_tty)
> >    gdb_assert (num_lwps (pid) == 1
> >  	      || (target_is_non_stop_p () && num_lwps (pid) == 0));
> >  
> > -  if (forks_exist_p ())
> > +  if (pid == inferior_ptid.pid () && forks_exist_p ())  
> 
> I see how this ties to the assert in linux_fork_detach.  And given the
> comments and use of inferior_ptid, I can see why you added the assert.
> 
> But I guess you added the check because some test triggered the assert.
> Do you recall which test that was?  I guess I'm curious what PID we are
> trying to detach from when this condition triggers.

I added that check and the asserts when I realized that the lwp that I
was (now) passing to linux_fork_detach might not be the same as that
for inferior_ptid.  There was no test that I ran which demonstrated
the problem.

I was imagining something like this, below, using two of the executables
from gdb.multi/base.exp:

kev@f39-1:gdb$ ./gdb
GNU gdb (GDB) 15.0.50.20231110-git
[snipped start-up messages...]
(gdb) file testsuite/outputs/gdb.multi/base/hello
Reading symbols from testsuite/outputs/gdb.multi/base/hello...
(gdb) start
Temporary breakpoint 1 at 0x401199: file /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/hello.c, line 51.
Starting program: /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/hello 
[snipped debuginfod stuff...]
Temporary breakpoint 1, main ()
    at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/hello.c:51
51	  alarm (240);
(gdb) info inferiors
  Num  Description       Connection           Executable        
* 1    process 238425    1 (native)           /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/hello 
(gdb) add-inferior -exec testsuite/outputs/gdb.multi/base/goodbye
[New inferior 2]
Added inferior 2 on connection 1 (native)
Reading symbols from testsuite/outputs/gdb.multi/base/goodbye...
(gdb) info inferiors
  Num  Description       Connection           Executable        
* 1    process 238425    1 (native)           /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/hello 
  2    <null>            1 (native)           /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/goodbye 
(gdb) inferior 2
[Switching to inferior 2 [<null>] (/mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/goodbye)]
(gdb) start
Temporary breakpoint 2 at 0x401199: -qualified main. (2 locations)
Starting program: /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/goodbye 
[Thread debugging using libthread_db enabled]                                   
Using host libthread_db library "/lib64/libthread_db.so.1".

Thread 2.1 "goodbye" hit Temporary breakpoint 2.2, main ()
    at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/goodbye.c:61
61	  mailand();
(gdb) checkpoint
checkpoint 1: fork returned pid 238435.
(gdb) info inferiors
  Num  Description       Connection           Executable        
  1    process 238425    1 (native)           /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/hello 
* 2    process 238434    1 (native)           /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/goodbye 
(gdb) info checkpoint
* 0 Thread 0x7ffff7cd3740 (LWP 238434) (main process) at 0x0
  1 process 238435 at 0x40124e, file /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/goodbye.c, line 61
(gdb) s
mailand ()
    at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/goodbye.c:46
46	  glob = 46;
(gdb) s
47	}
(gdb) s
main ()
    at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/goodbye.c:62
62	  foo(glob);
(gdb) s
foo (x=46)
    at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/goodbye.c:51
51	  return x + 92;
(gdb) inferior 1
[Switching to inferior 1 [process 238425] (/mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/hello)]
[Switching to thread 1.1 (Thread 0x7ffff7cd3740 (LWP 238425))]
#0  main ()
    at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/hello.c:51
51	  alarm (240);
(gdb) detach
/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:624: internal-error: lwp_lwpid_htab_add_lwp: Assertion `slot != NULL && *slot == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
0x4ef132 gdb_internal_backtrace_1
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/bt-utils.c:122
0x4ef132 _Z22gdb_internal_backtracev
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/bt-utils.c:168
0x8d9074 internal_vproblem
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/utils.c:396
0x8d92f8 _Z15internal_verrorPKciS0_P13__va_list_tag
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/utils.c:476
0xa1e431 _Z18internal_error_locPKciS0_z
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdbsupport/errors.cc:58
0x6c4a41 lwp_lwpid_htab_add_lwp
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:624
0x6c4a41 add_initial_lwp
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:792
0x6c7d58 add_lwp
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:806
0x6c7d58 _Z21linux_nat_switch_fork6ptid_t
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:887
0x6c28fe fork_load_infrun_state
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-fork.c:219
0x6c343b _Z17linux_fork_detachi
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-fork.c:381
0x6c8bd8 _ZN16linux_nat_target6detachEP8inferiori
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:1436
0x6d8652 _ZN16thread_db_target6detachEP8inferiori
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-thread-db.c:1385
0x85e943 _Z13target_detachP8inferiori
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/target.c:2526
0x680aed _Z14detach_commandPKci
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/infcmd.c:2863
0x5224ac _Z8cmd_funcP16cmd_list_elementPKci
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/cli/cli-decode.c:2735
0x86cd0a _Z15execute_commandPKci
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/top.c:575
0x600c4f _Z15command_handlerPKc
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/event-top.c:552
0x60204a _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/event-top.c:788
0x60149b gdb_rl_callback_handler
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/event-top.c:259
0x91ef44 rl_callback_read_char
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/readline/readline/callback.c:290
0x6015bd gdb_rl_callback_read_char_wrapper_noexcept
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/event-top.c:195
0x60173c gdb_rl_callback_read_char_wrapper
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/event-top.c:234
0x8a763f stdin_event_handler
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/ui.c:155
0xa1ed35 gdb_wait_for_event
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdbsupport/event-loop.cc:716
0xa1f7f7 _Z16gdb_do_one_eventi
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdbsupport/event-loop.cc:264
0x6e92c9 start_event_loop
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/main.c:407
0x6e92c9 captured_command_loop
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/main.c:471
0x6ebba4 captured_main
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/main.c:1324
0x6ebba4 _Z8gdb_mainP18captured_main_args
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/main.c:1343
0x446ad4 main
	/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/gdb.c:39
---------------------
/mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:624: internal-error: lwp_lwpid_htab_add_lwp: Assertion `slot != NULL && *slot == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.

I see this problem both with my patch and without, so there's more to
be done in to make the checkpoint support work with multiple
inferiors.  I would guess that the check that I added reduces by (at
least) one, the number of problems that exist with the linux
checkpoint code.

I'll file a bug and add this to my list of things to look at.

Kevin


  reply	other threads:[~2023-11-14  1:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-11 22:26 [PATCH 0/2] " Kevin Buettner
2023-11-11 22:26 ` [PATCH 1/2] linux-nat.c, linux-fork.c: " Kevin Buettner
2023-11-13 10:58   ` Andrew Burgess
2023-11-14  1:36     ` Kevin Buettner [this message]
2023-11-14  5:48       ` Kevin Buettner
2023-11-11 22:26 ` [PATCH 2/2] New test: gdb.base/process-dies-while-detaching.exp Kevin Buettner
2023-11-13 11:04   ` Andrew Burgess

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=20231113183635.7d5a81ae@f39-zbm-nv \
    --to=kevinb@redhat.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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).