mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-14 12:53:34 +08:00
a121b7c1ac
This is the remainder boring constification that all looks more of less borderline obvious IMO. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * ada-exp.y (yyerror): Constify. * ada-lang.c (bound_name, get_selections) (ada_variant_discrim_type) (ada_variant_discrim_name, ada_value_struct_elt) (ada_lookup_struct_elt_type, is_unchecked_variant) (ada_which_variant_applies, standard_exc, ada_get_next_arg) (catch_ada_exception_command_split) (catch_ada_assert_command_split, catch_assert_command) (ada_op_name): Constify. * ada-lang.h (ada_yyerror, get_selections) (ada_variant_discrim_name, ada_value_struct_elt): Constify. * arc-tdep.c (arc_print_frame_cache): Constify. * arm-tdep.c (arm_skip_stub): Constify. * ax-gdb.c (gen_binop, gen_struct_ref_recursive, gen_struct_ref) (gen_aggregate_elt_ref): Constify. * bcache.c (print_bcache_statistics): Constify. * bcache.h (print_bcache_statistics): Constify. * break-catch-throw.c (catch_exception_command_1): * breakpoint.c (struct ep_type_description::description): Constify. (add_solib_catchpoint): Constify. (catch_fork_command_1): Add cast. (add_catch_command): Constify. * breakpoint.h (add_catch_command, add_solib_catchpoint): Constify. * bsd-uthread.c (bsd_uthread_state): Constify. * buildsym.c (patch_subfile_names): Constify. * buildsym.h (next_symbol_text_func, patch_subfile_names): Constify. * c-exp.y (yyerror): Constify. (token::oper): Constify. * c-lang.h (c_yyerror, cp_print_class_member): Constify. * c-varobj.c (cplus_describe_child): Constify. * charset.c (find_charset_names): Add cast. (find_charset_names): Constify array and add const_cast. * cli/cli-cmds.c (complete_command, cd_command): Constify. (edit_command): Constify. * cli/cli-decode.c (lookup_cmd): Constify. * cli/cli-dump.c (dump_memory_command, dump_value_command): Constify. (struct dump_context): Constify. (add_dump_command, restore_command): Constify. * cli/cli-script.c (get_command_line): Constify. * cli/cli-script.h (get_command_line): Constify. * cli/cli-utils.c (check_for_argument): Constify. * cli/cli-utils.h (check_for_argument): Constify. * coff-pe-read.c (struct read_pe_section_data): Constify. * command.h (lookup_cmd): Constify. * common/print-utils.c (decimal2str): Constify. * completer.c (gdb_print_filename): Constify. * corefile.c (set_gnutarget): Constify. * cp-name-parser.y (yyerror): Constify. * cp-valprint.c (cp_print_class_member): Constify. * cris-tdep.c (cris_register_name, crisv32_register_name): Constify. * d-exp.y (yyerror): Constify. (struct token::oper): Constify. * d-lang.h (d_yyerror): Constify. * dbxread.c (struct header_file_location::name): Constify. (add_old_header_file, add_new_header_file, last_function_name) (dbx_next_symbol_text, add_bincl_to_list) (find_corresponding_bincl_psymtab, set_namestring) (find_stab_function_addr, read_dbx_symtab, start_psymtab) (dbx_end_psymtab, read_ofile_symtab, process_one_symbol): * defs.h (command_line_input, print_address_symbolic) (deprecated_readline_begin_hook): Constify. * dwarf2read.c (anonymous_struct_prefix, dwarf_bool_name): Constify. * event-top.c (handle_line_of_input): Constify and add cast. * exceptions.c (catch_errors): Constify. * exceptions.h (catch_errors): Constify. * expprint.c (print_subexp_standard, op_string, op_name) (op_name_standard, dump_raw_expression, dump_raw_expression): * expression.h (op_name, op_string, dump_raw_expression): Constify. * f-exp.y (yyerror): Constify. (struct token::oper): Constify. (struct f77_boolean_val::name): Constify. * f-lang.c (f_word_break_characters): Constify. * f-lang.h (f_yyerror): Constify. * fork-child.c (fork_inferior): Add cast. * frv-tdep.c (struct gdbarch_tdep::register_names): Constify. (new_variant): Constify. * gdbarch.sh (pstring_ptr, pstring_list): Constify. * gdbarch.c: Regenerate. * gdbcore.h (set_gnutarget): Constify. * go-exp.y (yyerror): Constify. (token::oper): Constify. * go-lang.h (go_yyerror): Constify. * go32-nat.c (go32_sysinfo): Constify. * guile/scm-breakpoint.c (gdbscm_breakpoint_expression): Constify. * guile/scm-cmd.c (cmdscm_function): Constify. * guile/scm-param.c (pascm_param_value): Constify. * h8300-tdep.c (h8300_register_name, h8300s_register_name) (h8300sx_register_name): Constify. * hppa-tdep.c (hppa32_register_name, hppa64_register_name): Constify. * ia64-tdep.c (ia64_register_names): Constify. * infcmd.c (construct_inferior_arguments): Constify. (path_command, attach_post_wait): Constify. * language.c (show_range_command, show_case_command) (unk_lang_error): Constify. * language.h (language_defn::la_error) (language_defn::la_name_of_this): Constify. * linespec.c (decode_line_2): Constify. * linux-thread-db.c (thread_db_err_str): Constify. * lm32-tdep.c (lm32_register_name): Constify. * m2-exp.y (yyerror): Constify. * m2-lang.h (m2_yyerror): Constify. * m32r-tdep.c (m32r_register_names): Constify and make static. * m68hc11-tdep.c (m68hc11_register_names): Constify. * m88k-tdep.c (m88k_register_name): Constify. * macroexp.c (appendmem): Constify. * mdebugread.c (fdr_name, add_data_symbol, parse_type) (upgrade_type, parse_external, parse_partial_symbols) (mdebug_next_symbol_text, cross_ref, mylookup_symbol, new_psymtab) (new_symbol): Constify. * memattr.c (mem_info_command): Constify. * mep-tdep.c (register_name_from_keyword): Constify. * mi/mi-cmd-env.c (mi_cmd_env_path, _initialize_mi_cmd_env): Constify. * mi/mi-cmd-stack.c (list_args_or_locals): Constify. * mi/mi-cmd-var.c (mi_cmd_var_show_attributes): Constify. * mi/mi-main.c (captured_mi_execute_command): Constify and add cast. (mi_execute_async_cli_command): Constify. * mips-tdep.c (mips_register_name): Constify. * mn10300-tdep.c (register_name, mn10300_generic_register_name) (am33_register_name, am33_2_register_name) * moxie-tdep.c (moxie_register_names): Constify. * nat/linux-osdata.c (osdata_type): Constify fields. * nto-tdep.c (nto_parse_redirection): Constify. * objc-lang.c (lookup_struct_typedef, lookup_objc_class) (lookup_child_selector): Constify. (objc_methcall::name): Constify. * objc-lang.h (lookup_objc_class, lookup_child_selector) (lookup_struct_typedef): Constify. * objfiles.c (pc_in_section): Constify. * objfiles.h (pc_in_section): Constify. * p-exp.y (struct token::oper): Constify. (yyerror): Constify. * p-lang.h (pascal_yyerror): Constify. * parser-defs.h (op_name_standard): Constify. (op_print::string): Constify. (exp_descriptor::op_name): Constify. * printcmd.c (print_address_symbolic): Constify. * psymtab.c (print_partial_symbols): Constify. * python/py-breakpoint.c (stop_func): Constify. (bppy_get_expression): Constify. * python/py-cmd.c (cmdpy_completer::name): Constify. (cmdpy_function): Constify. * python/py-event.c (evpy_add_attribute) (gdbpy_initialize_event_generic): Constify. * python/py-event.h (evpy_add_attribute) (gdbpy_initialize_event_generic): Constify. * python/py-evts.c (add_new_registry): Constify. * python/py-finishbreakpoint.c (outofscope_func): Constify. * python/py-framefilter.c (get_py_iter_from_func): Constify. * python/py-inferior.c (get_buffer): Add cast. * python/py-param.c (parm_constant::name): Constify. * python/py-unwind.c (fprint_frame_id): Constify. * python/python.c (gdbpy_parameter_value): Constify. * remote-fileio.c (remote_fio_func_map): Make 'name' const. * remote.c (memory_packet_config::name): Constify. (show_packet_config_cmd, remote_write_bytes) (remote_buffer_add_string): * reverse.c (exec_reverse_once): Constify. * rs6000-tdep.c (variant::name, variant::description): Constify. * rust-exp.y (rustyyerror): Constify. * rust-lang.c (rust_op_name): Constify. * rust-lang.h (rustyyerror): Constify. * serial.h (serial_ops::name): Constify. * sh-tdep.c (sh_sh_register_name, sh_sh3_register_name) (sh_sh3e_register_name, sh_sh2e_register_name) (sh_sh2a_register_name, sh_sh2a_nofpu_register_name) (sh_sh_dsp_register_name, sh_sh3_dsp_register_name) (sh_sh4_register_name, sh_sh4_nofpu_register_name) (sh_sh4al_dsp_register_name): Constify. * sh64-tdep.c (sh64_register_name): Constify. * solib-darwin.c (lookup_symbol_from_bfd): Constify. * spu-tdep.c (spu_register_name, info_spu_dma_cmdlist): Constify. * stabsread.c (patch_block_stabs, read_type_number) (ref_map::stabs, ref_add, process_reference) (symbol_reference_defined, define_symbol, define_symbol) (error_type, read_type, read_member_functions, read_cpp_abbrev) (read_one_struct_field, read_struct_fields, read_baseclasses) (read_tilde_fields, read_struct_type, read_array_type) (read_enum_type, read_sun_builtin_type, read_sun_floating_type) (read_huge_number, read_range_type, read_args, common_block_start) (find_name_end): Constify. * stabsread.h (common_block_start, define_symbol) (process_one_symbol, symbol_reference_defined, ref_add): * symfile.c (get_section_index, add_symbol_file_command): * symfile.h (get_section_index): Constify. * target-descriptions.c (tdesc_type::name): Constify. (tdesc_free_type): Add cast. * target.c (find_default_run_target): (add_deprecated_target_alias, find_default_run_target) (target_announce_detach): Constify. (do_option): Constify. * target.h (add_deprecated_target_alias): Constify. * thread.c (print_thread_info_1): Constify. * top.c (deprecated_readline_begin_hook, command_line_input): Constify. (init_main): Add casts. * top.h (handle_line_of_input): Constify. * tracefile-tfile.c (tfile_write_uploaded_tsv): Constify. * tracepoint.c (tvariables_info_1, trace_status_mi): Constify. (tfind_command): Rename to ... (tfind_command_1): ... this and constify. (tfind_command): New function. (tfind_end_command, tfind_start_command): Adjust. (encode_source_string): Constify. * tracepoint.h (encode_source_string): Constify. * tui/tui-data.c (tui_partial_win_by_name): Constify. * tui/tui-data.h (tui_partial_win_by_name): Constify. * tui/tui-source.c (tui_set_source_content_nil): Constify. * tui/tui-source.h (tui_set_source_content_nil): Constify. * tui/tui-win.c (parse_scrolling_args): Constify. * tui/tui-windata.c (tui_erase_data_content): Constify. * tui/tui-windata.h (tui_erase_data_content): Constify. * tui/tui-winsource.c (tui_erase_source_content): Constify. * tui/tui.c (tui_enable): Add cast. * utils.c (defaulted_query): Constify. (init_page_info): Add cast. (puts_debug, subset_compare): Constify. * utils.h (subset_compare): Constify. * varobj.c (varobj_format_string): Constify. * varobj.h (varobj_format_string): Constify. * vax-tdep.c (vax_register_name): Constify. * windows-nat.c (windows_detach): Constify. * xcoffread.c (process_linenos, xcoff_next_symbol_text): Constify. * xml-support.c (gdb_xml_end_element): Constify. * xml-tdesc.c (tdesc_start_reg): Constify. * xstormy16-tdep.c (xstormy16_register_name): Constify. * xtensa-tdep.c (xtensa_find_register_by_name): Constify. * xtensa-tdep.h (xtensa_register_t::name): Constify. gdb/gdbserver/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * gdbreplay.c (sync_error): Constify. * linux-x86-low.c (push_opcode): Constify.
780 lines
23 KiB
C
780 lines
23 KiB
C
/* Python frame unwinder interface.
|
|
|
|
Copyright (C) 2015-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 "arch-utils.h"
|
|
#include "frame-unwind.h"
|
|
#include "gdb_obstack.h"
|
|
#include "gdbcmd.h"
|
|
#include "language.h"
|
|
#include "observer.h"
|
|
#include "python-internal.h"
|
|
#include "regcache.h"
|
|
#include "valprint.h"
|
|
#include "user-regs.h"
|
|
#include "py-ref.h"
|
|
|
|
#define TRACE_PY_UNWIND(level, args...) if (pyuw_debug >= level) \
|
|
{ fprintf_unfiltered (gdb_stdlog, args); }
|
|
|
|
typedef struct
|
|
{
|
|
PyObject_HEAD
|
|
|
|
/* Frame we are unwinding. */
|
|
struct frame_info *frame_info;
|
|
|
|
/* Its architecture, passed by the sniffer caller. */
|
|
struct gdbarch *gdbarch;
|
|
} pending_frame_object;
|
|
|
|
/* Saved registers array item. */
|
|
|
|
typedef struct
|
|
{
|
|
int number;
|
|
PyObject *value;
|
|
} saved_reg;
|
|
DEF_VEC_O (saved_reg);
|
|
|
|
/* The data we keep for the PyUnwindInfo: pending_frame, saved registers
|
|
and frame ID. */
|
|
|
|
typedef struct
|
|
{
|
|
PyObject_HEAD
|
|
|
|
/* gdb.PendingFrame for the frame we are unwinding. */
|
|
PyObject *pending_frame;
|
|
|
|
/* Its ID. */
|
|
struct frame_id frame_id;
|
|
|
|
/* Saved registers array. */
|
|
VEC (saved_reg) *saved_regs;
|
|
} unwind_info_object;
|
|
|
|
/* The data we keep for a frame we can unwind: frame ID and an array of
|
|
(register_number, register_value) pairs. */
|
|
|
|
struct reg_info
|
|
{
|
|
/* Register number. */
|
|
int number;
|
|
|
|
/* Register data bytes pointer. */
|
|
gdb_byte data[MAX_REGISTER_SIZE];
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
/* Frame ID. */
|
|
struct frame_id frame_id;
|
|
|
|
/* GDB Architecture. */
|
|
struct gdbarch *gdbarch;
|
|
|
|
/* Length of the `reg' array below. */
|
|
int reg_count;
|
|
|
|
struct reg_info reg[];
|
|
} cached_frame_info;
|
|
|
|
extern PyTypeObject pending_frame_object_type
|
|
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("pending_frame_object");
|
|
|
|
extern PyTypeObject unwind_info_object_type
|
|
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("unwind_info_object");
|
|
|
|
static unsigned int pyuw_debug = 0;
|
|
|
|
static struct gdbarch_data *pyuw_gdbarch_data;
|
|
|
|
/* Parses register id, which can be either a number or a name.
|
|
Returns 1 on success, 0 otherwise. */
|
|
|
|
static int
|
|
pyuw_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id,
|
|
int *reg_num)
|
|
{
|
|
if (pyo_reg_id == NULL)
|
|
return 0;
|
|
if (gdbpy_is_string (pyo_reg_id))
|
|
{
|
|
gdb::unique_xmalloc_ptr<char> reg_name (gdbpy_obj_to_string (pyo_reg_id));
|
|
|
|
if (reg_name == NULL)
|
|
return 0;
|
|
*reg_num = user_reg_map_name_to_regnum (gdbarch, reg_name.get (),
|
|
strlen (reg_name.get ()));
|
|
return *reg_num >= 0;
|
|
}
|
|
else if (PyInt_Check (pyo_reg_id))
|
|
{
|
|
long value;
|
|
if (gdb_py_int_as_long (pyo_reg_id, &value) && (int) value == value)
|
|
{
|
|
*reg_num = (int) value;
|
|
return user_reg_map_regnum_to_name (gdbarch, *reg_num) != NULL;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* Convert gdb.Value instance to inferior's pointer. Return 1 on success,
|
|
0 on failure. */
|
|
|
|
static int
|
|
pyuw_value_obj_to_pointer (PyObject *pyo_value, CORE_ADDR *addr)
|
|
{
|
|
int rc = 0;
|
|
struct value *value;
|
|
|
|
TRY
|
|
{
|
|
if ((value = value_object_to_value (pyo_value)) != NULL)
|
|
{
|
|
*addr = unpack_pointer (value_type (value),
|
|
value_contents (value));
|
|
rc = 1;
|
|
}
|
|
}
|
|
CATCH (except, RETURN_MASK_ALL)
|
|
{
|
|
gdbpy_convert_exception (except);
|
|
}
|
|
END_CATCH
|
|
return rc;
|
|
}
|
|
|
|
/* Get attribute from an object and convert it to the inferior's
|
|
pointer value. Return 1 if attribute exists and its value can be
|
|
converted. Otherwise, if attribute does not exist or its value is
|
|
None, return 0. In all other cases set Python error and return
|
|
0. */
|
|
|
|
static int
|
|
pyuw_object_attribute_to_pointer (PyObject *pyo, const char *attr_name,
|
|
CORE_ADDR *addr)
|
|
{
|
|
int rc = 0;
|
|
|
|
if (PyObject_HasAttrString (pyo, attr_name))
|
|
{
|
|
gdbpy_ref<> pyo_value (PyObject_GetAttrString (pyo, attr_name));
|
|
|
|
if (pyo_value != NULL && pyo_value != Py_None)
|
|
{
|
|
rc = pyuw_value_obj_to_pointer (pyo_value.get (), addr);
|
|
if (!rc)
|
|
PyErr_Format (
|
|
PyExc_ValueError,
|
|
_("The value of the '%s' attribute is not a pointer."),
|
|
attr_name);
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
/* Called by the Python interpreter to obtain string representation
|
|
of the UnwindInfo object. */
|
|
|
|
static PyObject *
|
|
unwind_infopy_str (PyObject *self)
|
|
{
|
|
unwind_info_object *unwind_info = (unwind_info_object *) self;
|
|
string_file stb;
|
|
|
|
stb.puts ("Frame ID: ");
|
|
fprint_frame_id (&stb, unwind_info->frame_id);
|
|
{
|
|
const char *sep = "";
|
|
int i;
|
|
struct value_print_options opts;
|
|
saved_reg *reg;
|
|
|
|
get_user_print_options (&opts);
|
|
stb.printf ("\nSaved registers: (");
|
|
for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++)
|
|
{
|
|
struct value *value = value_object_to_value (reg->value);
|
|
|
|
stb.printf ("%s(%d, ", sep, reg->number);
|
|
if (value != NULL)
|
|
{
|
|
TRY
|
|
{
|
|
value_print (value, &stb, &opts);
|
|
stb.puts (")");
|
|
}
|
|
CATCH (except, RETURN_MASK_ALL)
|
|
{
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
}
|
|
END_CATCH
|
|
}
|
|
else
|
|
stb.puts ("<BAD>)");
|
|
sep = ", ";
|
|
}
|
|
stb.puts (")");
|
|
}
|
|
|
|
return PyString_FromString (stb.c_str ());
|
|
}
|
|
|
|
/* Create UnwindInfo instance for given PendingFrame and frame ID.
|
|
Sets Python error and returns NULL on error. */
|
|
|
|
static PyObject *
|
|
pyuw_create_unwind_info (PyObject *pyo_pending_frame,
|
|
struct frame_id frame_id)
|
|
{
|
|
unwind_info_object *unwind_info
|
|
= PyObject_New (unwind_info_object, &unwind_info_object_type);
|
|
|
|
if (((pending_frame_object *) pyo_pending_frame)->frame_info == NULL)
|
|
{
|
|
PyErr_SetString (PyExc_ValueError,
|
|
"Attempting to use stale PendingFrame");
|
|
return NULL;
|
|
}
|
|
unwind_info->frame_id = frame_id;
|
|
Py_INCREF (pyo_pending_frame);
|
|
unwind_info->pending_frame = pyo_pending_frame;
|
|
unwind_info->saved_regs = VEC_alloc (saved_reg, 4);
|
|
return (PyObject *) unwind_info;
|
|
}
|
|
|
|
/* The implementation of
|
|
gdb.UnwindInfo.add_saved_register (REG, VALUE) -> None. */
|
|
|
|
static PyObject *
|
|
unwind_infopy_add_saved_register (PyObject *self, PyObject *args)
|
|
{
|
|
unwind_info_object *unwind_info = (unwind_info_object *) self;
|
|
pending_frame_object *pending_frame
|
|
= (pending_frame_object *) (unwind_info->pending_frame);
|
|
PyObject *pyo_reg_id;
|
|
PyObject *pyo_reg_value;
|
|
int regnum;
|
|
|
|
if (pending_frame->frame_info == NULL)
|
|
{
|
|
PyErr_SetString (PyExc_ValueError,
|
|
"UnwindInfo instance refers to a stale PendingFrame");
|
|
return NULL;
|
|
}
|
|
if (!PyArg_UnpackTuple (args, "previous_frame_register", 2, 2,
|
|
&pyo_reg_id, &pyo_reg_value))
|
|
return NULL;
|
|
if (!pyuw_parse_register_id (pending_frame->gdbarch, pyo_reg_id, ®num))
|
|
{
|
|
PyErr_SetString (PyExc_ValueError, "Bad register");
|
|
return NULL;
|
|
}
|
|
{
|
|
struct value *value;
|
|
size_t data_size;
|
|
|
|
if (pyo_reg_value == NULL
|
|
|| (value = value_object_to_value (pyo_reg_value)) == NULL)
|
|
{
|
|
PyErr_SetString (PyExc_ValueError, "Bad register value");
|
|
return NULL;
|
|
}
|
|
data_size = register_size (pending_frame->gdbarch, regnum);
|
|
if (data_size != TYPE_LENGTH (value_type (value)))
|
|
{
|
|
PyErr_Format (
|
|
PyExc_ValueError,
|
|
"The value of the register returned by the Python "
|
|
"sniffer has unexpected size: %u instead of %u.",
|
|
(unsigned) TYPE_LENGTH (value_type (value)),
|
|
(unsigned) data_size);
|
|
return NULL;
|
|
}
|
|
}
|
|
{
|
|
int i;
|
|
saved_reg *reg;
|
|
|
|
for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++)
|
|
{
|
|
if (regnum == reg->number)
|
|
{
|
|
Py_DECREF (reg->value);
|
|
break;
|
|
}
|
|
}
|
|
if (reg == NULL)
|
|
{
|
|
reg = VEC_safe_push (saved_reg, unwind_info->saved_regs, NULL);
|
|
reg->number = regnum;
|
|
}
|
|
Py_INCREF (pyo_reg_value);
|
|
reg->value = pyo_reg_value;
|
|
}
|
|
Py_RETURN_NONE;
|
|
}
|
|
|
|
/* UnwindInfo cleanup. */
|
|
|
|
static void
|
|
unwind_infopy_dealloc (PyObject *self)
|
|
{
|
|
unwind_info_object *unwind_info = (unwind_info_object *) self;
|
|
int i;
|
|
saved_reg *reg;
|
|
|
|
Py_XDECREF (unwind_info->pending_frame);
|
|
for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++)
|
|
Py_DECREF (reg->value);
|
|
VEC_free (saved_reg, unwind_info->saved_regs);
|
|
Py_TYPE (self)->tp_free (self);
|
|
}
|
|
|
|
/* Called by the Python interpreter to obtain string representation
|
|
of the PendingFrame object. */
|
|
|
|
static PyObject *
|
|
pending_framepy_str (PyObject *self)
|
|
{
|
|
struct frame_info *frame = ((pending_frame_object *) self)->frame_info;
|
|
const char *sp_str = NULL;
|
|
const char *pc_str = NULL;
|
|
|
|
if (frame == NULL)
|
|
return PyString_FromString ("Stale PendingFrame instance");
|
|
TRY
|
|
{
|
|
sp_str = core_addr_to_string_nz (get_frame_sp (frame));
|
|
pc_str = core_addr_to_string_nz (get_frame_pc (frame));
|
|
}
|
|
CATCH (except, RETURN_MASK_ALL)
|
|
{
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
}
|
|
END_CATCH
|
|
|
|
return PyString_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
|
|
}
|
|
|
|
/* Implementation of gdb.PendingFrame.read_register (self, reg) -> gdb.Value.
|
|
Returns the value of register REG as gdb.Value instance. */
|
|
|
|
static PyObject *
|
|
pending_framepy_read_register (PyObject *self, PyObject *args)
|
|
{
|
|
pending_frame_object *pending_frame = (pending_frame_object *) self;
|
|
struct value *val = NULL;
|
|
int regnum;
|
|
PyObject *pyo_reg_id;
|
|
|
|
if (pending_frame->frame_info == NULL)
|
|
{
|
|
PyErr_SetString (PyExc_ValueError,
|
|
"Attempting to read register from stale PendingFrame");
|
|
return NULL;
|
|
}
|
|
if (!PyArg_UnpackTuple (args, "read_register", 1, 1, &pyo_reg_id))
|
|
return NULL;
|
|
if (!pyuw_parse_register_id (pending_frame->gdbarch, pyo_reg_id, ®num))
|
|
{
|
|
PyErr_SetString (PyExc_ValueError, "Bad register");
|
|
return NULL;
|
|
}
|
|
|
|
TRY
|
|
{
|
|
/* Fetch the value associated with a register, whether it's
|
|
a real register or a so called "user" register, like "pc",
|
|
which maps to a real register. In the past,
|
|
get_frame_register_value() was used here, which did not
|
|
handle the user register case. */
|
|
val = value_of_register (regnum, pending_frame->frame_info);
|
|
if (val == NULL)
|
|
PyErr_Format (PyExc_ValueError,
|
|
"Cannot read register %d from frame.",
|
|
regnum);
|
|
}
|
|
CATCH (except, RETURN_MASK_ALL)
|
|
{
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
}
|
|
END_CATCH
|
|
|
|
return val == NULL ? NULL : value_to_value_object (val);
|
|
}
|
|
|
|
/* Implementation of
|
|
PendingFrame.create_unwind_info (self, frameId) -> UnwindInfo. */
|
|
|
|
static PyObject *
|
|
pending_framepy_create_unwind_info (PyObject *self, PyObject *args)
|
|
{
|
|
PyObject *pyo_frame_id;
|
|
CORE_ADDR sp;
|
|
CORE_ADDR pc;
|
|
CORE_ADDR special;
|
|
|
|
if (!PyArg_ParseTuple (args, "O:create_unwind_info", &pyo_frame_id))
|
|
return NULL;
|
|
if (!pyuw_object_attribute_to_pointer (pyo_frame_id, "sp", &sp))
|
|
{
|
|
PyErr_SetString (PyExc_ValueError,
|
|
_("frame_id should have 'sp' attribute."));
|
|
return NULL;
|
|
}
|
|
|
|
/* The logic of building frame_id depending on the attributes of
|
|
the frame_id object:
|
|
Has Has Has Function to call
|
|
'sp'? 'pc'? 'special'?
|
|
------|------|--------------|-------------------------
|
|
Y N * frame_id_build_wild (sp)
|
|
Y Y N frame_id_build (sp, pc)
|
|
Y Y Y frame_id_build_special (sp, pc, special)
|
|
*/
|
|
if (!pyuw_object_attribute_to_pointer (pyo_frame_id, "pc", &pc))
|
|
return pyuw_create_unwind_info (self, frame_id_build_wild (sp));
|
|
if (!pyuw_object_attribute_to_pointer (pyo_frame_id, "special", &special))
|
|
return pyuw_create_unwind_info (self, frame_id_build (sp, pc));
|
|
else
|
|
return pyuw_create_unwind_info (self,
|
|
frame_id_build_special (sp, pc, special));
|
|
}
|
|
|
|
/* frame_unwind.this_id method. */
|
|
|
|
static void
|
|
pyuw_this_id (struct frame_info *this_frame, void **cache_ptr,
|
|
struct frame_id *this_id)
|
|
{
|
|
*this_id = ((cached_frame_info *) *cache_ptr)->frame_id;
|
|
if (pyuw_debug >= 1)
|
|
{
|
|
fprintf_unfiltered (gdb_stdlog, "%s: frame_id: ", __FUNCTION__);
|
|
fprint_frame_id (gdb_stdlog, *this_id);
|
|
fprintf_unfiltered (gdb_stdlog, "\n");
|
|
}
|
|
}
|
|
|
|
/* frame_unwind.prev_register. */
|
|
|
|
static struct value *
|
|
pyuw_prev_register (struct frame_info *this_frame, void **cache_ptr,
|
|
int regnum)
|
|
{
|
|
cached_frame_info *cached_frame = (cached_frame_info *) *cache_ptr;
|
|
struct reg_info *reg_info = cached_frame->reg;
|
|
struct reg_info *reg_info_end = reg_info + cached_frame->reg_count;
|
|
|
|
TRACE_PY_UNWIND (1, "%s (frame=%p,...,reg=%d)\n", __FUNCTION__, this_frame,
|
|
regnum);
|
|
for (; reg_info < reg_info_end; ++reg_info)
|
|
{
|
|
if (regnum == reg_info->number)
|
|
return frame_unwind_got_bytes (this_frame, regnum, reg_info->data);
|
|
}
|
|
|
|
return frame_unwind_got_optimized (this_frame, regnum);
|
|
}
|
|
|
|
/* Frame sniffer dispatch. */
|
|
|
|
static int
|
|
pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame,
|
|
void **cache_ptr)
|
|
{
|
|
struct gdbarch *gdbarch = (struct gdbarch *) (self->unwind_data);
|
|
cached_frame_info *cached_frame;
|
|
|
|
gdbpy_enter enter_py (gdbarch, current_language);
|
|
|
|
TRACE_PY_UNWIND (3, "%s (SP=%s, PC=%s)\n", __FUNCTION__,
|
|
paddress (gdbarch, get_frame_sp (this_frame)),
|
|
paddress (gdbarch, get_frame_pc (this_frame)));
|
|
|
|
/* Create PendingFrame instance to pass to sniffers. */
|
|
pending_frame_object *pfo = PyObject_New (pending_frame_object,
|
|
&pending_frame_object_type);
|
|
gdbpy_ref<> pyo_pending_frame ((PyObject *) pfo);
|
|
if (pyo_pending_frame == NULL)
|
|
{
|
|
gdbpy_print_stack ();
|
|
return 0;
|
|
}
|
|
pfo->gdbarch = gdbarch;
|
|
scoped_restore invalidate_frame = make_scoped_restore (&pfo->frame_info,
|
|
this_frame);
|
|
|
|
/* Run unwinders. */
|
|
if (gdb_python_module == NULL
|
|
|| ! PyObject_HasAttrString (gdb_python_module, "execute_unwinders"))
|
|
{
|
|
PyErr_SetString (PyExc_NameError,
|
|
"Installation error: gdb.execute_unwinders function "
|
|
"is missing");
|
|
gdbpy_print_stack ();
|
|
return 0;
|
|
}
|
|
gdbpy_ref<> pyo_execute (PyObject_GetAttrString (gdb_python_module,
|
|
"execute_unwinders"));
|
|
if (pyo_execute == NULL)
|
|
{
|
|
gdbpy_print_stack ();
|
|
return 0;
|
|
}
|
|
|
|
gdbpy_ref<> pyo_unwind_info
|
|
(PyObject_CallFunctionObjArgs (pyo_execute.get (),
|
|
pyo_pending_frame.get (), NULL));
|
|
if (pyo_unwind_info == NULL)
|
|
{
|
|
gdbpy_print_stack ();
|
|
return 0;
|
|
}
|
|
if (pyo_unwind_info == Py_None)
|
|
return 0;
|
|
|
|
/* Received UnwindInfo, cache data. */
|
|
if (PyObject_IsInstance (pyo_unwind_info.get (),
|
|
(PyObject *) &unwind_info_object_type) <= 0)
|
|
error (_("A Unwinder should return gdb.UnwindInfo instance."));
|
|
|
|
{
|
|
unwind_info_object *unwind_info =
|
|
(unwind_info_object *) pyo_unwind_info.get ();
|
|
int reg_count = VEC_length (saved_reg, unwind_info->saved_regs);
|
|
saved_reg *reg;
|
|
int i;
|
|
|
|
cached_frame
|
|
= ((cached_frame_info *)
|
|
xmalloc (sizeof (*cached_frame)
|
|
+ reg_count * sizeof (cached_frame->reg[0])));
|
|
cached_frame->gdbarch = gdbarch;
|
|
cached_frame->frame_id = unwind_info->frame_id;
|
|
cached_frame->reg_count = reg_count;
|
|
|
|
/* Populate registers array. */
|
|
for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++)
|
|
{
|
|
struct value *value = value_object_to_value (reg->value);
|
|
size_t data_size = register_size (gdbarch, reg->number);
|
|
|
|
cached_frame->reg[i].number = reg->number;
|
|
|
|
/* `value' validation was done before, just assert. */
|
|
gdb_assert (value != NULL);
|
|
gdb_assert (data_size == TYPE_LENGTH (value_type (value)));
|
|
gdb_assert (data_size <= MAX_REGISTER_SIZE);
|
|
|
|
memcpy (cached_frame->reg[i].data, value_contents (value), data_size);
|
|
}
|
|
}
|
|
|
|
*cache_ptr = cached_frame;
|
|
return 1;
|
|
}
|
|
|
|
/* Frame cache release shim. */
|
|
|
|
static void
|
|
pyuw_dealloc_cache (struct frame_info *this_frame, void *cache)
|
|
{
|
|
TRACE_PY_UNWIND (3, "%s: enter", __FUNCTION__);
|
|
xfree (cache);
|
|
}
|
|
|
|
struct pyuw_gdbarch_data_type
|
|
{
|
|
/* Has the unwinder shim been prepended? */
|
|
int unwinder_registered;
|
|
};
|
|
|
|
static void *
|
|
pyuw_gdbarch_data_init (struct gdbarch *gdbarch)
|
|
{
|
|
return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct pyuw_gdbarch_data_type);
|
|
}
|
|
|
|
/* New inferior architecture callback: register the Python unwinders
|
|
intermediary. */
|
|
|
|
static void
|
|
pyuw_on_new_gdbarch (struct gdbarch *newarch)
|
|
{
|
|
struct pyuw_gdbarch_data_type *data
|
|
= (struct pyuw_gdbarch_data_type *) gdbarch_data (newarch,
|
|
pyuw_gdbarch_data);
|
|
|
|
if (!data->unwinder_registered)
|
|
{
|
|
struct frame_unwind *unwinder
|
|
= GDBARCH_OBSTACK_ZALLOC (newarch, struct frame_unwind);
|
|
|
|
unwinder->type = NORMAL_FRAME;
|
|
unwinder->stop_reason = default_frame_unwind_stop_reason;
|
|
unwinder->this_id = pyuw_this_id;
|
|
unwinder->prev_register = pyuw_prev_register;
|
|
unwinder->unwind_data = (const struct frame_data *) newarch;
|
|
unwinder->sniffer = pyuw_sniffer;
|
|
unwinder->dealloc_cache = pyuw_dealloc_cache;
|
|
frame_unwind_prepend_unwinder (newarch, unwinder);
|
|
data->unwinder_registered = 1;
|
|
}
|
|
}
|
|
|
|
/* Initialize unwind machinery. */
|
|
|
|
int
|
|
gdbpy_initialize_unwind (void)
|
|
{
|
|
int rc;
|
|
add_setshow_zuinteger_cmd
|
|
("py-unwind", class_maintenance, &pyuw_debug,
|
|
_("Set Python unwinder debugging."),
|
|
_("Show Python unwinder debugging."),
|
|
_("When non-zero, Python unwinder debugging is enabled."),
|
|
NULL,
|
|
NULL,
|
|
&setdebuglist, &showdebuglist);
|
|
pyuw_gdbarch_data
|
|
= gdbarch_data_register_post_init (pyuw_gdbarch_data_init);
|
|
observer_attach_architecture_changed (pyuw_on_new_gdbarch);
|
|
|
|
if (PyType_Ready (&pending_frame_object_type) < 0)
|
|
return -1;
|
|
rc = gdb_pymodule_addobject (gdb_module, "PendingFrame",
|
|
(PyObject *) &pending_frame_object_type);
|
|
if (rc)
|
|
return rc;
|
|
|
|
if (PyType_Ready (&unwind_info_object_type) < 0)
|
|
return -1;
|
|
return gdb_pymodule_addobject (gdb_module, "UnwindInfo",
|
|
(PyObject *) &unwind_info_object_type);
|
|
}
|
|
|
|
static PyMethodDef pending_frame_object_methods[] =
|
|
{
|
|
{ "read_register", pending_framepy_read_register, METH_VARARGS,
|
|
"read_register (REG) -> gdb.Value\n"
|
|
"Return the value of the REG in the frame." },
|
|
{ "create_unwind_info",
|
|
pending_framepy_create_unwind_info, METH_VARARGS,
|
|
"create_unwind_info (FRAME_ID) -> gdb.UnwindInfo\n"
|
|
"Construct UnwindInfo for this PendingFrame, using FRAME_ID\n"
|
|
"to identify it." },
|
|
{NULL} /* Sentinel */
|
|
};
|
|
|
|
PyTypeObject pending_frame_object_type =
|
|
{
|
|
PyVarObject_HEAD_INIT (NULL, 0)
|
|
"gdb.PendingFrame", /* tp_name */
|
|
sizeof (pending_frame_object), /* tp_basicsize */
|
|
0, /* tp_itemsize */
|
|
0, /* tp_dealloc */
|
|
0, /* tp_print */
|
|
0, /* tp_getattr */
|
|
0, /* tp_setattr */
|
|
0, /* tp_compare */
|
|
0, /* tp_repr */
|
|
0, /* tp_as_number */
|
|
0, /* tp_as_sequence */
|
|
0, /* tp_as_mapping */
|
|
0, /* tp_hash */
|
|
0, /* tp_call */
|
|
pending_framepy_str, /* tp_str */
|
|
0, /* tp_getattro */
|
|
0, /* tp_setattro */
|
|
0, /* tp_as_buffer */
|
|
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|
"GDB PendingFrame object", /* tp_doc */
|
|
0, /* tp_traverse */
|
|
0, /* tp_clear */
|
|
0, /* tp_richcompare */
|
|
0, /* tp_weaklistoffset */
|
|
0, /* tp_iter */
|
|
0, /* tp_iternext */
|
|
pending_frame_object_methods, /* tp_methods */
|
|
0, /* tp_members */
|
|
0, /* tp_getset */
|
|
0, /* tp_base */
|
|
0, /* tp_dict */
|
|
0, /* tp_descr_get */
|
|
0, /* tp_descr_set */
|
|
0, /* tp_dictoffset */
|
|
0, /* tp_init */
|
|
0, /* tp_alloc */
|
|
};
|
|
|
|
static PyMethodDef unwind_info_object_methods[] =
|
|
{
|
|
{ "add_saved_register",
|
|
unwind_infopy_add_saved_register, METH_VARARGS,
|
|
"add_saved_register (REG, VALUE) -> None\n"
|
|
"Set the value of the REG in the previous frame to VALUE." },
|
|
{ NULL } /* Sentinel */
|
|
};
|
|
|
|
PyTypeObject unwind_info_object_type =
|
|
{
|
|
PyVarObject_HEAD_INIT (NULL, 0)
|
|
"gdb.UnwindInfo", /* tp_name */
|
|
sizeof (unwind_info_object), /* tp_basicsize */
|
|
0, /* tp_itemsize */
|
|
unwind_infopy_dealloc, /* tp_dealloc */
|
|
0, /* tp_print */
|
|
0, /* tp_getattr */
|
|
0, /* tp_setattr */
|
|
0, /* tp_compare */
|
|
0, /* tp_repr */
|
|
0, /* tp_as_number */
|
|
0, /* tp_as_sequence */
|
|
0, /* tp_as_mapping */
|
|
0, /* tp_hash */
|
|
0, /* tp_call */
|
|
unwind_infopy_str, /* tp_str */
|
|
0, /* tp_getattro */
|
|
0, /* tp_setattro */
|
|
0, /* tp_as_buffer */
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
|
"GDB UnwindInfo object", /* tp_doc */
|
|
0, /* tp_traverse */
|
|
0, /* tp_clear */
|
|
0, /* tp_richcompare */
|
|
0, /* tp_weaklistoffset */
|
|
0, /* tp_iter */
|
|
0, /* tp_iternext */
|
|
unwind_info_object_methods, /* tp_methods */
|
|
0, /* tp_members */
|
|
0, /* tp_getset */
|
|
0, /* tp_base */
|
|
0, /* tp_dict */
|
|
0, /* tp_descr_get */
|
|
0, /* tp_descr_set */
|
|
0, /* tp_dictoffset */
|
|
0, /* tp_init */
|
|
0, /* tp_alloc */
|
|
};
|