Bug 27682 - Continue event in Python delivered after thread dies: internal-error: thread_info* inferior_thread(): Assertion `current_thread_ != nullptr' failed.
Summary: Continue event in Python delivered after thread dies: internal-error: thread_...
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-01 13:51 UTC by Michał Radwański
Modified: 2021-09-16 01:11 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Radwański 2021-04-01 13:51:59 UTC
I have this C++ (this is C++, not C) code:

#include <pthread.h>
#include <stdlib.h>
#include <signal.h>
#include <stdint.h>

void* foo(void* ptr) {
    return NULL;
}

int main() {
    pthread_t th;
    pthread_create(&th, NULL, foo, NULL);
    pthread_kill(pthread_self(), SIGSEGV);
    pthread_join(th, NULL);
}


This is what happens:
/tmp $ /tmp/gdb/bin/gdb -q -n -ex 'pi gdb.events.cont.connect(lambda ev: gdb.parse_and_eval("2137"))' -ex 'run' ./test
Reading symbols from ./test...
Starting program: /tmp/test 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff7dae640 (LWP 426580)]
thread.c:72: internal-error: thread_info* inferior_thread(): Assertion `current_thread_ != nullptr' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)



I compile it in either of these ways:
    gcc -x c++ testcase.cc -g -pthread -o test
    g++ testcase.cc -g -pthread -o test
    clang++ testcase.cc -g -pthread -o test
These however don't trigger the bug:
    gcc -x c testcase.cc -g -pthread -o test
    gcc -x c++ testcase.cc -pthread -o test
    clang -x c testcase.cc -g -pthread -o test

My environment: fully upgraded Fedora 33 Desktop (amd64), with GDB just taken from master branch (GNU gdb (GDB) 11.0.50.20210331-git) 
Compilers: 
    gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)
    clang version 11.0.0 (Fedora 11.0.0-2.fc33)

Bug was confirmed on default configuration of Arch Linux.


It should be noted, that if I use GNU gdb (GDB) Fedora 10.1-4.fc33, the doesn't show up just after `run`, but if I make a `break main`, and later issue `continue`, it appears once again.

Possibly connected bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22474
Comment 1 Parke 2021-09-16 01:11:56 UTC
I encounter a similar bug.  Easy to reproduce.

On Arch Linux:

$  gdb  --version
GNU gdb (GDB) 10.2
[snip]

$  gdb  -q -ex run /bin/true
Reading symbols from /bin/true...
(No debugging symbols found in /bin/true)
Starting program: /usr/bin/true 
[Inferior 1 (process 339) exited normally]
../../gdb/thread.c:95: internal-error: thread_info* inferior_thread(): Assertion `current_thread_ != nullptr' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.

This is a bug, please report it.  For instructions, see:
<https://www.gnu.org/software/gdb/bugs/>.

Aborted (core dumped)

$  cat  ~/.gdbinit
define  hook-quit
  set  confirm  off
end

python

def  exit_handler  ( event ):
  if  hasattr ( event, 'exit_code' )  and  event .exit_code == 0:
    gdb .execute ( "quit" )

gdb .events .exited .connect ( exit_handler )

end


----

I encounter a similar bug on Ubuntu 20.04.

$  gdb --version
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
[snip]

$  gdb  -q  -ex run /bin/true
Reading symbols from /bin/true...
(No debugging symbols found in /bin/true)
Starting program: /usr/bin/true 
[Inferior 1 (process 4134946) exited normally]
/build/gdb-OxeNvS/gdb-9.2/gdb/inferior.c:283: internal-error: inferior* find_inferior_pid(int): Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.

This is a bug, please report it.  For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.

Aborted (core dumped)

Possibly related:
https://sourceware.org/bugzilla/show_bug.cgi?id=26761