Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit da3c873

Browse files
committed
Fix 8.2 regression in gdb.python/py-evthreads.exp w/ gdbserver (PR gdb/23379)
This commit fixes a 8.1->8.2 regression exposed by gdb.python/py-evthreads.exp when testing with --target_board=native-gdbserver. gdb.log shows: src/gdb/thread.c:93: internal-error: thread_info* inferior_thread(): Assertion `tp' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.python/py-evthreads.exp: run to breakpoint 1 (GDB internal error) A backtrace shows (frames #2 and #10 highlighted) that the assertion fails when GDB is setting up the connection to the remote target, in non-stop mode: #0 0x0000000000622ff0 in internal_error(char const*, int, char const*, ...) (file=0xc1ad98 "src/gdb/thread.c", line=93, fmt=0xc1ad20 "%s: Assertion `%s' failed.") at src/gdb/common/errors.c:54 #1 0x000000000089567e in inferior_thread() () at src/gdb/thread.c:93 = #2 0x00000000004da91d in get_event_thread() () at src/gdb/python/py-threadevent.c:38 #3 0x00000000004da9b7 in create_thread_event_object(_typeobject*, _object*) (py_type=0x11574c0 <continue_event_object_type>, thread=0x0) at src/gdb/python/py-threadevent.c:60 #4 0x00000000004bf6fe in create_continue_event_object() () at src/gdb/python/py-continueevent.c:27 #5 0x00000000004bf738 in emit_continue_event(ptid_t) (ptid=...) at src/gdb/python/py-continueevent.c:40 #6 0x00000000004c7d47 in python_on_resume(ptid_t) (ptid=...) at src/gdb/python/py-inferior.c:108 #7 0x0000000000485bfb in std::_Function_handler<void (ptid_t), void (*)(ptid_t)>::_M_invoke(std::_Any_data const&, ptid_t&&) (__functor=..., __args#0=...) at /usr/include/c++/7/bits/std_function.h:316 #8 0x000000000089b416 in std::function<void (ptid_t)>::operator()(ptid_t) const (this=0x12aa600, __args#0=...) at /usr/include/c++/7/bits/std_function.h:706 #9 0x000000000089aa0e in gdb::observers::observable<ptid_t>::notify(ptid_t) const (this=0x118a7a0 <gdb::observers::target_resumed>, args#0=...) at src/gdb/common/observable.h:106 = #10 0x0000000000896fbe in set_running(ptid_t, int) (ptid=..., running=1) at src/gdb/thread.c:880 #11 0x00000000007f750f in remote_target::remote_add_thread(ptid_t, bool, bool) (this=0x12c5440, ptid=..., running=true, executing=true) at src/gdb/remote.c:2434 #12 0x00000000007f779d in remote_target::remote_notice_new_inferior(ptid_t, int) (this=0x12c5440, currthread=..., executing=1) at src/gdb/remote.c:2515 #13 0x00000000007f9c44 in remote_target::update_thread_list() (this=0x12c5440) at src/gdb/remote.c:3831 #14 0x00000000007fb922 in remote_target::start_remote(int, int) (this=0x12c5440, from_tty=0, extended_p=0) at src/gdb/remote.c:4655 #15 0x00000000007fd102 in remote_target::open_1(char const*, int, int) (name=0x1a4f45e "localhost:2346", from_tty=0, extended_p=0) at src/gdb/remote.c:5638 #16 0x00000000007fbec1 in remote_target::open(char const*, int) (name=0x1a4f45e "localhost:2346", from_tty=0) at src/gdb/remote.c:4862 So on frame #10, we're marking a newly-discovered thread as running, and that causes the Python API to emit a gdb.ContinueEvent. gdb.ContinueEvent is a gdb.ThreadEvent, and as such includes the event thread as the "inferior_thread" attribute. The problem is that when we get to frame #3/#4, we lost all references to the thread that is being marked as running. create_continue_event_object assumes that it is the current thread, which is not true in this case. Fix this by passing down the right thread in create_continue_event_object. Also remove create_thread_event_object's default argument and have the only other caller left pass down the right thread explicitly too. gdb/ChangeLog: 2018-08-24 Pedro Alves <[email protected]> Simon Marchi <[email protected]> PR gdb/23379 * python/py-continueevent.c: Include "gdbthread.h". (create_continue_event_object): Add intro comment. Add 'ptid' parameter. Use it to find thread to pass to create_thread_event_object. (emit_continue_event): Pass PTID down to create_continue_event_object. * python/py-event.h (py_get_event_thread): Declare. (create_thread_event_object): Remove default from 'thread' parameter. * python/py-stopevent.c (create_stop_event_object): Use py_get_event_thread. * python/py-threadevent.c (get_event_thread): Rename to ... (py_get_event_thread): ... this, make extern, add 'ptid' parameter and use it to find the thread. (create_thread_event_object): Assert that THREAD isn't null. Don't find the event thread here.
1 parent 3da65cd commit da3c873

File tree

5 files changed

+64
-27
lines changed

5 files changed

+64
-27
lines changed

gdb/ChangeLog

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
2018-08-24 Pedro Alves <[email protected]>
2+
Simon Marchi <[email protected]>
3+
4+
PR gdb/23379
5+
* python/py-continueevent.c: Include "gdbthread.h".
6+
(create_continue_event_object): Add intro comment. Add 'ptid'
7+
parameter. Use it to find thread to pass to
8+
create_thread_event_object.
9+
(emit_continue_event): Pass PTID down to
10+
create_continue_event_object.
11+
* python/py-event.h (py_get_event_thread): Declare.
12+
(create_thread_event_object): Remove default from 'thread'
13+
parameter.
14+
* python/py-stopevent.c (create_stop_event_object): Use
15+
py_get_event_thread.
16+
* python/py-threadevent.c (get_event_thread): Rename to ...
17+
(py_get_event_thread): ... this, make extern, add 'ptid' parameter
18+
and use it to find the thread.
19+
(create_thread_event_object): Assert that THREAD isn't null.
20+
Don't find the event thread here.
21+
122
2018-08-23 Kevin Buettner <[email protected]>
223

324
* block.h (blockrange, blockranges): New struct declarations.

gdb/python/py-continueevent.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,24 @@
2020
#include "defs.h"
2121
#include "py-event.h"
2222
#include "py-ref.h"
23+
#include "gdbthread.h"
24+
25+
/* Create a gdb.ContinueEvent event. gdb.ContinueEvent is-a
26+
gdb.ThreadEvent, and thread events can either be thread specific or
27+
process wide. If gdb is running in non-stop mode then the event is
28+
thread specific (in which case the PTID thread is included in the
29+
event), otherwise it is process wide (in which case PTID is
30+
ignored). In either case a new reference is returned. */
2331

2432
static gdbpy_ref<>
25-
create_continue_event_object (void)
33+
create_continue_event_object (ptid_t ptid)
2634
{
27-
return create_thread_event_object (&continue_event_object_type);
35+
PyObject *py_thr = py_get_event_thread (ptid);
36+
37+
if (py_thr == nullptr)
38+
return nullptr;
39+
40+
return create_thread_event_object (&continue_event_object_type, py_thr);
2841
}
2942

3043
/* Callback function which notifies observers when a continue event occurs.
@@ -37,7 +50,7 @@ emit_continue_event (ptid_t ptid)
3750
if (evregpy_no_listeners_p (gdb_py_events.cont))
3851
return 0;
3952

40-
gdbpy_ref<> event (create_continue_event_object ());
53+
gdbpy_ref<> event (create_continue_event_object (ptid));
4154
if (event != NULL)
4255
return evpy_emit_event (event.get (), gdb_py_events.cont);
4356
return -1;

gdb/python/py-event.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,18 @@ extern int evpy_emit_event (PyObject *event,
6363
eventregistry_object *registry);
6464

6565
extern gdbpy_ref<> create_event_object (PyTypeObject *py_type);
66+
67+
/* thread events can either be thread specific or process wide. If gdb is
68+
running in non-stop mode then the event is thread specific, otherwise
69+
it is process wide.
70+
This function returns the currently stopped thread in non-stop mode and
71+
Py_None otherwise. In each case it returns a borrowed reference. */
72+
extern PyObject *py_get_event_thread (ptid_t ptid)
73+
CPYCHECKER_RETURNS_BORROWED_REF;
74+
6675
extern gdbpy_ref<> create_thread_event_object (PyTypeObject *py_type,
67-
PyObject *thread = nullptr);
76+
PyObject *thread);
77+
6878
extern int emit_new_objfile_event (struct objfile *objfile);
6979
extern int emit_clear_objfiles_event (void);
7080

gdb/python/py-stopevent.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
gdbpy_ref<>
2424
create_stop_event_object (PyTypeObject *py_type)
2525
{
26-
return create_thread_event_object (py_type);
26+
return create_thread_event_object (py_type,
27+
py_get_event_thread (inferior_ptid));
2728
}
2829

2930
/* Callback observers when a stop event occurs. This function will create a

gdb/python/py-threadevent.c

+14-22
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,40 @@
2020
#include "infrun.h"
2121
#include "gdbthread.h"
2222

23-
/* thread events can either be thread specific or process wide. If gdb is
24-
running in non-stop mode then the event is thread specific, otherwise
25-
it is process wide.
26-
This function returns the currently stopped thread in non-stop mode and
27-
Py_None otherwise. In each case it returns a borrowed reference. */
23+
/* See py-event.h. */
2824

29-
static PyObject *get_event_thread (void)
30-
CPYCHECKER_RETURNS_BORROWED_REF;
31-
32-
static PyObject *
33-
get_event_thread (void)
25+
PyObject *
26+
py_get_event_thread (ptid_t ptid)
3427
{
35-
PyObject *thread;
28+
PyObject *pythread;
3629

3730
if (non_stop)
38-
thread = (PyObject *) thread_to_thread_object (inferior_thread ());
31+
{
32+
thread_info *thread = find_thread_ptid (ptid);
33+
if (thread != nullptr)
34+
pythread = (PyObject *) thread_to_thread_object (thread);
35+
}
3936
else
40-
thread = Py_None;
37+
pythread = Py_None;
4138

42-
if (!thread)
39+
if (!pythread)
4340
{
4441
PyErr_SetString (PyExc_RuntimeError, "Could not find event thread");
4542
return NULL;
4643
}
4744

48-
return thread;
45+
return pythread;
4946
}
5047

5148
gdbpy_ref<>
5249
create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
5350
{
51+
gdb_assert (thread != NULL);
52+
5453
gdbpy_ref<> thread_event_obj (create_event_object (py_type));
5554
if (thread_event_obj == NULL)
5655
return NULL;
5756

58-
if (thread == NULL)
59-
{
60-
thread = get_event_thread ();
61-
if (!thread)
62-
return NULL;
63-
}
64-
6557
if (evpy_add_attribute (thread_event_obj.get (),
6658
"inferior_thread",
6759
thread) < 0)

0 commit comments

Comments
 (0)