mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-29 04:53:56 +08:00
f486487f55
This is a patch I extracted from Pedro's C++ branch. It contains the most trivial enum fixes, where an integer type/value was used instead of the appropriate enum type/value. It fixes many C++ errors, since in C++ you can't mix integers and enums implicitely. Regardless of the C++ conversion, I think this is a good cleanup to make use of the appropriate enum types. Regression-tested on native x86_64. gdb/ChangeLog: * aarch64-linux-nat.c (aarch64_linux_can_use_hw_breakpoint): Use enum type or value instead of integer. (aarch64_linux_insert_watchpoint): Likewise. (aarch64_linux_remove_watchpoint): Likewise. * ada-lang.c (ada_op_print_tab): Likewise. * amd64-linux-tdep.c (amd64_canonicalize_syscall): Likewise. (amd64_linux_syscall_record_common): Likewise. * arch-utils.c (target_byte_order_user): Likewise. (default_byte_order): Likewise. * arm-linux-nat.c (arm_linux_can_use_hw_breakpoint): Likewise. (arm_linux_get_hwbp_type): Likewise. (arm_linux_hw_watchpoint_initialize): Likewise. (arm_linux_insert_watchpoint): Likewise. * arm-linux-tdep.c (arm_canonicalize_syscall): Likewise. (arm_linux_syscall_record): Likewise. * breakpoint.c (update_watchpoint): Likewise. (breakpoint_here_p): Likewise. (bpstat_print): Likewise. (enable_breakpoint_disp): Likewise. * c-lang.c (c_op_print_tab): Likewise. * cli/cli-decode.c (add_info_alias): Likewise. * d-lang.c (d_op_print_tab): Likewise. * eval.c (evaluate_subexp_standard): Likewise. * f-exp.y (dot_ops): Likewise. (f77_keywords): Likewise. * f-lang.c (f_op_print_tab): Likewise. * go-lang.c (go_op_print_tab): Likewise. * guile/scm-breakpoint.c (gdbscm_make_breakpoint): Likewise. * guile/scm-cmd.c (gdbscm_make_command): Likewise. * guile/scm-param.c (gdbscm_make_parameter): Likewise. * guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer): Likewise. * guile/scm-string.c (struct scm_to_stringn_data): Likewise. (struct scm_from_stringn_data): Likewise. * i386-linux-tdep.c (i386_canonicalize_syscall): Likewise. * ia64-linux-nat.c (ia64_linux_insert_watchpoint): Likewise. (ia64_linux_remove_watchpoint): Likewise. (ia64_linux_can_use_hw_breakpoint): Likewise. * infrun.c (print_stop_event): Likewise. * jv-lang.c (java_op_print_tab): Likewise. * linux-nat.c (linux_proc_xfer_partial): Likewise. * linux-nat.h (struct lwp_info): Likewise. * linux-thread-db.c (enable_thread_event): Likewise. * m2-lang.c (m2_op_print_tab): Likewise. * mi/mi-cmd-stack.c (mi_cmd_stack_list_locals): Likewise. (mi_cmd_stack_list_variables): Likewise. * mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise. * mi/mi-out.c (mi_table_begin): Likewise. (mi_table_header): Likewise. * mips-linux-nat.c (mips_linux_can_use_hw_breakpoint): Likewise. (mips_linux_insert_watchpoint): Likewise. (mips_linux_remove_watchpoint): Likewise. * nat/mips-linux-watch.c (mips_linux_watch_type_to_irw): Likewise. * nat/mips-linux-watch.h (struct mips_watchpoint): Likewise. (mips_linux_watch_type_to_irw): Likewise. * nto-procfs.c (procfs_can_use_hw_breakpoint): Likewise. (procfs_insert_hw_watchpoint): Likewise. (procfs_remove_hw_watchpoint): Likewise. (procfs_hw_watchpoint): Likewise. (procfs_can_use_hw_breakpoint): Likewise. (procfs_remove_hw_watchpoint): Likewise. (procfs_insert_hw_watchpoint): Likewise. * p-lang.c (pascal_op_print_tab): Likewise. * ppc-linux-nat.c (ppc_linux_can_use_hw_breakpoint): Likewise. * ppc-linux-tdep.c (ppu2spu_unwind_register): Likewise. * ppc-sysv-tdep.c (get_decimal_float_return_value): Likewise. * procfs.c (procfs_can_use_hw_breakpoint): Likewise. (procfs_insert_watchpoint): Likewise. (procfs_remove_watchpoint): Likewise. * psymtab.c (recursively_search_psymtabs): Likewise. * remote-m32r-sdi.c (m32r_can_use_hw_watchpoint): Likewise. (m32r_insert_watchpoint): Likewise. * remote-mips.c (mips_can_use_watchpoint): Likewise. (mips_insert_watchpoint): Likewise. (mips_remove_watchpoint): Likewise. * remote.c (watchpoint_to_Z_packet): Likewise. (remote_insert_watchpoint): Likewise. (remote_remove_watchpoint): Likewise. (remote_check_watch_resources): Likewise. * s390-linux-nat.c (s390_insert_watchpoint): Likewise. (s390_remove_watchpoint): Likewise. (s390_can_use_hw_breakpoint): Likewise. * s390-linux-tdep.c (s390_gdbarch_init): Likewise. * spu-linux-nat.c (spu_can_use_hw_breakpoint): Likewise. * target.h (struct target_ops): Likewise. * tilegx-tdep.c (tilegx_analyze_prologue): Likewise. * ui-out.c (struct ui_out_hdr): Likewise. (append_header_to_list): Likewise. (get_next_header): Likewise. (verify_field): Likewise. (ui_out_begin): Likewise. (ui_out_field_int): Likewise. (ui_out_field_fmt_int): Likewise. (ui_out_field_skip): Likewise. (ui_out_field_string): Likewise. (ui_out_field_fmt): Likewise. * varobj.c (new_variable): Likewise. * x86-nat.c (x86_insert_watchpoint): Likewise. (x86_remove_watchpoint): Likewise. (x86_can_use_hw_breakpoint): Likewise. * xtensa-tdep.h (struct gdbarch_tdep): Likewise. * inflow.c (enum gdb_has_a_terminal_flag_enum): Add name to previously anonymous enumeration type.. * linux-record.h (enum gdb_syscall): Add gdb_sys_no_syscall value. * target-debug.h (target_debug_print_enum_target_hw_bp_type): New. (target_debug_print_enum_bptype): New. * target-delegates.c: Regenerate.
313 lines
9.3 KiB
C
313 lines
9.3 KiB
C
/* Native-dependent code for x86 (i386 and x86-64).
|
|
|
|
Copyright (C) 2001-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 "x86-nat.h"
|
|
#include "gdbcmd.h"
|
|
#include "inferior.h"
|
|
|
|
/* Support for hardware watchpoints and breakpoints using the x86
|
|
debug registers.
|
|
|
|
This provides several functions for inserting and removing
|
|
hardware-assisted breakpoints and watchpoints, testing if one or
|
|
more of the watchpoints triggered and at what address, checking
|
|
whether a given region can be watched, etc.
|
|
|
|
The functions below implement debug registers sharing by reference
|
|
counts, and allow to watch regions up to 16 bytes long. */
|
|
|
|
/* Low-level function vector. */
|
|
struct x86_dr_low_type x86_dr_low;
|
|
|
|
/* Per-process data. We don't bind this to a per-inferior registry
|
|
because of targets like x86 GNU/Linux that need to keep track of
|
|
processes that aren't bound to any inferior (e.g., fork children,
|
|
checkpoints). */
|
|
|
|
struct x86_process_info
|
|
{
|
|
/* Linked list. */
|
|
struct x86_process_info *next;
|
|
|
|
/* The process identifier. */
|
|
pid_t pid;
|
|
|
|
/* Copy of x86 hardware debug registers. */
|
|
struct x86_debug_reg_state state;
|
|
};
|
|
|
|
static struct x86_process_info *x86_process_list = NULL;
|
|
|
|
/* Find process data for process PID. */
|
|
|
|
static struct x86_process_info *
|
|
x86_find_process_pid (pid_t pid)
|
|
{
|
|
struct x86_process_info *proc;
|
|
|
|
for (proc = x86_process_list; proc; proc = proc->next)
|
|
if (proc->pid == pid)
|
|
return proc;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/* Add process data for process PID. Returns newly allocated info
|
|
object. */
|
|
|
|
static struct x86_process_info *
|
|
x86_add_process (pid_t pid)
|
|
{
|
|
struct x86_process_info *proc;
|
|
|
|
proc = xcalloc (1, sizeof (*proc));
|
|
proc->pid = pid;
|
|
|
|
proc->next = x86_process_list;
|
|
x86_process_list = proc;
|
|
|
|
return proc;
|
|
}
|
|
|
|
/* Get data specific info for process PID, creating it if necessary.
|
|
Never returns NULL. */
|
|
|
|
static struct x86_process_info *
|
|
x86_process_info_get (pid_t pid)
|
|
{
|
|
struct x86_process_info *proc;
|
|
|
|
proc = x86_find_process_pid (pid);
|
|
if (proc == NULL)
|
|
proc = x86_add_process (pid);
|
|
|
|
return proc;
|
|
}
|
|
|
|
/* Get debug registers state for process PID. */
|
|
|
|
struct x86_debug_reg_state *
|
|
x86_debug_reg_state (pid_t pid)
|
|
{
|
|
return &x86_process_info_get (pid)->state;
|
|
}
|
|
|
|
/* See declaration in i386-nat.h. */
|
|
|
|
void
|
|
x86_forget_process (pid_t pid)
|
|
{
|
|
struct x86_process_info *proc, **proc_link;
|
|
|
|
proc = x86_process_list;
|
|
proc_link = &x86_process_list;
|
|
|
|
while (proc != NULL)
|
|
{
|
|
if (proc->pid == pid)
|
|
{
|
|
*proc_link = proc->next;
|
|
|
|
xfree (proc);
|
|
return;
|
|
}
|
|
|
|
proc_link = &proc->next;
|
|
proc = *proc_link;
|
|
}
|
|
}
|
|
|
|
/* Clear the reference counts and forget everything we knew about the
|
|
debug registers. */
|
|
|
|
void
|
|
x86_cleanup_dregs (void)
|
|
{
|
|
/* Starting from scratch has the same effect. */
|
|
x86_forget_process (ptid_get_pid (inferior_ptid));
|
|
}
|
|
|
|
/* Insert a watchpoint to watch a memory region which starts at
|
|
address ADDR and whose length is LEN bytes. Watch memory accesses
|
|
of the type TYPE. Return 0 on success, -1 on failure. */
|
|
|
|
static int
|
|
x86_insert_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
|
|
enum target_hw_bp_type type, struct expression *cond)
|
|
{
|
|
struct x86_debug_reg_state *state
|
|
= x86_debug_reg_state (ptid_get_pid (inferior_ptid));
|
|
|
|
return x86_dr_insert_watchpoint (state, type, addr, len);
|
|
}
|
|
|
|
/* Remove a watchpoint that watched the memory region which starts at
|
|
address ADDR, whose length is LEN bytes, and for accesses of the
|
|
type TYPE. Return 0 on success, -1 on failure. */
|
|
static int
|
|
x86_remove_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
|
|
enum target_hw_bp_type type, struct expression *cond)
|
|
{
|
|
struct x86_debug_reg_state *state
|
|
= x86_debug_reg_state (ptid_get_pid (inferior_ptid));
|
|
|
|
return x86_dr_remove_watchpoint (state, type, addr, len);
|
|
}
|
|
|
|
/* Return non-zero if we can watch a memory region that starts at
|
|
address ADDR and whose length is LEN bytes. */
|
|
|
|
static int
|
|
x86_region_ok_for_watchpoint (struct target_ops *self,
|
|
CORE_ADDR addr, int len)
|
|
{
|
|
struct x86_debug_reg_state *state
|
|
= x86_debug_reg_state (ptid_get_pid (inferior_ptid));
|
|
|
|
return x86_dr_region_ok_for_watchpoint (state, addr, len);
|
|
}
|
|
|
|
/* If the inferior has some break/watchpoint that triggered, set the
|
|
address associated with that break/watchpoint and return non-zero.
|
|
Otherwise, return zero. */
|
|
|
|
static int
|
|
x86_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
|
|
{
|
|
struct x86_debug_reg_state *state
|
|
= x86_debug_reg_state (ptid_get_pid (inferior_ptid));
|
|
|
|
return x86_dr_stopped_data_address (state, addr_p);
|
|
}
|
|
|
|
/* Return non-zero if the inferior has some watchpoint that triggered.
|
|
Otherwise return zero. */
|
|
|
|
static int
|
|
x86_stopped_by_watchpoint (struct target_ops *ops)
|
|
{
|
|
struct x86_debug_reg_state *state
|
|
= x86_debug_reg_state (ptid_get_pid (inferior_ptid));
|
|
|
|
return x86_dr_stopped_by_watchpoint (state);
|
|
}
|
|
|
|
/* Insert a hardware-assisted breakpoint at BP_TGT->reqstd_address.
|
|
Return 0 on success, EBUSY on failure. */
|
|
|
|
static int
|
|
x86_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
|
|
struct bp_target_info *bp_tgt)
|
|
{
|
|
struct x86_debug_reg_state *state
|
|
= x86_debug_reg_state (ptid_get_pid (inferior_ptid));
|
|
|
|
bp_tgt->placed_address = bp_tgt->reqstd_address;
|
|
return x86_dr_insert_watchpoint (state, hw_execute,
|
|
bp_tgt->placed_address, 1) ? EBUSY : 0;
|
|
}
|
|
|
|
/* Remove a hardware-assisted breakpoint at BP_TGT->placed_address.
|
|
Return 0 on success, -1 on failure. */
|
|
|
|
static int
|
|
x86_remove_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
|
|
struct bp_target_info *bp_tgt)
|
|
{
|
|
struct x86_debug_reg_state *state
|
|
= x86_debug_reg_state (ptid_get_pid (inferior_ptid));
|
|
|
|
return x86_dr_remove_watchpoint (state, hw_execute,
|
|
bp_tgt->placed_address, 1);
|
|
}
|
|
|
|
/* Returns the number of hardware watchpoints of type TYPE that we can
|
|
set. Value is positive if we can set CNT watchpoints, zero if
|
|
setting watchpoints of type TYPE is not supported, and negative if
|
|
CNT is more than the maximum number of watchpoints of type TYPE
|
|
that we can support. TYPE is one of bp_hardware_watchpoint,
|
|
bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
|
|
CNT is the number of such watchpoints used so far (including this
|
|
one). OTHERTYPE is non-zero if other types of watchpoints are
|
|
currently enabled.
|
|
|
|
We always return 1 here because we don't have enough information
|
|
about possible overlap of addresses that they want to watch. As an
|
|
extreme example, consider the case where all the watchpoints watch
|
|
the same address and the same region length: then we can handle a
|
|
virtually unlimited number of watchpoints, due to debug register
|
|
sharing implemented via reference counts in i386-nat.c. */
|
|
|
|
static int
|
|
x86_can_use_hw_breakpoint (struct target_ops *self,
|
|
enum bptype type, int cnt, int othertype)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
static void
|
|
add_show_debug_regs_command (void)
|
|
{
|
|
/* A maintenance command to enable printing the internal DRi mirror
|
|
variables. */
|
|
add_setshow_boolean_cmd ("show-debug-regs", class_maintenance,
|
|
&show_debug_regs, _("\
|
|
Set whether to show variables that mirror the x86 debug registers."), _("\
|
|
Show whether to show variables that mirror the x86 debug registers."), _("\
|
|
Use \"on\" to enable, \"off\" to disable.\n\
|
|
If enabled, the debug registers values are shown when GDB inserts\n\
|
|
or removes a hardware breakpoint or watchpoint, and when the inferior\n\
|
|
triggers a breakpoint or watchpoint."),
|
|
NULL,
|
|
NULL,
|
|
&maintenance_set_cmdlist,
|
|
&maintenance_show_cmdlist);
|
|
}
|
|
|
|
/* There are only two global functions left. */
|
|
|
|
void
|
|
x86_use_watchpoints (struct target_ops *t)
|
|
{
|
|
/* After a watchpoint trap, the PC points to the instruction after the
|
|
one that caused the trap. Therefore we don't need to step over it.
|
|
But we do need to reset the status register to avoid another trap. */
|
|
t->to_have_continuable_watchpoint = 1;
|
|
|
|
t->to_can_use_hw_breakpoint = x86_can_use_hw_breakpoint;
|
|
t->to_region_ok_for_hw_watchpoint = x86_region_ok_for_watchpoint;
|
|
t->to_stopped_by_watchpoint = x86_stopped_by_watchpoint;
|
|
t->to_stopped_data_address = x86_stopped_data_address;
|
|
t->to_insert_watchpoint = x86_insert_watchpoint;
|
|
t->to_remove_watchpoint = x86_remove_watchpoint;
|
|
t->to_insert_hw_breakpoint = x86_insert_hw_breakpoint;
|
|
t->to_remove_hw_breakpoint = x86_remove_hw_breakpoint;
|
|
}
|
|
|
|
void
|
|
x86_set_debug_register_length (int len)
|
|
{
|
|
/* This function should be called only once for each native target. */
|
|
gdb_assert (x86_dr_low.debug_register_length == 0);
|
|
gdb_assert (len == 4 || len == 8);
|
|
x86_dr_low.debug_register_length = len;
|
|
add_show_debug_regs_command ();
|
|
}
|