diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 09adb916c0a..887c7fb68ae 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2019-10-24 Andrew Burgess + + * python/py-progspace.c (pspy_block_for_pc): Return None for all + error paths. + 2019-10-23 Tom Tromey * arc-tdep.c: Remove ".." from include. diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 4483d036ace..bdb70723e56 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -397,11 +397,7 @@ pspy_block_for_pc (PyObject *o, PyObject *args) } if (cust == NULL || COMPUNIT_OBJFILE (cust) == NULL) - { - PyErr_SetString (PyExc_RuntimeError, - _("Cannot locate object file for block.")); - return NULL; - } + Py_RETURN_NONE; if (block) return block_to_block_object (block, COMPUNIT_OBJFILE (cust)); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0d1fed93e69..12ef1fe4954 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-24 Andrew Burgess + + * gdb.python/py-progspace.exp: Add tests for the + Progspace.block_for_pc method. + 2019-10-23 Tom Tromey * configure: Rebuild. diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp index 53943824674..d1bcb81bb47 100644 --- a/gdb/testsuite/gdb.python/py-progspace.exp +++ b/gdb/testsuite/gdb.python/py-progspace.exp @@ -57,6 +57,20 @@ if {![runto_main]} { return } +# Check we can get a block for the current $pc. +set pc_val [get_integer_valueof "\$pc" 0] +gdb_py_test_silent_cmd "python blk = gdb.current_progspace ().block_for_pc (${pc_val})" \ + "get block for the current \$pc" 1 +gdb_test "python print blk.start <= ${pc_val}" "True" \ + "block start is before \$pc" +gdb_test "python print blk.end >= ${pc_val}" "True" \ + "block end is after \$pc" + +# Check what happens when we ask for a block of an invalid address. +if ![is_address_zero_readable] { + gdb_test "python print gdb.current_progspace ().block_for_pc (0)" "None" +} + # With a single inferior, progspace.objfiles () and gdb.objfiles () should # be identical. gdb_test "python print (progspace.objfiles () == gdb.objfiles ())" "True"