diff options
author | Jan Vrany <jan.vrany@labware.com> | 2024-11-21 12:31:21 +0000 |
---|---|---|
committer | Jan Vrany <jan.vrany@labware.com> | 2024-11-21 13:52:21 +0000 |
commit | b09d63cdccbb0c49f9f94743c11a96c861d56d83 (patch) | |
tree | 49e32cbbe7f34e88d3a7921ff194ff7ab284a292 | |
parent | 6b8c17b72994a488eb35e358caa585f865fed10e (diff) | |
download | fsf-binutils-gdb-b09d63cdccbb0c49f9f94743c11a96c861d56d83.zip fsf-binutils-gdb-b09d63cdccbb0c49f9f94743c11a96c861d56d83.tar.gz fsf-binutils-gdb-b09d63cdccbb0c49f9f94743c11a96c861d56d83.tar.bz2 |
gdb/python: allow instantiation of gdb.LineTableEntry objects
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
-rw-r--r-- | gdb/doc/python.texi | 8 | ||||
-rw-r--r-- | gdb/python/py-linetable.c | 52 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-linetable.exp | 25 |
3 files changed, 77 insertions, 8 deletions
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index f1b8037..7d7441b 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -6691,6 +6691,14 @@ True if pc (associated with this entry) marks the start of the epilogue. This attribute is not writable. @end defvar +@code{LineTableEntry} objects have the following methods: + +@defun LineTableEntry.__init__ (line, pc@r{[}, is_stmt@r{][}, prologue_end@r{][}, epilogue_begin@r{]}) +Create new line table entry. Arguments correspond to @code{LineTableEntry} +attributes described above. Optional arguments @var{is_stmt}, +@var{prologue_end} and @var{epilogue_begin} default to @code{False}. +@end defun + As there can be multiple addresses for a single source line, you may receive multiple @code{LineTableEntry} objects with matching @code{line} attributes, but with different @code{pc} attributes. The diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c index 8b6806a..83a3238 100644 --- a/gdb/python/py-linetable.c +++ b/gdb/python/py-linetable.c @@ -146,7 +146,7 @@ build_line_table_tuple_from_entries ( for (i = 0; i < entries.size (); ++i) { - auto entry = entries[i]; + const linetable_entry *entry = entries[i]; gdbpy_ref<> obj (build_linetable_entry ( entry->line, entry->pc (objfile), entry->is_stmt, entry->prologue_end, entry->epilogue_begin)); @@ -390,6 +390,41 @@ ltpy_entry_get_epilogue_begin (PyObject *self, void *closure) Py_RETURN_FALSE; } +/* Object initializer; creates new linetable entry. + + Use: __init__(LINE, PC, IS_STMT, PROLOGUE_END, EPILOGUE_BEGIN). */ + +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", + "epilogue_begin", nullptr }; + int line = 0; + CORE_ADDR pc = 0; + int is_stmt = 0; + int prologue_end = 0; + int epilogue_begin = 0; + + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "iK|ppp", + keywords, + &line, + &pc, + &is_stmt, + &prologue_end, + &epilogue_begin)) + return -1; + + self->line = line; + self->pc = pc; + self->is_stmt = is_stmt == 1 ? true : false; + self->prologue_end = prologue_end == 1 ? true : false; + self->epilogue_begin = epilogue_begin == 1 ? true : false; + + return 0; +} + /* LineTable iterator functions. */ /* Return a new line table iterator. */ @@ -604,12 +639,12 @@ static gdb_PyGetSetDef linetable_entry_object_getset[] = { "The line number in the source file.", NULL }, { "pc", ltpy_entry_get_pc, NULL, "The memory address for this line number.", NULL }, - { "is_stmt", ltpy_entry_get_is_stmt, NULL, - "Whether this is a good location to place a breakpoint for associated LINE.", NULL }, - { "prologue_end", ltpy_entry_get_prologue_end, NULL, - "Whether this is a good location to place a breakpoint after method prologue.", NULL }, - { "epilogue_begin", ltpy_entry_get_epilogue_begin, NULL, - "True if this location marks the start of the epilogue.", NULL }, + { "is_stmt", ltpy_entry_get_is_stmt, nullptr, + "Whether this is a good location to place a breakpoint for associated LINE.", nullptr }, + { "prologue_end", ltpy_entry_get_prologue_end, nullptr, + "Whether this is a good location to place a breakpoint after method prologue.", nullptr }, + { "epilogue_begin", ltpy_entry_get_epilogue_begin, nullptr, + "True if this location marks the start of the epilogue.", nullptr }, { NULL } /* Sentinel */ }; @@ -650,6 +685,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 0f591e1..e14a3bc 100644 --- a/gdb/testsuite/gdb.python/py-linetable.exp +++ b/gdb/testsuite/gdb.python/py-linetable.exp @@ -81,3 +81,28 @@ 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" + +gdb_test "python print( gdb.LineTableEntry(10, 123456).is_stmt)" \ + "False" \ + "test new LineTableEntry is_stmt" +gdb_test "python print( gdb.LineTableEntry(10, 123456).prologue_end)" \ + "False" \ + "test new LineTableEntry prologue_end" +gdb_test "python print( gdb.LineTableEntry(10, 123456).epilogue_begin)" \ + "False" \ + "test new LineTableEntry epilogue_begin" +gdb_test "python print( gdb.LineTableEntry('xx', 123456).pc)" \ + "TypeError.*:.*" \ + "test creating invalid gdb.LineTableEntry" +gdb_test "python print( gdb.LineTableEntry(10, 123456, prologue_end = True).prologue_end)" \ + "True" \ + "test prologue_end keyword argument" |