1 /* Python interface to btrace instruction history.
3 Copyright 2016-2017 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/>. */
23 #include "gdbthread.h"
25 #include "py-record-btrace.h"
30 #define BTPY_PYSLICE(x) (x)
34 #define BTPY_PYSLICE(x) ((PySliceObject *) x)
38 #define BTPY_REQUIRE_VALID_INSN(obj, iter) \
40 struct thread_info *tinfo = find_thread_ptid (obj->ptid); \
41 if (tinfo == NULL || btrace_is_empty (tinfo)) \
42 return PyErr_Format (gdbpy_gdb_error, _("Empty branch trace."));\
43 if (0 == btrace_find_insn_by_number (&iter, &tinfo->btrace, \
45 return PyErr_Format (gdbpy_gdb_error, _("No such instruction."));\
48 #define BTPY_REQUIRE_VALID_CALL(obj, iter) \
50 struct thread_info *tinfo = find_thread_ptid (obj->ptid); \
51 if (tinfo == NULL || btrace_is_empty (tinfo)) \
52 return PyErr_Format (gdbpy_gdb_error, _("Empty branch trace."));\
53 if (0 == btrace_find_call_by_number (&iter, &tinfo->btrace, \
55 return PyErr_Format (gdbpy_gdb_error, _("No such call segment."));\
58 /* This can either be a btrace instruction or a function call segment,
59 depending on the chosen type. */
64 /* The thread this object belongs to. */
67 /* Instruction number or function call segment number, depending on the type
72 /* Python object for btrace record lists. */
77 /* The thread this list belongs to. */
80 /* The first index being part of this list. */
83 /* The last index begin part of this list. */
89 /* Either &BTPY_CALL_TYPE or &BTPY_INSN_TYPE. */
90 PyTypeObject
* element_type
;
93 /* Python type for btrace instructions. */
95 static PyTypeObject btpy_insn_type
= {
96 PyVarObject_HEAD_INIT (NULL
, 0)
99 /* Python type for btrace function-calls. */
101 static PyTypeObject btpy_call_type
= {
102 PyVarObject_HEAD_INIT (NULL
, 0)
105 /* Python type for btrace lists. */
107 static PyTypeObject btpy_list_type
= {
108 PyVarObject_HEAD_INIT (NULL
, 0)
111 /* Create a new gdb.BtraceInstruction or gdb.BtraceFunctionCall object,
112 depending on TYPE. */
115 btpy_new (ptid_t ptid
, Py_ssize_t number
, PyTypeObject
* type
)
117 btpy_object
* const obj
= PyObject_New (btpy_object
, type
);
123 obj
->number
= number
;
125 return (PyObject
*) obj
;
128 /* Create a new gdb.BtraceInstruction object. */
131 btpy_insn_new (ptid_t ptid
, Py_ssize_t number
)
133 return btpy_new (ptid
, number
, &btpy_insn_type
);
136 /* Create a new gdb.BtraceFunctionCall object. */
139 btpy_call_new (ptid_t ptid
, Py_ssize_t number
)
141 return btpy_new (ptid
, number
, &btpy_call_type
);
144 /* Create a new gdb.BtraceList object. */
147 btpy_list_new (ptid_t ptid
, Py_ssize_t first
, Py_ssize_t last
, Py_ssize_t step
,
148 PyTypeObject
*element_type
)
150 btpy_list_object
* const obj
= PyObject_New (btpy_list_object
,
160 obj
->element_type
= element_type
;
162 return (PyObject
*) obj
;
165 /* Implementation of BtraceInstruction.number [int] and
166 BtraceFunctionCall.number [int]. */
169 btpy_number (PyObject
*self
, void *closure
)
171 const btpy_object
* const obj
= (btpy_object
*) self
;
173 return PyInt_FromSsize_t (obj
->number
);
176 /* Implementation of BtraceInstruction.__hash__ () -> int and
177 BtraceFunctionCall.__hash__ () -> int. */
180 btpy_hash (PyObject
*self
)
182 const btpy_object
* const obj
= (btpy_object
*) self
;
187 /* Implementation of BtraceInstruction.error [int]. Returns the
188 error code for gaps. */
191 btpy_insn_error (PyObject
*self
, void *closure
)
193 const btpy_object
* const obj
= (btpy_object
*) self
;
194 struct btrace_insn_iterator iter
;
197 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
199 error
= btrace_insn_get_error (&iter
);
204 return PyInt_FromLong (error
);
207 /* Implementation of BtraceInstruction.sal [gdb.Symtab_and_line].
208 Return the SAL associated with this instruction. */
211 btpy_insn_sal (PyObject
*self
, void *closure
)
213 const btpy_object
* const obj
= (btpy_object
*) self
;
214 const struct btrace_insn
*insn
;
215 struct btrace_insn_iterator iter
;
216 PyObject
*result
= NULL
;
218 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
220 insn
= btrace_insn_get (&iter
);
226 result
= symtab_and_line_to_sal_object (find_pc_line (insn
->pc
, 0));
228 CATCH (except
, RETURN_MASK_ALL
)
230 GDB_PY_HANDLE_EXCEPTION (except
);
237 /* Implementation of BtraceInstruction.pc [int]. Returns
238 the instruction address. */
241 btpy_insn_pc (PyObject
*self
, void *closure
)
243 const btpy_object
* const obj
= (btpy_object
*) self
;
244 const struct btrace_insn
*insn
;
245 struct btrace_insn_iterator iter
;
247 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
249 insn
= btrace_insn_get (&iter
);
253 return gdb_py_long_from_ulongest (insn
->pc
);
256 /* Implementation of BtraceInstruction.size [int]. Returns
257 the instruction size. */
260 btpy_insn_size (PyObject
*self
, void *closure
)
262 const btpy_object
* const obj
= (btpy_object
*) self
;
263 const struct btrace_insn
*insn
;
264 struct btrace_insn_iterator iter
;
266 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
268 insn
= btrace_insn_get (&iter
);
272 return PyInt_FromLong (insn
->size
);
275 /* Implementation of BtraceInstruction.is_speculative [bool].
276 Returns if this instruction was executed speculatively. */
279 btpy_insn_is_speculative (PyObject
*self
, void *closure
)
281 const btpy_object
* const obj
= (btpy_object
*) self
;
282 const struct btrace_insn
*insn
;
283 struct btrace_insn_iterator iter
;
285 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
287 insn
= btrace_insn_get (&iter
);
291 if (insn
->flags
& BTRACE_INSN_FLAG_SPECULATIVE
)
297 /* Implementation of BtraceInstruction.data [buffer].
298 Returns raw instruction data. */
301 btpy_insn_data (PyObject
*self
, void *closure
)
303 const btpy_object
* const obj
= (btpy_object
*) self
;
304 const struct btrace_insn
*insn
;
305 struct btrace_insn_iterator iter
;
306 gdb_byte
*buffer
= NULL
;
309 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
311 insn
= btrace_insn_get (&iter
);
317 buffer
= (gdb_byte
*) xmalloc (insn
->size
);
318 read_memory (insn
->pc
, buffer
, insn
->size
);
320 CATCH (except
, RETURN_MASK_ALL
)
323 GDB_PY_HANDLE_EXCEPTION (except
);
327 object
= PyBytes_FromStringAndSize ((const char*) buffer
, insn
->size
);
334 return PyMemoryView_FromObject (object
);
336 return PyBuffer_FromObject (object
, 0, Py_END_OF_BUFFER
);
341 /* Implementation of BtraceInstruction.decode [str]. Returns
342 the instruction as human readable string. */
345 btpy_insn_decode (PyObject
*self
, void *closure
)
347 const btpy_object
* const obj
= (btpy_object
*) self
;
348 const struct btrace_insn
*insn
;
349 struct btrace_insn_iterator iter
;
352 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
354 insn
= btrace_insn_get (&iter
);
357 int error_code
= btrace_insn_get_error (&iter
);
358 const struct btrace_config
*config
;
360 config
= btrace_conf (&find_thread_ptid (obj
->ptid
)->btrace
);
361 return PyBytes_FromString (btrace_decode_error (config
->format
,
367 gdb_print_insn (target_gdbarch (), insn
->pc
, &strfile
, NULL
);
369 CATCH (except
, RETURN_MASK_ALL
)
371 gdbpy_convert_exception (except
);
377 return PyBytes_FromString (strfile
.string ().c_str ());
380 /* Implementation of BtraceFunctionCall.level [int]. Returns the
384 btpy_call_level (PyObject
*self
, void *closure
)
386 const btpy_object
* const obj
= (btpy_object
*) self
;
387 const struct btrace_function
*func
;
388 struct btrace_call_iterator iter
;
390 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
392 func
= btrace_call_get (&iter
);
396 return PyInt_FromLong (iter
.btinfo
->level
+ func
->level
);
399 /* Implementation of BtraceFunctionCall.symbol [gdb.Symbol]. Returns
400 the symbol associated with this function call. */
403 btpy_call_symbol (PyObject
*self
, void *closure
)
405 const btpy_object
* const obj
= (btpy_object
*) self
;
406 const struct btrace_function
*func
;
407 struct btrace_call_iterator iter
;
409 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
411 func
= btrace_call_get (&iter
);
415 if (func
->sym
== NULL
)
418 return symbol_to_symbol_object (func
->sym
);
421 /* Implementation of BtraceFunctionCall.instructions [list].
422 Return the list of instructions that belong to this function call. */
425 btpy_call_instructions (PyObject
*self
, void *closure
)
427 const btpy_object
* const obj
= (btpy_object
*) self
;
428 const struct btrace_function
*func
;
429 struct btrace_call_iterator iter
;
432 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
434 func
= btrace_call_get (&iter
);
438 len
= VEC_length (btrace_insn_s
, func
->insn
);
440 /* Gaps count as one instruction. */
444 return btpy_list_new (obj
->ptid
, func
->insn_offset
, func
->insn_offset
+ len
,
448 /* Implementation of BtraceFunctionCall.up [gdb.BtraceRecordCall].
449 Return the caller / returnee of this function. */
452 btpy_call_up (PyObject
*self
, void *closure
)
454 const btpy_object
* const obj
= (btpy_object
*) self
;
455 const struct btrace_function
*func
;
456 struct btrace_call_iterator iter
;
458 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
460 func
= btrace_call_get (&iter
);
464 if (func
->up
== NULL
)
467 return btpy_call_new (obj
->ptid
, func
->up
->number
);
470 /* Implementation of BtraceFunctionCall.prev_sibling [BtraceFunctionCall].
471 Return a previous segment of this function. */
474 btpy_call_prev_sibling (PyObject
*self
, void *closure
)
476 const btpy_object
* const obj
= (btpy_object
*) self
;
477 const struct btrace_function
*func
;
478 struct btrace_call_iterator iter
;
480 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
482 func
= btrace_call_get (&iter
);
486 if (func
->segment
.prev
== NULL
)
489 return btpy_call_new (obj
->ptid
, func
->segment
.prev
->number
);
492 /* Implementation of BtraceFunctionCall.next_sibling [BtraceFunctionCall].
493 Return a following segment of this function. */
496 btpy_call_next_sibling (PyObject
*self
, void *closure
)
498 const btpy_object
* const obj
= (btpy_object
*) self
;
499 const struct btrace_function
*func
;
500 struct btrace_call_iterator iter
;
502 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
504 func
= btrace_call_get (&iter
);
508 if (func
->segment
.next
== NULL
)
511 return btpy_call_new (obj
->ptid
, func
->segment
.next
->number
);
514 /* Python rich compare function to allow for equality and inequality checks
518 btpy_richcompare (PyObject
*self
, PyObject
*other
, int op
)
520 const btpy_object
* const obj1
= (btpy_object
*) self
;
521 const btpy_object
* const obj2
= (btpy_object
*) other
;
523 if (Py_TYPE (self
) != Py_TYPE (other
))
525 Py_INCREF (Py_NotImplemented
);
526 return Py_NotImplemented
;
532 if (ptid_equal (obj1
->ptid
, obj2
->ptid
) && obj1
->number
== obj2
->number
)
538 if (!ptid_equal (obj1
->ptid
, obj2
->ptid
) || obj1
->number
!= obj2
->number
)
547 Py_INCREF (Py_NotImplemented
);
548 return Py_NotImplemented
;
551 /* Implementation of BtraceList.__len__ (self) -> int. */
554 btpy_list_length (PyObject
*self
)
556 const btpy_list_object
* const obj
= (btpy_list_object
*) self
;
557 const Py_ssize_t distance
= obj
->last
- obj
->first
;
558 const Py_ssize_t result
= distance
/ obj
->step
;
560 if ((distance
% obj
->step
) == 0)
567 BtraceList.__getitem__ (self, key) -> BtraceInstruction and
568 BtraceList.__getitem__ (self, key) -> BtraceFunctionCall. */
571 btpy_list_item (PyObject
*self
, Py_ssize_t index
)
573 const btpy_list_object
* const obj
= (btpy_list_object
*) self
;
574 struct thread_info
* const tinfo
= find_thread_ptid (obj
->ptid
);
576 if (index
< 0 || index
>= btpy_list_length (self
))
577 return PyErr_Format (PyExc_IndexError
, _("Index out of range: %zd."),
580 return btpy_new (obj
->ptid
, obj
->first
+ (obj
->step
* index
),
584 /* Implementation of BtraceList.__getitem__ (self, slice) -> BtraceList. */
587 btpy_list_slice (PyObject
*self
, PyObject
*value
)
589 const btpy_list_object
* const obj
= (btpy_list_object
*) self
;
590 const Py_ssize_t length
= btpy_list_length (self
);
591 Py_ssize_t start
, stop
, step
, slicelength
;
593 if (PyInt_Check (value
))
595 Py_ssize_t index
= PyInt_AsSsize_t (value
);
597 /* Emulate Python behavior for negative indices. */
601 return btpy_list_item (self
, index
);
604 if (!PySlice_Check (value
))
605 return PyErr_Format (PyExc_TypeError
, _("Index must be int or slice."));
607 if (0 != PySlice_GetIndicesEx (BTPY_PYSLICE (value
), length
, &start
, &stop
,
608 &step
, &slicelength
))
611 return btpy_list_new (obj
->ptid
, obj
->first
+ obj
->step
* start
,
612 obj
->first
+ obj
->step
* stop
, obj
->step
* step
,
616 /* Helper function that returns the position of an element in a BtraceList
617 or -1 if the element is not in the list. */
620 btpy_list_position (PyObject
*self
, PyObject
*value
)
622 const btpy_list_object
* const list_obj
= (btpy_list_object
*) self
;
623 const btpy_object
* const obj
= (btpy_object
*) value
;
624 Py_ssize_t index
= obj
->number
;
626 if (list_obj
->element_type
!= Py_TYPE (value
))
629 if (!ptid_equal (list_obj
->ptid
, obj
->ptid
))
632 if (index
< list_obj
->first
|| index
> list_obj
->last
)
635 index
-= list_obj
->first
;
637 if (index
% list_obj
->step
!= 0)
640 return index
/ list_obj
->step
;
643 /* Implementation of "in" operator for BtraceLists. */
646 btpy_list_contains (PyObject
*self
, PyObject
*value
)
648 if (btpy_list_position (self
, value
) < 0)
654 /* Implementation of BtraceLists.index (self, value) -> int. */
657 btpy_list_index (PyObject
*self
, PyObject
*value
)
659 const LONGEST index
= btpy_list_position (self
, value
);
662 return PyErr_Format (PyExc_ValueError
, _("Not in list."));
664 return gdb_py_long_from_longest (index
);
667 /* Implementation of BtraceList.count (self, value) -> int. */
670 btpy_list_count (PyObject
*self
, PyObject
*value
)
672 /* We know that if an element is in the list, it is so exactly one time,
673 enabling us to reuse the "is element of" check. */
674 return PyInt_FromLong (btpy_list_contains (self
, value
));
677 /* Python rich compare function to allow for equality and inequality checks
681 btpy_list_richcompare (PyObject
*self
, PyObject
*other
, int op
)
683 const btpy_list_object
* const obj1
= (btpy_list_object
*) self
;
684 const btpy_list_object
* const obj2
= (btpy_list_object
*) other
;
686 if (Py_TYPE (self
) != Py_TYPE (other
))
688 Py_INCREF (Py_NotImplemented
);
689 return Py_NotImplemented
;
695 if (ptid_equal (obj1
->ptid
, obj2
->ptid
)
696 && obj1
->element_type
== obj2
->element_type
697 && obj1
->first
== obj2
->first
698 && obj1
->last
== obj2
->last
699 && obj1
->step
== obj2
->step
)
705 if (!ptid_equal (obj1
->ptid
, obj2
->ptid
)
706 || obj1
->element_type
!= obj2
->element_type
707 || obj1
->first
!= obj2
->first
708 || obj1
->last
!= obj2
->last
709 || obj1
->step
!= obj2
->step
)
718 Py_INCREF (Py_NotImplemented
);
719 return Py_NotImplemented
;
723 BtraceRecord.method [str]. */
726 recpy_bt_method (PyObject
*self
, void *closure
)
728 return PyString_FromString ("btrace");
732 BtraceRecord.format [str]. */
735 recpy_bt_format (PyObject
*self
, void *closure
)
737 const struct thread_info
* const tinfo
= find_thread_ptid (inferior_ptid
);
738 const struct btrace_config
* config
;
743 config
= btrace_conf (&tinfo
->btrace
);
748 return PyString_FromString (btrace_format_short_string (config
->format
));
752 BtraceRecord.replay_position [BtraceInstruction]. */
755 recpy_bt_replay_position (PyObject
*self
, void *closure
)
757 const struct thread_info
* const tinfo
= find_thread_ptid (inferior_ptid
);
762 if (tinfo
->btrace
.replay
== NULL
)
765 return btpy_insn_new (inferior_ptid
,
766 btrace_insn_number (tinfo
->btrace
.replay
));
770 BtraceRecord.begin [BtraceInstruction]. */
773 recpy_bt_begin (PyObject
*self
, void *closure
)
775 struct thread_info
* const tinfo
= find_thread_ptid (inferior_ptid
);
776 struct btrace_insn_iterator iterator
;
781 btrace_fetch (tinfo
);
783 if (btrace_is_empty (tinfo
))
786 btrace_insn_begin (&iterator
, &tinfo
->btrace
);
787 return btpy_insn_new (inferior_ptid
, btrace_insn_number (&iterator
));
791 BtraceRecord.end [BtraceInstruction]. */
794 recpy_bt_end (PyObject
*self
, void *closure
)
796 struct thread_info
* const tinfo
= find_thread_ptid (inferior_ptid
);
797 struct btrace_insn_iterator iterator
;
802 btrace_fetch (tinfo
);
804 if (btrace_is_empty (tinfo
))
807 btrace_insn_end (&iterator
, &tinfo
->btrace
);
808 return btpy_insn_new (inferior_ptid
, btrace_insn_number (&iterator
));
812 BtraceRecord.instruction_history [list]. */
815 recpy_bt_instruction_history (PyObject
*self
, void *closure
)
817 struct thread_info
* const tinfo
= find_thread_ptid (inferior_ptid
);
818 struct btrace_insn_iterator iterator
;
819 unsigned long first
= 0;
820 unsigned long last
= 0;
825 btrace_fetch (tinfo
);
827 if (btrace_is_empty (tinfo
))
830 btrace_insn_begin (&iterator
, &tinfo
->btrace
);
831 first
= btrace_insn_number (&iterator
);
833 btrace_insn_end (&iterator
, &tinfo
->btrace
);
834 last
= btrace_insn_number (&iterator
);
836 return btpy_list_new (inferior_ptid
, first
, last
, 1, &btpy_insn_type
);
840 BtraceRecord.function_call_history [list]. */
843 recpy_bt_function_call_history (PyObject
*self
, void *closure
)
845 struct thread_info
* const tinfo
= find_thread_ptid (inferior_ptid
);
846 struct btrace_call_iterator iterator
;
847 unsigned long first
= 0;
848 unsigned long last
= 0;
853 btrace_fetch (tinfo
);
855 if (btrace_is_empty (tinfo
))
858 btrace_call_begin (&iterator
, &tinfo
->btrace
);
859 first
= btrace_call_number (&iterator
);
861 btrace_call_end (&iterator
, &tinfo
->btrace
);
862 last
= btrace_call_number (&iterator
);
864 return btpy_list_new (inferior_ptid
, first
, last
, 1, &btpy_call_type
);
867 /* Implementation of BtraceRecord.goto (self, BtraceInstruction) -> None. */
870 recpy_bt_goto (PyObject
*self
, PyObject
*args
)
872 struct thread_info
* const tinfo
= find_thread_ptid (inferior_ptid
);
873 const btpy_object
*obj
;
875 if (tinfo
== NULL
|| btrace_is_empty (tinfo
))
876 return PyErr_Format (gdbpy_gdb_error
, _("Empty branch trace."));
878 if (!PyArg_ParseTuple (args
, "O", &obj
))
881 if (Py_TYPE (obj
) != &btpy_insn_type
)
882 return PyErr_Format (PyExc_TypeError
, _("Argument must be instruction."));
886 struct btrace_insn_iterator iter
;
888 btrace_insn_end (&iter
, &tinfo
->btrace
);
890 if (btrace_insn_number (&iter
) == obj
->number
)
891 target_goto_record_end ();
893 target_goto_record (obj
->number
);
895 CATCH (except
, RETURN_MASK_ALL
)
897 GDB_PY_HANDLE_EXCEPTION (except
);
904 /* BtraceInstruction members. */
906 struct PyGetSetDef btpy_insn_getset
[] =
908 { "number", btpy_number
, NULL
, "instruction number", NULL
},
909 { "error", btpy_insn_error
, NULL
, "error number for gaps", NULL
},
910 { "sal", btpy_insn_sal
, NULL
, "associated symbol and line", NULL
},
911 { "pc", btpy_insn_pc
, NULL
, "instruction address", NULL
},
912 { "data", btpy_insn_data
, NULL
, "raw instruction data", NULL
},
913 { "decoded", btpy_insn_decode
, NULL
, "decoded instruction or error message \
914 if the instruction is a gap", NULL
},
915 { "size", btpy_insn_size
, NULL
, "instruction size in byte", NULL
},
916 { "is_speculative", btpy_insn_is_speculative
, NULL
, "if the instruction was \
917 executed speculatively", NULL
},
921 /* BtraceFunctionCall members. */
923 static PyGetSetDef btpy_call_getset
[] =
925 { "number", btpy_number
, NULL
, "function call number", NULL
},
926 { "level", btpy_call_level
, NULL
, "call stack level", NULL
},
927 { "symbol", btpy_call_symbol
, NULL
, "associated line and symbol", NULL
},
928 { "instructions", btpy_call_instructions
, NULL
, "list of instructions in \
929 this function segment", NULL
},
930 { "up", btpy_call_up
, NULL
, "caller or returned-to function segment", NULL
},
931 { "prev_sibling", btpy_call_prev_sibling
, NULL
, "previous segment of this \
933 { "next_sibling", btpy_call_next_sibling
, NULL
, "next segment of this \
938 /* BtraceList methods. */
940 struct PyMethodDef btpy_list_methods
[] =
942 { "count", btpy_list_count
, METH_O
, "count number of occurences"},
943 { "index", btpy_list_index
, METH_O
, "index of entry"},
947 /* BtraceList sequence methods. */
949 static PySequenceMethods btpy_list_sequence_methods
=
954 /* BtraceList mapping methods. Necessary for slicing. */
956 static PyMappingMethods btpy_list_mapping_methods
=
961 /* Sets up the btrace record API. */
964 gdbpy_initialize_btrace (void)
966 btpy_insn_type
.tp_new
= PyType_GenericNew
;
967 btpy_insn_type
.tp_flags
= Py_TPFLAGS_DEFAULT
;
968 btpy_insn_type
.tp_basicsize
= sizeof (btpy_object
);
969 btpy_insn_type
.tp_name
= "gdb.BtraceInstruction";
970 btpy_insn_type
.tp_doc
= "GDB btrace instruction object";
971 btpy_insn_type
.tp_getset
= btpy_insn_getset
;
972 btpy_insn_type
.tp_richcompare
= btpy_richcompare
;
973 btpy_insn_type
.tp_hash
= btpy_hash
;
975 btpy_call_type
.tp_new
= PyType_GenericNew
;
976 btpy_call_type
.tp_flags
= Py_TPFLAGS_DEFAULT
;
977 btpy_call_type
.tp_basicsize
= sizeof (btpy_object
);
978 btpy_call_type
.tp_name
= "gdb.BtraceFunctionCall";
979 btpy_call_type
.tp_doc
= "GDB btrace call object";
980 btpy_call_type
.tp_getset
= btpy_call_getset
;
981 btpy_call_type
.tp_richcompare
= btpy_richcompare
;
982 btpy_call_type
.tp_hash
= btpy_hash
;
984 btpy_list_type
.tp_new
= PyType_GenericNew
;
985 btpy_list_type
.tp_flags
= Py_TPFLAGS_DEFAULT
;
986 btpy_list_type
.tp_basicsize
= sizeof (btpy_list_object
);
987 btpy_list_type
.tp_name
= "gdb.BtraceObjectList";
988 btpy_list_type
.tp_doc
= "GDB btrace list object";
989 btpy_list_type
.tp_methods
= btpy_list_methods
;
990 btpy_list_type
.tp_as_sequence
= &btpy_list_sequence_methods
;
991 btpy_list_type
.tp_as_mapping
= &btpy_list_mapping_methods
;
992 btpy_list_type
.tp_richcompare
= btpy_list_richcompare
;
994 btpy_list_sequence_methods
.sq_item
= btpy_list_item
;
995 btpy_list_sequence_methods
.sq_length
= btpy_list_length
;
996 btpy_list_sequence_methods
.sq_contains
= btpy_list_contains
;
998 btpy_list_mapping_methods
.mp_subscript
= btpy_list_slice
;
1000 if (PyType_Ready (&btpy_insn_type
) < 0
1001 || PyType_Ready (&btpy_call_type
) < 0
1002 || PyType_Ready (&btpy_list_type
) < 0)