1 /* Python interface to breakpoints
3 Copyright (C) 2008-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "python-internal.h"
24 #include "breakpoint.h"
25 #include "cli/cli-cmds.h"
26 #include "gdbthread.h"
27 #include "observable.h"
28 #include "cli/cli-script.h"
30 #include "arch-utils.h"
35 #include "gdbsupport/common-utils.h"
37 extern PyTypeObject breakpoint_location_object_type
38 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("breakpoint_location_object");
40 struct gdbpy_breakpoint_location_object
44 /* An owning reference to the gdb breakpoint location object. */
47 /* An owning reference to the location's breakpoint owner. */
48 gdbpy_breakpoint_object
*owner
;
51 /* Require that BREAKPOINT and LOCATION->OWNER are the same; throw a Python
52 exception if they are not. */
53 #define BPLOCPY_REQUIRE_VALID(Breakpoint, Location) \
55 if ((Breakpoint)->bp != (Location)->bp_loc->owner) \
56 return PyErr_Format (PyExc_RuntimeError, \
57 _("Breakpoint location is invalid.")); \
60 /* Require that BREAKPOINT and LOCATION->OWNER are the same; throw a Python
61 exception if they are not. This macro is for use in setter functions. */
62 #define BPLOCPY_SET_REQUIRE_VALID(Breakpoint, Location) \
64 if ((Breakpoint)->bp != (Location)->bp_loc->owner) \
66 PyErr_Format (PyExc_RuntimeError, \
67 _("Breakpoint location is invalid.")); \
72 /* Debugging of Python breakpoints. */
74 static bool pybp_debug
;
76 /* Implementation of "show debug py-breakpoint". */
79 show_pybp_debug (struct ui_file
*file
, int from_tty
,
80 struct cmd_list_element
*c
, const char *value
)
82 gdb_printf (file
, _("Python breakpoint debugging is %s.\n"), value
);
85 /* Print a "py-breakpoint" debug statement. */
87 #define pybp_debug_printf(fmt, ...) \
88 debug_prefixed_printf_cond (pybp_debug, "py-breakpoint", fmt, ##__VA_ARGS__)
90 /* Print a "py-breakpoint" enter/exit debug statements. */
92 #define PYBP_SCOPED_DEBUG_ENTER_EXIT \
93 scoped_debug_enter_exit (pybp_debug, "py-breakpoint")
95 /* Number of live breakpoints. */
98 /* Variables used to pass information between the Breakpoint
99 constructor and the breakpoint-created hook function. */
100 gdbpy_breakpoint_object
*bppy_pending_object
;
102 /* Function that is called when a Python condition is evaluated. */
103 static const char stop_func
[] = "stop";
105 /* This is used to initialize various gdb.bp_* constants. */
114 /* Entries related to the type of user set breakpoints. */
115 static struct pybp_code pybp_codes
[] =
117 { "BP_NONE", bp_none
},
118 { "BP_BREAKPOINT", bp_breakpoint
},
119 { "BP_HARDWARE_BREAKPOINT", bp_hardware_breakpoint
},
120 { "BP_WATCHPOINT", bp_watchpoint
},
121 { "BP_HARDWARE_WATCHPOINT", bp_hardware_watchpoint
},
122 { "BP_READ_WATCHPOINT", bp_read_watchpoint
},
123 { "BP_ACCESS_WATCHPOINT", bp_access_watchpoint
},
124 { "BP_CATCHPOINT", bp_catchpoint
},
125 {NULL
} /* Sentinel. */
128 /* Entries related to the type of watchpoint. */
129 static struct pybp_code pybp_watch_types
[] =
131 { "WP_READ", hw_read
},
132 { "WP_WRITE", hw_write
},
133 { "WP_ACCESS", hw_access
},
134 {NULL
} /* Sentinel. */
137 /* Python function which checks the validity of a breakpoint object. */
139 bppy_is_valid (PyObject
*self
, PyObject
*args
)
141 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
148 /* Python function to test whether or not the breakpoint is enabled. */
150 bppy_get_enabled (PyObject
*self
, void *closure
)
152 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
154 BPPY_REQUIRE_VALID (self_bp
);
157 if (self_bp
->bp
->enable_state
== bp_enabled
)
162 /* Python function to test whether or not the breakpoint is silent. */
164 bppy_get_silent (PyObject
*self
, void *closure
)
166 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
168 BPPY_REQUIRE_VALID (self_bp
);
169 if (self_bp
->bp
->silent
)
174 /* Python function to set the enabled state of a breakpoint. */
176 bppy_set_enabled (PyObject
*self
, PyObject
*newvalue
, void *closure
)
178 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
181 BPPY_SET_REQUIRE_VALID (self_bp
);
183 if (newvalue
== NULL
)
185 PyErr_SetString (PyExc_TypeError
,
186 _("Cannot delete `enabled' attribute."));
190 else if (! PyBool_Check (newvalue
))
192 PyErr_SetString (PyExc_TypeError
,
193 _("The value of `enabled' must be a boolean."));
197 cmp
= PyObject_IsTrue (newvalue
);
204 enable_breakpoint (self_bp
->bp
);
206 disable_breakpoint (self_bp
->bp
);
208 catch (const gdb_exception
&except
)
210 return gdbpy_handle_gdb_exception (-1, except
);
216 /* Python function to set the 'silent' state of a breakpoint. */
218 bppy_set_silent (PyObject
*self
, PyObject
*newvalue
, void *closure
)
220 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
223 BPPY_SET_REQUIRE_VALID (self_bp
);
225 if (newvalue
== NULL
)
227 PyErr_SetString (PyExc_TypeError
,
228 _("Cannot delete `silent' attribute."));
231 else if (! PyBool_Check (newvalue
))
233 PyErr_SetString (PyExc_TypeError
,
234 _("The value of `silent' must be a boolean."));
238 cmp
= PyObject_IsTrue (newvalue
);
242 breakpoint_set_silent (self_bp
->bp
, cmp
);
247 /* Python function to set the thread of a breakpoint. */
249 bppy_set_thread (PyObject
*self
, PyObject
*newvalue
, void *closure
)
251 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
254 BPPY_SET_REQUIRE_VALID (self_bp
);
256 if (newvalue
== NULL
)
258 PyErr_SetString (PyExc_TypeError
,
259 _("Cannot delete `thread' attribute."));
262 else if (PyLong_Check (newvalue
))
264 if (! gdb_py_int_as_long (newvalue
, &id
))
267 if (!valid_global_thread_id (id
))
269 PyErr_SetString (PyExc_RuntimeError
,
270 _("Invalid thread ID."));
274 if (self_bp
->bp
->task
!= -1)
276 PyErr_SetString (PyExc_RuntimeError
,
277 _("Cannot set both task and thread attributes."));
281 else if (newvalue
== Py_None
)
285 PyErr_SetString (PyExc_TypeError
,
286 _("The value of `thread' must be an integer or None."));
290 if (self_bp
->bp
->inferior
!= -1 && id
!= -1)
292 PyErr_SetString (PyExc_RuntimeError
,
293 _("Cannot have both 'thread' and 'inferior' "
294 "conditions on a breakpoint"));
298 breakpoint_set_thread (self_bp
->bp
, id
);
303 /* Python function to set the inferior of a breakpoint. */
306 bppy_set_inferior (PyObject
*self
, PyObject
*newvalue
, void *closure
)
308 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
311 BPPY_SET_REQUIRE_VALID (self_bp
);
313 if (newvalue
== NULL
)
315 PyErr_SetString (PyExc_TypeError
,
316 _("Cannot delete 'inferior' attribute."));
319 else if (PyLong_Check (newvalue
))
321 if (!gdb_py_int_as_long (newvalue
, &id
))
324 if (!valid_global_inferior_id (id
))
326 PyErr_SetString (PyExc_RuntimeError
,
327 _("Invalid inferior ID."));
331 else if (newvalue
== Py_None
)
335 PyErr_SetString (PyExc_TypeError
,
336 _("The value of 'inferior' must be an integer or None."));
340 if (self_bp
->bp
->type
!= bp_breakpoint
341 && self_bp
->bp
->type
!= bp_hardware_breakpoint
)
343 PyErr_SetString (PyExc_RuntimeError
,
344 _("Cannot set 'inferior' attribute on a gdb.Breakpoint "
349 if (self_bp
->bp
->thread
!= -1 && id
!= -1)
351 PyErr_SetString (PyExc_RuntimeError
,
352 _("Cannot have both 'thread' and 'inferior' conditions "
357 if (self_bp
->bp
->task
!= -1 && id
!= -1)
359 PyErr_SetString (PyExc_RuntimeError
,
360 _("Cannot have both 'task' and 'inferior' conditions "
365 breakpoint_set_inferior (self_bp
->bp
, id
);
370 /* Python function to set the (Ada) task of a breakpoint. */
372 bppy_set_task (PyObject
*self
, PyObject
*newvalue
, void *closure
)
374 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
378 BPPY_SET_REQUIRE_VALID (self_bp
);
380 if (newvalue
== NULL
)
382 PyErr_SetString (PyExc_TypeError
,
383 _("Cannot delete `task' attribute."));
386 else if (PyLong_Check (newvalue
))
388 if (! gdb_py_int_as_long (newvalue
, &id
))
393 valid_id
= valid_task_id (id
);
395 catch (const gdb_exception
&except
)
397 return gdbpy_handle_gdb_exception (-1, except
);
402 PyErr_SetString (PyExc_RuntimeError
,
403 _("Invalid task ID."));
407 if (self_bp
->bp
->thread
!= -1)
409 PyErr_SetString (PyExc_RuntimeError
,
410 _("Cannot set both task and thread attributes."));
414 else if (newvalue
== Py_None
)
418 PyErr_SetString (PyExc_TypeError
,
419 _("The value of `task' must be an integer or None."));
423 breakpoint_set_task (self_bp
->bp
, id
);
428 /* Python function which deletes the underlying GDB breakpoint. This
429 triggers the breakpoint_deleted observer which will call
430 gdbpy_breakpoint_deleted; that function cleans up the Python
434 bppy_delete_breakpoint (PyObject
*self
, PyObject
*args
)
436 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
438 BPPY_REQUIRE_VALID (self_bp
);
442 delete_breakpoint (self_bp
->bp
);
444 catch (const gdb_exception
&except
)
446 return gdbpy_handle_gdb_exception (nullptr, except
);
453 /* Python function to set the ignore count of a breakpoint. */
455 bppy_set_ignore_count (PyObject
*self
, PyObject
*newvalue
, void *closure
)
457 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
460 BPPY_SET_REQUIRE_VALID (self_bp
);
462 if (newvalue
== NULL
)
464 PyErr_SetString (PyExc_TypeError
,
465 _("Cannot delete `ignore_count' attribute."));
468 else if (!PyLong_Check (newvalue
))
470 PyErr_SetString (PyExc_TypeError
,
471 _("The value of `ignore_count' must be an integer."));
475 if (! gdb_py_int_as_long (newvalue
, &value
))
483 set_ignore_count (self_bp
->number
, (int) value
, 0);
485 catch (const gdb_exception
&except
)
487 return gdbpy_handle_gdb_exception (-1, except
);
493 /* Python function to set the hit count of a breakpoint. */
495 bppy_set_hit_count (PyObject
*self
, PyObject
*newvalue
, void *closure
)
497 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
499 BPPY_SET_REQUIRE_VALID (self_bp
);
501 if (newvalue
== NULL
)
503 PyErr_SetString (PyExc_TypeError
,
504 _("Cannot delete `hit_count' attribute."));
511 if (! gdb_py_int_as_long (newvalue
, &value
))
516 PyErr_SetString (PyExc_AttributeError
,
517 _("The value of `hit_count' must be zero."));
522 self_bp
->bp
->hit_count
= 0;
527 /* Python function to get the location of a breakpoint. */
529 bppy_get_location (PyObject
*self
, void *closure
)
531 gdbpy_breakpoint_object
*obj
= (gdbpy_breakpoint_object
*) self
;
533 BPPY_REQUIRE_VALID (obj
);
535 if (obj
->bp
->type
!= bp_breakpoint
536 && obj
->bp
->type
!= bp_hardware_breakpoint
)
539 const char *str
= obj
->bp
->locspec
->to_string ();
542 return host_string_to_python_string (str
).release ();
545 /* Python function to get the breakpoint expression. */
547 bppy_get_expression (PyObject
*self
, void *closure
)
550 gdbpy_breakpoint_object
*obj
= (gdbpy_breakpoint_object
*) self
;
552 BPPY_REQUIRE_VALID (obj
);
554 if (!is_watchpoint (obj
->bp
))
557 watchpoint
*wp
= gdb::checked_static_cast
<watchpoint
*> (obj
->bp
);
559 str
= wp
->exp_string
.get ();
563 return host_string_to_python_string (str
).release ();
566 /* Python function to get the condition expression of a breakpoint. */
568 bppy_get_condition (PyObject
*self
, void *closure
)
571 gdbpy_breakpoint_object
*obj
= (gdbpy_breakpoint_object
*) self
;
573 BPPY_REQUIRE_VALID (obj
);
575 str
= obj
->bp
->cond_string
.get ();
579 return host_string_to_python_string (str
).release ();
582 /* Returns 0 on success. Returns -1 on error, with a python exception set.
586 bppy_set_condition (PyObject
*self
, PyObject
*newvalue
, void *closure
)
588 gdb::unique_xmalloc_ptr
<char> exp_holder
;
589 const char *exp
= NULL
;
590 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
592 BPPY_SET_REQUIRE_VALID (self_bp
);
594 if (newvalue
== NULL
)
596 PyErr_SetString (PyExc_TypeError
,
597 _("Cannot delete `condition' attribute."));
600 else if (newvalue
== Py_None
)
604 exp_holder
= python_string_to_host_string (newvalue
);
605 if (exp_holder
== NULL
)
607 exp
= exp_holder
.get ();
612 set_breakpoint_condition (self_bp
->bp
, exp
, 0, false);
614 catch (const gdb_exception
&ex
)
616 return gdbpy_handle_gdb_exception (-1, ex
);
622 /* Python function to get the commands attached to a breakpoint. */
624 bppy_get_commands (PyObject
*self
, void *closure
)
626 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
627 struct breakpoint
*bp
= self_bp
->bp
;
629 BPPY_REQUIRE_VALID (self_bp
);
631 if (! self_bp
->bp
->commands
)
638 ui_out_redirect_pop
redir (current_uiout
, &stb
);
639 print_command_lines (current_uiout
, breakpoint_commands (bp
), 0);
641 catch (const gdb_exception
&except
)
643 return gdbpy_handle_gdb_exception (nullptr, except
);
646 return host_string_to_python_string (stb
.c_str ()).release ();
649 /* Set the commands attached to a breakpoint. Returns 0 on success.
650 Returns -1 on error, with a python exception set. */
652 bppy_set_commands (PyObject
*self
, PyObject
*newvalue
, void *closure
)
654 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
656 BPPY_SET_REQUIRE_VALID (self_bp
);
658 gdb::unique_xmalloc_ptr
<char> commands
659 (python_string_to_host_string (newvalue
));
660 if (commands
== nullptr)
666 char *save_ptr
= nullptr;
668 = [&] (std::string
&buffer
)
670 const char *result
= strtok_r (first
? commands
.get () : nullptr,
676 counted_command_line lines
= read_command_lines_1 (reader
, 1, nullptr);
677 breakpoint_set_commands (self_bp
->bp
, std::move (lines
));
679 catch (const gdb_exception
&ex
)
681 return gdbpy_handle_gdb_exception (-1, ex
);
687 /* Python function to get the breakpoint type. */
689 bppy_get_type (PyObject
*self
, void *closure
)
691 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
693 BPPY_REQUIRE_VALID (self_bp
);
695 return gdb_py_object_from_longest (self_bp
->bp
->type
).release ();
698 /* Python function to get the visibility of the breakpoint. */
701 bppy_get_visibility (PyObject
*self
, void *closure
)
703 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
705 BPPY_REQUIRE_VALID (self_bp
);
707 if (user_breakpoint_p (self_bp
->bp
))
713 /* Python function to determine if the breakpoint is a temporary
717 bppy_get_temporary (PyObject
*self
, void *closure
)
719 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
721 BPPY_REQUIRE_VALID (self_bp
);
723 if (self_bp
->bp
->disposition
== disp_del
724 || self_bp
->bp
->disposition
== disp_del_at_next_stop
)
730 /* Python function to determine if the breakpoint is a pending
734 bppy_get_pending (PyObject
*self
, void *closure
)
736 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
738 BPPY_REQUIRE_VALID (self_bp
);
740 if (is_watchpoint (self_bp
->bp
))
742 if (pending_breakpoint_p (self_bp
->bp
))
748 /* Python function to get the breakpoint's number. */
750 bppy_get_number (PyObject
*self
, void *closure
)
752 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
754 BPPY_REQUIRE_VALID (self_bp
);
756 return gdb_py_object_from_longest (self_bp
->number
).release ();
759 /* Python function to get the breakpoint's thread ID. */
761 bppy_get_thread (PyObject
*self
, void *closure
)
763 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
765 BPPY_REQUIRE_VALID (self_bp
);
767 if (self_bp
->bp
->thread
== -1)
770 return gdb_py_object_from_longest (self_bp
->bp
->thread
).release ();
773 /* Python function to get the breakpoint's inferior ID. */
775 bppy_get_inferior (PyObject
*self
, void *closure
)
777 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
779 BPPY_REQUIRE_VALID (self_bp
);
781 if (self_bp
->bp
->inferior
== -1)
784 return gdb_py_object_from_longest (self_bp
->bp
->inferior
).release ();
787 /* Python function to get the breakpoint's task ID (in Ada). */
789 bppy_get_task (PyObject
*self
, void *closure
)
791 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
793 BPPY_REQUIRE_VALID (self_bp
);
795 if (self_bp
->bp
->task
== -1)
798 return gdb_py_object_from_longest (self_bp
->bp
->task
).release ();
801 /* Python function to get the breakpoint's hit count. */
803 bppy_get_hit_count (PyObject
*self
, void *closure
)
805 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
807 BPPY_REQUIRE_VALID (self_bp
);
809 return gdb_py_object_from_longest (self_bp
->bp
->hit_count
).release ();
812 /* Python function to get the breakpoint's ignore count. */
814 bppy_get_ignore_count (PyObject
*self
, void *closure
)
816 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
818 BPPY_REQUIRE_VALID (self_bp
);
820 return gdb_py_object_from_longest (self_bp
->bp
->ignore_count
).release ();
823 /* Python function to get the breakpoint locations of an owner breakpoint. */
826 bppy_get_locations (PyObject
*self
, void *closure
)
828 using py_bploc_t
= gdbpy_breakpoint_location_object
;
829 auto *self_bp
= (gdbpy_breakpoint_object
*) self
;
830 BPPY_REQUIRE_VALID (self_bp
);
832 gdbpy_ref
<> list (PyList_New (0));
836 for (bp_location
&loc
: self_bp
->bp
->locations ())
838 gdbpy_ref
<py_bploc_t
> py_bploc
839 (PyObject_New (py_bploc_t
, &breakpoint_location_object_type
));
840 if (py_bploc
== nullptr)
843 bp_location_ref_ptr ref
= bp_location_ref_ptr::new_reference (&loc
);
844 /* The location takes a reference to the owner breakpoint.
845 Decrements when they are de-allocated in bplocpy_dealloc */
847 py_bploc
->owner
= self_bp
;
848 py_bploc
->bp_loc
= ref
.release ();
849 if (PyList_Append (list
.get (), (PyObject
*) py_bploc
.get ()) != 0)
852 return list
.release ();
855 /* Internal function to validate the Python parameters/keywords
856 provided to bppy_init. */
859 bppy_init_validate_args (const char *spec
, char *source
,
860 char *function
, char *label
,
861 char *line
, enum bptype type
)
863 /* If spec is defined, ensure that none of the explicit location
864 keywords are also defined. */
867 if (source
!= NULL
|| function
!= NULL
|| label
!= NULL
|| line
!= NULL
)
869 PyErr_SetString (PyExc_RuntimeError
,
870 _("Breakpoints specified with spec cannot "
871 "have source, function, label or line defined."));
877 /* If spec isn't defined, ensure that the user is not trying to
878 define a watchpoint with an explicit location. */
879 if (type
== bp_watchpoint
)
881 PyErr_SetString (PyExc_RuntimeError
,
882 _("Watchpoints cannot be set by explicit "
883 "location parameters."));
888 /* Otherwise, ensure some explicit locations are defined. */
889 if (source
== NULL
&& function
== NULL
&& label
== NULL
892 PyErr_SetString (PyExc_RuntimeError
,
893 _("Neither spec nor explicit location set."));
896 /* Finally, if source is specified, ensure that line, label
897 or function are specified too. */
898 if (source
!= NULL
&& function
== NULL
&& label
== NULL
901 PyErr_SetString (PyExc_RuntimeError
,
902 _("Specifying a source must also include a "
903 "line, label or function."));
911 /* Python function to create a new breakpoint. */
913 bppy_init (PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
915 static const char *keywords
[] = { "spec", "type", "wp_class", "internal",
916 "temporary","source", "function",
917 "label", "line", "qualified", NULL
};
918 const char *spec
= NULL
;
919 enum bptype type
= bp_breakpoint
;
920 int access_type
= hw_write
;
921 PyObject
*internal
= NULL
;
922 PyObject
*temporary
= NULL
;
923 PyObject
*lineobj
= NULL
;;
925 int temporary_bp
= 0;
926 gdb::unique_xmalloc_ptr
<char> line
;
929 char *function
= NULL
;
930 PyObject
* qualified
= NULL
;
932 if (!gdb_PyArg_ParseTupleAndKeywords (args
, kwargs
, "|siiOOsssOO", keywords
,
933 &spec
, &type
, &access_type
,
936 &function
, &label
, &lineobj
,
943 if (PyLong_Check (lineobj
))
944 line
= xstrprintf ("%ld", PyLong_AsLong (lineobj
));
945 else if (PyUnicode_Check (lineobj
))
946 line
= python_string_to_host_string (lineobj
);
949 PyErr_SetString (PyExc_RuntimeError
,
950 _("Line keyword should be an integer or a string. "));
957 internal_bp
= PyObject_IsTrue (internal
);
958 if (internal_bp
== -1)
962 if (temporary
!= NULL
)
964 temporary_bp
= PyObject_IsTrue (temporary
);
965 if (temporary_bp
== -1)
969 if (bppy_init_validate_args (spec
, source
, function
, label
, line
.get (),
973 bppy_pending_object
= (gdbpy_breakpoint_object
*) self
;
974 bppy_pending_object
->number
= -1;
975 bppy_pending_object
->bp
= NULL
;
982 case bp_hardware_breakpoint
:
984 location_spec_up locspec
;
985 symbol_name_match_type func_name_match_type
986 = (qualified
!= NULL
&& PyObject_IsTrue (qualified
)
987 ? symbol_name_match_type::FULL
988 : symbol_name_match_type::WILD
);
992 gdb::unique_xmalloc_ptr
<char>
993 copy_holder (xstrdup (skip_spaces (spec
)));
994 const char *copy
= copy_holder
.get ();
996 locspec
= string_to_location_spec (©
,
998 func_name_match_type
);
1002 std::unique_ptr
<explicit_location_spec
> explicit_loc
1003 (new explicit_location_spec ());
1005 if (source
!= nullptr)
1006 explicit_loc
->source_filename
= make_unique_xstrdup (source
);
1007 if (function
!= nullptr)
1008 explicit_loc
->function_name
= make_unique_xstrdup (function
);
1009 if (label
!= nullptr)
1010 explicit_loc
->label_name
= make_unique_xstrdup (label
);
1013 explicit_loc
->line_offset
1014 = linespec_parse_line_offset (line
.get ());
1016 explicit_loc
->func_name_match_type
= func_name_match_type
;
1018 locspec
.reset (explicit_loc
.release ());
1021 const struct breakpoint_ops
*ops
1022 = breakpoint_ops_for_location_spec (locspec
.get (), false);
1024 create_breakpoint (gdbpy_enter::get_gdbarch (),
1025 locspec
.get (), NULL
, -1, -1, NULL
, false,
1031 0, 1, internal_bp
, 0);
1036 spec
= skip_spaces (spec
);
1038 if (access_type
== hw_write
)
1039 watch_command_wrapper (spec
, 0, internal_bp
);
1040 else if (access_type
== hw_access
)
1041 awatch_command_wrapper (spec
, 0, internal_bp
);
1042 else if (access_type
== hw_read
)
1043 rwatch_command_wrapper (spec
, 0, internal_bp
);
1045 error(_("Cannot understand watchpoint access type."));
1049 error (_("BP_CATCHPOINT not supported"));
1051 error(_("Do not understand breakpoint type to set."));
1054 catch (const gdb_exception
&except
)
1056 bppy_pending_object
= NULL
;
1057 return gdbpy_handle_gdb_exception (-1, except
);
1060 BPPY_SET_REQUIRE_VALID ((gdbpy_breakpoint_object
*) self
);
1064 /* __repr__ implementation for gdb.Breakpoint. */
1067 bppy_repr (PyObject
*self
)
1069 const auto bp
= (struct gdbpy_breakpoint_object
*) self
;
1070 if (bp
->bp
== nullptr)
1071 return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self
)->tp_name
);
1073 std::string str
= " ";
1074 if (bp
->bp
->thread
!= -1)
1075 str
+= string_printf ("thread=%d ", bp
->bp
->thread
);
1076 if (bp
->bp
->task
> 0)
1077 str
+= string_printf ("task=%d ", bp
->bp
->task
);
1078 if (bp
->bp
->enable_count
> 0)
1079 str
+= string_printf ("enable_count=%d ", bp
->bp
->enable_count
);
1082 return PyUnicode_FromFormat ("<%s%s number=%d hits=%d%s>",
1083 Py_TYPE (self
)->tp_name
,
1084 (bp
->bp
->enable_state
== bp_enabled
1085 ? "" : " disabled"), bp
->bp
->number
,
1086 bp
->bp
->hit_count
, str
.c_str ());
1089 /* Append to LIST the breakpoint Python object associated to B.
1091 Return true on success. Return false on failure, with the Python error
1095 build_bp_list (struct breakpoint
*b
, PyObject
*list
)
1097 PyObject
*bp
= (PyObject
*) b
->py_bp_object
;
1099 /* Not all breakpoints will have a companion Python object.
1100 Only breakpoints that were created via bppy_new, or
1101 breakpoints that were created externally and are tracked by
1102 the Python Scripting API. */
1106 return PyList_Append (list
, bp
) == 0;
1109 /* See python-internal.h. */
1112 gdbpy_breakpoint_init_breakpoint_type ()
1114 if (breakpoint_object_type
.tp_new
== nullptr)
1116 breakpoint_object_type
.tp_new
= PyType_GenericNew
;
1117 if (gdbpy_type_ready (&breakpoint_object_type
) < 0)
1119 /* Reset tp_new back to nullptr so future calls to this function
1120 will try calling PyType_Ready again. */
1121 breakpoint_object_type
.tp_new
= nullptr;
1129 /* Static function to return a tuple holding all breakpoints. */
1132 gdbpy_breakpoints (PyObject
*self
, PyObject
*args
)
1135 return PyTuple_New (0);
1137 gdbpy_ref
<> list (PyList_New (0));
1141 /* If build_bp_list returns false, it signals an error condition. In that
1142 case abandon building the list and return nullptr. */
1143 for (breakpoint
&bp
: all_breakpoints ())
1144 if (!build_bp_list (&bp
, list
.get ()))
1147 return PyList_AsTuple (list
.get ());
1150 /* Call the "stop" method (if implemented) in the breakpoint
1151 class. If the method returns True, the inferior will be
1152 stopped at the breakpoint. Otherwise the inferior will be
1153 allowed to continue. */
1155 enum ext_lang_bp_stop
1156 gdbpy_breakpoint_cond_says_stop (const struct extension_language_defn
*extlang
,
1157 struct breakpoint
*b
)
1160 struct gdbpy_breakpoint_object
*bp_obj
= b
->py_bp_object
;
1161 PyObject
*py_bp
= (PyObject
*) bp_obj
;
1164 return EXT_LANG_BP_STOP_UNSET
;
1168 gdbpy_enter
enter_py (b
->gdbarch
);
1170 if (bp_obj
->is_finish_bp
)
1171 bpfinishpy_pre_stop_hook (bp_obj
);
1173 if (PyObject_HasAttrString (py_bp
, stop_func
))
1175 gdbpy_ref
<> result
= gdbpy_call_method (py_bp
, stop_func
);
1180 int evaluate
= PyObject_IsTrue (result
.get ());
1183 gdbpy_print_stack ();
1185 /* If the "stop" function returns False that means
1186 the Python breakpoint wants GDB to continue. */
1191 gdbpy_print_stack ();
1194 if (bp_obj
->is_finish_bp
)
1195 bpfinishpy_post_stop_hook (bp_obj
);
1198 return EXT_LANG_BP_STOP_UNSET
;
1199 return stop
? EXT_LANG_BP_STOP_YES
: EXT_LANG_BP_STOP_NO
;
1202 /* Checks if the "stop" method exists in this breakpoint.
1203 Used by condition_command to ensure mutual exclusion of breakpoint
1207 gdbpy_breakpoint_has_cond (const struct extension_language_defn
*extlang
,
1208 struct breakpoint
*b
)
1212 if (b
->py_bp_object
== NULL
)
1215 py_bp
= (PyObject
*) b
->py_bp_object
;
1217 gdbpy_enter
enter_py (b
->gdbarch
);
1218 return PyObject_HasAttrString (py_bp
, stop_func
);
1223 /* Event callback functions. */
1225 /* Callback that is used when a breakpoint is created. This function
1226 will create a new Python breakpoint object. */
1228 gdbpy_breakpoint_created (struct breakpoint
*bp
)
1230 PYBP_SCOPED_DEBUG_ENTER_EXIT
;
1232 gdbpy_breakpoint_object
*newbp
;
1234 if (!user_breakpoint_p (bp
) && bppy_pending_object
== NULL
)
1236 pybp_debug_printf ("not attaching python object to this breakpoint");
1240 if (bp
->type
!= bp_breakpoint
1241 && bp
->type
!= bp_hardware_breakpoint
1242 && bp
->type
!= bp_watchpoint
1243 && bp
->type
!= bp_hardware_watchpoint
1244 && bp
->type
!= bp_read_watchpoint
1245 && bp
->type
!= bp_access_watchpoint
1246 && bp
->type
!= bp_catchpoint
)
1248 pybp_debug_printf ("is not a breakpoint or watchpoint");
1252 gdbpy_enter
enter_py (bp
->gdbarch
);
1254 if (bppy_pending_object
)
1256 newbp
= bppy_pending_object
;
1258 bppy_pending_object
= NULL
;
1259 pybp_debug_printf ("attaching existing breakpoint object");
1263 newbp
= PyObject_New (gdbpy_breakpoint_object
, &breakpoint_object_type
);
1264 pybp_debug_printf ("attaching new breakpoint object");
1268 newbp
->number
= bp
->number
;
1270 newbp
->bp
->py_bp_object
= newbp
;
1271 newbp
->is_finish_bp
= 0;
1276 PyErr_SetString (PyExc_RuntimeError
,
1277 _("Error while creating breakpoint from GDB."));
1278 gdbpy_print_stack ();
1281 if (!evregpy_no_listeners_p (gdb_py_events
.breakpoint_created
))
1283 if (evpy_emit_event ((PyObject
*) newbp
,
1284 gdb_py_events
.breakpoint_created
) < 0)
1285 gdbpy_print_stack ();
1289 /* Callback that is used when a breakpoint is deleted. This will
1290 invalidate the corresponding Python object. */
1292 gdbpy_breakpoint_deleted (struct breakpoint
*b
)
1294 PYBP_SCOPED_DEBUG_ENTER_EXIT
;
1296 int num
= b
->number
;
1297 struct breakpoint
*bp
= NULL
;
1299 bp
= get_breakpoint (num
);
1302 gdbpy_enter
enter_py (b
->gdbarch
);
1304 gdbpy_ref
<gdbpy_breakpoint_object
> bp_obj (bp
->py_bp_object
);
1307 if (bp_obj
->is_finish_bp
)
1308 bpfinishpy_pre_delete_hook (bp_obj
.get ());
1310 if (!evregpy_no_listeners_p (gdb_py_events
.breakpoint_deleted
))
1312 if (evpy_emit_event ((PyObject
*) bp_obj
.get (),
1313 gdb_py_events
.breakpoint_deleted
) < 0)
1314 gdbpy_print_stack ();
1323 /* Callback that is used when a breakpoint is modified. */
1326 gdbpy_breakpoint_modified (struct breakpoint
*b
)
1328 PYBP_SCOPED_DEBUG_ENTER_EXIT
;
1330 int num
= b
->number
;
1331 struct breakpoint
*bp
= NULL
;
1333 bp
= get_breakpoint (num
);
1336 gdbpy_enter
enter_py (b
->gdbarch
);
1338 PyObject
*bp_obj
= (PyObject
*) bp
->py_bp_object
;
1341 if (!evregpy_no_listeners_p (gdb_py_events
.breakpoint_modified
))
1343 if (evpy_emit_event (bp_obj
,
1344 gdb_py_events
.breakpoint_modified
) < 0)
1345 gdbpy_print_stack ();
1353 /* Initialize the Python breakpoint code. */
1354 static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
1355 gdbpy_initialize_breakpoints (void)
1359 if (!gdbpy_breakpoint_init_breakpoint_type ())
1362 gdb::observers::breakpoint_created
.attach (gdbpy_breakpoint_created
,
1364 gdb::observers::breakpoint_deleted
.attach (gdbpy_breakpoint_deleted
,
1366 gdb::observers::breakpoint_modified
.attach (gdbpy_breakpoint_modified
,
1369 /* Add breakpoint types constants. */
1370 for (i
= 0; pybp_codes
[i
].name
; ++i
)
1372 if (PyModule_AddIntConstant (gdb_module
, pybp_codes
[i
].name
,
1373 pybp_codes
[i
].code
) < 0)
1377 /* Add watchpoint types constants. */
1378 for (i
= 0; pybp_watch_types
[i
].name
; ++i
)
1380 if (PyModule_AddIntConstant (gdb_module
, pybp_watch_types
[i
].name
,
1381 pybp_watch_types
[i
].code
) < 0)
1388 /* Initialize the Python BreakpointLocation code. */
1390 static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
1391 gdbpy_initialize_breakpoint_locations ()
1393 return gdbpy_type_ready (&breakpoint_location_object_type
);
1398 /* Helper function that overrides this Python object's
1399 PyObject_GenericSetAttr to allow extra validation of the attribute
1403 local_setattro (PyObject
*self
, PyObject
*name
, PyObject
*v
)
1405 gdbpy_breakpoint_object
*obj
= (gdbpy_breakpoint_object
*) self
;
1406 gdb::unique_xmalloc_ptr
<char> attr (python_string_to_host_string (name
));
1411 /* If the attribute trying to be set is the "stop" method,
1412 but we already have a condition set in the CLI or other extension
1413 language, disallow this operation. */
1414 if (strcmp (attr
.get (), stop_func
) == 0)
1416 const struct extension_language_defn
*extlang
= NULL
;
1418 if (obj
->bp
->cond_string
!= NULL
)
1419 extlang
= get_ext_lang_defn (EXT_LANG_GDB
);
1420 if (extlang
== NULL
)
1421 extlang
= get_breakpoint_cond_ext_lang (obj
->bp
, EXT_LANG_PYTHON
);
1422 if (extlang
!= NULL
)
1424 std::string error_text
1425 = string_printf (_("Only one stop condition allowed. There is"
1426 " currently a %s stop condition defined for"
1427 " this breakpoint."),
1428 ext_lang_capitalized_name (extlang
));
1429 PyErr_SetString (PyExc_RuntimeError
, error_text
.c_str ());
1434 return PyObject_GenericSetAttr (self
, name
, v
);
1437 static gdb_PyGetSetDef breakpoint_object_getset
[] = {
1438 { "enabled", bppy_get_enabled
, bppy_set_enabled
,
1439 "Boolean telling whether the breakpoint is enabled.", NULL
},
1440 { "silent", bppy_get_silent
, bppy_set_silent
,
1441 "Boolean telling whether the breakpoint is silent.", NULL
},
1442 { "thread", bppy_get_thread
, bppy_set_thread
,
1443 "Thread ID for the breakpoint.\n\
1444 If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
1445 If the value is None, then this breakpoint is not thread-specific.\n\
1446 No other type of value can be used.", NULL
},
1447 { "inferior", bppy_get_inferior
, bppy_set_inferior
,
1448 "Inferior ID for the breakpoint.\n\
1449 If the value is an inferior ID (integer), then this is an inferior-specific\n\
1450 breakpoint. If the value is None, then this breakpoint is not\n\
1451 inferior-specific. No other type of value can be used.", NULL
},
1452 { "task", bppy_get_task
, bppy_set_task
,
1453 "Thread ID for the breakpoint.\n\
1454 If the value is a task ID (integer), then this is an Ada task-specific breakpoint.\n\
1455 If the value is None, then this breakpoint is not task-specific.\n\
1456 No other type of value can be used.", NULL
},
1457 { "ignore_count", bppy_get_ignore_count
, bppy_set_ignore_count
,
1458 "Number of times this breakpoint should be automatically continued.",
1460 { "number", bppy_get_number
, NULL
,
1461 "Breakpoint's number assigned by GDB.", NULL
},
1462 { "hit_count", bppy_get_hit_count
, bppy_set_hit_count
,
1463 "Number of times the breakpoint has been hit.\n\
1464 Can be set to zero to clear the count. No other value is valid\n\
1465 when setting this property.", NULL
},
1466 { "location", bppy_get_location
, NULL
,
1467 "Location of the breakpoint, as specified by the user.", NULL
},
1468 { "expression", bppy_get_expression
, NULL
,
1469 "Expression of the breakpoint, as specified by the user.", NULL
},
1470 { "condition", bppy_get_condition
, bppy_set_condition
,
1471 "Condition of the breakpoint, as specified by the user,\
1472 or None if no condition set."},
1473 { "commands", bppy_get_commands
, bppy_set_commands
,
1474 "Commands of the breakpoint, as specified by the user."},
1475 { "type", bppy_get_type
, NULL
,
1476 "Type of breakpoint."},
1477 { "visible", bppy_get_visibility
, NULL
,
1478 "Whether the breakpoint is visible to the user."},
1479 { "temporary", bppy_get_temporary
, NULL
,
1480 "Whether this breakpoint is a temporary breakpoint."},
1481 { "pending", bppy_get_pending
, NULL
,
1482 "Whether this breakpoint is a pending breakpoint."},
1483 { "locations", bppy_get_locations
, NULL
,
1484 "Get locations where this breakpoint was set"},
1485 { NULL
} /* Sentinel. */
1488 static PyMethodDef breakpoint_object_methods
[] =
1490 { "is_valid", bppy_is_valid
, METH_NOARGS
,
1491 "Return true if this breakpoint is valid, false if not." },
1492 { "delete", bppy_delete_breakpoint
, METH_NOARGS
,
1493 "Delete the underlying GDB breakpoint." },
1494 { NULL
} /* Sentinel. */
1497 PyTypeObject breakpoint_object_type
=
1499 PyVarObject_HEAD_INIT (NULL
, 0)
1500 "gdb.Breakpoint", /*tp_name*/
1501 sizeof (gdbpy_breakpoint_object
), /*tp_basicsize*/
1508 bppy_repr
, /*tp_repr*/
1510 0, /*tp_as_sequence*/
1511 0, /*tp_as_mapping*/
1516 (setattrofunc
)local_setattro
, /*tp_setattro */
1518 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
, /*tp_flags*/
1519 "GDB breakpoint object", /* tp_doc */
1520 0, /* tp_traverse */
1522 0, /* tp_richcompare */
1523 0, /* tp_weaklistoffset */
1525 0, /* tp_iternext */
1526 breakpoint_object_methods
, /* tp_methods */
1528 breakpoint_object_getset
, /* tp_getset */
1531 0, /* tp_descr_get */
1532 0, /* tp_descr_set */
1533 0, /* tp_dictoffset */
1534 bppy_init
, /* tp_init */
1538 void _initialize_py_breakpoint ();
1540 _initialize_py_breakpoint ()
1542 add_setshow_boolean_cmd
1543 ("py-breakpoint", class_maintenance
, &pybp_debug
,
1544 _("Set Python breakpoint debugging."),
1545 _("Show Python breakpoint debugging."),
1546 _("When on, Python breakpoint debugging is enabled."),
1549 &setdebuglist
, &showdebuglist
);
1552 GDBPY_INITIALIZE_FILE (gdbpy_initialize_breakpoints
);
1553 GDBPY_INITIALIZE_FILE (gdbpy_initialize_breakpoint_locations
);
1555 /* Python function to set the enabled state of a breakpoint location. */
1558 bplocpy_set_enabled (PyObject
*py_self
, PyObject
*newvalue
, void *closure
)
1560 auto *self
= (gdbpy_breakpoint_location_object
*) py_self
;
1561 BPPY_SET_REQUIRE_VALID (self
->owner
);
1562 BPLOCPY_SET_REQUIRE_VALID (self
->owner
, self
);
1564 if (newvalue
== nullptr)
1566 PyErr_SetString (PyExc_TypeError
,
1567 _("Cannot delete 'enabled' attribute."));
1570 else if (!PyBool_Check (newvalue
))
1572 PyErr_SetString (PyExc_TypeError
,
1573 _("The value of 'enabled' must be a boolean."));
1577 int cmp
= PyObject_IsTrue (newvalue
);
1583 enable_disable_bp_location (self
->bp_loc
, cmp
== 1);
1585 catch (const gdb_exception
&except
)
1587 return gdbpy_handle_gdb_exception (-1, except
);
1592 /* Python function to test whether or not the breakpoint location is enabled. */
1595 bplocpy_get_enabled (PyObject
*py_self
, void *closure
)
1597 auto *self
= (gdbpy_breakpoint_location_object
*) py_self
;
1598 BPPY_REQUIRE_VALID (self
->owner
);
1599 BPLOCPY_REQUIRE_VALID (self
->owner
, self
);
1601 if (self
->bp_loc
->enabled
)
1607 /* Python function to get address of breakpoint location. */
1610 bplocpy_get_address (PyObject
*py_self
, void *closure
)
1612 auto *self
= (gdbpy_breakpoint_location_object
*) py_self
;
1613 BPPY_REQUIRE_VALID (self
->owner
);
1614 BPLOCPY_REQUIRE_VALID (self
->owner
, self
);
1615 return gdb_py_object_from_ulongest (self
->bp_loc
->address
).release ();
1618 /* Python function to get owner of breakpoint location, which
1619 is of type gdb.Breakpoint. */
1622 bplocpy_get_owner (PyObject
*py_self
, void *closure
)
1624 auto *self
= (gdbpy_breakpoint_location_object
*) py_self
;
1625 BPPY_REQUIRE_VALID (self
->owner
);
1626 BPLOCPY_REQUIRE_VALID (self
->owner
, self
);
1627 Py_INCREF (self
->owner
);
1628 return (PyObject
*) self
->owner
;
1631 /* Python function to get the source file name path and line number
1632 where this breakpoint location was set. */
1635 bplocpy_get_source_location (PyObject
*py_self
, void *closure
)
1637 auto *self
= (gdbpy_breakpoint_location_object
*) py_self
;
1638 BPPY_REQUIRE_VALID (self
->owner
);
1639 BPLOCPY_REQUIRE_VALID (self
->owner
, self
);
1640 if (self
->bp_loc
->symtab
)
1642 gdbpy_ref
<> tup (PyTuple_New (2));
1645 /* symtab->filename is never NULL. */
1646 gdbpy_ref
<> filename
1647 = host_string_to_python_string (self
->bp_loc
->symtab
->filename
);
1648 if (filename
== nullptr)
1650 auto line
= gdb_py_object_from_ulongest (self
->bp_loc
->line_number
);
1651 if (line
== nullptr)
1653 if (PyTuple_SetItem (tup
.get (), 0, filename
.release ()) == -1
1654 || PyTuple_SetItem (tup
.get (), 1, line
.release ()) == -1)
1656 return tup
.release ();
1662 /* Python function to get the function name of where this location was set. */
1665 bplocpy_get_function (PyObject
*py_self
, void *closure
)
1667 auto *self
= (gdbpy_breakpoint_location_object
*) py_self
;
1668 BPPY_REQUIRE_VALID (self
->owner
);
1669 BPLOCPY_REQUIRE_VALID (self
->owner
, self
);
1670 const auto fn_name
= self
->bp_loc
->function_name
.get ();
1671 if (fn_name
!= nullptr)
1672 return host_string_to_python_string (fn_name
).release ();
1677 bplocpy_get_thread_groups (PyObject
*py_self
, void *closure
)
1679 auto *self
= (gdbpy_breakpoint_location_object
*) py_self
;
1680 BPPY_REQUIRE_VALID (self
->owner
);
1681 BPLOCPY_REQUIRE_VALID (self
->owner
, self
);
1682 gdbpy_ref
<> list (PyList_New (0));
1683 if (list
== nullptr)
1685 for (inferior
*inf
: all_inferiors ())
1687 if (inf
->pspace
== self
->bp_loc
->pspace
)
1689 gdbpy_ref
<> num
= gdb_py_object_from_ulongest (inf
->num
);
1692 if (PyList_Append (list
.get (), num
.release ()) != 0)
1696 return list
.release ();
1700 bplocpy_get_fullname (PyObject
*py_self
, void *closure
)
1702 auto *self
= (gdbpy_breakpoint_location_object
*) py_self
;
1703 BPPY_REQUIRE_VALID (self
->owner
);
1704 BPLOCPY_REQUIRE_VALID (self
->owner
, self
);
1705 const auto symtab
= self
->bp_loc
->symtab
;
1706 if (symtab
!= nullptr && symtab
->fullname () != nullptr)
1708 gdbpy_ref
<> fullname
1709 = host_string_to_python_string (symtab
->fullname ());
1710 return fullname
.release ();
1715 /* De-allocation function to be called for the Python object. */
1718 bplocpy_dealloc (PyObject
*py_self
)
1720 auto *self
= (gdbpy_breakpoint_location_object
*) py_self
;
1721 bp_location_ref_ptr decrementing_ref
{self
->bp_loc
};
1722 Py_XDECREF (self
->owner
);
1723 Py_TYPE (py_self
)->tp_free (py_self
);
1726 /* __repr__ implementation for gdb.BreakpointLocation. */
1729 bplocpy_repr (PyObject
*py_self
)
1731 const auto self
= (gdbpy_breakpoint_location_object
*) py_self
;
1732 if (self
->owner
== nullptr || self
->owner
->bp
== nullptr
1733 || self
->owner
->bp
!= self
->bp_loc
->owner
)
1734 return gdb_py_invalid_object_repr (py_self
);
1736 const auto enabled
= self
->bp_loc
->enabled
? "enabled" : "disabled";
1738 std::string
str (enabled
);
1740 str
+= string_printf (" address=%s",
1741 paddress (self
->bp_loc
->owner
->gdbarch
,
1742 self
->bp_loc
->address
));
1744 if (self
->bp_loc
->requested_address
!= self
->bp_loc
->address
)
1745 str
+= string_printf (" requested_address=%s",
1746 paddress (self
->bp_loc
->owner
->gdbarch
,
1747 self
->bp_loc
->requested_address
));
1748 if (self
->bp_loc
->symtab
!= nullptr)
1749 str
+= string_printf (" source=%s:%d", self
->bp_loc
->symtab
->filename
,
1750 self
->bp_loc
->line_number
);
1752 const auto fn_name
= self
->bp_loc
->function_name
.get ();
1753 if (fn_name
!= nullptr)
1759 return PyUnicode_FromFormat ("<%s %s>", Py_TYPE (self
)->tp_name
,
1763 /* Attribute get/set Python definitions. */
1765 static gdb_PyGetSetDef bp_location_object_getset
[] = {
1766 { "enabled", bplocpy_get_enabled
, bplocpy_set_enabled
,
1767 "Boolean telling whether the breakpoint is enabled.", NULL
},
1768 { "owner", bplocpy_get_owner
, NULL
,
1769 "Get the breakpoint owner object", NULL
},
1770 { "address", bplocpy_get_address
, NULL
,
1771 "Get address of where this location was set", NULL
},
1772 { "source", bplocpy_get_source_location
, NULL
,
1773 "Get file and line number of where this location was set", NULL
},
1774 { "function", bplocpy_get_function
, NULL
,
1775 "Get function of where this location was set", NULL
},
1776 { "fullname", bplocpy_get_fullname
, NULL
,
1777 "Get fullname of where this location was set", NULL
},
1778 { "thread_groups", bplocpy_get_thread_groups
, NULL
,
1779 "Get thread groups where this location is in", NULL
},
1780 { NULL
} /* Sentinel. */
1783 PyTypeObject breakpoint_location_object_type
=
1785 PyVarObject_HEAD_INIT (NULL
, 0)
1786 "gdb.BreakpointLocation", /*tp_name*/
1787 sizeof (gdbpy_breakpoint_location_object
), /*tp_basicsize*/
1789 bplocpy_dealloc
, /*tp_dealloc*/
1794 bplocpy_repr
, /*tp_repr*/
1796 0, /*tp_as_sequence*/
1797 0, /*tp_as_mapping*/
1804 Py_TPFLAGS_DEFAULT
, /*tp_flags*/
1805 "GDB breakpoint location object", /* tp_doc */
1806 0, /* tp_traverse */
1808 0, /* tp_richcompare */
1809 0, /* tp_weaklistoffset */
1811 0, /* tp_iternext */
1814 bp_location_object_getset
, /* tp_getset */
1817 0, /* tp_descr_get */
1818 0, /* tp_descr_set */
1819 0, /* tp_dictoffset */