diff options
author | Jan Vrany <jan.vrany@labware.com> | 2022-04-06 23:13:19 +0200 |
---|---|---|
committer | Jan Vrany <jan.vrany@labware.com> | 2023-04-21 16:30:11 +0100 |
commit | 2f8491466e45728a01ce66cb7cf6bb07212fd828 (patch) | |
tree | 1e253d9f8694f84c9db1b8dde06152d1ed009923 | |
parent | 39fa230101bc40d2ef335cb7e54ca9bee9ef4d22 (diff) | |
download | binutils-gdb-2f8491466e45728a01ce66cb7cf6bb07212fd828.tar.gz |
gdb/python: allow to instantiate gdb.LineTableEntry objects
This commit allows users to instantiate gdb.LineTableEntry objects. This
feature will be used later to allow Python code to build and set a symtab
linetable.
-rw-r--r-- | gdb/python/py-linetable.c | 39 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-linetable.exp | 9 |
2 files changed, 44 insertions, 4 deletions
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c index 75e8d003f3f..df113bf0d8c 100644 --- a/gdb/python/py-linetable.c +++ b/gdb/python/py-linetable.c @@ -338,7 +338,7 @@ ltpy_entry_get_pc (PyObject *self, void *closure) return gdb_py_object_from_ulongest (CORE_ADDR (obj->entry.raw_pc ())).release (); } -/* Implementation of gdb.LineTableEntry.is_stmt (self) -> bool. Returns +/* Implementation of gdb.LineTableEntry.is_stmt (self) -> bool. Returns True if associated PC is a good location to place a breakpoint for associatated LINE. */ @@ -353,8 +353,8 @@ ltpy_entry_get_is_stmt (PyObject *self, void *closure) Py_RETURN_FALSE; } -/* Implementation of gdb.LineTableEntry.prologue_end (self) -> bool. Returns - True if associated PC is a good location to place a breakpoint after a +/* Implementation of gdb.LineTableEntry.prologue_end (self) -> bool. Returns + True if associated PC is a good location to place a breakpoint after a function prologue. */ static PyObject * @@ -368,6 +368,36 @@ ltpy_entry_get_prologue_end (PyObject *self, void *closure) Py_RETURN_FALSE; } +/* Object initializer; creates new linetable entry. + + Use: __init__(LINE, PC, IS_STMT, PROLOGUE_END). */ + +static int +ltpy_entry_init (PyObject *zelf, PyObject *args, PyObject *kw) +{ + linetable_entry_object *self = (linetable_entry_object *) zelf; + + static const char *keywords[] = { "line", "pc", "is_stmt", "prologue_end", NULL }; + + int is_stmt = 0; + int prologue_end = 0; + CORE_ADDR pc = 0; + + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "ik|pp", + keywords, + &(self->entry.line), + &pc, + &is_stmt, + &prologue_end)) + return -1; + + self->entry.set_raw_pc( unrelocated_addr (pc)); + self->entry.is_stmt = is_stmt; + self->entry.prologue_end = prologue_end == 1 ? true : false; + + return 0; +} + /* LineTable iterator functions. */ /* Return a new line table iterator. */ @@ -621,6 +651,7 @@ PyTypeObject linetable_entry_object_type = { 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - 0, /* tp_init */ + ltpy_entry_init, /* tp_init */ 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; diff --git a/gdb/testsuite/gdb.python/py-linetable.exp b/gdb/testsuite/gdb.python/py-linetable.exp index c43fb7fc987..1333e4c962c 100644 --- a/gdb/testsuite/gdb.python/py-linetable.exp +++ b/gdb/testsuite/gdb.python/py-linetable.exp @@ -71,3 +71,12 @@ gdb_test "python print(lt.has_line(44))" \ gdb_test "python print(lt.has_line(10))" \ "False.*" \ "test has_pcs at line 10" + +# Test gdb.LineTableEntry.__init__ () +gdb_test "python print( gdb.LineTableEntry(10, 0xcafe0000).line)" \ + "10" \ + "test new LineTableEntry line" + +gdb_test "python print( gdb.LineTableEntry(10, 123456).pc)" \ + "123456" \ + "test new LineTableEntry pc" |