2011-01-05 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / python / py-breakpoint.c
CommitLineData
adc36818
PM
1/* Python interface to breakpoints
2
7b6bb8da 3 Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
adc36818
PM
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "defs.h"
21#include "value.h"
22#include "exceptions.h"
23#include "python-internal.h"
24#include "charset.h"
25#include "breakpoint.h"
26#include "gdbcmd.h"
27#include "gdbthread.h"
28#include "observer.h"
29#include "cli/cli-script.h"
30#include "ada-lang.h"
31
32/* From breakpoint.c. */
33typedef struct breakpoint_object breakpoint_object;
34
35static PyTypeObject breakpoint_object_type;
36
adc36818
PM
37/* Number of live breakpoints. */
38static int bppy_live;
39
40/* Variables used to pass information between the Breakpoint
41 constructor and the breakpoint-created hook function. */
42static breakpoint_object *bppy_pending_object;
43
44struct breakpoint_object
45{
46 PyObject_HEAD
47
48 /* The breakpoint number according to gdb. */
49 int number;
50
51 /* The gdb breakpoint object, or NULL if the breakpoint has been
52 deleted. */
53 struct breakpoint *bp;
54};
55
56/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
57 exception if it is invalid. */
58#define BPPY_REQUIRE_VALID(Breakpoint) \
59 do { \
84f4c1fe 60 if ((Breakpoint)->bp == NULL) \
9a2b4c1b
MS
61 return PyErr_Format (PyExc_RuntimeError, \
62 _("Breakpoint %d is invalid."), \
adc36818
PM
63 (Breakpoint)->number); \
64 } while (0)
65
66/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
67 exception if it is invalid. This macro is for use in setter functions. */
68#define BPPY_SET_REQUIRE_VALID(Breakpoint) \
69 do { \
9a2b4c1b 70 if ((Breakpoint)->bp == NULL) \
adc36818
PM
71 { \
72 PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
73 (Breakpoint)->number); \
74 return -1; \
75 } \
76 } while (0)
77
78/* This is used to initialize various gdb.bp_* constants. */
79struct pybp_code
80{
81 /* The name. */
82 const char *name;
83 /* The code. */
84 enum type_code code;
85};
86
87/* Entries related to the type of user set breakpoints. */
88static struct pybp_code pybp_codes[] =
89{
90 { "BP_NONE", bp_none},
91 { "BP_BREAKPOINT", bp_breakpoint},
92 { "BP_WATCHPOINT", bp_watchpoint},
93 { "BP_HARDWARE_WATCHPOINT", bp_hardware_watchpoint},
94 { "BP_READ_WATCHPOINT", bp_read_watchpoint},
95 { "BP_ACCESS_WATCHPOINT", bp_access_watchpoint},
96 {NULL} /* Sentinel. */
97};
98
99/* Entries related to the type of watchpoint. */
100static struct pybp_code pybp_watch_types[] =
101{
102 { "WP_READ", hw_read},
103 { "WP_WRITE", hw_write},
104 { "WP_ACCESS", hw_access},
105 {NULL} /* Sentinel. */
106};
107
adc36818
PM
108/* Python function which checks the validity of a breakpoint object. */
109static PyObject *
110bppy_is_valid (PyObject *self, PyObject *args)
111{
112 breakpoint_object *self_bp = (breakpoint_object *) self;
113
114 if (self_bp->bp)
115 Py_RETURN_TRUE;
116 Py_RETURN_FALSE;
117}
118
119/* Python function to test whether or not the breakpoint is enabled. */
120static PyObject *
121bppy_get_enabled (PyObject *self, void *closure)
122{
123 breakpoint_object *self_bp = (breakpoint_object *) self;
124
125 BPPY_REQUIRE_VALID (self_bp);
126 if (! self_bp->bp)
127 Py_RETURN_FALSE;
128 if (self_bp->bp->enable_state == bp_enabled)
129 Py_RETURN_TRUE;
130 Py_RETURN_FALSE;
131}
132
133/* Python function to test whether or not the breakpoint is silent. */
134static PyObject *
135bppy_get_silent (PyObject *self, void *closure)
136{
137 breakpoint_object *self_bp = (breakpoint_object *) self;
138
139 BPPY_REQUIRE_VALID (self_bp);
140 if (self_bp->bp->silent)
141 Py_RETURN_TRUE;
142 Py_RETURN_FALSE;
143}
144
145/* Python function to set the enabled state of a breakpoint. */
146static int
147bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
148{
149 breakpoint_object *self_bp = (breakpoint_object *) self;
150 int cmp;
151
152 BPPY_SET_REQUIRE_VALID (self_bp);
153
154 if (newvalue == NULL)
155 {
156 PyErr_SetString (PyExc_TypeError,
157 _("Cannot delete `enabled' attribute."));
158
159 return -1;
160 }
161 else if (! PyBool_Check (newvalue))
162 {
163 PyErr_SetString (PyExc_TypeError,
164 _("The value of `enabled' must be a boolean."));
165 return -1;
166 }
167
168 cmp = PyObject_IsTrue (newvalue);
169 if (cmp < 0)
170 return -1;
171 else if (cmp == 1)
172 enable_breakpoint (self_bp->bp);
173 else
174 disable_breakpoint (self_bp->bp);
175 return 0;
176}
177
178/* Python function to set the 'silent' state of a breakpoint. */
179static int
180bppy_set_silent (PyObject *self, PyObject *newvalue, void *closure)
181{
182 breakpoint_object *self_bp = (breakpoint_object *) self;
183 int cmp;
184
185 BPPY_SET_REQUIRE_VALID (self_bp);
186
187 if (newvalue == NULL)
188 {
189 PyErr_SetString (PyExc_TypeError,
190 _("Cannot delete `silent' attribute."));
191 return -1;
192 }
193 else if (! PyBool_Check (newvalue))
194 {
195 PyErr_SetString (PyExc_TypeError,
196 _("The value of `silent' must be a boolean."));
197 return -1;
198 }
199
200 cmp = PyObject_IsTrue (newvalue);
201 if (cmp < 0)
202 return -1;
203 else
204 self_bp->bp->silent = cmp;
205
206 return 0;
207}
208
209/* Python function to set the thread of a breakpoint. */
210static int
211bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
212{
213 breakpoint_object *self_bp = (breakpoint_object *) self;
214 int id;
215
216 BPPY_SET_REQUIRE_VALID (self_bp);
217
218 if (newvalue == NULL)
219 {
220 PyErr_SetString (PyExc_TypeError,
221 _("Cannot delete `thread' attribute."));
222 return -1;
223 }
224 else if (PyInt_Check (newvalue))
225 {
226 id = (int) PyInt_AsLong (newvalue);
227 if (! valid_thread_id (id))
228 {
229 PyErr_SetString (PyExc_RuntimeError,
230 _("Invalid thread ID."));
231 return -1;
232 }
233 }
234 else if (newvalue == Py_None)
235 id = -1;
236 else
237 {
238 PyErr_SetString (PyExc_TypeError,
239 _("The value of `thread' must be an integer or None."));
240 return -1;
241 }
242
243 self_bp->bp->thread = id;
244
245 return 0;
246}
247
248/* Python function to set the (Ada) task of a breakpoint. */
249static int
250bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
251{
252 breakpoint_object *self_bp = (breakpoint_object *) self;
253 int id;
254
255 BPPY_SET_REQUIRE_VALID (self_bp);
256
257 if (newvalue == NULL)
258 {
259 PyErr_SetString (PyExc_TypeError,
260 _("Cannot delete `task' attribute."));
261 return -1;
262 }
263 else if (PyInt_Check (newvalue))
264 {
265 id = (int) PyInt_AsLong (newvalue);
266 if (! valid_task_id (id))
267 {
268 PyErr_SetString (PyExc_RuntimeError,
269 _("Invalid task ID."));
270 return -1;
271 }
272 }
273 else if (newvalue == Py_None)
274 id = 0;
275 else
276 {
277 PyErr_SetString (PyExc_TypeError,
278 _("The value of `task' must be an integer or None."));
279 return -1;
280 }
281
282 self_bp->bp->task = id;
283
284 return 0;
285}
286
94b6973e
PM
287/* Python function which deletes the underlying GDB breakpoint. This
288 triggers the breakpoint_deleted observer which will call
289 gdbpy_breakpoint_deleted; that function cleans up the Python
290 sections. */
291
292static PyObject *
293bppy_delete_breakpoint (PyObject *self, PyObject *args)
294{
295 breakpoint_object *self_bp = (breakpoint_object *) self;
296
297 BPPY_REQUIRE_VALID (self_bp);
298
299 delete_breakpoint (self_bp->bp);
300
301 Py_RETURN_NONE;
302}
303
adc36818
PM
304
305/* Python function to set the ignore count of a breakpoint. */
306static int
307bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
308{
309 breakpoint_object *self_bp = (breakpoint_object *) self;
310 long value;
311
312 BPPY_SET_REQUIRE_VALID (self_bp);
313
314 if (newvalue == NULL)
315 {
316 PyErr_SetString (PyExc_TypeError,
317 _("Cannot delete `ignore_count' attribute."));
318 return -1;
319 }
320 else if (! PyInt_Check (newvalue))
321 {
322 PyErr_SetString (PyExc_TypeError,
323 _("The value of `ignore_count' must be an integer."));
324 return -1;
325 }
326
327 value = PyInt_AsLong (newvalue);
328 if (value < 0)
329 value = 0;
330 set_ignore_count (self_bp->number, (int) value, 0);
331
332 return 0;
333}
334
335/* Python function to set the hit count of a breakpoint. */
336static int
337bppy_set_hit_count (PyObject *self, PyObject *newvalue, void *closure)
338{
339 breakpoint_object *self_bp = (breakpoint_object *) self;
340
341 BPPY_SET_REQUIRE_VALID (self_bp);
342
343 if (newvalue == NULL)
344 {
345 PyErr_SetString (PyExc_TypeError,
346 _("Cannot delete `hit_count' attribute."));
347 return -1;
348 }
349 else if (! PyInt_Check (newvalue) || PyInt_AsLong (newvalue) != 0)
350 {
351 PyErr_SetString (PyExc_AttributeError,
352 _("The value of `hit_count' must be zero."));
353 return -1;
354 }
355
356 self_bp->bp->hit_count = 0;
357
358 return 0;
359}
360
361/* Python function to get the location of a breakpoint. */
362static PyObject *
363bppy_get_location (PyObject *self, void *closure)
364{
365 char *str;
366 breakpoint_object *obj = (breakpoint_object *) self;
367
368 BPPY_REQUIRE_VALID (obj);
369
370 if (obj->bp->type != bp_breakpoint)
371 Py_RETURN_NONE;
372
373 str = obj->bp->addr_string;
374
375 if (! str)
376 str = "";
377 return PyString_Decode (str, strlen (str), host_charset (), NULL);
378}
379
380/* Python function to get the breakpoint expression. */
381static PyObject *
382bppy_get_expression (PyObject *self, void *closure)
383{
384 char *str;
385 breakpoint_object *obj = (breakpoint_object *) self;
386
387 BPPY_REQUIRE_VALID (obj);
388
389 if (obj->bp->type != bp_watchpoint
390 && obj->bp->type != bp_hardware_watchpoint
391 && obj->bp->type != bp_read_watchpoint
392 && obj->bp->type != bp_access_watchpoint)
393 Py_RETURN_NONE;
394
395 str = obj->bp->exp_string;
396 if (! str)
397 str = "";
398
399 return PyString_Decode (str, strlen (str), host_charset (), NULL);
400}
401
402/* Python function to get the condition expression of a breakpoint. */
403static PyObject *
404bppy_get_condition (PyObject *self, void *closure)
405{
406 char *str;
407 breakpoint_object *obj = (breakpoint_object *) self;
408
409 BPPY_REQUIRE_VALID (obj);
410
411 str = obj->bp->cond_string;
412 if (! str)
413 Py_RETURN_NONE;
414
415 return PyString_Decode (str, strlen (str), host_charset (), NULL);
416}
417
8dc78533
JK
418/* Returns 0 on success. Returns -1 on error, with a python exception set.
419 */
420
adc36818
PM
421static int
422bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
423{
424 char *exp;
425 breakpoint_object *self_bp = (breakpoint_object *) self;
426 volatile struct gdb_exception except;
427
428 BPPY_SET_REQUIRE_VALID (self_bp);
429
430 if (newvalue == NULL)
431 {
432 PyErr_SetString (PyExc_TypeError,
433 _("Cannot delete `condition' attribute."));
434 return -1;
435 }
436 else if (newvalue == Py_None)
437 exp = "";
438 else
439 {
440 exp = python_string_to_host_string (newvalue);
441 if (exp == NULL)
442 return -1;
443 }
444
445 TRY_CATCH (except, RETURN_MASK_ALL)
446 {
447 set_breakpoint_condition (self_bp->bp, exp, 0);
448 }
449 GDB_PY_SET_HANDLE_EXCEPTION (except);
450
451 return 0;
452}
453
454/* Python function to get the commands attached to a breakpoint. */
455static PyObject *
456bppy_get_commands (PyObject *self, void *closure)
457{
458 breakpoint_object *self_bp = (breakpoint_object *) self;
459 struct breakpoint *bp = self_bp->bp;
460 long length;
461 volatile struct gdb_exception except;
462 struct ui_file *string_file;
463 struct cleanup *chain;
464 PyObject *result;
465 char *cmdstr;
466
467 BPPY_REQUIRE_VALID (self_bp);
468
469 if (! self_bp->bp->commands)
470 Py_RETURN_NONE;
471
472 string_file = mem_fileopen ();
473 chain = make_cleanup_ui_file_delete (string_file);
474
14dba4b4 475 ui_out_redirect (uiout, string_file);
adc36818
PM
476 TRY_CATCH (except, RETURN_MASK_ALL)
477 {
adc36818 478 print_command_lines (uiout, breakpoint_commands (bp), 0);
adc36818 479 }
14dba4b4 480 ui_out_redirect (uiout, NULL);
adc36818
PM
481 cmdstr = ui_file_xstrdup (string_file, &length);
482 GDB_PY_HANDLE_EXCEPTION (except);
483
484 result = PyString_Decode (cmdstr, strlen (cmdstr), host_charset (), NULL);
485 do_cleanups (chain);
486 xfree (cmdstr);
487 return result;
488}
489
490/* Python function to get the breakpoint type. */
491static PyObject *
492bppy_get_type (PyObject *self, void *closure)
493{
494 breakpoint_object *self_bp = (breakpoint_object *) self;
495
496 BPPY_REQUIRE_VALID (self_bp);
497
498 return PyInt_FromLong (self_bp->bp->type);
499}
500
84f4c1fe
PM
501/* Python function to get the visibility of the breakpoint. */
502
503static PyObject *
504bppy_get_visibility (PyObject *self, void *closure)
505{
506 breakpoint_object *self_bp = (breakpoint_object *) self;
507
508 BPPY_REQUIRE_VALID (self_bp);
509
510 if (self_bp->bp->number < 0)
511 Py_RETURN_FALSE;
512
513 Py_RETURN_TRUE;
514}
515
adc36818
PM
516/* Python function to get the breakpoint's number. */
517static PyObject *
518bppy_get_number (PyObject *self, void *closure)
519{
520 breakpoint_object *self_bp = (breakpoint_object *) self;
521
522 BPPY_REQUIRE_VALID (self_bp);
523
524 return PyInt_FromLong (self_bp->number);
525}
526
527/* Python function to get the breakpoint's thread ID. */
528static PyObject *
529bppy_get_thread (PyObject *self, void *closure)
530{
531 breakpoint_object *self_bp = (breakpoint_object *) self;
532
533 BPPY_REQUIRE_VALID (self_bp);
534
535 if (self_bp->bp->thread == -1)
536 Py_RETURN_NONE;
537
538 return PyInt_FromLong (self_bp->bp->thread);
539}
540
541/* Python function to get the breakpoint's task ID (in Ada). */
542static PyObject *
543bppy_get_task (PyObject *self, void *closure)
544{
545 breakpoint_object *self_bp = (breakpoint_object *) self;
546
547 BPPY_REQUIRE_VALID (self_bp);
548
549 if (self_bp->bp->task == 0)
550 Py_RETURN_NONE;
551
552 return PyInt_FromLong (self_bp->bp->task);
553}
554
555/* Python function to get the breakpoint's hit count. */
556static PyObject *
557bppy_get_hit_count (PyObject *self, void *closure)
558{
559 breakpoint_object *self_bp = (breakpoint_object *) self;
560
561 BPPY_REQUIRE_VALID (self_bp);
562
563 return PyInt_FromLong (self_bp->bp->hit_count);
564}
565
566/* Python function to get the breakpoint's ignore count. */
567static PyObject *
568bppy_get_ignore_count (PyObject *self, void *closure)
569{
570 breakpoint_object *self_bp = (breakpoint_object *) self;
571
572 BPPY_REQUIRE_VALID (self_bp);
573
574 return PyInt_FromLong (self_bp->bp->ignore_count);
575}
576
577/* Python function to create a new breakpoint. */
578static PyObject *
579bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
580{
581 PyObject *result;
84f4c1fe 582 static char *keywords[] = { "spec", "type", "wp_class", "internal", NULL };
adc36818
PM
583 char *spec;
584 int type = bp_breakpoint;
585 int access_type = hw_write;
84f4c1fe
PM
586 PyObject *internal = NULL;
587 int internal_bp = 0;
adc36818
PM
588 volatile struct gdb_exception except;
589
84f4c1fe
PM
590 if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiO", keywords,
591 &spec, &type, &access_type, &internal))
adc36818
PM
592 return NULL;
593
84f4c1fe
PM
594 if (internal)
595 {
596 internal_bp = PyObject_IsTrue (internal);
597 if (internal_bp == -1)
598 return NULL;
599 }
600
adc36818
PM
601 result = subtype->tp_alloc (subtype, 0);
602 if (! result)
603 return NULL;
604 bppy_pending_object = (breakpoint_object *) result;
605 bppy_pending_object->number = -1;
606 bppy_pending_object->bp = NULL;
607
608 TRY_CATCH (except, RETURN_MASK_ALL)
609 {
610 switch (type)
611 {
612 case bp_breakpoint:
613 {
614 create_breakpoint (python_gdbarch,
615 spec, NULL, -1,
616 0,
0fb4aa4b 617 0, bp_breakpoint,
adc36818
PM
618 0,
619 AUTO_BOOLEAN_TRUE,
84f4c1fe 620 NULL, 0, 1, internal_bp);
adc36818
PM
621 break;
622 }
623 case bp_watchpoint:
624 {
625 if (access_type == hw_write)
84f4c1fe 626 watch_command_wrapper (spec, 0, internal_bp);
adc36818 627 else if (access_type == hw_access)
84f4c1fe 628 awatch_command_wrapper (spec, 0, internal_bp);
adc36818 629 else if (access_type == hw_read)
84f4c1fe 630 rwatch_command_wrapper (spec, 0, internal_bp);
adc36818
PM
631 else
632 error(_("Cannot understand watchpoint access type."));
633 break;
634 }
635 default:
636 error(_("Do not understand breakpoint type to set."));
637 }
638 }
639 if (except.reason < 0)
640 {
641 subtype->tp_free (result);
642 return PyErr_Format (except.reason == RETURN_QUIT
643 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
644 "%s", except.message);
645 }
646
647 BPPY_REQUIRE_VALID ((breakpoint_object *) result);
648 return result;
649}
650
651\f
652
84f4c1fe
PM
653static int
654build_bp_list (struct breakpoint *b, void *arg)
655{
656 PyObject *list = arg;
50389644 657 PyObject *bp = (PyObject *) b->py_bp_object;
84f4c1fe
PM
658 int iserr = 0;
659
660 /* Not all breakpoints will have a companion Python object.
661 Only breakpoints that were created via bppy_new, or
662 breakpoints that were created externally and are tracked by
663 the Python Scripting API. */
664 if (bp)
665 iserr = PyList_Append (list, bp);
666
667 if (iserr == -1)
668 return 1;
669
670 return 0;
671}
672
adc36818
PM
673/* Static function to return a tuple holding all breakpoints. */
674
675PyObject *
676gdbpy_breakpoints (PyObject *self, PyObject *args)
677{
84f4c1fe 678 PyObject *list;
adc36818
PM
679
680 if (bppy_live == 0)
681 Py_RETURN_NONE;
682
84f4c1fe
PM
683 list = PyList_New (0);
684 if (!list)
685 return NULL;
d59b6f6c 686
84f4c1fe
PM
687 /* If iteratre_over_breakpoints returns non NULL it signals an error
688 condition. In that case abandon building the list and return
689 NULL. */
690 if (iterate_over_breakpoints (build_bp_list, list) != NULL)
691 {
692 Py_DECREF (list);
693 return NULL;
adc36818 694 }
84f4c1fe
PM
695
696 return PyList_AsTuple (list);
adc36818
PM
697}
698
699\f
700
701/* Event callback functions. */
702
703/* Callback that is used when a breakpoint is created. This function
704 will create a new Python breakpoint object. */
705static void
706gdbpy_breakpoint_created (int num)
707{
708 breakpoint_object *newbp;
709 struct breakpoint *bp = NULL;
710 PyGILState_STATE state;
711
adc36818
PM
712 bp = get_breakpoint (num);
713 if (! bp)
714 return;
715
84f4c1fe
PM
716 if (num < 0 && bppy_pending_object == NULL)
717 return;
718
adc36818
PM
719 if (bp->type != bp_breakpoint
720 && bp->type != bp_watchpoint
721 && bp->type != bp_hardware_watchpoint
722 && bp->type != bp_read_watchpoint
723 && bp->type != bp_access_watchpoint)
724 return;
725
adc36818
PM
726 state = PyGILState_Ensure ();
727
728 if (bppy_pending_object)
729 {
730 newbp = bppy_pending_object;
731 bppy_pending_object = NULL;
732 }
733 else
734 newbp = PyObject_New (breakpoint_object, &breakpoint_object_type);
735 if (newbp)
736 {
adc36818
PM
737 newbp->number = num;
738 newbp->bp = bp;
50389644 739 newbp->bp->py_bp_object = newbp;
adc36818 740 Py_INCREF (newbp);
84f4c1fe
PM
741 ++bppy_live;
742 }
743 else
744 {
745 PyErr_SetString (PyExc_RuntimeError,
746 _("Error while creating breakpoint from GDB."));
747 gdbpy_print_stack ();
adc36818 748 }
adc36818
PM
749
750 PyGILState_Release (state);
751}
752
753/* Callback that is used when a breakpoint is deleted. This will
754 invalidate the corresponding Python object. */
755static void
756gdbpy_breakpoint_deleted (int num)
757{
758 PyGILState_STATE state;
84f4c1fe
PM
759 struct breakpoint *bp = NULL;
760 breakpoint_object *bp_obj;
adc36818
PM
761
762 state = PyGILState_Ensure ();
84f4c1fe
PM
763 bp = get_breakpoint (num);
764 if (! bp)
765 return;
766
50389644 767 bp_obj = bp->py_bp_object;
84f4c1fe 768 if (bp_obj)
adc36818 769 {
84f4c1fe 770 bp_obj->bp = NULL;
adc36818 771 --bppy_live;
84f4c1fe 772 Py_DECREF (bp_obj);
adc36818
PM
773 }
774 PyGILState_Release (state);
775}
776
777\f
778
779/* Initialize the Python breakpoint code. */
780void
781gdbpy_initialize_breakpoints (void)
782{
783 int i;
784
785 breakpoint_object_type.tp_new = bppy_new;
786 if (PyType_Ready (&breakpoint_object_type) < 0)
787 return;
788
789 Py_INCREF (&breakpoint_object_type);
790 PyModule_AddObject (gdb_module, "Breakpoint",
791 (PyObject *) &breakpoint_object_type);
792
793 observer_attach_breakpoint_created (gdbpy_breakpoint_created);
794 observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
795
796 /* Add breakpoint types constants. */
797 for (i = 0; pybp_codes[i].name; ++i)
798 {
799 if (PyModule_AddIntConstant (gdb_module,
800 /* Cast needed for Python 2.4. */
801 (char *) pybp_codes[i].name,
802 pybp_codes[i].code) < 0)
803 return;
804 }
805
806 /* Add watchpoint types constants. */
807 for (i = 0; pybp_watch_types[i].name; ++i)
808 {
809 if (PyModule_AddIntConstant (gdb_module,
810 /* Cast needed for Python 2.4. */
811 (char *) pybp_watch_types[i].name,
812 pybp_watch_types[i].code) < 0)
813 return;
814 }
815
816}
817
818\f
819
820static PyGetSetDef breakpoint_object_getset[] = {
821 { "enabled", bppy_get_enabled, bppy_set_enabled,
822 "Boolean telling whether the breakpoint is enabled.", NULL },
823 { "silent", bppy_get_silent, bppy_set_silent,
824 "Boolean telling whether the breakpoint is silent.", NULL },
825 { "thread", bppy_get_thread, bppy_set_thread,
826 "Thread ID for the breakpoint.\n\
827If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
828If the value is None, then this breakpoint is not thread-specific.\n\
829No other type of value can be used.", NULL },
830 { "task", bppy_get_task, bppy_set_task,
831 "Thread ID for the breakpoint.\n\
832If the value is a task ID (integer), then this is an Ada task-specific breakpoint.\n\
833If the value is None, then this breakpoint is not task-specific.\n\
834No other type of value can be used.", NULL },
835 { "ignore_count", bppy_get_ignore_count, bppy_set_ignore_count,
836 "Number of times this breakpoint should be automatically continued.",
837 NULL },
838 { "number", bppy_get_number, NULL,
839 "Breakpoint's number assigned by GDB.", NULL },
840 { "hit_count", bppy_get_hit_count, bppy_set_hit_count,
841 "Number of times the breakpoint has been hit.\n\
842Can be set to zero to clear the count. No other value is valid\n\
843when setting this property.", NULL },
844 { "location", bppy_get_location, NULL,
845 "Location of the breakpoint, as specified by the user.", NULL},
846 { "expression", bppy_get_expression, NULL,
847 "Expression of the breakpoint, as specified by the user.", NULL},
848 { "condition", bppy_get_condition, bppy_set_condition,
849 "Condition of the breakpoint, as specified by the user,\
850or None if no condition set."},
851 { "commands", bppy_get_commands, NULL,
852 "Commands of the breakpoint, as specified by the user."},
853 { "type", bppy_get_type, NULL,
854 "Type of breakpoint."},
84f4c1fe
PM
855 { "visible", bppy_get_visibility, NULL,
856 "Whether the breakpoint is visible to the user."},
adc36818
PM
857 { NULL } /* Sentinel. */
858};
859
860static PyMethodDef breakpoint_object_methods[] =
861{
862 { "is_valid", bppy_is_valid, METH_NOARGS,
863 "Return true if this breakpoint is valid, false if not." },
94b6973e
PM
864 { "delete", bppy_delete_breakpoint, METH_NOARGS,
865 "Delete the underlying GDB breakpoint." },
adc36818
PM
866 { NULL } /* Sentinel. */
867};
868
869static PyTypeObject breakpoint_object_type =
870{
871 PyObject_HEAD_INIT (NULL)
872 0, /*ob_size*/
873 "gdb.Breakpoint", /*tp_name*/
874 sizeof (breakpoint_object), /*tp_basicsize*/
875 0, /*tp_itemsize*/
876 0, /*tp_dealloc*/
877 0, /*tp_print*/
878 0, /*tp_getattr*/
879 0, /*tp_setattr*/
880 0, /*tp_compare*/
881 0, /*tp_repr*/
882 0, /*tp_as_number*/
883 0, /*tp_as_sequence*/
884 0, /*tp_as_mapping*/
885 0, /*tp_hash */
886 0, /*tp_call*/
887 0, /*tp_str*/
888 0, /*tp_getattro*/
889 0, /*tp_setattro*/
890 0, /*tp_as_buffer*/
891 Py_TPFLAGS_DEFAULT, /*tp_flags*/
892 "GDB breakpoint object", /* tp_doc */
893 0, /* tp_traverse */
894 0, /* tp_clear */
895 0, /* tp_richcompare */
896 0, /* tp_weaklistoffset */
897 0, /* tp_iter */
898 0, /* tp_iternext */
899 breakpoint_object_methods, /* tp_methods */
900 0, /* tp_members */
901 breakpoint_object_getset /* tp_getset */
902};
This page took 0.131338 seconds and 4 git commands to generate.