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.h"
26 #include "py-record-btrace.h"
31 #define BTPY_PYSLICE(x) (x)
35 #define BTPY_PYSLICE(x) ((PySliceObject *) x)
39 #define BTPY_REQUIRE_VALID_INSN(obj, iter) \
41 struct thread_info *tinfo = find_thread_ptid (obj->ptid); \
42 if (tinfo == NULL || btrace_is_empty (tinfo)) \
43 return PyErr_Format (gdbpy_gdb_error, _("Empty branch trace.")); \
44 if (0 == btrace_find_insn_by_number (&iter, &tinfo->btrace, \
46 return PyErr_Format (gdbpy_gdb_error, _("No such instruction.")); \
49 #define BTPY_REQUIRE_VALID_CALL(obj, iter) \
51 struct thread_info *tinfo = find_thread_ptid (obj->ptid); \
52 if (tinfo == NULL || btrace_is_empty (tinfo)) \
53 return PyErr_Format (gdbpy_gdb_error, _("Empty branch trace.")); \
54 if (0 == btrace_find_call_by_number (&iter, &tinfo->btrace, \
56 return PyErr_Format (gdbpy_gdb_error, _("No such call segment."));\
59 /* This can either be a btrace instruction or a function call segment,
60 depending on the chosen type. */
65 /* The thread this object belongs to. */
68 /* Instruction number or function call segment number, depending on the type
73 /* Python object for btrace record lists. */
78 /* The thread this list belongs to. */
81 /* The first index being part of this list. */
84 /* The last index begin part of this list. */
90 /* Either &BTPY_CALL_TYPE or &BTPY_INSN_TYPE. */
91 PyTypeObject
* element_type
;
94 /* Python type for btrace instructions. */
96 static PyTypeObject btpy_insn_type
= {
97 PyVarObject_HEAD_INIT (NULL
, 0)
100 /* Python type for btrace function-calls. */
102 static PyTypeObject btpy_call_type
= {
103 PyVarObject_HEAD_INIT (NULL
, 0)
106 /* Python type for btrace lists. */
108 static PyTypeObject btpy_list_type
= {
109 PyVarObject_HEAD_INIT (NULL
, 0)
112 /* Create a new gdb.BtraceInstruction or gdb.BtraceFunctionCall object,
113 depending on TYPE. */
116 btpy_new (ptid_t ptid
, Py_ssize_t number
, PyTypeObject
* type
)
118 btpy_object
* const obj
= PyObject_New (btpy_object
, type
);
124 obj
->number
= number
;
126 return (PyObject
*) obj
;
129 /* Create a new gdb.BtraceInstruction object. */
132 btpy_insn_new (ptid_t ptid
, Py_ssize_t number
)
134 return btpy_new (ptid
, number
, &btpy_insn_type
);
137 /* Create a new gdb.BtraceFunctionCall object. */
140 btpy_call_new (ptid_t ptid
, Py_ssize_t number
)
142 return btpy_new (ptid
, number
, &btpy_call_type
);
145 /* Create a new gdb.BtraceList object. */
148 btpy_list_new (ptid_t ptid
, Py_ssize_t first
, Py_ssize_t last
, Py_ssize_t step
,
149 PyTypeObject
*element_type
)
151 btpy_list_object
* const obj
= PyObject_New (btpy_list_object
,
161 obj
->element_type
= element_type
;
163 return (PyObject
*) obj
;
166 /* Implementation of BtraceInstruction.number [int] and
167 BtraceFunctionCall.number [int]. */
170 btpy_number (PyObject
*self
, void *closure
)
172 const btpy_object
* const obj
= (btpy_object
*) self
;
174 return PyInt_FromSsize_t (obj
->number
);
177 /* Implementation of BtraceInstruction.__hash__ () -> int and
178 BtraceFunctionCall.__hash__ () -> int. */
181 btpy_hash (PyObject
*self
)
183 const btpy_object
* const obj
= (btpy_object
*) self
;
188 /* Implementation of BtraceInstruction.error [int]. Returns the
189 error code for gaps. */
192 btpy_insn_error (PyObject
*self
, void *closure
)
194 const btpy_object
* const obj
= (btpy_object
*) self
;
195 struct btrace_insn_iterator iter
;
198 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
200 error
= btrace_insn_get_error (&iter
);
205 return PyInt_FromLong (error
);
208 /* Implementation of BtraceInstruction.sal [gdb.Symtab_and_line].
209 Return the SAL associated with this instruction. */
212 btpy_insn_sal (PyObject
*self
, void *closure
)
214 const btpy_object
* const obj
= (btpy_object
*) self
;
215 const struct btrace_insn
*insn
;
216 struct btrace_insn_iterator iter
;
217 PyObject
*result
= NULL
;
219 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
221 insn
= btrace_insn_get (&iter
);
227 result
= symtab_and_line_to_sal_object (find_pc_line (insn
->pc
, 0));
229 CATCH (except
, RETURN_MASK_ALL
)
231 GDB_PY_HANDLE_EXCEPTION (except
);
238 /* Implementation of BtraceInstruction.pc [int]. Returns
239 the instruction address. */
242 btpy_insn_pc (PyObject
*self
, void *closure
)
244 const btpy_object
* const obj
= (btpy_object
*) self
;
245 const struct btrace_insn
*insn
;
246 struct btrace_insn_iterator iter
;
248 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
250 insn
= btrace_insn_get (&iter
);
254 return gdb_py_long_from_ulongest (insn
->pc
);
257 /* Implementation of BtraceInstruction.size [int]. Returns
258 the instruction size. */
261 btpy_insn_size (PyObject
*self
, void *closure
)
263 const btpy_object
* const obj
= (btpy_object
*) self
;
264 const struct btrace_insn
*insn
;
265 struct btrace_insn_iterator iter
;
267 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
269 insn
= btrace_insn_get (&iter
);
273 return PyInt_FromLong (insn
->size
);
276 /* Implementation of BtraceInstruction.is_speculative [bool].
277 Returns if this instruction was executed speculatively. */
280 btpy_insn_is_speculative (PyObject
*self
, void *closure
)
282 const btpy_object
* const obj
= (btpy_object
*) self
;
283 const struct btrace_insn
*insn
;
284 struct btrace_insn_iterator iter
;
286 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
288 insn
= btrace_insn_get (&iter
);
292 if (insn
->flags
& BTRACE_INSN_FLAG_SPECULATIVE
)
298 /* Implementation of BtraceInstruction.data [buffer].
299 Returns raw instruction data. */
302 btpy_insn_data (PyObject
*self
, void *closure
)
304 const btpy_object
* const obj
= (btpy_object
*) self
;
305 const struct btrace_insn
*insn
;
306 struct btrace_insn_iterator iter
;
307 gdb_byte
*buffer
= NULL
;
310 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
312 insn
= btrace_insn_get (&iter
);
318 buffer
= (gdb_byte
*) xmalloc (insn
->size
);
319 read_memory (insn
->pc
, buffer
, insn
->size
);
321 CATCH (except
, RETURN_MASK_ALL
)
324 GDB_PY_HANDLE_EXCEPTION (except
);
328 object
= PyBytes_FromStringAndSize ((const char*) buffer
, insn
->size
);
335 return PyMemoryView_FromObject (object
);
337 return PyBuffer_FromObject (object
, 0, Py_END_OF_BUFFER
);
342 /* Implementation of BtraceInstruction.decode [str]. Returns
343 the instruction as human readable string. */
346 btpy_insn_decode (PyObject
*self
, void *closure
)
348 const btpy_object
* const obj
= (btpy_object
*) self
;
349 const struct btrace_insn
*insn
;
350 struct btrace_insn_iterator iter
;
353 BTPY_REQUIRE_VALID_INSN (obj
, iter
);
355 insn
= btrace_insn_get (&iter
);
358 int error_code
= btrace_insn_get_error (&iter
);
359 const struct btrace_config
*config
;
361 config
= btrace_conf (&find_thread_ptid (obj
->ptid
)->btrace
);
362 return PyBytes_FromString (btrace_decode_error (config
->format
,
368 gdb_print_insn (target_gdbarch (), insn
->pc
, &strfile
, NULL
);
370 CATCH (except
, RETURN_MASK_ALL
)
372 gdbpy_convert_exception (except
);
378 return PyBytes_FromString (strfile
.string ().c_str ());
381 /* Implementation of BtraceFunctionCall.level [int]. Returns the
385 btpy_call_level (PyObject
*self
, void *closure
)
387 const btpy_object
* const obj
= (btpy_object
*) self
;
388 const struct btrace_function
*func
;
389 struct btrace_call_iterator iter
;
391 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
393 func
= btrace_call_get (&iter
);
397 return PyInt_FromLong (iter
.btinfo
->level
+ func
->level
);
400 /* Implementation of BtraceFunctionCall.symbol [gdb.Symbol]. Returns
401 the symbol associated with this function call. */
404 btpy_call_symbol (PyObject
*self
, void *closure
)
406 const btpy_object
* const obj
= (btpy_object
*) self
;
407 const struct btrace_function
*func
;
408 struct btrace_call_iterator iter
;
410 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
412 func
= btrace_call_get (&iter
);
416 if (func
->sym
== NULL
)
419 return symbol_to_symbol_object (func
->sym
);
422 /* Implementation of BtraceFunctionCall.instructions [list].
423 Return the list of instructions that belong to this function call. */
426 btpy_call_instructions (PyObject
*self
, void *closure
)
428 const btpy_object
* const obj
= (btpy_object
*) self
;
429 const struct btrace_function
*func
;
430 struct btrace_call_iterator iter
;
433 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
435 func
= btrace_call_get (&iter
);
439 len
= VEC_length (btrace_insn_s
, func
->insn
);
441 /* Gaps count as one instruction. */
445 return btpy_list_new (obj
->ptid
, func
->insn_offset
, func
->insn_offset
+ len
,
449 /* Implementation of BtraceFunctionCall.up [gdb.BtraceRecordCall].
450 Return the caller / returnee of this function. */
453 btpy_call_up (PyObject
*self
, void *closure
)
455 const btpy_object
* const obj
= (btpy_object
*) self
;
456 const struct btrace_function
*func
;
457 struct btrace_call_iterator iter
;
459 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
461 func
= btrace_call_get (&iter
);
465 if (func
->up
== NULL
)
468 return btpy_call_new (obj
->ptid
, func
->up
->number
);
471 /* Implementation of BtraceFunctionCall.prev_sibling [BtraceFunctionCall].
472 Return a previous segment of this function. */
475 btpy_call_prev_sibling (PyObject
*self
, void *closure
)
477 const btpy_object
* const obj
= (btpy_object
*) self
;
478 const struct btrace_function
*func
;
479 struct btrace_call_iterator iter
;
481 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
483 func
= btrace_call_get (&iter
);
487 if (func
->segment
.prev
== NULL
)
490 return btpy_call_new (obj
->ptid
, func
->segment
.prev
->number
);
493 /* Implementation of BtraceFunctionCall.next_sibling [BtraceFunctionCall].
494 Return a following segment of this function. */
497 btpy_call_next_sibling (PyObject
*self
, void *closure
)
499 const btpy_object
* const obj
= (btpy_object
*) self
;
500 const struct btrace_function
*func
;
501 struct btrace_call_iterator iter
;
503 BTPY_REQUIRE_VALID_CALL (obj
, iter
);
505 func
= btrace_call_get (&iter
);
509 if (func
->segment
.next
== NULL
)
512 return btpy_call_new (obj
->ptid
, func
->segment
.next
->number
);
515 /* Python rich compare function to allow for equality and inequality checks
519 btpy_richcompare (PyObject
*self
, PyObject
*other
, int op
)
521 const btpy_object
* const obj1
= (btpy_object
*) self
;
522 const btpy_object
* const obj2
= (btpy_object
*) other
;
524 if (Py_TYPE (self
) != Py_TYPE (other
))
526 Py_INCREF (Py_NotImplemented
);
527 return Py_NotImplemented
;
533 if (ptid_equal (obj1
->ptid
, obj2
->ptid
) && obj1
->number
== obj2
->number
)
539 if (!ptid_equal (obj1
->ptid
, obj2
->ptid
) || obj1
->number
!= obj2
->number
)
548 Py_INCREF (Py_NotImplemented
);
549 return Py_NotImplemented
;
552 /* Implementation of BtraceList.__len__ (self) -> int. */
555 btpy_list_length (PyObject
*self
)
557 const btpy_list_object
* const obj
= (btpy_list_object
*) self
;
558 const Py_ssize_t distance
= obj
->last
- obj
->first
;
559 const Py_ssize_t result
= distance
/ obj
->step
;
561 if ((distance
% obj
->step
) == 0)
568 BtraceList.__getitem__ (self, key) -> BtraceInstruction and
569 BtraceList.__getitem__ (self, key) -> BtraceFunctionCall. */
572 btpy_list_item (PyObject
*self
, Py_ssize_t index
)
574 const btpy_list_object
* const obj
= (btpy_list_object
*) self
;
575 struct thread_info
* const tinfo
= find_thread_ptid (obj
->ptid
);
577 if (index
< 0 || index
>= btpy_list_length (self
))
578 return PyErr_Format (PyExc_IndexError
, _("Index out of range: %zd."),
581 return btpy_new (obj
->ptid
, obj
->first
+ (obj
->step
* index
),
585 /* Implementation of BtraceList.__getitem__ (self, slice) -> BtraceList. */
588 btpy_list_slice (PyObject
*self
, PyObject
*value
)
590 const btpy_list_object
* const obj
= (btpy_list_object
*) self
;
591 const Py_ssize_t length
= btpy_list_length (self
);
592 Py_ssize_t start
, stop
, step
, slicelength
;
594 if (PyInt_Check (value
))
596 Py_ssize_t index
= PyInt_AsSsize_t (value
);
598 /* Emulate Python behavior for negative indices. */
602 return btpy_list_item (self
, index
);
605 if (!PySlice_Check (value
))
606 return PyErr_Format (PyExc_TypeError
, _("Index must be int or slice."));
608 if (0 != PySlice_GetIndicesEx (BTPY_PYSLICE (value
), length
, &start
, &stop
,
609 &step
, &slicelength
))
612 return btpy_list_new (obj
->ptid
, obj
->first
+ obj
->step
* start
,
613 obj
->first
+ obj
->step
* stop
, obj
->step
* step
,
617 /* Helper function that returns the position of an element in a BtraceList
618 or -1 if the element is not in the list. */
621 btpy_list_position (PyObject
*self
, PyObject
*value
)
623 const btpy_list_object
* const list_obj
= (btpy_list_object
*) self
;
624 const btpy_object
* const obj
= (btpy_object
*) value
;
625 Py_ssize_t index
= obj
->number
;
627 if (list_obj
->element_type
!= Py_TYPE (value
))
630 if (!ptid_equal (list_obj
->ptid
, obj
->ptid
))
633 if (index
< list_obj
->first
|| index
> list_obj
->last
)
636 index
-= list_obj
->first
;
638 if (index
% list_obj
->step
!= 0)
641 return index
/ list_obj
->step
;
644 /* Implementation of "in" operator for BtraceLists. */
647 btpy_list_contains (PyObject
*self
, PyObject
*value
)
649 if (btpy_list_position (self
, value
) < 0)
655 /* Implementation of BtraceLists.index (self, value) -> int. */
658 btpy_list_index (PyObject
*self
, PyObject
*value
)
660 const LONGEST index
= btpy_list_position (self
, value
);
663 return PyErr_Format (PyExc_ValueError
, _("Not in list."));
665 return gdb_py_long_from_longest (index
);
668 /* Implementation of BtraceList.count (self, value) -> int. */
671 btpy_list_count (PyObject
*self
, PyObject
*value
)
673 /* We know that if an element is in the list, it is so exactly one time,
674 enabling us to reuse the "is element of" check. */
675 return PyInt_FromLong (btpy_list_contains (self
, value
));
678 /* Python rich compare function to allow for equality and inequality checks
682 btpy_list_richcompare (PyObject
*self
, PyObject
*other
, int op
)
684 const btpy_list_object
* const obj1
= (btpy_list_object
*) self
;
685 const btpy_list_object
* const obj2
= (btpy_list_object
*) other
;
687 if (Py_TYPE (self
) != Py_TYPE (other
))
689 Py_INCREF (Py_NotImplemented
);
690 return Py_NotImplemented
;
696 if (ptid_equal (obj1
->ptid
, obj2
->ptid
)
697 && obj1
->element_type
== obj2
->element_type
698 && obj1
->first
== obj2
->first
699 && obj1
->last
== obj2
->last
700 && obj1
->step
== obj2
->step
)
706 if (!ptid_equal (obj1
->ptid
, obj2
->ptid
)
707 || obj1
->element_type
!= obj2
->element_type
708 || obj1
->first
!= obj2
->first
709 || obj1
->last
!= obj2
->last
710 || obj1
->step
!= obj2
->step
)
719 Py_INCREF (Py_NotImplemented
);
720 return Py_NotImplemented
;
724 BtraceRecord.method [str]. */
727 recpy_bt_method (PyObject
*self
, void *closure
)
729 return PyString_FromString ("btrace");
733 BtraceRecord.format [str]. */
736 recpy_bt_format (PyObject
*self
, void *closure
)
738 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
739 const struct thread_info
* const tinfo
= find_thread_ptid (record
->ptid
);
740 const struct btrace_config
* config
;
745 config
= btrace_conf (&tinfo
->btrace
);
750 return PyString_FromString (btrace_format_short_string (config
->format
));
754 BtraceRecord.replay_position [BtraceInstruction]. */
757 recpy_bt_replay_position (PyObject
*self
, void *closure
)
759 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
760 const struct thread_info
* const tinfo
= find_thread_ptid (record
->ptid
);
765 if (tinfo
->btrace
.replay
== NULL
)
768 return btpy_insn_new (record
->ptid
,
769 btrace_insn_number (tinfo
->btrace
.replay
));
773 BtraceRecord.begin [BtraceInstruction]. */
776 recpy_bt_begin (PyObject
*self
, void *closure
)
778 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
779 struct thread_info
* const tinfo
= find_thread_ptid (record
->ptid
);
780 struct btrace_insn_iterator iterator
;
785 btrace_fetch (tinfo
);
787 if (btrace_is_empty (tinfo
))
790 btrace_insn_begin (&iterator
, &tinfo
->btrace
);
791 return btpy_insn_new (record
->ptid
, btrace_insn_number (&iterator
));
795 BtraceRecord.end [BtraceInstruction]. */
798 recpy_bt_end (PyObject
*self
, void *closure
)
800 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
801 struct thread_info
* const tinfo
= find_thread_ptid (record
->ptid
);
802 struct btrace_insn_iterator iterator
;
807 btrace_fetch (tinfo
);
809 if (btrace_is_empty (tinfo
))
812 btrace_insn_end (&iterator
, &tinfo
->btrace
);
813 return btpy_insn_new (record
->ptid
, btrace_insn_number (&iterator
));
817 BtraceRecord.instruction_history [list]. */
820 recpy_bt_instruction_history (PyObject
*self
, void *closure
)
822 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
823 struct thread_info
* const tinfo
= find_thread_ptid (record
->ptid
);
824 struct btrace_insn_iterator iterator
;
825 unsigned long first
= 0;
826 unsigned long last
= 0;
831 btrace_fetch (tinfo
);
833 if (btrace_is_empty (tinfo
))
836 btrace_insn_begin (&iterator
, &tinfo
->btrace
);
837 first
= btrace_insn_number (&iterator
);
839 btrace_insn_end (&iterator
, &tinfo
->btrace
);
840 last
= btrace_insn_number (&iterator
);
842 return btpy_list_new (record
->ptid
, first
, last
, 1, &btpy_insn_type
);
846 BtraceRecord.function_call_history [list]. */
849 recpy_bt_function_call_history (PyObject
*self
, void *closure
)
851 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
852 struct thread_info
* const tinfo
= find_thread_ptid (record
->ptid
);
853 struct btrace_call_iterator iterator
;
854 unsigned long first
= 0;
855 unsigned long last
= 0;
860 btrace_fetch (tinfo
);
862 if (btrace_is_empty (tinfo
))
865 btrace_call_begin (&iterator
, &tinfo
->btrace
);
866 first
= btrace_call_number (&iterator
);
868 btrace_call_end (&iterator
, &tinfo
->btrace
);
869 last
= btrace_call_number (&iterator
);
871 return btpy_list_new (record
->ptid
, first
, last
, 1, &btpy_call_type
);
874 /* Implementation of BtraceRecord.goto (self, BtraceInstruction) -> None. */
877 recpy_bt_goto (PyObject
*self
, PyObject
*args
)
879 const recpy_record_object
* const record
= (recpy_record_object
*) self
;
880 struct thread_info
* const tinfo
= find_thread_ptid (record
->ptid
);
881 const btpy_object
*obj
;
883 if (tinfo
== NULL
|| btrace_is_empty (tinfo
))
884 return PyErr_Format (gdbpy_gdb_error
, _("Empty branch trace."));
886 if (!PyArg_ParseTuple (args
, "O", &obj
))
889 if (Py_TYPE (obj
) != &btpy_insn_type
)
890 return PyErr_Format (PyExc_TypeError
, _("Argument must be instruction."));
894 struct btrace_insn_iterator iter
;
896 btrace_insn_end (&iter
, &tinfo
->btrace
);
898 if (btrace_insn_number (&iter
) == obj
->number
)
899 target_goto_record_end ();
901 target_goto_record (obj
->number
);
903 CATCH (except
, RETURN_MASK_ALL
)
905 GDB_PY_HANDLE_EXCEPTION (except
);
912 /* BtraceInstruction members. */
914 struct gdb_PyGetSetDef btpy_insn_getset
[] =
916 { "number", btpy_number
, NULL
, "instruction number", NULL
},
917 { "error", btpy_insn_error
, NULL
, "error number for gaps", NULL
},
918 { "sal", btpy_insn_sal
, NULL
, "associated symbol and line", NULL
},
919 { "pc", btpy_insn_pc
, NULL
, "instruction address", NULL
},
920 { "data", btpy_insn_data
, NULL
, "raw instruction data", NULL
},
921 { "decoded", btpy_insn_decode
, NULL
, "decoded instruction or error message \
922 if the instruction is a gap", NULL
},
923 { "size", btpy_insn_size
, NULL
, "instruction size in byte", NULL
},
924 { "is_speculative", btpy_insn_is_speculative
, NULL
, "if the instruction was \
925 executed speculatively", NULL
},
929 /* BtraceFunctionCall members. */
931 static gdb_PyGetSetDef btpy_call_getset
[] =
933 { "number", btpy_number
, NULL
, "function call number", NULL
},
934 { "level", btpy_call_level
, NULL
, "call stack level", NULL
},
935 { "symbol", btpy_call_symbol
, NULL
, "associated line and symbol", NULL
},
936 { "instructions", btpy_call_instructions
, NULL
, "list of instructions in \
937 this function segment", NULL
},
938 { "up", btpy_call_up
, NULL
, "caller or returned-to function segment", NULL
},
939 { "prev_sibling", btpy_call_prev_sibling
, NULL
, "previous segment of this \
941 { "next_sibling", btpy_call_next_sibling
, NULL
, "next segment of this \
946 /* BtraceList methods. */
948 struct PyMethodDef btpy_list_methods
[] =
950 { "count", btpy_list_count
, METH_O
, "count number of occurences"},
951 { "index", btpy_list_index
, METH_O
, "index of entry"},
955 /* BtraceList sequence methods. */
957 static PySequenceMethods btpy_list_sequence_methods
=
962 /* BtraceList mapping methods. Necessary for slicing. */
964 static PyMappingMethods btpy_list_mapping_methods
=
969 /* Sets up the btrace record API. */
972 gdbpy_initialize_btrace (void)
974 btpy_insn_type
.tp_new
= PyType_GenericNew
;
975 btpy_insn_type
.tp_flags
= Py_TPFLAGS_DEFAULT
;
976 btpy_insn_type
.tp_basicsize
= sizeof (btpy_object
);
977 btpy_insn_type
.tp_name
= "gdb.BtraceInstruction";
978 btpy_insn_type
.tp_doc
= "GDB btrace instruction object";
979 btpy_insn_type
.tp_getset
= btpy_insn_getset
;
980 btpy_insn_type
.tp_richcompare
= btpy_richcompare
;
981 btpy_insn_type
.tp_hash
= btpy_hash
;
983 btpy_call_type
.tp_new
= PyType_GenericNew
;
984 btpy_call_type
.tp_flags
= Py_TPFLAGS_DEFAULT
;
985 btpy_call_type
.tp_basicsize
= sizeof (btpy_object
);
986 btpy_call_type
.tp_name
= "gdb.BtraceFunctionCall";
987 btpy_call_type
.tp_doc
= "GDB btrace call object";
988 btpy_call_type
.tp_getset
= btpy_call_getset
;
989 btpy_call_type
.tp_richcompare
= btpy_richcompare
;
990 btpy_call_type
.tp_hash
= btpy_hash
;
992 btpy_list_type
.tp_new
= PyType_GenericNew
;
993 btpy_list_type
.tp_flags
= Py_TPFLAGS_DEFAULT
;
994 btpy_list_type
.tp_basicsize
= sizeof (btpy_list_object
);
995 btpy_list_type
.tp_name
= "gdb.BtraceObjectList";
996 btpy_list_type
.tp_doc
= "GDB btrace list object";
997 btpy_list_type
.tp_methods
= btpy_list_methods
;
998 btpy_list_type
.tp_as_sequence
= &btpy_list_sequence_methods
;
999 btpy_list_type
.tp_as_mapping
= &btpy_list_mapping_methods
;
1000 btpy_list_type
.tp_richcompare
= btpy_list_richcompare
;
1002 btpy_list_sequence_methods
.sq_item
= btpy_list_item
;
1003 btpy_list_sequence_methods
.sq_length
= btpy_list_length
;
1004 btpy_list_sequence_methods
.sq_contains
= btpy_list_contains
;
1006 btpy_list_mapping_methods
.mp_subscript
= btpy_list_slice
;
1008 if (PyType_Ready (&btpy_insn_type
) < 0
1009 || PyType_Ready (&btpy_call_type
) < 0
1010 || PyType_Ready (&btpy_list_type
) < 0)