]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/py: add some debugging to py-breakpoint.c
authorAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 5 May 2021 12:46:36 +0000 (13:46 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Sun, 9 May 2021 15:50:16 +0000 (16:50 +0100)
Adds some new debugging to python/py-breakpoint.c.

gdb/ChangeLog:

* python/py-breakpoint.c (pybp_debug): New static global.
(show_pybp_debug): New function.
(pybp_debug_printf): Define.
(PYBP_SCOPED_DEBUG_ENTER_EXIT): Define.
(gdbpy_breakpoint_created): Add some debugging.
(gdbpy_breakpoint_deleted): Likewise.
(gdbpy_breakpoint_modified): Likewise.
(_initialize_py_breakpoint): New function.

gdb/doc/ChangeLog:

* python.texinfo (Python Commands): Document 'set debug
py-breakpoint' and 'show debug py-breakpoint'.

gdb/ChangeLog
gdb/doc/ChangeLog
gdb/doc/python.texi
gdb/python/py-breakpoint.c

index db21675e8e2d2cfc96bc49a2e96d9270e30ef260..8fa698023410cadca17918aa3b8fc7297946559a 100644 (file)
@@ -1,3 +1,14 @@
+2021-05-09  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * python/py-breakpoint.c (pybp_debug): New static global.
+       (show_pybp_debug): New function.
+       (pybp_debug_printf): Define.
+       (PYBP_SCOPED_DEBUG_ENTER_EXIT): Define.
+       (gdbpy_breakpoint_created): Add some debugging.
+       (gdbpy_breakpoint_deleted): Likewise.
+       (gdbpy_breakpoint_modified): Likewise.
+       (_initialize_py_breakpoint): New function.
+
 2021-05-09  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * python/py-unwind.c (pyuw_debug): Convert to bool.
index a56735896c567ea4d1c06fe95edbf4cd23d1be0e..f50e32bee3d4a892e85ce054640933f1e3c1435d 100644 (file)
@@ -1,3 +1,8 @@
+2021-05-09  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * python.texinfo (Python Commands): Document 'set debug
+       py-breakpoint' and 'show debug py-breakpoint'.
+
 2021-05-07  Tom de Vries  <tdevries@suse.de>
 
        PR symtab/26327
index 482d328de44a93b91afa3bb8aa9ffde3a85d3aca..18e578a68323641a2fc7f4d9396ff4ce7979929b 100644 (file)
@@ -153,6 +153,17 @@ to recognize the script language based on filename extension using
 the @code{script-extension} setting.  @xref{Extending GDB, ,Extending GDB}.
 @end table
 
+The following commands are intended to help debug @value{GDBN} itself:
+
+@table @code
+@kindex set debug py-breakpoint
+@kindex show debug py-breakpoint
+@item set debug py-breakpoint on@r{|}off
+@itemx show debug py-breakpoint
+When @samp{on}, @value{GDBN} prints debug messages related to the
+Python breakpoint API.  This is @samp{off} by default.
+@end table
+
 @node Python API
 @subsection Python API
 @cindex python api
index b41407136136a6f82b7e4e97c74607fa2e489f25..4710f3e9e6a6f70b95f62bd70a0ddad7b58093bd 100644 (file)
 #include "py-event.h"
 #include "linespec.h"
 
+/* Debugging of Python breakpoints.  */
+
+static bool pybp_debug;
+
+/* Implementation of "show debug py-breakpoint".  */
+
+static void
+show_pybp_debug (struct ui_file *file, int from_tty,
+                struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Python breakpoint debugging is %s.\n"), value);
+}
+
+/* Print a "py-breakpoint" debug statement.  */
+
+#define pybp_debug_printf(fmt, ...) \
+  debug_prefixed_printf_cond (pybp_debug, "py-breakpoint", fmt, ##__VA_ARGS__)
+
+/* Print a "py-breakpoint" enter/exit debug statements.  */
+
+#define PYBP_SCOPED_DEBUG_ENTER_EXIT \
+  scoped_debug_enter_exit (pybp_debug, "py-breakpoint")
+
 /* Number of live breakpoints.  */
 static int bppy_live;
 
@@ -1005,10 +1028,15 @@ gdbpy_breakpoint_has_cond (const struct extension_language_defn *extlang,
 static void
 gdbpy_breakpoint_created (struct breakpoint *bp)
 {
+  PYBP_SCOPED_DEBUG_ENTER_EXIT;
+
   gdbpy_breakpoint_object *newbp;
 
   if (!user_breakpoint_p (bp) && bppy_pending_object == NULL)
-    return;
+    {
+      pybp_debug_printf ("not attaching python object to this breakpoint");
+      return;
+    }
 
   if (bp->type != bp_breakpoint
       && bp->type != bp_hardware_breakpoint
@@ -1016,7 +1044,10 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
       && bp->type != bp_hardware_watchpoint
       && bp->type != bp_read_watchpoint
       && bp->type != bp_access_watchpoint)
-    return;
+    {
+      pybp_debug_printf ("is not a breakpoint or watchpoint");
+      return;
+    }
 
   struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch ();
   gdbpy_enter enter_py (garch, current_language);
@@ -1026,9 +1057,13 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
       newbp = bppy_pending_object;
       Py_INCREF (newbp);
       bppy_pending_object = NULL;
+      pybp_debug_printf ("attaching existing breakpoint object");
     }
   else
-    newbp = PyObject_New (gdbpy_breakpoint_object, &breakpoint_object_type);
+    {
+      newbp = PyObject_New (gdbpy_breakpoint_object, &breakpoint_object_type);
+      pybp_debug_printf ("attaching new breakpoint object");
+    }
   if (newbp)
     {
       newbp->number = bp->number;
@@ -1057,6 +1092,8 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
 static void
 gdbpy_breakpoint_deleted (struct breakpoint *b)
 {
+  PYBP_SCOPED_DEBUG_ENTER_EXIT;
+
   int num = b->number;
   struct breakpoint *bp = NULL;
 
@@ -1087,6 +1124,8 @@ gdbpy_breakpoint_deleted (struct breakpoint *b)
 static void
 gdbpy_breakpoint_modified (struct breakpoint *b)
 {
+  PYBP_SCOPED_DEBUG_ENTER_EXIT;
+
   int num = b->number;
   struct breakpoint *bp = NULL;
 
@@ -1285,3 +1324,17 @@ PyTypeObject breakpoint_object_type =
   bppy_init,                     /* tp_init */
   0,                             /* tp_alloc */
 };
+
+void _initialize_py_breakpoint ();
+void
+_initialize_py_breakpoint ()
+{
+  add_setshow_boolean_cmd
+      ("py-breakpoint", class_maintenance, &pybp_debug,
+       _("Set Python breakpoint debugging."),
+       _("Show Python breakpoint debugging."),
+       _("When on, Python breakpoint debugging is enabled."),
+       NULL,
+       show_pybp_debug,
+       &setdebuglist, &showdebuglist);
+}