aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-breakpoint.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python/py-breakpoint.c')
-rw-r--r--gdb/python/py-breakpoint.c87
1 files changed, 46 insertions, 41 deletions
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index e7dd470..9ce8671 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -1,6 +1,6 @@
/* Python interface to breakpoints
- Copyright (C) 2008-2024 Free Software Foundation, Inc.
+ Copyright (C) 2008-2025 Free Software Foundation, Inc.
This file is part of GDB.
@@ -17,6 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#include "source.h"
#include "value.h"
#include "python-internal.h"
#include "python.h"
@@ -207,7 +208,7 @@ bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
}
catch (const gdb_exception &except)
{
- GDB_PY_SET_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (-1, except);
}
return 0;
@@ -394,7 +395,7 @@ bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
}
catch (const gdb_exception &except)
{
- GDB_PY_SET_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (-1, except);
}
if (! valid_id)
@@ -443,7 +444,7 @@ bppy_delete_breakpoint (PyObject *self, PyObject *args)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
Py_RETURN_NONE;
@@ -484,7 +485,7 @@ bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
}
catch (const gdb_exception &except)
{
- GDB_PY_SET_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (-1, except);
}
return 0;
@@ -611,9 +612,9 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
{
set_breakpoint_condition (self_bp->bp, exp, 0, false);
}
- catch (gdb_exception &ex)
+ catch (const gdb_exception &ex)
{
- GDB_PY_SET_HANDLE_EXCEPTION (ex);
+ return gdbpy_handle_gdb_exception (-1, ex);
}
return 0;
@@ -640,8 +641,7 @@ bppy_get_commands (PyObject *self, void *closure)
}
catch (const gdb_exception &except)
{
- gdbpy_convert_exception (except);
- return NULL;
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
return host_string_to_python_string (stb.c_str ()).release ();
@@ -677,9 +677,9 @@ bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
counted_command_line lines = read_command_lines_1 (reader, 1, nullptr);
breakpoint_set_commands (self_bp->bp, std::move (lines));
}
- catch (gdb_exception &ex)
+ catch (const gdb_exception &ex)
{
- GDB_PY_SET_HANDLE_EXCEPTION (ex);
+ return gdbpy_handle_gdb_exception (-1, ex);
}
return 0;
@@ -928,14 +928,14 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
char *label = NULL;
char *source = NULL;
char *function = NULL;
- PyObject * qualified = NULL;
+ PyObject *qualified = Py_False;
- if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO", keywords,
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO!", keywords,
&spec, &type, &access_type,
&internal,
&temporary, &source,
&function, &label, &lineobj,
- &qualified))
+ &PyBool_Type, &qualified))
return -1;
@@ -948,7 +948,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
else
{
PyErr_SetString (PyExc_RuntimeError,
- _("Line keyword should be an integer or a string. "));
+ _("Line keyword should be an integer or a string."));
return -1;
}
}
@@ -983,10 +983,11 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
case bp_hardware_breakpoint:
{
location_spec_up locspec;
+ gdb_assert (PyBool_Check (qualified));
symbol_name_match_type func_name_match_type
- = (qualified != NULL && PyObject_IsTrue (qualified)
- ? symbol_name_match_type::FULL
- : symbol_name_match_type::WILD);
+ = (qualified == Py_True
+ ? symbol_name_match_type::FULL
+ : symbol_name_match_type::WILD);
if (spec != NULL)
{
@@ -1055,8 +1056,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
catch (const gdb_exception &except)
{
bppy_pending_object = NULL;
- gdbpy_convert_exception (except);
- return -1;
+ return gdbpy_handle_gdb_exception (-1, except);
}
BPPY_SET_REQUIRE_VALID ((gdbpy_breakpoint_object *) self);
@@ -1116,7 +1116,7 @@ gdbpy_breakpoint_init_breakpoint_type ()
if (breakpoint_object_type.tp_new == nullptr)
{
breakpoint_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&breakpoint_object_type) < 0)
+ if (gdbpy_type_ready (&breakpoint_object_type) < 0)
{
/* Reset tp_new back to nullptr so future calls to this function
will try calling PyType_Ready again. */
@@ -1361,10 +1361,6 @@ gdbpy_initialize_breakpoints (void)
if (!gdbpy_breakpoint_init_breakpoint_type ())
return -1;
- if (gdb_pymodule_addobject (gdb_module, "Breakpoint",
- (PyObject *) &breakpoint_object_type) < 0)
- return -1;
-
gdb::observers::breakpoint_created.attach (gdbpy_breakpoint_created,
"py-breakpoint");
gdb::observers::breakpoint_deleted.attach (gdbpy_breakpoint_deleted,
@@ -1396,14 +1392,7 @@ gdbpy_initialize_breakpoints (void)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_breakpoint_locations ()
{
- if (PyType_Ready (&breakpoint_location_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_module, "BreakpointLocation",
- (PyObject *) &breakpoint_location_object_type)
- < 0)
- return -1;
- return 0;
+ return gdbpy_type_ready (&breakpoint_location_object_type);
}
@@ -1548,9 +1537,7 @@ PyTypeObject breakpoint_object_type =
0, /* tp_alloc */
};
-void _initialize_py_breakpoint ();
-void
-_initialize_py_breakpoint ()
+INIT_GDB_FILE (py_breakpoint)
{
add_setshow_boolean_cmd
("py-breakpoint", class_maintenance, &pybp_debug,
@@ -1597,7 +1584,7 @@ bplocpy_set_enabled (PyObject *py_self, PyObject *newvalue, void *closure)
}
catch (const gdb_exception &except)
{
- GDB_PY_SET_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (-1, except);
}
return 0;
}
@@ -1641,6 +1628,26 @@ bplocpy_get_owner (PyObject *py_self, void *closure)
return (PyObject *) self->owner;
}
+/* Attempt to get fully resolved file path for symtab. */
+
+static gdbpy_ref<>
+bploc_filepath (struct symtab *bploc_symtab)
+{
+ /* The exception is not ours to handle. We should always
+ return some string value and filename is never null. */
+ try
+ {
+ const char *full = symtab_to_fullname (bploc_symtab);
+ if (full)
+ return host_string_to_python_string (full);
+ }
+ catch (const gdb_exception &except)
+ {
+ }
+
+ return host_string_to_python_string (bploc_symtab->filename);
+}
+
/* Python function to get the source file name path and line number
where this breakpoint location was set. */
@@ -1655,9 +1662,7 @@ bplocpy_get_source_location (PyObject *py_self, void *closure)
gdbpy_ref<> tup (PyTuple_New (2));
if (tup == nullptr)
return nullptr;
- /* symtab->filename is never NULL. */
- gdbpy_ref<> filename
- = host_string_to_python_string (self->bp_loc->symtab->filename);
+ gdbpy_ref<> filename = bploc_filepath (self->bp_loc->symtab);
if (filename == nullptr)
return nullptr;
auto line = gdb_py_object_from_ulongest (self->bp_loc->line_number);
@@ -1702,7 +1707,7 @@ bplocpy_get_thread_groups (PyObject *py_self, void *closure)
gdbpy_ref<> num = gdb_py_object_from_ulongest (inf->num);
if (num == nullptr)
return nullptr;
- if (PyList_Append (list.get (), num.release ()) != 0)
+ if (PyList_Append (list.get (), num.get ()) != 0)
return nullptr;
}
}