binutils-gdb/gdb/python/py-record-btrace.c
Simon Marchi 798a7429f9 Remove some unused variables
This patch removes some unused variables, found with -Wunused.  I have
not removed everything reported by -Wunused, because some expressions
such as

  struct type *arg_type = check_typedef (value_type);

in bfin-tdep.c could have an unexpected but important side-effect.  I
removed others that I considered more low-risk, such as:

  struct gdbarch *gdbarch = get_objfile_arch (objfile);

I tested building with Python 2/Python 3/no Python, with/without expat,
with/without libipt and with/without babeltrace.

gdb/ChangeLog:

	* ada-lang.c (ada_collect_symbol_completion_matches): Remove
	unused variables.
	(ada_is_redundant_range_encoding): Likewise.
	* ada-varobj.c (ada_varobj_get_value_of_array_variable):
	Likewise.
	* alpha-tdep.c (alpha_software_single_step): Likewise.
	* arm-tdep.c (_initialize_arm_tdep): Likewise.
	* auto-load.c (info_auto_load_cmd): Likewise.
	* break-catch-syscall.c (insert_catch_syscall): Likewise.
	(remove_catch_syscall): Likewise.
	* breakpoint.c (condition_completer): Likewise.
	(clear_command): Likewise.
	(update_breakpoint_locations): Likewise.
	* btrace.c (btrace_disable): Likewise.
	(btrace_teardown): Likewise.
	(btrace_maint_update_pt_packets): Likewise.
	(maint_btrace_clear_cmd): Likewise.
	* cli/cli-decode.c (lookup_cmd_1): Likewise.
	(lookup_cmd_composition): Likewise.
	* cli/cli-dump.c (scan_filename): Likewise.
	(restore_command): Likewise.
	* compile/compile-loc2c.c (compute_stack_depth): Likewise.
	* compile/compile-object-load.c (compile_object_load): Likewise.
	* compile/compile-object-run.c (compile_object_run): Likewise.
	* compile/compile.c (compile_to_object): Likewise.
	* completer.c (filename_completer): Likewise.
	(complete_files_symbols): Likewise.
	(complete_expression): Likewise.
	* corelow.c (core_open): Likewise.
	* ctf.c (ctf_start): Likewise.
	(ctf_write_status): Likewise.
	(ctf_write_uploaded_tsv): Likewise.
	(ctf_write_definition_end): Likewise.
	(ctf_open_dir): Likewise.
	(ctf_xfer_partial): Likewise.
	(ctf_trace_find): Likewise.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
	Likewise.
	* dwarf2loc.c (allocate_piece_closure): Likewise.
	(indirect_pieced_value): Likewise.
	(dwarf2_evaluate_loc_desc_full): Likewise.
	* dwarf2read.c (dw2_expand_marked_cus): Likewise.
	(dw2_expand_symtabs_matching): Likewise.
	(dw2_map_symbol_filenames): Likewise.
	(read_and_check_comp_unit_head): Likewise.
	(read_cutu_die_from_dwo): Likewise.
	(lookup_dwo_unit): Likewise.
	(read_comp_units_from_section): Likewise.
	(dwarf2_compute_name): Likewise.
	(handle_DW_AT_stmt_list): Likewise.
	(create_cus_hash_table): Likewise.
	(create_dwp_v2_section): Likewise.
	(dwarf2_rnglists_process): Likewise.
	(dwarf2_ranges_process): Likewise.
	(dwarf2_record_block_ranges): Likewise.
	(is_vtable_name): Likewise.
	(read_formatted_entries): Likewise.
	(skip_form_bytes): Likewise.
	* elfread.c (elf_symtab_read): Likewise.
	* exec.c (exec_file_command): Likewise.
	* f-valprint.c (f_val_print): Likewise.
	(info_common_command_for_block): Likewise.
	* guile/guile.c (initialize_scheme_side): Likewise.
	* guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Likewise.
	* guile/scm-cmd.c (cmdscm_completer): Likewise.
	(gdbscm_register_command_x): Likewise.
	* guile/scm-frame.c (gdbscm_frame_read_var): Likewise.
	* guile/scm-param.c (gdbscm_parameter_value): Likewise.
	* guile/scm-ports.c (file_port_magic): Likewise.
	* guile/scm-pretty-print.c (ppscm_search_pp_list): Likewise.
	(ppscm_pretty_print_one_value): Likewise.
	(ppscm_print_children): Likewise.
	* guile/scm-string.c (gdbscm_string_to_argv): Likewise.
	* guile/scm-symtab.c (gdbscm_sal_symtab): Likewise.
	* guile/scm-type.c (gdbscm_type_next_field_x): Likewise.
	* guile/scm-utils.c (gdbscm_parse_function_args): Likewise.
	* i386-tdep.c (i386_register_reggroup_p): Likewise.
	* infcmd.c (run_command_1): Likewise.
	(until_next_fsm_clean_up): Likewise.
	* linespec.c (linespec_complete): Likewise.
	(find_label_symbols): Likewise.
	* m2-valprint.c (m2_val_print): Likewise.
	* memattr.c (require_user_regions): Likewise.
	(lookup_mem_region): Likewise.
	(disable_mem_command): Likewise.
	(mem_delete): Likewise.
	* mep-tdep.c (mep_register_name): Likewise.
	(mep_analyze_prologue): Likewise.
	* mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Likewise.
	* mi/mi-interp.c (mi_on_sync_execution_done): Likewise.
	* mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise.
	* microblaze-linux-tdep.c (microblaze_linux_init_abi): Likewise.
	* minidebug.c (lzma_open): Likewise.
	* minsyms.c (lookup_minimal_symbol): Likewise.
	* mips-linux-tdep.c (mips64_fill_fpregset): Likewise.
	* mips-tdep.c (mips_stub_frame_sniffer): Likewise.
	(mips_o64_return_value): Likewise.
	(mips_single_step_through_delay): Likewise.
	(_initialize_mips_tdep): Likewise.
	* nios2-tdep.c (nios2_push_dummy_call): Likewise.
	(nios2_software_single_step): Likewise.
	* parse.c (find_minsym_type_and_address): Likewise.
	* psymtab.c (psym_relocate): Likewise.
	* python/py-breakpoint.c (bppy_get_commands): Likewise.
	(gdbpy_breakpoint_modified): Likewise.
	* python/py-infevents.c (create_inferior_call_event_object):
	Likewise.
	* python/py-record-btrace.c (btpy_list_item): Likewise.
	* python/py-type.c (typy_str): Likewise.
	* python/py-value.c (valpy_call): Likewise.
	* python/python.c (do_start_initialization): Likewise.
	* record-btrace.c (record_btrace_insn_history_range): Likewise.
	(record_btrace_call_history_range): Likewise.
	(record_btrace_record_method): Likewise.
	(record_btrace_xfer_partial): Likewise.
	(btrace_get_frame_function): Likewise.
	* record-full.c (record_full_open): Likewise.
	* record.c (get_context_size): Likewise.
	* registry.h (DEFINE_REGISTRY): Likewise.
	* remote-fileio.c (remote_fileio_request): Likewise.
	* remote.c (remote_update_thread_list): Likewise.
	(remote_check_symbols): Likewise.
	(remote_commit_resume): Likewise.
	(remote_interrupt): Likewise.
	(remote_insert_breakpoint): Likewise.
	(compare_sections_command): Likewise.
	* rust-exp.y (super_name): Likewise.
	(lex_string): Likewise.
	(convert_ast_to_type): Likewise.
	(convert_ast_to_expression): Likewise.
	* rust-lang.c (rust_print_struct_def): Likewise.
	(rust_print_type): Likewise.
	(rust_evaluate_subexp): Likewise.
	* rx-tdep.c (rx_register_type): Likewise.
	* ser-event.c (serial_event_clear): Likewise.
	* serial.c (serial_open): Likewise.
	* spu-tdep.c (spu_overlay_new_objfile): Likewise.
	* symfile.c (section_is_overlay): Likewise.
	(overlay_unmapped_address): Likewise.
	(overlay_mapped_address): Likewise.
	(simple_overlay_update_1): Likewise.
	(simple_overlay_update): Likewise.
	* symtab.c (symbol_find_demangled_name): Likewise.
	(search_symbols): Likewise.
	* target-descriptions.c (tdesc_predefined_type): Likewise.
	* target.c (target_commit_resume): Likewise.
	* thread.c (print_selected_thread_frame): Likewise.
	* top.c (new_ui_command): Likewise.
	(gdb_readline_no_editing): Likewise.
	* tracefile-tfile.c (tfile_open): Likewise.
	* tracepoint.c (create_tsv_from_upload): Likewise.
	* utils.c (quit): Likewise.
	(defaulted_query): Likewise.
	* valarith.c (value_concat): Likewise.
	* xml-syscall.c (xml_list_syscalls_by_group): Likewise.
	* xml-tdesc.c (target_fetch_description_xml): Likewise.
	* xtensa-tdep.c (xtensa_pseudo_register_read): Likewise.
	(xtensa_pseudo_register_write): Likewise.

gdb/gdbserver/ChangeLog:

	* regcache.c (registers_to_string): Remove unused variable.
2017-12-05 16:05:50 -05:00

853 lines
21 KiB
C

/* Python interface to btrace instruction history.
Copyright 2016-2017 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "gdbcore.h"
#include "gdbcmd.h"
#include "gdbthread.h"
#include "btrace.h"
#include "py-record.h"
#include "py-record-btrace.h"
#include "disasm.h"
#if defined (IS_PY3K)
#define BTPY_PYSLICE(x) (x)
#else
#define BTPY_PYSLICE(x) ((PySliceObject *) x)
#endif
/* Python object for btrace record lists. */
typedef struct {
PyObject_HEAD
/* The thread this list belongs to. */
ptid_t ptid;
/* The first index being part of this list. */
Py_ssize_t first;
/* The last index begin part of this list. */
Py_ssize_t last;
/* Stride size. */
Py_ssize_t step;
/* Either &BTPY_CALL_TYPE or &RECPY_INSN_TYPE. */
PyTypeObject* element_type;
} btpy_list_object;
/* Python type for btrace lists. */
static PyTypeObject btpy_list_type = {
PyVarObject_HEAD_INIT (NULL, 0)
};
/* Returns either a btrace_insn for the given Python gdb.RecordInstruction
object or sets an appropriate Python exception and returns NULL. */
static const btrace_insn *
btrace_insn_from_recpy_insn (const PyObject * const pyobject)
{
const btrace_insn *insn;
const recpy_element_object *obj;
thread_info *tinfo;
btrace_insn_iterator iter;
if (Py_TYPE (pyobject) != &recpy_insn_type)
{
PyErr_Format (gdbpy_gdb_error, _("Must be gdb.RecordInstruction"));
return NULL;
}
obj = (const recpy_element_object *) pyobject;
tinfo = find_thread_ptid (obj->ptid);
if (tinfo == NULL || btrace_is_empty (tinfo))
{
PyErr_Format (gdbpy_gdb_error, _("No such instruction."));
return NULL;
}
if (btrace_find_insn_by_number (&iter, &tinfo->btrace, obj->number) == 0)
{
PyErr_Format (gdbpy_gdb_error, _("No such instruction."));
return NULL;
}
insn = btrace_insn_get (&iter);
if (insn == NULL)
{
PyErr_Format (gdbpy_gdb_error, _("Not a valid instruction."));
return NULL;
}
return insn;
}
/* Returns either a btrace_function for the given Python
gdb.RecordFunctionSegment object or sets an appropriate Python exception and
returns NULL. */
static const btrace_function *
btrace_func_from_recpy_func (const PyObject * const pyobject)
{
const btrace_function *func;
const recpy_element_object *obj;
thread_info *tinfo;
btrace_call_iterator iter;
if (Py_TYPE (pyobject) != &recpy_func_type)
{
PyErr_Format (gdbpy_gdb_error, _("Must be gdb.RecordFunctionSegment"));
return NULL;
}
obj = (const recpy_element_object *) pyobject;
tinfo = find_thread_ptid (obj->ptid);
if (tinfo == NULL || btrace_is_empty (tinfo))
{
PyErr_Format (gdbpy_gdb_error, _("No such function segment."));
return NULL;
}
if (btrace_find_call_by_number (&iter, &tinfo->btrace, obj->number) == 0)
{
PyErr_Format (gdbpy_gdb_error, _("No such function segment."));
return NULL;
}
func = btrace_call_get (&iter);
if (func == NULL)
{
PyErr_Format (gdbpy_gdb_error, _("Not a valid function segment."));
return NULL;
}
return func;
}
/* Looks at the recorded item with the number NUMBER and create a
gdb.RecordInstruction or gdb.RecordGap object for it accordingly. */
static PyObject *
btpy_insn_or_gap_new (const thread_info *tinfo, Py_ssize_t number)
{
btrace_insn_iterator iter;
int err_code;
btrace_find_insn_by_number (&iter, &tinfo->btrace, number);
err_code = btrace_insn_get_error (&iter);
if (err_code != 0)
{
const btrace_config *config;
const char *err_string;
config = btrace_conf (&tinfo->btrace);
err_string = btrace_decode_error (config->format, err_code);
return recpy_gap_new (err_code, err_string, number);
}
return recpy_insn_new (tinfo->ptid, RECORD_METHOD_BTRACE, number);
}
/* Create a new gdb.BtraceList object. */
static PyObject *
btpy_list_new (ptid_t ptid, Py_ssize_t first, Py_ssize_t last, Py_ssize_t step,
PyTypeObject *element_type)
{
btpy_list_object * const obj = PyObject_New (btpy_list_object,
&btpy_list_type);
if (obj == NULL)
return NULL;
obj->ptid = ptid;
obj->first = first;
obj->last = last;
obj->step = step;
obj->element_type = element_type;
return (PyObject *) obj;
}
/* Implementation of RecordInstruction.sal [gdb.Symtab_and_line] for btrace.
Returns the SAL associated with this instruction. */
PyObject *
recpy_bt_insn_sal (PyObject *self, void *closure)
{
const btrace_insn * const insn = btrace_insn_from_recpy_insn (self);
PyObject *result = NULL;
if (insn == NULL)
return NULL;
TRY
{
result = symtab_and_line_to_sal_object (find_pc_line (insn->pc, 0));
}
CATCH (except, RETURN_MASK_ALL)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
END_CATCH
return result;
}
/* Implementation of RecordInstruction.pc [int] for btrace.
Returns the instruction address. */
PyObject *
recpy_bt_insn_pc (PyObject *self, void *closure)
{
const btrace_insn * const insn = btrace_insn_from_recpy_insn (self);
if (insn == NULL)
return NULL;
return gdb_py_long_from_ulongest (insn->pc);
}
/* Implementation of RecordInstruction.size [int] for btrace.
Returns the instruction size. */
PyObject *
recpy_bt_insn_size (PyObject *self, void *closure)
{
const btrace_insn * const insn = btrace_insn_from_recpy_insn (self);
if (insn == NULL)
return NULL;
return PyInt_FromLong (insn->size);
}
/* Implementation of RecordInstruction.is_speculative [bool] for btrace.
Returns if this instruction was executed speculatively. */
PyObject *
recpy_bt_insn_is_speculative (PyObject *self, void *closure)
{
const btrace_insn * const insn = btrace_insn_from_recpy_insn (self);
if (insn == NULL)
return NULL;
if (insn->flags & BTRACE_INSN_FLAG_SPECULATIVE)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
/* Implementation of RecordInstruction.data [buffer] for btrace.
Returns raw instruction data. */
PyObject *
recpy_bt_insn_data (PyObject *self, void *closure)
{
const btrace_insn * const insn = btrace_insn_from_recpy_insn (self);
gdb_byte *buffer = NULL;
PyObject *object;
if (insn == NULL)
return NULL;
TRY
{
buffer = (gdb_byte *) xmalloc (insn->size);
read_memory (insn->pc, buffer, insn->size);
}
CATCH (except, RETURN_MASK_ALL)
{
xfree (buffer);
GDB_PY_HANDLE_EXCEPTION (except);
}
END_CATCH
object = PyBytes_FromStringAndSize ((const char*) buffer, insn->size);
xfree (buffer);
if (object == NULL)
return NULL;
#ifdef IS_PY3K
return PyMemoryView_FromObject (object);
#else
return PyBuffer_FromObject (object, 0, Py_END_OF_BUFFER);
#endif
}
/* Implementation of RecordInstruction.decoded [str] for btrace.
Returns the instruction as human readable string. */
PyObject *
recpy_bt_insn_decoded (PyObject *self, void *closure)
{
const btrace_insn * const insn = btrace_insn_from_recpy_insn (self);
string_file strfile;
if (insn == NULL)
return NULL;
TRY
{
gdb_print_insn (target_gdbarch (), insn->pc, &strfile, NULL);
}
CATCH (except, RETURN_MASK_ALL)
{
gdbpy_convert_exception (except);
return NULL;
}
END_CATCH
return PyBytes_FromString (strfile.string ().c_str ());
}
/* Implementation of RecordFunctionSegment.level [int] for btrace.
Returns the call level. */
PyObject *
recpy_bt_func_level (PyObject *self, void *closure)
{
const btrace_function * const func = btrace_func_from_recpy_func (self);
thread_info *tinfo;
if (func == NULL)
return NULL;
tinfo = find_thread_ptid (((recpy_element_object *) self)->ptid);
return PyInt_FromLong (tinfo->btrace.level + func->level);
}
/* Implementation of RecordFunctionSegment.symbol [gdb.Symbol] for btrace.
Returns the symbol associated with this function call. */
PyObject *
recpy_bt_func_symbol (PyObject *self, void *closure)
{
const btrace_function * const func = btrace_func_from_recpy_func (self);
if (func == NULL)
return NULL;
if (func->sym == NULL)
Py_RETURN_NONE;
return symbol_to_symbol_object (func->sym);
}
/* Implementation of RecordFunctionSegment.instructions [list] for btrace.
Returns the list of instructions that belong to this function call. */
PyObject *
recpy_bt_func_instructions (PyObject *self, void *closure)
{
const btrace_function * const func = btrace_func_from_recpy_func (self);
unsigned int len;
if (func == NULL)
return NULL;
len = func->insn.size ();
/* Gaps count as one instruction. */
if (len == 0)
len = 1;
return btpy_list_new (((recpy_element_object *) self)->ptid,
func->insn_offset, func->insn_offset + len, 1,
&recpy_insn_type);
}
/* Implementation of RecordFunctionSegment.up [RecordFunctionSegment] for
btrace. Returns the caller / returnee of this function. */
PyObject *
recpy_bt_func_up (PyObject *self, void *closure)
{
const btrace_function * const func = btrace_func_from_recpy_func (self);
if (func == NULL)
return NULL;
if (func->up == 0)
Py_RETURN_NONE;
return recpy_func_new (((recpy_element_object *) self)->ptid,
RECORD_METHOD_BTRACE, func->up);
}
/* Implementation of RecordFunctionSegment.prev [RecordFunctionSegment] for
btrace. Returns a previous segment of this function. */
PyObject *
recpy_bt_func_prev (PyObject *self, void *closure)
{
const btrace_function * const func = btrace_func_from_recpy_func (self);
if (func == NULL)
return NULL;
if (func->prev == 0)
Py_RETURN_NONE;
return recpy_func_new (((recpy_element_object *) self)->ptid,
RECORD_METHOD_BTRACE, func->prev);
}
/* Implementation of RecordFunctionSegment.next [RecordFunctionSegment] for
btrace. Returns a following segment of this function. */
PyObject *
recpy_bt_func_next (PyObject *self, void *closure)
{
const btrace_function * const func = btrace_func_from_recpy_func (self);
if (func == NULL)
return NULL;
if (func->next == 0)
Py_RETURN_NONE;
return recpy_func_new (((recpy_element_object *) self)->ptid,
RECORD_METHOD_BTRACE, func->next);
}
/* Implementation of BtraceList.__len__ (self) -> int. */
static Py_ssize_t
btpy_list_length (PyObject *self)
{
const btpy_list_object * const obj = (btpy_list_object *) self;
const Py_ssize_t distance = obj->last - obj->first;
const Py_ssize_t result = distance / obj->step;
if ((distance % obj->step) == 0)
return result;
return result + 1;
}
/* Implementation of
BtraceList.__getitem__ (self, key) -> BtraceInstruction and
BtraceList.__getitem__ (self, key) -> BtraceFunctionCall. */
static PyObject *
btpy_list_item (PyObject *self, Py_ssize_t index)
{
const btpy_list_object * const obj = (btpy_list_object *) self;
Py_ssize_t number;
if (index < 0 || index >= btpy_list_length (self))
return PyErr_Format (PyExc_IndexError, _("Index out of range: %zd."),
index);
number = obj->first + (obj->step * index);
if (obj->element_type == &recpy_insn_type)
return recpy_insn_new (obj->ptid, RECORD_METHOD_BTRACE, number);
else
return recpy_func_new (obj->ptid, RECORD_METHOD_BTRACE, number);
}
/* Implementation of BtraceList.__getitem__ (self, slice) -> BtraceList. */
static PyObject *
btpy_list_slice (PyObject *self, PyObject *value)
{
const btpy_list_object * const obj = (btpy_list_object *) self;
const Py_ssize_t length = btpy_list_length (self);
Py_ssize_t start, stop, step, slicelength;
if (PyInt_Check (value))
{
Py_ssize_t index = PyInt_AsSsize_t (value);
/* Emulate Python behavior for negative indices. */
if (index < 0)
index += length;
return btpy_list_item (self, index);
}
if (!PySlice_Check (value))
return PyErr_Format (PyExc_TypeError, _("Index must be int or slice."));
if (0 != PySlice_GetIndicesEx (BTPY_PYSLICE (value), length, &start, &stop,
&step, &slicelength))
return NULL;
return btpy_list_new (obj->ptid, obj->first + obj->step * start,
obj->first + obj->step * stop, obj->step * step,
obj->element_type);
}
/* Helper function that returns the position of an element in a BtraceList
or -1 if the element is not in the list. */
static LONGEST
btpy_list_position (PyObject *self, PyObject *value)
{
const btpy_list_object * const list_obj = (btpy_list_object *) self;
const recpy_element_object * const obj = (const recpy_element_object *) value;
Py_ssize_t index = obj->number;
if (list_obj->element_type != Py_TYPE (value))
return -1;
if (!ptid_equal (list_obj->ptid, obj->ptid))
return -1;
if (index < list_obj->first || index > list_obj->last)
return -1;
index -= list_obj->first;
if (index % list_obj->step != 0)
return -1;
return index / list_obj->step;
}
/* Implementation of "in" operator for BtraceLists. */
static int
btpy_list_contains (PyObject *self, PyObject *value)
{
if (btpy_list_position (self, value) < 0)
return 0;
return 1;
}
/* Implementation of BtraceLists.index (self, value) -> int. */
static PyObject *
btpy_list_index (PyObject *self, PyObject *value)
{
const LONGEST index = btpy_list_position (self, value);
if (index < 0)
return PyErr_Format (PyExc_ValueError, _("Not in list."));
return gdb_py_long_from_longest (index);
}
/* Implementation of BtraceList.count (self, value) -> int. */
static PyObject *
btpy_list_count (PyObject *self, PyObject *value)
{
/* We know that if an element is in the list, it is so exactly one time,
enabling us to reuse the "is element of" check. */
return PyInt_FromLong (btpy_list_contains (self, value));
}
/* Python rich compare function to allow for equality and inequality checks
in Python. */
static PyObject *
btpy_list_richcompare (PyObject *self, PyObject *other, int op)
{
const btpy_list_object * const obj1 = (btpy_list_object *) self;
const btpy_list_object * const obj2 = (btpy_list_object *) other;
if (Py_TYPE (self) != Py_TYPE (other))
{
Py_INCREF (Py_NotImplemented);
return Py_NotImplemented;
}
switch (op)
{
case Py_EQ:
if (ptid_equal (obj1->ptid, obj2->ptid)
&& obj1->element_type == obj2->element_type
&& obj1->first == obj2->first
&& obj1->last == obj2->last
&& obj1->step == obj2->step)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
case Py_NE:
if (!ptid_equal (obj1->ptid, obj2->ptid)
|| obj1->element_type != obj2->element_type
|| obj1->first != obj2->first
|| obj1->last != obj2->last
|| obj1->step != obj2->step)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
default:
break;
}
Py_INCREF (Py_NotImplemented);
return Py_NotImplemented;
}
/* Implementation of
BtraceRecord.method [str]. */
PyObject *
recpy_bt_method (PyObject *self, void *closure)
{
return PyString_FromString ("btrace");
}
/* Implementation of
BtraceRecord.format [str]. */
PyObject *
recpy_bt_format (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
const struct thread_info * const tinfo = find_thread_ptid (record->ptid);
const struct btrace_config * config;
if (tinfo == NULL)
Py_RETURN_NONE;
config = btrace_conf (&tinfo->btrace);
if (config == NULL)
Py_RETURN_NONE;
return PyString_FromString (btrace_format_short_string (config->format));
}
/* Implementation of
BtraceRecord.replay_position [BtraceInstruction]. */
PyObject *
recpy_bt_replay_position (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
const struct thread_info * const tinfo = find_thread_ptid (record->ptid);
if (tinfo == NULL)
Py_RETURN_NONE;
if (tinfo->btrace.replay == NULL)
Py_RETURN_NONE;
return btpy_insn_or_gap_new (tinfo,
btrace_insn_number (tinfo->btrace.replay));
}
/* Implementation of
BtraceRecord.begin [BtraceInstruction]. */
PyObject *
recpy_bt_begin (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
struct thread_info * const tinfo = find_thread_ptid (record->ptid);
struct btrace_insn_iterator iterator;
if (tinfo == NULL)
Py_RETURN_NONE;
btrace_fetch (tinfo);
if (btrace_is_empty (tinfo))
Py_RETURN_NONE;
btrace_insn_begin (&iterator, &tinfo->btrace);
return btpy_insn_or_gap_new (tinfo, btrace_insn_number (&iterator));
}
/* Implementation of
BtraceRecord.end [BtraceInstruction]. */
PyObject *
recpy_bt_end (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
struct thread_info * const tinfo = find_thread_ptid (record->ptid);
struct btrace_insn_iterator iterator;
if (tinfo == NULL)
Py_RETURN_NONE;
btrace_fetch (tinfo);
if (btrace_is_empty (tinfo))
Py_RETURN_NONE;
btrace_insn_end (&iterator, &tinfo->btrace);
return btpy_insn_or_gap_new (tinfo, btrace_insn_number (&iterator));
}
/* Implementation of
BtraceRecord.instruction_history [list]. */
PyObject *
recpy_bt_instruction_history (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
struct thread_info * const tinfo = find_thread_ptid (record->ptid);
struct btrace_insn_iterator iterator;
unsigned long first = 0;
unsigned long last = 0;
if (tinfo == NULL)
Py_RETURN_NONE;
btrace_fetch (tinfo);
if (btrace_is_empty (tinfo))
Py_RETURN_NONE;
btrace_insn_begin (&iterator, &tinfo->btrace);
first = btrace_insn_number (&iterator);
btrace_insn_end (&iterator, &tinfo->btrace);
last = btrace_insn_number (&iterator);
return btpy_list_new (record->ptid, first, last, 1, &recpy_insn_type);
}
/* Implementation of
BtraceRecord.function_call_history [list]. */
PyObject *
recpy_bt_function_call_history (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
struct thread_info * const tinfo = find_thread_ptid (record->ptid);
struct btrace_call_iterator iterator;
unsigned long first = 0;
unsigned long last = 0;
if (tinfo == NULL)
Py_RETURN_NONE;
btrace_fetch (tinfo);
if (btrace_is_empty (tinfo))
Py_RETURN_NONE;
btrace_call_begin (&iterator, &tinfo->btrace);
first = btrace_call_number (&iterator);
btrace_call_end (&iterator, &tinfo->btrace);
last = btrace_call_number (&iterator);
return btpy_list_new (record->ptid, first, last, 1, &recpy_func_type);
}
/* Implementation of BtraceRecord.goto (self, BtraceInstruction) -> None. */
PyObject *
recpy_bt_goto (PyObject *self, PyObject *args)
{
const recpy_record_object * const record = (recpy_record_object *) self;
struct thread_info * const tinfo = find_thread_ptid (record->ptid);
const recpy_element_object *obj;
if (tinfo == NULL || btrace_is_empty (tinfo))
return PyErr_Format (gdbpy_gdb_error, _("Empty branch trace."));
if (!PyArg_ParseTuple (args, "O", &obj))
return NULL;
if (Py_TYPE (obj) != &recpy_insn_type)
return PyErr_Format (PyExc_TypeError, _("Argument must be instruction."));
TRY
{
struct btrace_insn_iterator iter;
btrace_insn_end (&iter, &tinfo->btrace);
if (btrace_insn_number (&iter) == obj->number)
target_goto_record_end ();
else
target_goto_record (obj->number);
}
CATCH (except, RETURN_MASK_ALL)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
END_CATCH
Py_RETURN_NONE;
}
/* BtraceList methods. */
struct PyMethodDef btpy_list_methods[] =
{
{ "count", btpy_list_count, METH_O, "count number of occurences"},
{ "index", btpy_list_index, METH_O, "index of entry"},
{NULL}
};
/* BtraceList sequence methods. */
static PySequenceMethods btpy_list_sequence_methods =
{
NULL
};
/* BtraceList mapping methods. Necessary for slicing. */
static PyMappingMethods btpy_list_mapping_methods =
{
NULL
};
/* Sets up the btrace record API. */
int
gdbpy_initialize_btrace (void)
{
btpy_list_type.tp_new = PyType_GenericNew;
btpy_list_type.tp_flags = Py_TPFLAGS_DEFAULT;
btpy_list_type.tp_basicsize = sizeof (btpy_list_object);
btpy_list_type.tp_name = "gdb.BtraceObjectList";
btpy_list_type.tp_doc = "GDB btrace list object";
btpy_list_type.tp_methods = btpy_list_methods;
btpy_list_type.tp_as_sequence = &btpy_list_sequence_methods;
btpy_list_type.tp_as_mapping = &btpy_list_mapping_methods;
btpy_list_type.tp_richcompare = btpy_list_richcompare;
btpy_list_sequence_methods.sq_item = btpy_list_item;
btpy_list_sequence_methods.sq_length = btpy_list_length;
btpy_list_sequence_methods.sq_contains = btpy_list_contains;
btpy_list_mapping_methods.mp_subscript = btpy_list_slice;
return PyType_Ready (&btpy_list_type);
}