1 /* Python interface to btrace instruction history.
3 Copyright 2016-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 "cli/cli-cmds.h"
22 #include "gdbthread.h"
24 #include "py-record.h"
25 #include "py-record-btrace.h"
26 #include "record-btrace.h"
30 /* Python object for btrace record lists. */
32 struct btpy_list_object
{
35 /* The thread this list belongs to. */
38 /* The first index being part of this list. */
41 /* The last index begin part of this list. */
47 /* Either &recpy_func_type, &recpy_insn_type, &recpy_aux_type or
49 PyTypeObject
* element_type
;
52 /* Python type for btrace lists. */
54 static PyTypeObject btpy_list_type
= {
55 PyVarObject_HEAD_INIT (NULL
, 0)
58 /* Returns either a btrace_insn for the given Python gdb.RecordInstruction
59 object or sets an appropriate Python exception and returns NULL. */
61 static const btrace_insn
*
62 btrace_insn_from_recpy_insn (const PyObject
* const pyobject
)
64 const btrace_insn
*insn
;
65 const recpy_element_object
*obj
;
67 btrace_insn_iterator iter
;
69 if (Py_TYPE (pyobject
) != &recpy_insn_type
)
71 PyErr_Format (gdbpy_gdb_error
, _("Must be gdb.RecordInstruction"));
75 obj
= (const recpy_element_object
*) pyobject
;
78 if (tinfo
== NULL
|| btrace_is_empty (tinfo
))
80 PyErr_Format (gdbpy_gdb_error
, _("No such instruction."));
84 if (btrace_find_insn_by_number (&iter
, &tinfo
->btrace
, obj
->number
) == 0)
86 PyErr_Format (gdbpy_gdb_error
, _("No such instruction."));
90 insn
= btrace_insn_get (&iter
);
93 PyErr_Format (gdbpy_gdb_error
, _("Not a valid instruction."));
100 /* Returns either a btrace_function for the given Python
101 gdb.RecordFunctionSegment object or sets an appropriate Python exception and
104 static const btrace_function
*
105 btrace_func_from_recpy_func (const PyObject
* const pyobject
)
107 const btrace_function
*func
;
108 const recpy_element_object
*obj
;
110 btrace_call_iterator iter
;
112 if (Py_TYPE (pyobject
) != &recpy_func_type
)
114 PyErr_Format (gdbpy_gdb_error
, _("Must be gdb.RecordFunctionSegment"));
118 obj
= (const recpy_element_object
*) pyobject
;
121 if (tinfo
== NULL
|| btrace_is_empty (tinfo
))
123 PyErr_Format (gdbpy_gdb_error
, _("No such function segment."));
127 if (btrace_find_call_by_number (&iter
, &tinfo
->btrace
, obj
->number
) == 0)
129 PyErr_Format (gdbpy_gdb_error
, _("No such function segment."));
133 func
= btrace_call_get (&iter
);
136 PyErr_Format (gdbpy_gdb_error
, _("Not a valid function segment."));
143 /* Looks at the recorded item with the number NUMBER and create a
144 gdb.RecordInstruction, gdb.RecordGap or gdb.RecordAuxiliary object
145 for it accordingly. */
148 btpy_item_new (thread_info
*tinfo
, Py_ssize_t number
)
150 btrace_insn_iterator iter
;
153 if (btrace_find_insn_by_number (&iter
, &tinfo
->btrace
, number
) == 0)
155 PyErr_Format (gdbpy_gdb_error
, _("No such instruction."));
159 err_code
= btrace_insn_get_error (&iter
);
163 const btrace_config
*config
;
164 const char *err_string
;
166 config
= btrace_conf (&tinfo
->btrace
);
167 err_string
= btrace_decode_error (config
->format
, err_code
);
169 return recpy_gap_new (err_code
, err_string
, number
);
172 const struct btrace_insn
*insn
= btrace_insn_get (&iter
);
173 gdb_assert (insn
!= nullptr);
175 if (insn
->iclass
== BTRACE_INSN_AUX
)
176 return recpy_aux_new (tinfo
, RECORD_METHOD_BTRACE
, number
);
178 return recpy_insn_new (tinfo
, RECORD_METHOD_BTRACE
, number
);
181 /* Create a new gdb.BtraceList object. */
184 btpy_list_new (thread_info
*thread
, Py_ssize_t first
, Py_ssize_t last
,
185 Py_ssize_t step
, PyTypeObject
*element_type
)
187 btpy_list_object
* const obj
= PyObject_New (btpy_list_object
,
193 obj
->thread
= thread
;
197 obj
->element_type
= element_type
;
199 return (PyObject
*) obj
;
202 /* Implementation of RecordInstruction.sal [gdb.Symtab_and_line] for btrace.
203 Returns the SAL associated with this instruction. */
206 recpy_bt_insn_sal (PyObject
*self
, void *closure
)
208 const btrace_insn
* const insn
= btrace_insn_from_recpy_insn (self
);
209 PyObject
*result
= NULL
;
216 result
= symtab_and_line_to_sal_object (find_pc_line (insn
->pc
, 0));
218 catch (const gdb_exception
&except
)
220 return gdbpy_handle_gdb_exception (nullptr, except
);
226 /* Implementation of RecordInstruction.pc [int] for btrace.
227 Returns the instruction address. */
230 recpy_bt_insn_pc (PyObject
*self
, void *closure
)
232 const btrace_insn
* const insn
= btrace_insn_from_recpy_insn (self
);
237 return gdb_py_object_from_ulongest (insn
->pc
).release ();
240 /* Implementation of RecordInstruction.size [int] for btrace.
241 Returns the instruction size. */
244 recpy_bt_insn_size (PyObject
*self
, void *closure
)
246 const btrace_insn
* const insn
= btrace_insn_from_recpy_insn (self
);
251 return gdb_py_object_from_longest (insn
->size
).release ();
254 /* Implementation of RecordInstruction.is_speculative [bool] for btrace.
255 Returns if this instruction was executed speculatively. */
258 recpy_bt_insn_is_speculative (PyObject
*self
, void *closure
)
260 const btrace_insn
* const insn
= btrace_insn_from_recpy_insn (self
);
265 if (insn
->flags
& BTRACE_INSN_FLAG_SPECULATIVE
)
271 /* Implementation of RecordInstruction.data [buffer] for btrace.
272 Returns raw instruction data. */
275 recpy_bt_insn_data (PyObject
*self
, void *closure
)
277 const btrace_insn
* const insn
= btrace_insn_from_recpy_insn (self
);
278 gdb::byte_vector buffer
;
286 buffer
.resize (insn
->size
);
287 read_memory (insn
->pc
, buffer
.data (), insn
->size
);
289 catch (const gdb_exception
&except
)
291 return gdbpy_handle_gdb_exception (nullptr, except
);
294 object
= PyBytes_FromStringAndSize ((const char *) buffer
.data (),
300 return PyMemoryView_FromObject (object
);
303 /* Implementation of RecordInstruction.decoded [str] for btrace.
304 Returns the instruction as human readable string. */
307 recpy_bt_insn_decoded (PyObject
*self
, void *closure
)
309 const btrace_insn
* const insn
= btrace_insn_from_recpy_insn (self
);
317 gdb_print_insn (current_inferior ()->arch (), insn
->pc
, &strfile
, NULL
);
319 catch (const gdb_exception
&except
)
321 return gdbpy_handle_gdb_exception (nullptr, except
);
324 return PyBytes_FromString (strfile
.string ().c_str ());
327 /* Implementation of RecordFunctionSegment.level [int] for btrace.
328 Returns the call level. */
331 recpy_bt_func_level (PyObject
*self
, void *closure
)
333 const btrace_function
* const func
= btrace_func_from_recpy_func (self
);
339 tinfo
= ((recpy_element_object
*) self
)->thread
;
340 return gdb_py_object_from_longest (tinfo
->btrace
.level
341 + func
->level
).release ();
344 /* Implementation of RecordFunctionSegment.symbol [gdb.Symbol] for btrace.
345 Returns the symbol associated with this function call. */
348 recpy_bt_func_symbol (PyObject
*self
, void *closure
)
350 const btrace_function
* const func
= btrace_func_from_recpy_func (self
);
355 if (func
->sym
== NULL
)
358 return symbol_to_symbol_object (func
->sym
);
361 /* Implementation of RecordFunctionSegment.instructions [list] for btrace.
362 Returns the list of instructions that belong to this function call. */
365 recpy_bt_func_instructions (PyObject
*self
, void *closure
)
367 const btrace_function
* const func
= btrace_func_from_recpy_func (self
);
373 len
= func
->insn
.size ();
375 /* Gaps count as one instruction. */
379 return btpy_list_new (((recpy_element_object
*) self
)->thread
,
380 func
->insn_offset
, func
->insn_offset
+ len
, 1,
384 /* Implementation of RecordFunctionSegment.up [RecordFunctionSegment] for
385 btrace. Returns the caller / returnee of this function. */
388 recpy_bt_func_up (PyObject
*self
, void *closure
)
390 const btrace_function
* const func
= btrace_func_from_recpy_func (self
);
398 return recpy_func_new (((recpy_element_object
*) self
)->thread
,
399 RECORD_METHOD_BTRACE
, func
->up
);
402 /* Implementation of RecordFunctionSegment.prev [RecordFunctionSegment] for
403 btrace. Returns a previous segment of this function. */
406 recpy_bt_func_prev (PyObject
*self
, void *closure
)
408 const btrace_function
* const func
= btrace_func_from_recpy_func (self
);
416 return recpy_func_new (((recpy_element_object
*) self
)->thread
,
417 RECORD_METHOD_BTRACE
, func
->prev
);
420 /* Implementation of RecordFunctionSegment.next [RecordFunctionSegment] for
421 btrace. Returns a following segment of this function. */
424 recpy_bt_func_next (PyObject
*self
, void *closure
)
426 const btrace_function
* const func
= btrace_func_from_recpy_func (self
);
434 return recpy_func_new (((recpy_element_object
*) self
)->thread
,
435 RECORD_METHOD_BTRACE
, func
->next
);
438 /* Implementation of Auxiliary.data [str] for btrace. */
441 recpy_bt_aux_data (PyObject
*self
, void *closure
)
443 const btrace_insn
*insn
;
444 const recpy_element_object
*obj
;
446 btrace_insn_iterator iter
;
448 if (Py_TYPE (self
) != &recpy_aux_type
)
450 PyErr_Format (gdbpy_gdb_error
, _("Must be a gdb.Auxiliary."));
454 obj
= (const recpy_element_object
*) self
;
457 if (tinfo
== nullptr || btrace_is_empty (tinfo
))
459 PyErr_Format (gdbpy_gdb_error
, _("No such auxiliary object."));
463 if (btrace_find_insn_by_number (&iter
, &tinfo
->btrace
, obj
->number
) == 0)
465 PyErr_Format (gdbpy_gdb_error
, _("No such auxiliary object."));
469 insn
= btrace_insn_get (&iter
);
470 if (insn
== nullptr || insn
->iclass
!= BTRACE_INSN_AUX
)
472 PyErr_Format (gdbpy_gdb_error
, _("Not a valid auxiliary object."));
476 return PyUnicode_FromString
477 (iter
.btinfo
->aux_data
.at (insn
->aux_data_index
).c_str ());
480 /* Implementation of BtraceList.__len__ (self) -> int. */
483 btpy_list_length (PyObject
*self
)
485 const btpy_list_object
* const obj
= (btpy_list_object
*) self
;
486 const Py_ssize_t distance
= obj
->last
- obj
->first
;
487 const Py_ssize_t result
= distance
/ obj
->step
;
489 if ((distance
% obj
->step
) == 0)
496 BtraceList.__getitem__ (self, key) -> BtraceInstruction,
497 BtraceList.__getitem__ (self, key) -> BtraceFunctionCall,
498 BtraceList.__getitem__ (self, key) -> BtraceAuxiliary. */
501 btpy_list_item (PyObject
*self
, Py_ssize_t index
)
503 const btpy_list_object
* const obj
= (btpy_list_object
*) self
;
506 if (index
< 0 || index
>= btpy_list_length (self
))
507 return PyErr_Format (PyExc_IndexError
, _("Index out of range: %zd."),
510 number
= obj
->first
+ (obj
->step
* index
);
512 if (obj
->element_type
== &recpy_func_type
)
513 return recpy_func_new (obj
->thread
, RECORD_METHOD_BTRACE
, number
);
514 else if (obj
->element_type
== &recpy_insn_type
515 || obj
->element_type
== &recpy_aux_type
)
516 return btpy_item_new (obj
->thread
, number
);
518 return PyErr_Format (gdbpy_gdb_error
, _("Not a valid BtraceList object."));
521 /* Implementation of BtraceList.__getitem__ (self, slice) -> BtraceList. */
524 btpy_list_slice (PyObject
*self
, PyObject
*value
)
526 const btpy_list_object
* const obj
= (btpy_list_object
*) self
;
527 const Py_ssize_t length
= btpy_list_length (self
);
528 Py_ssize_t start
, stop
, step
, slicelength
;
530 if (PyLong_Check (value
))
532 Py_ssize_t index
= PyLong_AsSsize_t (value
);
534 /* Emulate Python behavior for negative indices. */
538 return btpy_list_item (self
, index
);
541 if (!PySlice_Check (value
))
542 return PyErr_Format (PyExc_TypeError
, _("Index must be int or slice."));
544 if (0 != PySlice_GetIndicesEx (value
, length
, &start
, &stop
,
545 &step
, &slicelength
))
548 return btpy_list_new (obj
->thread
, obj
->first
+ obj
->step
* start
,
549 obj
->first
+ obj
->step
* stop
, obj
->step
* step
,
553 /* Helper function that returns the position of an element in a BtraceList
554 or -1 if the element is not in the list. */
557 btpy_list_position (PyObject
*self
, PyObject
*value
)
559 const btpy_list_object
* const list_obj
= (btpy_list_object
*) self
;
560 const recpy_element_object
* const obj
= (const recpy_element_object
*) value
;
561 Py_ssize_t index
= obj
->number
;
563 if (list_obj
->element_type
!= Py_TYPE (value
))
566 if (list_obj
->thread
!= obj
->thread
)
569 if (index
< list_obj
->first
|| index
> list_obj
->last
)
572 index
-= list_obj
->first
;
574 if (index
% list_obj
->step
!= 0)
577 return index
/ list_obj
->step
;
580 /* Implementation of "in" operator for BtraceLists. */
583 btpy_list_contains (PyObject
*self
, PyObject
*value
)
585 if (btpy_list_position (self
, value
) < 0)
591 /* Implementation of BtraceLists.index (self, value) -> int. */
594 btpy_list_index (PyObject
*self
, PyObject
*value
)
596 const LONGEST index
= btpy_list_position (self
, value
);
599 return PyErr_Format (PyExc_ValueError
, _("Not in list."));
601 return gdb_py_object_from_longest (index
).release ();
604 /* Implementation of BtraceList.count (self, value) -> int. */
607 btpy_list_count (PyObject
*self
, PyObject
*value
)
609 /* We know that if an element is in the list, it is so exactly one time,
610 enabling us to reuse the "is element of" check. */
611 return gdb_py_object_from_longest (btpy_list_contains (self
,
615 /* Python rich compare function to allow for equality and inequality checks
619 btpy_list_richcompare (PyObject
*self
, PyObject
*other
, int op
)
621 const btpy_list_object
* const obj1
= (btpy_list_object
*) self
;
622 const btpy_list_object
* const obj2
= (btpy_list_object
*) other
;
624 if (Py_TYPE (self
) != Py_TYPE (other
))
626 Py_INCREF (Py_NotImplemented
);
627 return Py_NotImplemented
;
633 if (obj1
->thread
== obj2
->thread
634 && obj1
->element_type
== obj2
->element_type
635 && obj1
->first
== obj2
->first
636 && obj1
->last
== obj2
->last
637 && obj1
->step
== obj2
->step
)
643 if (obj1
->thread
!= obj2
->thread
644 || obj1
->element_type
!= obj2
->element_type
645 || obj1
->first
!= obj2
->first
646 || obj1
->last
!= obj2
->last
647 || obj1
->step
!= obj2
->step
)
656 Py_INCREF (Py_NotImplemented
);
657 return Py_NotImplemented
;
661 BtraceRecord.method [str]. */
664 recpy_bt_method (PyObject
*self
, void *closure
)
666 return PyUnicode_FromString ("btrace");
670 BtraceRecord.format [str]. */
673 recpy_bt_format (PyObject
*self
, void *closure
)
675 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
676 const struct thread_info
* const tinfo
= record
->thread
;
677 const struct btrace_config
* config
;
682 config
= btrace_conf (&tinfo
->btrace
);
687 return PyUnicode_FromString (btrace_format_short_string (config
->format
));
691 BtraceRecord.replay_position [BtraceInstruction]. */
694 recpy_bt_replay_position (PyObject
*self
, void *closure
)
696 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
697 thread_info
* tinfo
= record
->thread
;
702 if (tinfo
->btrace
.replay
== NULL
)
705 return btpy_item_new (tinfo
, btrace_insn_number (tinfo
->btrace
.replay
));
709 BtraceRecord.begin [BtraceInstruction]. */
712 recpy_bt_begin (PyObject
*self
, void *closure
)
714 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
715 thread_info
*const tinfo
= record
->thread
;
716 struct btrace_insn_iterator iterator
;
721 btrace_fetch (tinfo
, record_btrace_get_cpu ());
723 if (btrace_is_empty (tinfo
))
726 btrace_insn_begin (&iterator
, &tinfo
->btrace
);
727 return btpy_item_new (tinfo
, btrace_insn_number (&iterator
));
731 BtraceRecord.end [BtraceInstruction]. */
734 recpy_bt_end (PyObject
*self
, void *closure
)
736 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
737 thread_info
*const tinfo
= record
->thread
;
738 struct btrace_insn_iterator iterator
;
743 btrace_fetch (tinfo
, record_btrace_get_cpu ());
745 if (btrace_is_empty (tinfo
))
748 btrace_insn_end (&iterator
, &tinfo
->btrace
);
749 return btpy_item_new (tinfo
, btrace_insn_number (&iterator
));
753 BtraceRecord.instruction_history [list]. */
756 recpy_bt_instruction_history (PyObject
*self
, void *closure
)
758 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
759 thread_info
*const tinfo
= record
->thread
;
760 struct btrace_insn_iterator iterator
;
761 unsigned long first
= 0;
762 unsigned long last
= 0;
767 btrace_fetch (tinfo
, record_btrace_get_cpu ());
769 if (btrace_is_empty (tinfo
))
772 btrace_insn_begin (&iterator
, &tinfo
->btrace
);
773 first
= btrace_insn_number (&iterator
);
775 btrace_insn_end (&iterator
, &tinfo
->btrace
);
776 last
= btrace_insn_number (&iterator
);
778 return btpy_list_new (tinfo
, first
, last
, 1, &recpy_insn_type
);
782 BtraceRecord.function_call_history [list]. */
785 recpy_bt_function_call_history (PyObject
*self
, void *closure
)
787 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
788 thread_info
*const tinfo
= record
->thread
;
789 struct btrace_call_iterator iterator
;
790 unsigned long first
= 0;
791 unsigned long last
= 0;
796 btrace_fetch (tinfo
, record_btrace_get_cpu ());
798 if (btrace_is_empty (tinfo
))
801 btrace_call_begin (&iterator
, &tinfo
->btrace
);
802 first
= btrace_call_number (&iterator
);
804 btrace_call_end (&iterator
, &tinfo
->btrace
);
805 last
= btrace_call_number (&iterator
);
807 return btpy_list_new (tinfo
, first
, last
, 1, &recpy_func_type
);
810 /* Helper function that calls PTW_FILTER with PAYLOAD and IP as arguments.
811 Returns the string that will be printed, if there is a filter to call. */
812 static std::optional
<std::string
>
813 recpy_call_filter (const uint64_t payload
, std::optional
<uint64_t> ip
,
814 const void *ptw_filter
)
816 std::optional
<std::string
> result
;
818 gdb_assert (ptw_filter
!= nullptr);
819 if ((PyObject
*) ptw_filter
== Py_None
)
822 gdbpy_enter enter_py
;
824 gdbpy_ref
<> py_payload
= gdb_py_object_from_ulongest (payload
);
827 if (!ip
.has_value ())
828 py_ip
= gdbpy_ref
<>::new_reference (Py_None
);
830 py_ip
= gdb_py_object_from_ulongest (*ip
);
832 gdbpy_ref
<> py_result (PyObject_CallFunctionObjArgs ((PyObject
*) ptw_filter
,
837 if (py_result
== nullptr)
839 gdbpy_print_stack ();
840 gdbpy_error (_("Couldn't call the ptwrite filter."));
843 /* Py_None is valid and results in no output. */
844 if (py_result
== Py_None
)
850 gdb::unique_xmalloc_ptr
<char> user_string
851 = gdbpy_obj_to_string (py_result
.get ());
853 if (user_string
== nullptr)
855 gdbpy_print_stack ();
856 gdbpy_error (_("The ptwrite filter didn't return a string."));
859 result
= user_string
.get ();
864 /* Helper function returning the current ptwrite filter. */
867 get_ptwrite_filter ()
869 gdbpy_ref
<> module (PyImport_ImportModule ("gdb.ptwrite"));
871 if (PyErr_Occurred ())
873 gdbpy_print_stack ();
874 gdbpy_error (_("Couldn't import gdb.ptwrite."));
877 /* We need to keep the reference count. */
878 gdbpy_ref
<> ptw_filter (gdbpy_call_method (module
.get (), "get_filter"));
880 if (PyErr_Occurred ())
882 gdbpy_print_stack ();
883 gdbpy_error (_("Couldn't get the ptwrite filter."));
886 return ptw_filter
.get();
889 /* Used for registering any python ptwrite filter to the current thread. A
890 pointer to this function is stored in the python extension interface. */
893 gdbpy_load_ptwrite_filter (const struct extension_language_defn
*extlang
,
894 struct btrace_thread_info
*btinfo
)
896 gdb_assert (btinfo
!= nullptr);
898 gdbpy_enter enter_py
;
900 btinfo
->ptw_context
= get_ptwrite_filter ();
902 #if defined (HAVE_STRUCT_PT_EVENT_VARIANT_PTWRITE)
903 if (!btinfo
->target
->conf
.pt
.ptwrite
&& btinfo
->ptw_context
!= Py_None
)
904 warning (_("The target doesn't support decoding ptwrite events."));
906 if (btinfo
->ptw_context
!= Py_None
)
907 warning (_("Libipt doesn't support decoding ptwrite events."));
908 #endif /* defined (HAVE_STRUCT_PT_EVENT_VARIANT_PTWRITE) */
910 btinfo
->ptw_callback_fun
= &recpy_call_filter
;
913 /* Implementation of BtraceRecord.goto (self, BtraceInstruction) -> None. */
916 recpy_bt_goto (PyObject
*self
, PyObject
*args
)
918 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
919 thread_info
*const tinfo
= record
->thread
;
920 const recpy_element_object
*obj
;
923 if (tinfo
== NULL
|| btrace_is_empty (tinfo
))
924 return PyErr_Format (gdbpy_gdb_error
, _("Empty branch trace."));
926 if (!PyArg_ParseTuple (args
, "O", &parse_obj
))
929 if (Py_TYPE (parse_obj
) != &recpy_insn_type
)
930 return PyErr_Format (PyExc_TypeError
, _("Argument must be instruction."));
931 obj
= (const recpy_element_object
*) parse_obj
;
935 struct btrace_insn_iterator iter
;
937 btrace_insn_end (&iter
, &tinfo
->btrace
);
939 if (btrace_insn_number (&iter
) == obj
->number
)
940 target_goto_record_end ();
942 target_goto_record (obj
->number
);
944 catch (const gdb_exception
&except
)
946 return gdbpy_handle_gdb_exception (nullptr, except
);
952 /* Implementation of BtraceRecord.clear (self) -> None. */
955 recpy_bt_clear (PyObject
*self
, PyObject
*args
)
957 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
958 thread_info
*const tinfo
= record
->thread
;
960 btrace_clear (tinfo
);
965 /* BtraceList methods. */
967 static PyMethodDef btpy_list_methods
[] =
969 { "count", btpy_list_count
, METH_O
, "count number of occurrences"},
970 { "index", btpy_list_index
, METH_O
, "index of entry"},
974 /* BtraceList sequence methods. */
976 static PySequenceMethods btpy_list_sequence_methods
=
981 /* BtraceList mapping methods. Necessary for slicing. */
983 static PyMappingMethods btpy_list_mapping_methods
=
988 /* Sets up the btrace record API. */
990 static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
991 gdbpy_initialize_btrace (void)
993 btpy_list_type
.tp_new
= PyType_GenericNew
;
994 btpy_list_type
.tp_flags
= Py_TPFLAGS_DEFAULT
;
995 btpy_list_type
.tp_basicsize
= sizeof (btpy_list_object
);
996 btpy_list_type
.tp_name
= "gdb.BtraceObjectList";
997 btpy_list_type
.tp_doc
= "GDB btrace list object";
998 btpy_list_type
.tp_methods
= btpy_list_methods
;
999 btpy_list_type
.tp_as_sequence
= &btpy_list_sequence_methods
;
1000 btpy_list_type
.tp_as_mapping
= &btpy_list_mapping_methods
;
1001 btpy_list_type
.tp_richcompare
= btpy_list_richcompare
;
1003 btpy_list_sequence_methods
.sq_item
= btpy_list_item
;
1004 btpy_list_sequence_methods
.sq_length
= btpy_list_length
;
1005 btpy_list_sequence_methods
.sq_contains
= btpy_list_contains
;
1007 btpy_list_mapping_methods
.mp_subscript
= btpy_list_slice
;
1009 return gdbpy_type_ready (&btpy_list_type
);
1012 GDBPY_INITIALIZE_FILE (gdbpy_initialize_btrace
);