8d7493201c
This patch is part of the make-gdb-buildable-in-C++ effort. The idea is to change some calls to the xmalloc family of functions to calls to the equivalents in the XNEW family. This avoids adding an explicit cast, so it keeps the code a bit more readable. Some of them also map relatively well to a C++ equivalent (XNEW (struct foo) -> new foo), so it will be possible to do scripted replacements if needed. I only changed calls that were obviously allocating memory for one or multiple "objects". Allocation of variable sizes (such as strings or buffer handling) will be for later (and won't use XNEW). - xmalloc (sizeof (struct foo)) -> XNEW (struct foo) - xmalloc (num * sizeof (struct foo)) -> XNEWVEC (struct foo, num) - xcalloc (1, sizeof (struct foo)) -> XCNEW (struct foo) - xcalloc (num, sizeof (struct foo)) -> XCNEWVEC (struct foo, num) - xrealloc (p, num * sizeof (struct foo) -> XRESIZEVEC (struct foo, p, num) - obstack_alloc (ob, sizeof (struct foo)) -> XOBNEW (ob, struct foo) - obstack_alloc (ob, num * sizeof (struct foo)) -> XOBNEWVEC (ob, struct foo, num) - alloca (sizeof (struct foo)) -> XALLOCA (struct foo) - alloca (num * sizeof (struct foo)) -> XALLOCAVEC (struct foo, num) Some instances of xmalloc followed by memset to zero the buffer were replaced by XCNEW or XCNEWVEC. I regtested on x86-64, Ubuntu 14.04, but the patch touches many architecture-specific files. For those I'll have to rely on the buildbot or people complaining that I broke their gdb. gdb/ChangeLog: * aarch64-linux-nat.c (aarch64_add_process): Likewise. * aarch64-tdep.c (aarch64_gdbarch_init): Likewise. * ada-exp.y (write_ambiguous_var): Likewise. * ada-lang.c (resolve_subexp): Likewise. (user_select_syms): Likewise. (assign_aggregate): Likewise. (ada_evaluate_subexp): Likewise. (cache_symbol): Likewise. * addrmap.c (allocate_key): Likewise. (addrmap_create_mutable): Likewise. * aix-thread.c (sync_threadlists): Likewise. * alpha-tdep.c (alpha_push_dummy_call): Likewise. (alpha_gdbarch_init): Likewise. * amd64-windows-tdep.c (amd64_windows_push_arguments): Likewise. * arm-linux-nat.c (arm_linux_add_process): Likewise. * arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise. * arm-tdep.c (push_stack_item): Likewise. (arm_displaced_step_copy_insn): Likewise. (arm_gdbarch_init): Likewise. (_initialize_arm_tdep): Likewise. * avr-tdep.c (push_stack_item): Likewise. * ax-general.c (new_agent_expr): Likewise. * block.c (block_initialize_namespace): Likewise. * breakpoint.c (alloc_counted_command_line): Likewise. (update_dprintf_command_list): Likewise. (parse_breakpoint_sals): Likewise. (decode_static_tracepoint_spec): Likewise. (until_break_command): Likewise. (clear_command): Likewise. (update_global_location_list): Likewise. (get_breakpoint_objfile_data) Likewise. * btrace.c (ftrace_new_function): Likewise. (btrace_set_insn_history): Likewise. (btrace_set_call_history): Likewise. * buildsym.c (add_symbol_to_list): Likewise. (record_pending_block): Likewise. (start_subfile): Likewise. (start_buildsym_compunit): Likewise. (push_subfile): Likewise. (end_symtab_get_static_block): Likewise. (buildsym_init): Likewise. * cli/cli-cmds.c (source_command): Likewise. * cli/cli-decode.c (add_cmd): Likewise. * cli/cli-script.c (build_command_line): Likewise. (setup_user_args): Likewise. (realloc_body_list): Likewise. (process_next_line): Likewise. (copy_command_lines): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (read_pe_exported_syms): Likewise. * coffread.c (coff_locate_sections): Likewise. (coff_symtab_read): Likewise. (coff_read_struct_type): Likewise. * common/cleanups.c (make_my_cleanup2): Likewise. * common/common-exceptions.c (throw_it): Likewise. * common/filestuff.c (make_cleanup_close): Likewise. * common/format.c (parse_format_string): Likewise. * common/queue.h (DEFINE_QUEUE_P): Likewise. * compile/compile-object-load.c (munmap_list_add): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * compile/compile.c (append_args): Likewise. * corefile.c (specify_exec_file_hook): Likewise. * cp-support.c (make_symbol_overload_list): Likewise. * cris-tdep.c (push_stack_item): Likewise. (cris_gdbarch_init): Likewise. * ctf.c (ctf_trace_file_writer_new): Likewise. * dbxread.c (init_header_files): Likewise. (add_new_header_file): Likewise. (init_bincl_list): Likewise. (dbx_end_psymtab): Likewise. (start_psymtab): Likewise. (dbx_end_psymtab): Likewise. * dcache.c (dcache_init): Likewise. * dictionary.c (dict_create_hashed): Likewise. (dict_create_hashed_expandable): Likewise. (dict_create_linear): Likewise. (dict_create_linear_expandable): Likewise. * dtrace-probe.c (dtrace_process_dof_probe): Likewise. * dummy-frame.c (register_dummy_frame_dtor): Likewise. * dwarf2-frame-tailcall.c (cache_new_ref1): Likewise. * dwarf2-frame.c (dwarf2_build_frame_info): Likewise. (decode_frame_entry_1): Likewise. * dwarf2expr.c (new_dwarf_expr_context): Likewise. * dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise. * dwarf2read.c (dwarf2_has_info): Likewise. (create_signatured_type_table_from_index): Likewise. (dwarf2_read_index): Likewise. (dw2_get_file_names_reader): Likewise. (create_all_type_units): Likewise. (read_cutu_die_from_dwo): Likewise. (init_tu_and_read_dwo_dies): Likewise. (init_cutu_and_read_dies): Likewise. (create_all_comp_units): Likewise. (queue_comp_unit): Likewise. (inherit_abstract_dies): Likewise. (read_call_site_scope): Likewise. (dwarf2_add_field): Likewise. (dwarf2_add_typedef): Likewise. (dwarf2_add_member_fn): Likewise. (attr_to_dynamic_prop): Likewise. (abbrev_table_alloc_abbrev): Likewise. (abbrev_table_read_table): Likewise. (add_include_dir): Likewise. (add_file_name): Likewise. (dwarf_decode_line_header): Likewise. (dwarf2_const_value_attr): Likewise. (dwarf_alloc_block): Likewise. (parse_macro_definition): Likewise. (set_die_type): Likewise. (write_psymtabs_to_index): Likewise. (create_cus_from_index): Likewise. (dwarf2_create_include_psymtab): Likewise. (process_psymtab_comp_unit_reader): Likewise. (build_type_psymtab_dependencies): Likewise. (read_comp_units_from_section): Likewise. (compute_compunit_symtab_includes): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (load_partial_dies): Likewise. (dwarf2_symbol_mark_computed): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_read_minimal_symbols): Likewise. * environ.c (make_environ): Likewise. * eval.c (evaluate_subexp_standard): Likewise. * event-loop.c (create_file_handler): Likewise. (create_async_signal_handler): Likewise. (create_async_event_handler): Likewise. (create_timer): Likewise. * exec.c (build_section_table): Likewise. * fbsd-nat.c (fbsd_remember_child): Likewise. * fork-child.c (fork_inferior): Likewise. * frv-tdep.c (new_variant): Likewise. * gdbarch.sh (gdbarch_alloc): Likewise. (append_name): Likewise. * gdbtypes.c (rank_function): Likewise. (copy_type_recursive): Likewise. (add_dyn_prop): Likewise. * gnu-nat.c (make_proc): Likewise. (make_inf): Likewise. (gnu_write_inferior): Likewise. * gnu-v3-abi.c (build_gdb_vtable_type): Likewise. (build_std_type_info_type): Likewise. * guile/scm-param.c (compute_enum_list): Likewise. * guile/scm-utils.c (gdbscm_parse_function_args): Likewise. * guile/scm-value.c (gdbscm_value_call): Likewise. * h8300-tdep.c (h8300_gdbarch_init): Likewise. * hppa-tdep.c (hppa_init_objfile_priv_data): Likewise. (read_unwind_info): Likewise. * ia64-tdep.c (ia64_gdbarch_init): Likewise. * infcall.c (dummy_frame_context_saver_setup): Likewise. (call_function_by_hand_dummy): Likewise. * infcmd.c (step_once): Likewise. (finish_forward): Likewise. (attach_command): Likewise. (notice_new_inferior): Likewise. * inferior.c (add_inferior_silent): Likewise. * infrun.c (add_displaced_stepping_state): Likewise. (save_infcall_control_state): Likewise. (save_inferior_ptid): Likewise. (_initialize_infrun): Likewise. * jit.c (bfd_open_from_target_memory): Likewise. (jit_gdbarch_data_init): Likewise. * language.c (add_language): Likewise. * linespec.c (decode_line_2): Likewise. * linux-nat.c (add_to_pid_list): Likewise. (add_initial_lwp): Likewise. * linux-thread-db.c (add_thread_db_info): Likewise. (record_thread): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_gdbarch_init): Likewise. * m68hc11-tdep.c (m68hc11_gdbarch_init): Likewise. * m68k-tdep.c (m68k_gdbarch_init): Likewise. * m88k-tdep.c (m88k_analyze_prologue): Likewise. * macrocmd.c (macro_define_command): Likewise. * macroexp.c (gather_arguments): Likewise. * macroscope.c (sal_macro_scope): Likewise. * macrotab.c (new_macro_table): Likewise. * mdebugread.c (push_parse_stack): Likewise. (parse_partial_symbols): Likewise. (parse_symbol): Likewise. (psymtab_to_symtab_1): Likewise. (new_block): Likewise. (new_psymtab): Likewise. (mdebug_build_psymtabs): Likewise. (add_pending): Likewise. (elfmdebug_build_psymtabs): Likewise. * mep-tdep.c (mep_gdbarch_init): Likewise. * mi/mi-main.c (mi_execute_command): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. * minidebug.c (lzma_open): Likewise. * minsyms.c (terminate_minimal_symbol_table): Likewise. * mips-linux-nat.c (mips_linux_insert_watchpoint): Likewise. * mips-tdep.c (mips_gdbarch_init): Likewise. * mn10300-tdep.c (mn10300_gdbarch_init): Likewise. * msp430-tdep.c (msp430_gdbarch_init): Likewise. * mt-tdep.c (mt_registers_info): Likewise. * nat/aarch64-linux.c (aarch64_linux_new_thread): Likewise. * nat/linux-btrace.c (linux_enable_bts): Likewise. (linux_enable_pt): Likewise. * nat/linux-osdata.c (linux_xfer_osdata_processes): Likewise. (linux_xfer_osdata_processgroups): Likewise. * nios2-tdep.c (nios2_gdbarch_init): Likewise. * nto-procfs.c (procfs_meminfo): Likewise. * objc-lang.c (start_msglist): Likewise. (selectors_info): Likewise. (classes_info): Likewise. (find_methods): Likewise. * objfiles.c (allocate_objfile): Likewise. (update_section_map): Likewise. * osabi.c (gdbarch_register_osabi): Likewise. (gdbarch_register_osabi_sniffer): Likewise. * parse.c (start_arglist): Likewise. * ppc-linux-nat.c (hwdebug_find_thread_points_by_tid): Likewise. (hwdebug_insert_point): Likewise. * printcmd.c (display_command): Likewise. (ui_printf): Likewise. * procfs.c (create_procinfo): Likewise. (load_syscalls): Likewise. (proc_get_LDT_entry): Likewise. (proc_update_threads): Likewise. * prologue-value.c (make_pv_area): Likewise. (pv_area_store): Likewise. * psymtab.c (extend_psymbol_list): Likewise. (init_psymbol_list): Likewise. (allocate_psymtab): Likewise. * python/py-inferior.c (add_thread_object): Likewise. * python/py-param.c (compute_enum_values): Likewise. * python/py-value.c (valpy_call): Likewise. * python/py-varobj.c (py_varobj_iter_next): Likewise. * python/python.c (ensure_python_env): Likewise. * record-btrace.c (record_btrace_start_replaying): Likewise. * record-full.c (record_full_reg_alloc): Likewise. (record_full_mem_alloc): Likewise. (record_full_end_alloc): Likewise. (record_full_core_xfer_partial): Likewise. * regcache.c (get_thread_arch_aspace_regcache): Likewise. * remote-fileio.c (remote_fileio_init_fd_map): Likewise. * remote-notif.c (remote_notif_state_allocate): Likewise. * remote.c (demand_private_info): Likewise. (remote_notif_stop_alloc_reply): Likewise. (remote_enable_btrace): Likewise. * reverse.c (save_bookmark_command): Likewise. * rl78-tdep.c (rl78_gdbarch_init): Likewise. * rx-tdep.c (rx_gdbarch_init): Likewise. * s390-linux-nat.c (s390_insert_watchpoint): Likewise. * ser-go32.c (dos_get_tty_state): Likewise. (dos_copy_tty_state): Likewise. * ser-mingw.c (ser_windows_open): Likewise. (ser_console_wait_handle): Likewise. (ser_console_get_tty_state): Likewise. (make_pipe_state): Likewise. (net_windows_open): Likewise. * ser-unix.c (hardwire_get_tty_state): Likewise. (hardwire_copy_tty_state): Likewise. * solib-aix.c (solib_aix_new_lm_info): Likewise. * solib-dsbt.c (dsbt_current_sos): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (frv_current_sos): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_bfd_fopen): Likewise. * solib-svr4.c (lm_info_read): Likewise. (svr4_copy_library_list): Likewise. (svr4_default_sos): Likewise. * source.c (find_source_lines): Likewise. (line_info): Likewise. (add_substitute_path_rule): Likewise. * spu-linux-nat.c (spu_bfd_open): Likewise. * spu-tdep.c (info_spu_dma_cmdlist): Likewise. * stabsread.c (dbx_lookup_type): Likewise. (read_type): Likewise. (read_member_functions): Likewise. (read_struct_fields): Likewise. (read_baseclasses): Likewise. (read_args): Likewise. (_initialize_stabsread): Likewise. * stack.c (func_command): Likewise. * stap-probe.c (handle_stap_probe): Likewise. * symfile.c (addrs_section_sort): Likewise. (addr_info_make_relative): Likewise. (load_section_callback): Likewise. (add_symbol_file_command): Likewise. (init_filename_language_table): Likewise. * symtab.c (create_filename_seen_cache): Likewise. (sort_search_symbols_remove_dups): Likewise. (search_symbols): Likewise. * target.c (make_cleanup_restore_target_terminal): Likewise. * thread.c (new_thread): Likewise. (enable_thread_stack_temporaries): Likewise. (make_cleanup_restore_current_thread): Likewise. (thread_apply_all_command): Likewise. * tic6x-tdep.c (tic6x_gdbarch_init): Likewise. * top.c (gdb_readline_wrapper): Likewise. * tracefile-tfile.c (tfile_trace_file_writer_new): Likewise. * tracepoint.c (trace_find_line_command): Likewise. (all_tracepoint_actions_and_cleanup): Likewise. (make_cleanup_restore_current_traceframe): Likewise. (get_uploaded_tp): Likewise. (get_uploaded_tsv): Likewise. * tui/tui-data.c (tui_alloc_generic_win_info): Likewise. (tui_alloc_win_info): Likewise. (tui_alloc_content): Likewise. (tui_add_content_elements): Likewise. * tui/tui-disasm.c (tui_find_disassembly_address): Likewise. (tui_set_disassem_content): Likewise. * ui-file.c (ui_file_new): Likewise. (stdio_file_new): Likewise. (tee_file_new): Likewise. * utils.c (make_cleanup_restore_integer): Likewise. (add_internal_problem_command): Likewise. * v850-tdep.c (v850_gdbarch_init): Likewise. * valops.c (find_oload_champ): Likewise. * value.c (allocate_value_lazy): Likewise. (record_latest_value): Likewise. (create_internalvar): Likewise. * varobj.c (install_variable): Likewise. (new_variable): Likewise. (new_root_variable): Likewise. (cppush): Likewise. (_initialize_varobj): Likewise. * windows-nat.c (windows_make_so): Likewise. * x86-nat.c (x86_add_process): Likewise. * xcoffread.c (arrange_linetable): Likewise. (allocate_include_entry): Likewise. (process_linenos): Likewise. (SYMBOL_DUP): Likewise. (xcoff_start_psymtab): Likewise. (xcoff_end_psymtab): Likewise. * xml-support.c (gdb_xml_parse_attr_ulongest): Likewise. * xtensa-tdep.c (xtensa_register_type): Likewise. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Likewise. (compile_bytecodes): Likewise. * dll.c (loaded_dll): Likewise. * event-loop.c (append_callback_event): Likewise. (create_file_handler): Likewise. (create_file_event): Likewise. * hostio.c (handle_open): Likewise. * inferiors.c (add_thread): Likewise. (add_process): Likewise. * linux-aarch64-low.c (aarch64_linux_new_process): Likewise. * linux-arm-low.c (arm_new_process): Likewise. (arm_new_thread): Likewise. * linux-low.c (add_to_pid_list): Likewise. (linux_add_process): Likewise. (handle_extended_wait): Likewise. (add_lwp): Likewise. (enqueue_one_deferred_signal): Likewise. (enqueue_pending_signal): Likewise. (linux_resume_one_lwp_throw): Likewise. (linux_resume_one_thread): Likewise. (linux_read_memory): Likewise. (linux_write_memory): Likewise. * linux-mips-low.c (mips_linux_new_process): Likewise. (mips_linux_new_thread): Likewise. (mips_add_watchpoint): Likewise. * linux-x86-low.c (initialize_low_arch): Likewise. * lynx-low.c (lynx_add_process): Likewise. * mem-break.c (set_raw_breakpoint_at): Likewise. (set_breakpoint): Likewise. (add_condition_to_breakpoint): Likewise. (add_commands_to_breakpoint): Likewise. (clone_agent_expr): Likewise. (clone_one_breakpoint): Likewise. * regcache.c (new_register_cache): Likewise. * remote-utils.c (look_up_one_symbol): Likewise. * server.c (queue_stop_reply): Likewise. (start_inferior): Likewise. (queue_stop_reply_callback): Likewise. (handle_target_event): Likewise. * spu-low.c (fetch_ppc_memory): Likewise. (store_ppc_memory): Likewise. * target.c (set_target_ops): Likewise. * thread-db.c (thread_db_load_search): Likewise. (try_thread_db_load_1): Likewise. * tracepoint.c (add_tracepoint): Likewise. (add_tracepoint_action): Likewise. (create_trace_state_variable): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtro): Likewise. (add_while_stepping_state): Likewise. * win32-low.c (child_add_thread): Likewise. (get_image_name): Likewise.
1040 lines
24 KiB
C
1040 lines
24 KiB
C
/* Python interface to inferiors.
|
|
|
|
Copyright (C) 2009-2015 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 "gdbthread.h"
|
|
#include "inferior.h"
|
|
#include "objfiles.h"
|
|
#include "observer.h"
|
|
#include "python-internal.h"
|
|
#include "arch-utils.h"
|
|
#include "language.h"
|
|
#include "gdb_signals.h"
|
|
#include "py-event.h"
|
|
#include "py-stopevent.h"
|
|
|
|
struct threadlist_entry {
|
|
thread_object *thread_obj;
|
|
struct threadlist_entry *next;
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
PyObject_HEAD
|
|
|
|
/* The inferior we represent. */
|
|
struct inferior *inferior;
|
|
|
|
/* thread_object instances under this inferior. This list owns a
|
|
reference to each object it contains. */
|
|
struct threadlist_entry *threads;
|
|
|
|
/* Number of threads in the list. */
|
|
int nthreads;
|
|
} inferior_object;
|
|
|
|
extern PyTypeObject inferior_object_type
|
|
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("inferior_object");
|
|
|
|
static const struct inferior_data *infpy_inf_data_key;
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
void *buffer;
|
|
|
|
/* These are kept just for mbpy_str. */
|
|
CORE_ADDR addr;
|
|
CORE_ADDR length;
|
|
} membuf_object;
|
|
|
|
extern PyTypeObject membuf_object_type
|
|
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("membuf_object");
|
|
|
|
/* Require that INFERIOR be a valid inferior ID. */
|
|
#define INFPY_REQUIRE_VALID(Inferior) \
|
|
do { \
|
|
if (!Inferior->inferior) \
|
|
{ \
|
|
PyErr_SetString (PyExc_RuntimeError, \
|
|
_("Inferior no longer exists.")); \
|
|
return NULL; \
|
|
} \
|
|
} while (0)
|
|
|
|
static void
|
|
python_on_normal_stop (struct bpstats *bs, int print_frame)
|
|
{
|
|
struct cleanup *cleanup;
|
|
enum gdb_signal stop_signal;
|
|
|
|
if (!gdb_python_initialized)
|
|
return;
|
|
|
|
if (!find_thread_ptid (inferior_ptid))
|
|
return;
|
|
|
|
stop_signal = inferior_thread ()->suspend.stop_signal;
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
|
|
|
if (emit_stop_event (bs, stop_signal) < 0)
|
|
gdbpy_print_stack ();
|
|
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
static void
|
|
python_on_resume (ptid_t ptid)
|
|
{
|
|
struct cleanup *cleanup;
|
|
|
|
if (!gdb_python_initialized)
|
|
return;
|
|
|
|
cleanup = ensure_python_env (target_gdbarch (), current_language);
|
|
|
|
if (emit_continue_event (ptid) < 0)
|
|
gdbpy_print_stack ();
|
|
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
/* Callback, registered as an observer, that notifies Python listeners
|
|
when an inferior function call is about to be made. */
|
|
|
|
static void
|
|
python_on_inferior_call_pre (ptid_t thread, CORE_ADDR address)
|
|
{
|
|
struct cleanup *cleanup;
|
|
|
|
cleanup = ensure_python_env (target_gdbarch (), current_language);
|
|
|
|
if (emit_inferior_call_event (INFERIOR_CALL_PRE, thread, address) < 0)
|
|
gdbpy_print_stack ();
|
|
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
/* Callback, registered as an observer, that notifies Python listeners
|
|
when an inferior function call has completed. */
|
|
|
|
static void
|
|
python_on_inferior_call_post (ptid_t thread, CORE_ADDR address)
|
|
{
|
|
struct cleanup *cleanup;
|
|
|
|
cleanup = ensure_python_env (target_gdbarch (), current_language);
|
|
|
|
if (emit_inferior_call_event (INFERIOR_CALL_POST, thread, address) < 0)
|
|
gdbpy_print_stack ();
|
|
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
/* Callback, registered as an observer, that notifies Python listeners
|
|
when a part of memory has been modified by user action (eg via a
|
|
'set' command). */
|
|
|
|
static void
|
|
python_on_memory_change (struct inferior *inferior, CORE_ADDR addr, ssize_t len, const bfd_byte *data)
|
|
{
|
|
struct cleanup *cleanup;
|
|
|
|
cleanup = ensure_python_env (target_gdbarch (), current_language);
|
|
|
|
if (emit_memory_changed_event (addr, len) < 0)
|
|
gdbpy_print_stack ();
|
|
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
/* Callback, registered as an observer, that notifies Python listeners
|
|
when a register has been modified by user action (eg via a 'set'
|
|
command). */
|
|
|
|
static void
|
|
python_on_register_change (struct frame_info *frame, int regnum)
|
|
{
|
|
struct cleanup *cleanup;
|
|
|
|
cleanup = ensure_python_env (target_gdbarch (), current_language);
|
|
|
|
if (emit_register_changed_event (frame, regnum) < 0)
|
|
gdbpy_print_stack ();
|
|
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
static void
|
|
python_inferior_exit (struct inferior *inf)
|
|
{
|
|
struct cleanup *cleanup;
|
|
const LONGEST *exit_code = NULL;
|
|
|
|
if (!gdb_python_initialized)
|
|
return;
|
|
|
|
cleanup = ensure_python_env (target_gdbarch (), current_language);
|
|
|
|
if (inf->has_exit_code)
|
|
exit_code = &inf->exit_code;
|
|
|
|
if (emit_exited_event (exit_code, inf) < 0)
|
|
gdbpy_print_stack ();
|
|
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
/* Callback used to notify Python listeners about new objfiles loaded in the
|
|
inferior. OBJFILE may be NULL which means that the objfile list has been
|
|
cleared (emptied). */
|
|
|
|
static void
|
|
python_new_objfile (struct objfile *objfile)
|
|
{
|
|
struct cleanup *cleanup;
|
|
|
|
if (!gdb_python_initialized)
|
|
return;
|
|
|
|
cleanup = ensure_python_env (objfile != NULL
|
|
? get_objfile_arch (objfile)
|
|
: target_gdbarch (),
|
|
current_language);
|
|
|
|
if (objfile == NULL)
|
|
{
|
|
if (emit_clear_objfiles_event () < 0)
|
|
gdbpy_print_stack ();
|
|
}
|
|
else
|
|
{
|
|
if (emit_new_objfile_event (objfile) < 0)
|
|
gdbpy_print_stack ();
|
|
}
|
|
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
/* Return a reference to the Python object of type Inferior
|
|
representing INFERIOR. If the object has already been created,
|
|
return it and increment the reference count, otherwise, create it.
|
|
Return NULL on failure. */
|
|
PyObject *
|
|
inferior_to_inferior_object (struct inferior *inferior)
|
|
{
|
|
inferior_object *inf_obj;
|
|
|
|
inf_obj = inferior_data (inferior, infpy_inf_data_key);
|
|
if (!inf_obj)
|
|
{
|
|
inf_obj = PyObject_New (inferior_object, &inferior_object_type);
|
|
if (!inf_obj)
|
|
return NULL;
|
|
|
|
inf_obj->inferior = inferior;
|
|
inf_obj->threads = NULL;
|
|
inf_obj->nthreads = 0;
|
|
|
|
set_inferior_data (inferior, infpy_inf_data_key, inf_obj);
|
|
|
|
}
|
|
else
|
|
Py_INCREF ((PyObject *)inf_obj);
|
|
|
|
return (PyObject *) inf_obj;
|
|
}
|
|
|
|
/* Finds the Python Inferior object for the given PID. Returns a
|
|
reference, or NULL if PID does not match any inferior object. */
|
|
|
|
PyObject *
|
|
find_inferior_object (int pid)
|
|
{
|
|
struct inferior *inf = find_inferior_pid (pid);
|
|
|
|
if (inf)
|
|
return inferior_to_inferior_object (inf);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
thread_object *
|
|
find_thread_object (ptid_t ptid)
|
|
{
|
|
int pid;
|
|
struct threadlist_entry *thread;
|
|
PyObject *inf_obj;
|
|
thread_object *found = NULL;
|
|
|
|
pid = ptid_get_pid (ptid);
|
|
if (pid == 0)
|
|
return NULL;
|
|
|
|
inf_obj = find_inferior_object (pid);
|
|
|
|
if (! inf_obj)
|
|
return NULL;
|
|
|
|
for (thread = ((inferior_object *)inf_obj)->threads; thread;
|
|
thread = thread->next)
|
|
if (ptid_equal (thread->thread_obj->thread->ptid, ptid))
|
|
{
|
|
found = thread->thread_obj;
|
|
break;
|
|
}
|
|
|
|
Py_DECREF (inf_obj);
|
|
|
|
if (found)
|
|
return found;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static void
|
|
add_thread_object (struct thread_info *tp)
|
|
{
|
|
struct cleanup *cleanup;
|
|
thread_object *thread_obj;
|
|
inferior_object *inf_obj;
|
|
struct threadlist_entry *entry;
|
|
|
|
if (!gdb_python_initialized)
|
|
return;
|
|
|
|
cleanup = ensure_python_env (python_gdbarch, python_language);
|
|
|
|
thread_obj = create_thread_object (tp);
|
|
if (!thread_obj)
|
|
{
|
|
gdbpy_print_stack ();
|
|
do_cleanups (cleanup);
|
|
return;
|
|
}
|
|
|
|
inf_obj = (inferior_object *) thread_obj->inf_obj;
|
|
|
|
entry = XNEW (struct threadlist_entry);
|
|
entry->thread_obj = thread_obj;
|
|
entry->next = inf_obj->threads;
|
|
|
|
inf_obj->threads = entry;
|
|
inf_obj->nthreads++;
|
|
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
static void
|
|
delete_thread_object (struct thread_info *tp, int ignore)
|
|
{
|
|
struct cleanup *cleanup;
|
|
inferior_object *inf_obj;
|
|
struct threadlist_entry **entry, *tmp;
|
|
|
|
if (!gdb_python_initialized)
|
|
return;
|
|
|
|
cleanup = ensure_python_env (python_gdbarch, python_language);
|
|
|
|
inf_obj
|
|
= (inferior_object *) find_inferior_object (ptid_get_pid (tp->ptid));
|
|
if (!inf_obj)
|
|
{
|
|
do_cleanups (cleanup);
|
|
return;
|
|
}
|
|
|
|
/* Find thread entry in its inferior's thread_list. */
|
|
for (entry = &inf_obj->threads; *entry != NULL; entry =
|
|
&(*entry)->next)
|
|
if ((*entry)->thread_obj->thread == tp)
|
|
break;
|
|
|
|
if (!*entry)
|
|
{
|
|
Py_DECREF (inf_obj);
|
|
do_cleanups (cleanup);
|
|
return;
|
|
}
|
|
|
|
tmp = *entry;
|
|
tmp->thread_obj->thread = NULL;
|
|
|
|
*entry = (*entry)->next;
|
|
inf_obj->nthreads--;
|
|
|
|
Py_DECREF (tmp->thread_obj);
|
|
Py_DECREF (inf_obj);
|
|
xfree (tmp);
|
|
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
static PyObject *
|
|
infpy_threads (PyObject *self, PyObject *args)
|
|
{
|
|
int i;
|
|
struct threadlist_entry *entry;
|
|
inferior_object *inf_obj = (inferior_object *) self;
|
|
PyObject *tuple;
|
|
|
|
INFPY_REQUIRE_VALID (inf_obj);
|
|
|
|
TRY
|
|
{
|
|
update_thread_list ();
|
|
}
|
|
CATCH (except, RETURN_MASK_ALL)
|
|
{
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
}
|
|
END_CATCH
|
|
|
|
tuple = PyTuple_New (inf_obj->nthreads);
|
|
if (!tuple)
|
|
return NULL;
|
|
|
|
for (i = 0, entry = inf_obj->threads; i < inf_obj->nthreads;
|
|
i++, entry = entry->next)
|
|
{
|
|
Py_INCREF (entry->thread_obj);
|
|
PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->thread_obj);
|
|
}
|
|
|
|
return tuple;
|
|
}
|
|
|
|
static PyObject *
|
|
infpy_get_num (PyObject *self, void *closure)
|
|
{
|
|
inferior_object *inf = (inferior_object *) self;
|
|
|
|
INFPY_REQUIRE_VALID (inf);
|
|
|
|
return PyLong_FromLong (inf->inferior->num);
|
|
}
|
|
|
|
static PyObject *
|
|
infpy_get_pid (PyObject *self, void *closure)
|
|
{
|
|
inferior_object *inf = (inferior_object *) self;
|
|
|
|
INFPY_REQUIRE_VALID (inf);
|
|
|
|
return PyLong_FromLong (inf->inferior->pid);
|
|
}
|
|
|
|
static PyObject *
|
|
infpy_get_was_attached (PyObject *self, void *closure)
|
|
{
|
|
inferior_object *inf = (inferior_object *) self;
|
|
|
|
INFPY_REQUIRE_VALID (inf);
|
|
if (inf->inferior->attach_flag)
|
|
Py_RETURN_TRUE;
|
|
Py_RETURN_FALSE;
|
|
}
|
|
|
|
static int
|
|
build_inferior_list (struct inferior *inf, void *arg)
|
|
{
|
|
PyObject *list = arg;
|
|
PyObject *inferior = inferior_to_inferior_object (inf);
|
|
int success = 0;
|
|
|
|
if (! inferior)
|
|
return 0;
|
|
|
|
success = PyList_Append (list, inferior);
|
|
Py_DECREF (inferior);
|
|
|
|
if (success)
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Implementation of gdb.inferiors () -> (gdb.Inferior, ...).
|
|
Returns a tuple of all inferiors. */
|
|
PyObject *
|
|
gdbpy_inferiors (PyObject *unused, PyObject *unused2)
|
|
{
|
|
PyObject *list, *tuple;
|
|
|
|
list = PyList_New (0);
|
|
if (!list)
|
|
return NULL;
|
|
|
|
if (iterate_over_inferiors (build_inferior_list, list))
|
|
{
|
|
Py_DECREF (list);
|
|
return NULL;
|
|
}
|
|
|
|
tuple = PyList_AsTuple (list);
|
|
Py_DECREF (list);
|
|
|
|
return tuple;
|
|
}
|
|
|
|
/* Membuf and memory manipulation. */
|
|
|
|
/* Implementation of Inferior.read_memory (address, length).
|
|
Returns a Python buffer object with LENGTH bytes of the inferior's
|
|
memory at ADDRESS. Both arguments are integers. Returns NULL on error,
|
|
with a python exception set. */
|
|
static PyObject *
|
|
infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|
{
|
|
CORE_ADDR addr, length;
|
|
void *buffer = NULL;
|
|
membuf_object *membuf_obj;
|
|
PyObject *addr_obj, *length_obj, *result;
|
|
static char *keywords[] = { "address", "length", NULL };
|
|
|
|
if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords,
|
|
&addr_obj, &length_obj))
|
|
return NULL;
|
|
|
|
if (get_addr_from_python (addr_obj, &addr) < 0
|
|
|| get_addr_from_python (length_obj, &length) < 0)
|
|
return NULL;
|
|
|
|
TRY
|
|
{
|
|
buffer = xmalloc (length);
|
|
|
|
read_memory (addr, buffer, length);
|
|
}
|
|
CATCH (except, RETURN_MASK_ALL)
|
|
{
|
|
xfree (buffer);
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
}
|
|
END_CATCH
|
|
|
|
membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
|
|
if (membuf_obj == NULL)
|
|
{
|
|
xfree (buffer);
|
|
return NULL;
|
|
}
|
|
|
|
membuf_obj->buffer = buffer;
|
|
membuf_obj->addr = addr;
|
|
membuf_obj->length = length;
|
|
|
|
#ifdef IS_PY3K
|
|
result = PyMemoryView_FromObject ((PyObject *) membuf_obj);
|
|
#else
|
|
result = PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
|
|
Py_END_OF_BUFFER);
|
|
#endif
|
|
Py_DECREF (membuf_obj);
|
|
|
|
return result;
|
|
}
|
|
|
|
/* Implementation of Inferior.write_memory (address, buffer [, length]).
|
|
Writes the contents of BUFFER (a Python object supporting the read
|
|
buffer protocol) at ADDRESS in the inferior's memory. Write LENGTH
|
|
bytes from BUFFER, or its entire contents if the argument is not
|
|
provided. The function returns nothing. Returns NULL on error, with
|
|
a python exception set. */
|
|
static PyObject *
|
|
infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|
{
|
|
struct gdb_exception except = exception_none;
|
|
Py_ssize_t buf_len;
|
|
const char *buffer;
|
|
CORE_ADDR addr, length;
|
|
PyObject *addr_obj, *length_obj = NULL;
|
|
static char *keywords[] = { "address", "buffer", "length", NULL };
|
|
#ifdef IS_PY3K
|
|
Py_buffer pybuf;
|
|
|
|
if (! PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords,
|
|
&addr_obj, &pybuf,
|
|
&length_obj))
|
|
return NULL;
|
|
|
|
buffer = pybuf.buf;
|
|
buf_len = pybuf.len;
|
|
#else
|
|
if (! PyArg_ParseTupleAndKeywords (args, kw, "Os#|O", keywords,
|
|
&addr_obj, &buffer, &buf_len,
|
|
&length_obj))
|
|
return NULL;
|
|
#endif
|
|
|
|
if (get_addr_from_python (addr_obj, &addr) < 0)
|
|
goto fail;
|
|
|
|
if (!length_obj)
|
|
length = buf_len;
|
|
else if (get_addr_from_python (length_obj, &length) < 0)
|
|
goto fail;
|
|
|
|
TRY
|
|
{
|
|
write_memory_with_notification (addr, (gdb_byte *) buffer, length);
|
|
}
|
|
CATCH (ex, RETURN_MASK_ALL)
|
|
{
|
|
except = ex;
|
|
}
|
|
END_CATCH
|
|
|
|
#ifdef IS_PY3K
|
|
PyBuffer_Release (&pybuf);
|
|
#endif
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
fail:
|
|
#ifdef IS_PY3K
|
|
PyBuffer_Release (&pybuf);
|
|
#endif
|
|
return NULL;
|
|
}
|
|
|
|
/* Destructor of Membuf objects. */
|
|
static void
|
|
mbpy_dealloc (PyObject *self)
|
|
{
|
|
xfree (((membuf_object *) self)->buffer);
|
|
Py_TYPE (self)->tp_free (self);
|
|
}
|
|
|
|
/* Return a description of the Membuf object. */
|
|
static PyObject *
|
|
mbpy_str (PyObject *self)
|
|
{
|
|
membuf_object *membuf_obj = (membuf_object *) self;
|
|
|
|
return PyString_FromFormat (_("Memory buffer for address %s, \
|
|
which is %s bytes long."),
|
|
paddress (python_gdbarch, membuf_obj->addr),
|
|
pulongest (membuf_obj->length));
|
|
}
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
static int
|
|
get_buffer (PyObject *self, Py_buffer *buf, int flags)
|
|
{
|
|
membuf_object *membuf_obj = (membuf_object *) self;
|
|
int ret;
|
|
|
|
ret = PyBuffer_FillInfo (buf, self, membuf_obj->buffer,
|
|
membuf_obj->length, 0,
|
|
PyBUF_CONTIG);
|
|
buf->format = "c";
|
|
|
|
return ret;
|
|
}
|
|
|
|
#else
|
|
|
|
static Py_ssize_t
|
|
get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
|
|
{
|
|
membuf_object *membuf_obj = (membuf_object *) self;
|
|
|
|
if (segment)
|
|
{
|
|
PyErr_SetString (PyExc_SystemError,
|
|
_("The memory buffer supports only one segment."));
|
|
return -1;
|
|
}
|
|
|
|
*ptrptr = membuf_obj->buffer;
|
|
|
|
return membuf_obj->length;
|
|
}
|
|
|
|
static Py_ssize_t
|
|
get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
|
|
{
|
|
return get_read_buffer (self, segment, ptrptr);
|
|
}
|
|
|
|
static Py_ssize_t
|
|
get_seg_count (PyObject *self, Py_ssize_t *lenp)
|
|
{
|
|
if (lenp)
|
|
*lenp = ((membuf_object *) self)->length;
|
|
|
|
return 1;
|
|
}
|
|
|
|
static Py_ssize_t
|
|
get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
|
|
{
|
|
void *ptr = NULL;
|
|
Py_ssize_t ret;
|
|
|
|
ret = get_read_buffer (self, segment, &ptr);
|
|
*ptrptr = (char *) ptr;
|
|
|
|
return ret;
|
|
}
|
|
|
|
#endif /* IS_PY3K */
|
|
|
|
/* Implementation of
|
|
gdb.search_memory (address, length, pattern). ADDRESS is the
|
|
address to start the search. LENGTH specifies the scope of the
|
|
search from ADDRESS. PATTERN is the pattern to search for (and
|
|
must be a Python object supporting the buffer protocol).
|
|
Returns a Python Long object holding the address where the pattern
|
|
was located, or if the pattern was not found, returns None. Returns NULL
|
|
on error, with a python exception set. */
|
|
static PyObject *
|
|
infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|
{
|
|
struct gdb_exception except = exception_none;
|
|
CORE_ADDR start_addr, length;
|
|
static char *keywords[] = { "address", "length", "pattern", NULL };
|
|
PyObject *start_addr_obj, *length_obj;
|
|
Py_ssize_t pattern_size;
|
|
const void *buffer;
|
|
CORE_ADDR found_addr;
|
|
int found = 0;
|
|
#ifdef IS_PY3K
|
|
Py_buffer pybuf;
|
|
|
|
if (! PyArg_ParseTupleAndKeywords (args, kw, "OOs*", keywords,
|
|
&start_addr_obj, &length_obj,
|
|
&pybuf))
|
|
return NULL;
|
|
|
|
buffer = pybuf.buf;
|
|
pattern_size = pybuf.len;
|
|
#else
|
|
PyObject *pattern;
|
|
|
|
if (! PyArg_ParseTupleAndKeywords (args, kw, "OOO", keywords,
|
|
&start_addr_obj, &length_obj,
|
|
&pattern))
|
|
return NULL;
|
|
|
|
if (!PyObject_CheckReadBuffer (pattern))
|
|
{
|
|
PyErr_SetString (PyExc_RuntimeError,
|
|
_("The pattern is not a Python buffer."));
|
|
|
|
return NULL;
|
|
}
|
|
|
|
if (PyObject_AsReadBuffer (pattern, &buffer, &pattern_size) == -1)
|
|
return NULL;
|
|
#endif
|
|
|
|
if (get_addr_from_python (start_addr_obj, &start_addr) < 0)
|
|
goto fail;
|
|
|
|
if (get_addr_from_python (length_obj, &length) < 0)
|
|
goto fail;
|
|
|
|
if (!length)
|
|
{
|
|
PyErr_SetString (PyExc_ValueError,
|
|
_("Search range is empty."));
|
|
goto fail;
|
|
}
|
|
/* Watch for overflows. */
|
|
else if (length > CORE_ADDR_MAX
|
|
|| (start_addr + length - 1) < start_addr)
|
|
{
|
|
PyErr_SetString (PyExc_ValueError,
|
|
_("The search range is too large."));
|
|
goto fail;
|
|
}
|
|
|
|
TRY
|
|
{
|
|
found = target_search_memory (start_addr, length,
|
|
buffer, pattern_size,
|
|
&found_addr);
|
|
}
|
|
CATCH (ex, RETURN_MASK_ALL)
|
|
{
|
|
except = ex;
|
|
}
|
|
END_CATCH
|
|
|
|
#ifdef IS_PY3K
|
|
PyBuffer_Release (&pybuf);
|
|
#endif
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
if (found)
|
|
return PyLong_FromLong (found_addr);
|
|
else
|
|
Py_RETURN_NONE;
|
|
|
|
fail:
|
|
#ifdef IS_PY3K
|
|
PyBuffer_Release (&pybuf);
|
|
#endif
|
|
return NULL;
|
|
}
|
|
|
|
/* Implementation of gdb.Inferior.is_valid (self) -> Boolean.
|
|
Returns True if this inferior object still exists in GDB. */
|
|
|
|
static PyObject *
|
|
infpy_is_valid (PyObject *self, PyObject *args)
|
|
{
|
|
inferior_object *inf = (inferior_object *) self;
|
|
|
|
if (! inf->inferior)
|
|
Py_RETURN_FALSE;
|
|
|
|
Py_RETURN_TRUE;
|
|
}
|
|
|
|
static void
|
|
infpy_dealloc (PyObject *obj)
|
|
{
|
|
inferior_object *inf_obj = (inferior_object *) obj;
|
|
struct inferior *inf = inf_obj->inferior;
|
|
|
|
if (! inf)
|
|
return;
|
|
|
|
set_inferior_data (inf, infpy_inf_data_key, NULL);
|
|
}
|
|
|
|
/* Clear the INFERIOR pointer in an Inferior object and clear the
|
|
thread list. */
|
|
static void
|
|
py_free_inferior (struct inferior *inf, void *datum)
|
|
{
|
|
|
|
struct cleanup *cleanup;
|
|
inferior_object *inf_obj = datum;
|
|
struct threadlist_entry *th_entry, *th_tmp;
|
|
|
|
if (!gdb_python_initialized)
|
|
return;
|
|
|
|
cleanup = ensure_python_env (python_gdbarch, python_language);
|
|
|
|
inf_obj->inferior = NULL;
|
|
|
|
/* Deallocate threads list. */
|
|
for (th_entry = inf_obj->threads; th_entry != NULL;)
|
|
{
|
|
Py_DECREF (th_entry->thread_obj);
|
|
|
|
th_tmp = th_entry;
|
|
th_entry = th_entry->next;
|
|
xfree (th_tmp);
|
|
}
|
|
|
|
inf_obj->nthreads = 0;
|
|
|
|
Py_DECREF ((PyObject *) inf_obj);
|
|
do_cleanups (cleanup);
|
|
}
|
|
|
|
/* Implementation of gdb.selected_inferior() -> gdb.Inferior.
|
|
Returns the current inferior object. */
|
|
|
|
PyObject *
|
|
gdbpy_selected_inferior (PyObject *self, PyObject *args)
|
|
{
|
|
return inferior_to_inferior_object (current_inferior ());
|
|
}
|
|
|
|
int
|
|
gdbpy_initialize_inferior (void)
|
|
{
|
|
if (PyType_Ready (&inferior_object_type) < 0)
|
|
return -1;
|
|
|
|
if (gdb_pymodule_addobject (gdb_module, "Inferior",
|
|
(PyObject *) &inferior_object_type) < 0)
|
|
return -1;
|
|
|
|
infpy_inf_data_key =
|
|
register_inferior_data_with_cleanup (NULL, py_free_inferior);
|
|
|
|
observer_attach_new_thread (add_thread_object);
|
|
observer_attach_thread_exit (delete_thread_object);
|
|
observer_attach_normal_stop (python_on_normal_stop);
|
|
observer_attach_target_resumed (python_on_resume);
|
|
observer_attach_inferior_call_pre (python_on_inferior_call_pre);
|
|
observer_attach_inferior_call_post (python_on_inferior_call_post);
|
|
observer_attach_memory_changed (python_on_memory_change);
|
|
observer_attach_register_changed (python_on_register_change);
|
|
observer_attach_inferior_exit (python_inferior_exit);
|
|
observer_attach_new_objfile (python_new_objfile);
|
|
|
|
membuf_object_type.tp_new = PyType_GenericNew;
|
|
if (PyType_Ready (&membuf_object_type) < 0)
|
|
return -1;
|
|
|
|
return gdb_pymodule_addobject (gdb_module, "Membuf", (PyObject *)
|
|
&membuf_object_type);
|
|
}
|
|
|
|
static PyGetSetDef inferior_object_getset[] =
|
|
{
|
|
{ "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL },
|
|
{ "pid", infpy_get_pid, NULL, "PID of inferior, as assigned by the OS.",
|
|
NULL },
|
|
{ "was_attached", infpy_get_was_attached, NULL,
|
|
"True if the inferior was created using 'attach'.", NULL },
|
|
{ NULL }
|
|
};
|
|
|
|
static PyMethodDef inferior_object_methods[] =
|
|
{
|
|
{ "is_valid", infpy_is_valid, METH_NOARGS,
|
|
"is_valid () -> Boolean.\n\
|
|
Return true if this inferior is valid, false if not." },
|
|
{ "threads", infpy_threads, METH_NOARGS,
|
|
"Return all the threads of this inferior." },
|
|
{ "read_memory", (PyCFunction) infpy_read_memory,
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
"read_memory (address, length) -> buffer\n\
|
|
Return a buffer object for reading from the inferior's memory." },
|
|
{ "write_memory", (PyCFunction) infpy_write_memory,
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
"write_memory (address, buffer [, length])\n\
|
|
Write the given buffer object to the inferior's memory." },
|
|
{ "search_memory", (PyCFunction) infpy_search_memory,
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
"search_memory (address, length, pattern) -> long\n\
|
|
Return a long with the address of a match, or None." },
|
|
{ NULL }
|
|
};
|
|
|
|
PyTypeObject inferior_object_type =
|
|
{
|
|
PyVarObject_HEAD_INIT (NULL, 0)
|
|
"gdb.Inferior", /* tp_name */
|
|
sizeof (inferior_object), /* tp_basicsize */
|
|
0, /* tp_itemsize */
|
|
infpy_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 */
|
|
0, /* tp_str */
|
|
0, /* tp_getattro */
|
|
0, /* tp_setattro */
|
|
0, /* tp_as_buffer */
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, /* tp_flags */
|
|
"GDB inferior object", /* tp_doc */
|
|
0, /* tp_traverse */
|
|
0, /* tp_clear */
|
|
0, /* tp_richcompare */
|
|
0, /* tp_weaklistoffset */
|
|
0, /* tp_iter */
|
|
0, /* tp_iternext */
|
|
inferior_object_methods, /* tp_methods */
|
|
0, /* tp_members */
|
|
inferior_object_getset, /* 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 */
|
|
};
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
static PyBufferProcs buffer_procs =
|
|
{
|
|
get_buffer
|
|
};
|
|
|
|
#else
|
|
|
|
/* Python doesn't provide a decent way to get compatibility here. */
|
|
#if HAVE_LIBPYTHON2_4
|
|
#define CHARBUFFERPROC_NAME getcharbufferproc
|
|
#else
|
|
#define CHARBUFFERPROC_NAME charbufferproc
|
|
#endif
|
|
|
|
static PyBufferProcs buffer_procs = {
|
|
get_read_buffer,
|
|
get_write_buffer,
|
|
get_seg_count,
|
|
/* The cast here works around a difference between Python 2.4 and
|
|
Python 2.5. */
|
|
(CHARBUFFERPROC_NAME) get_char_buffer
|
|
};
|
|
#endif /* IS_PY3K */
|
|
|
|
PyTypeObject membuf_object_type = {
|
|
PyVarObject_HEAD_INIT (NULL, 0)
|
|
"gdb.Membuf", /*tp_name*/
|
|
sizeof (membuf_object), /*tp_basicsize*/
|
|
0, /*tp_itemsize*/
|
|
mbpy_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*/
|
|
mbpy_str, /*tp_str*/
|
|
0, /*tp_getattro*/
|
|
0, /*tp_setattro*/
|
|
&buffer_procs, /*tp_as_buffer*/
|
|
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
|
"GDB memory buffer object", /*tp_doc*/
|
|
0, /* tp_traverse */
|
|
0, /* tp_clear */
|
|
0, /* tp_richcompare */
|
|
0, /* tp_weaklistoffset */
|
|
0, /* tp_iter */
|
|
0, /* tp_iternext */
|
|
0, /* 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 */
|
|
};
|