diff options
author | Tim Wiederhake <tim.wiederhake@intel.com> | 2017-05-02 11:35:54 +0200 |
---|---|---|
committer | Tim Wiederhake <tim.wiederhake@intel.com> | 2017-05-02 11:35:54 +0200 |
commit | ae20e79ae852fee8f7d42701a54a95de3b79ecea (patch) | |
tree | 616d593dcb7ef8249449028538998a7ff6a180e4 /gdb/python | |
parent | 8d0050ea192c41349c1f2b000866c1bdb761abeb (diff) | |
download | gdb-ae20e79ae852fee8f7d42701a54a95de3b79ecea.zip gdb-ae20e79ae852fee8f7d42701a54a95de3b79ecea.tar.gz gdb-ae20e79ae852fee8f7d42701a54a95de3b79ecea.tar.bz2 |
Python: Use correct ptid in btrace recording
The user would always get the instruction_history and function_call_history
objects of the current thread, not the thread for which the gdb.Record object
was created.
The attached testcase fails without this patch and passes with the patch.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-record-btrace.c | 32 | ||||
-rw-r--r-- | gdb/python/py-record.c | 17 | ||||
-rw-r--r-- | gdb/python/py-record.h | 40 |
3 files changed, 61 insertions, 28 deletions
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c index 6ba9d7e..5f9264d 100644 --- a/gdb/python/py-record-btrace.c +++ b/gdb/python/py-record-btrace.c @@ -22,6 +22,7 @@ #include "gdbcmd.h" #include "gdbthread.h" #include "btrace.h" +#include "py-record.h" #include "py-record-btrace.h" #include "disasm.h" @@ -734,7 +735,8 @@ recpy_bt_method (PyObject *self, void *closure) PyObject * recpy_bt_format (PyObject *self, void *closure) { - const struct thread_info * const tinfo = find_thread_ptid (inferior_ptid); + const recpy_record_object * const record = (recpy_record_object *) self; + const struct thread_info * const tinfo = find_thread_ptid (record->ptid); const struct btrace_config * config; if (tinfo == NULL) @@ -754,7 +756,8 @@ recpy_bt_format (PyObject *self, void *closure) PyObject * recpy_bt_replay_position (PyObject *self, void *closure) { - const struct thread_info * const tinfo = find_thread_ptid (inferior_ptid); + const recpy_record_object * const record = (recpy_record_object *) self; + const struct thread_info * const tinfo = find_thread_ptid (record->ptid); if (tinfo == NULL) Py_RETURN_NONE; @@ -762,7 +765,7 @@ recpy_bt_replay_position (PyObject *self, void *closure) if (tinfo->btrace.replay == NULL) Py_RETURN_NONE; - return btpy_insn_new (inferior_ptid, + return btpy_insn_new (record->ptid, btrace_insn_number (tinfo->btrace.replay)); } @@ -772,7 +775,8 @@ recpy_bt_replay_position (PyObject *self, void *closure) PyObject * recpy_bt_begin (PyObject *self, void *closure) { - struct thread_info * const tinfo = find_thread_ptid (inferior_ptid); + const recpy_record_object * const record = (recpy_record_object *) self; + struct thread_info * const tinfo = find_thread_ptid (record->ptid); struct btrace_insn_iterator iterator; if (tinfo == NULL) @@ -784,7 +788,7 @@ recpy_bt_begin (PyObject *self, void *closure) Py_RETURN_NONE; btrace_insn_begin (&iterator, &tinfo->btrace); - return btpy_insn_new (inferior_ptid, btrace_insn_number (&iterator)); + return btpy_insn_new (record->ptid, btrace_insn_number (&iterator)); } /* Implementation of @@ -793,7 +797,8 @@ recpy_bt_begin (PyObject *self, void *closure) PyObject * recpy_bt_end (PyObject *self, void *closure) { - struct thread_info * const tinfo = find_thread_ptid (inferior_ptid); + const recpy_record_object * const record = (recpy_record_object *) self; + struct thread_info * const tinfo = find_thread_ptid (record->ptid); struct btrace_insn_iterator iterator; if (tinfo == NULL) @@ -805,7 +810,7 @@ recpy_bt_end (PyObject *self, void *closure) Py_RETURN_NONE; btrace_insn_end (&iterator, &tinfo->btrace); - return btpy_insn_new (inferior_ptid, btrace_insn_number (&iterator)); + return btpy_insn_new (record->ptid, btrace_insn_number (&iterator)); } /* Implementation of @@ -814,7 +819,8 @@ recpy_bt_end (PyObject *self, void *closure) PyObject * recpy_bt_instruction_history (PyObject *self, void *closure) { - struct thread_info * const tinfo = find_thread_ptid (inferior_ptid); + const recpy_record_object * const record = (recpy_record_object *) self; + struct thread_info * const tinfo = find_thread_ptid (record->ptid); struct btrace_insn_iterator iterator; unsigned long first = 0; unsigned long last = 0; @@ -833,7 +839,7 @@ recpy_bt_instruction_history (PyObject *self, void *closure) btrace_insn_end (&iterator, &tinfo->btrace); last = btrace_insn_number (&iterator); - return btpy_list_new (inferior_ptid, first, last, 1, &btpy_insn_type); + return btpy_list_new (record->ptid, first, last, 1, &btpy_insn_type); } /* Implementation of @@ -842,7 +848,8 @@ recpy_bt_instruction_history (PyObject *self, void *closure) PyObject * recpy_bt_function_call_history (PyObject *self, void *closure) { - struct thread_info * const tinfo = find_thread_ptid (inferior_ptid); + const recpy_record_object * const record = (recpy_record_object *) self; + struct thread_info * const tinfo = find_thread_ptid (record->ptid); struct btrace_call_iterator iterator; unsigned long first = 0; unsigned long last = 0; @@ -861,7 +868,7 @@ recpy_bt_function_call_history (PyObject *self, void *closure) btrace_call_end (&iterator, &tinfo->btrace); last = btrace_call_number (&iterator); - return btpy_list_new (inferior_ptid, first, last, 1, &btpy_call_type); + return btpy_list_new (record->ptid, first, last, 1, &btpy_call_type); } /* Implementation of BtraceRecord.goto (self, BtraceInstruction) -> None. */ @@ -869,7 +876,8 @@ recpy_bt_function_call_history (PyObject *self, void *closure) PyObject * recpy_bt_goto (PyObject *self, PyObject *args) { - struct thread_info * const tinfo = find_thread_ptid (inferior_ptid); + const recpy_record_object * const record = (recpy_record_object *) self; + struct thread_info * const tinfo = find_thread_ptid (record->ptid); const btpy_object *obj; if (tinfo == NULL || btrace_is_empty (tinfo)) diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c index 60c0a7c..63cd293 100644 --- a/gdb/python/py-record.c +++ b/gdb/python/py-record.c @@ -18,26 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "defs.h" -#include "inferior.h" -#include "record.h" -#include "python-internal.h" +#include "py-record.h" #include "py-record-btrace.h" #include "py-record-full.h" #include "target.h" -/* Python Record object. */ - -typedef struct -{ - PyObject_HEAD - - /* The ptid this object refers to. */ - ptid_t ptid; - - /* The current recording method. */ - enum record_method method; -} recpy_record_object; - /* Python Record type. */ static PyTypeObject recpy_record_type = { diff --git a/gdb/python/py-record.h b/gdb/python/py-record.h new file mode 100644 index 0000000..c386ba2 --- /dev/null +++ b/gdb/python/py-record.h @@ -0,0 +1,40 @@ +/* Python interface to record targets. + + Copyright 2017 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 <http://www.gnu.org/licenses/>. */ + +#ifndef GDB_PY_RECORD_H +#define GDB_PY_RECORD_H + +#include "inferior.h" +#include "python-internal.h" +#include "record.h" + +/* Python Record object. */ + +typedef struct +{ + PyObject_HEAD + + /* The ptid this object refers to. */ + ptid_t ptid; + + /* The current recording method. */ + enum record_method method; +} recpy_record_object; + +#endif /* GDB_PY_RECORD_H */ |