/* PPC GNU/Linux native support.
- Copyright (C) 1988-2013 Free Software Foundation, Inc.
+ Copyright (C) 1988-2015 Free Software Foundation, Inc.
This file is part of GDB.
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
-#include "gdb_string.h"
#include "observer.h"
#include "frame.h"
#include "inferior.h"
#include "gdbthread.h"
#include "gdbcore.h"
#include "regcache.h"
-#include "gdb_assert.h"
#include "target.h"
#include "linux-nat.h"
-
-#include <stdint.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/user.h>
#include "gdb_wait.h"
#include <fcntl.h>
#include <sys/procfs.h>
-#include <sys/ptrace.h>
+#include "nat/gdb_ptrace.h"
/* Prototypes for supply_gregset etc. */
#include "gregset.h"
#include "elf/common.h"
#include "auxv.h"
-/* This sometimes isn't defined. */
-#ifndef PT_ORIG_R3
-#define PT_ORIG_R3 34
-#endif
-#ifndef PT_TRAP
-#define PT_TRAP 40
-#endif
-
-/* The PPC_FEATURE_* defines should be provided by <asm/cputable.h>.
- If they aren't, we can provide them ourselves (their values are fixed
- because they are part of the kernel ABI). They are used in the AT_HWCAP
- entry of the AUXV. */
-#ifndef PPC_FEATURE_CELL
-#define PPC_FEATURE_CELL 0x00010000
-#endif
-#ifndef PPC_FEATURE_BOOKE
-#define PPC_FEATURE_BOOKE 0x00008000
-#endif
-#ifndef PPC_FEATURE_HAS_DFP
-#define PPC_FEATURE_HAS_DFP 0x00000400 /* Decimal Floating Point. */
-#endif
-
-/* Glibc's headers don't define PTRACE_GETVRREGS so we cannot use a
- configure time check. Some older glibc's (for instance 2.2.1)
- don't have a specific powerpc version of ptrace.h, and fall back on
- a generic one. In such cases, sys/ptrace.h defines
- PTRACE_GETFPXREGS and PTRACE_SETFPXREGS to the same numbers that
- ppc kernel's asm/ptrace.h defines PTRACE_GETVRREGS and
- PTRACE_SETVRREGS to be. This also makes a configury check pretty
- much useless. */
-
-/* These definitions should really come from the glibc header files,
- but Glibc doesn't know about the vrregs yet. */
-#ifndef PTRACE_GETVRREGS
-#define PTRACE_GETVRREGS 18
-#define PTRACE_SETVRREGS 19
-#endif
-
-/* PTRACE requests for POWER7 VSX registers. */
-#ifndef PTRACE_GETVSXREGS
-#define PTRACE_GETVSXREGS 27
-#define PTRACE_SETVSXREGS 28
-#endif
-
-/* Similarly for the ptrace requests for getting / setting the SPE
- registers (ev0 -- ev31, acc, and spefscr). See the description of
- gdb_evrregset_t for details. */
-#ifndef PTRACE_GETEVRREGS
-#define PTRACE_GETEVRREGS 20
-#define PTRACE_SETEVRREGS 21
-#endif
+#include "nat/ppc-linux.h"
/* Similarly for the hardware watchpoint support. These requests are used
when the PowerPC HWDEBUG ptrace interface is not available. */
struct regcache *regcache, int regno)
{
/* Overload thread id onto process id. */
- int tid = TIDGET (inferior_ptid);
+ int tid = ptid_get_lwp (inferior_ptid);
/* No thread id, just use process id. */
if (tid == 0)
- tid = PIDGET (inferior_ptid);
+ tid = ptid_get_pid (inferior_ptid);
if (regno == -1)
fetch_ppc_registers (regcache, tid);
{
int tid;
- tid = TIDGET (inferior_ptid);
+ tid = ptid_get_lwp (inferior_ptid);
if (tid == 0)
- tid = PIDGET (inferior_ptid);
+ tid = ptid_get_pid (inferior_ptid);
/* Check for kernel support for PowerPC HWDEBUG ptrace interface. */
if (ptrace (PPC_PTRACE_GETHWDBGINFO, tid, 0, &hwdebug_info) >= 0)
}
static int
-ppc_linux_can_use_hw_breakpoint (int type, int cnt, int ot)
+ppc_linux_can_use_hw_breakpoint (struct target_ops *self,
+ int type, int cnt, int ot)
{
int total_hw_wp, total_hw_bp;
}
else if (type == bp_hardware_breakpoint)
{
+ if (total_hw_bp == 0)
+ {
+ /* No hardware breakpoint support. */
+ return 0;
+ }
if (cnt > total_hw_bp)
return -1;
}
/* We need to know whether ptrace supports PTRACE_SET_DEBUGREG
and whether the target has DABR. If either answer is no, the
ptrace call will return -1. Fail in that case. */
- tid = TIDGET (ptid);
+ tid = ptid_get_lwp (ptid);
if (tid == 0)
- tid = PIDGET (ptid);
+ tid = ptid_get_pid (ptid);
if (ptrace (PTRACE_SET_DEBUGREG, tid, 0, 0) == -1)
return 0;
}
static int
-ppc_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
+ppc_linux_region_ok_for_hw_watchpoint (struct target_ops *self,
+ CORE_ADDR addr, int len)
{
/* Handle sub-8-byte quantities. */
if (len <= 0)
success, 1 if hardware breakpoints are not supported or -1 for failure. */
static int
-ppc_linux_insert_hw_breakpoint (struct gdbarch *gdbarch,
+ppc_linux_insert_hw_breakpoint (struct target_ops *self,
+ struct gdbarch *gdbarch,
struct bp_target_info *bp_tgt)
{
struct lwp_info *lp;
p.version = PPC_DEBUG_CURRENT_VERSION;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
- p.addr = (uint64_t) bp_tgt->placed_address;
+ p.addr = (uint64_t) (bp_tgt->placed_address = bp_tgt->reqstd_address);
p.condition_value = 0;
if (bp_tgt->length)
}
ALL_LWPS (lp)
- hwdebug_insert_point (&p, TIDGET (lp->ptid));
+ hwdebug_insert_point (&p, ptid_get_lwp (lp->ptid));
return 0;
}
static int
-ppc_linux_remove_hw_breakpoint (struct gdbarch *gdbarch,
+ppc_linux_remove_hw_breakpoint (struct target_ops *self,
+ struct gdbarch *gdbarch,
struct bp_target_info *bp_tgt)
{
struct lwp_info *lp;
}
ALL_LWPS (lp)
- hwdebug_remove_point (&p, TIDGET (lp->ptid));
+ hwdebug_remove_point (&p, ptid_get_lwp (lp->ptid));
return 0;
}
p.condition_value = 0;
ALL_LWPS (lp)
- hwdebug_insert_point (&p, TIDGET (lp->ptid));
+ hwdebug_insert_point (&p, ptid_get_lwp (lp->ptid));
return 0;
}
p.condition_value = 0;
ALL_LWPS (lp)
- hwdebug_remove_point (&p, TIDGET (lp->ptid));
+ hwdebug_remove_point (&p, ptid_get_lwp (lp->ptid));
return 0;
}
can_use_watchpoint_cond_accel (void)
{
struct thread_points *p;
- int tid = TIDGET (inferior_ptid);
+ int tid = ptid_get_lwp (inferior_ptid);
int cnt = hwdebug_info.num_condition_regs, i;
CORE_ADDR tmp_value;
if (cond->elts[0].opcode != BINOP_EQUAL)
return 0;
- fetch_subexp_value (cond, &pc, &left_val, NULL, &left_chain);
+ fetch_subexp_value (cond, &pc, &left_val, NULL, &left_chain, 0);
num_accesses_left = num_memory_accesses (left_chain);
if (left_val == NULL || num_accesses_left < 0)
return 0;
}
- fetch_subexp_value (cond, &pc, &right_val, NULL, &right_chain);
+ fetch_subexp_value (cond, &pc, &right_val, NULL, &right_chain, 0);
num_accesses_right = num_memory_accesses (right_chain);
if (right_val == NULL || num_accesses_right < 0)
the condition expression, thus only triggering the watchpoint when it is
true. */
static int
-ppc_linux_can_accel_watchpoint_condition (CORE_ADDR addr, int len, int rw,
+ppc_linux_can_accel_watchpoint_condition (struct target_ops *self,
+ CORE_ADDR addr, int len, int rw,
struct expression *cond)
{
CORE_ADDR data_value;
}
static int
-ppc_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw,
+ppc_linux_insert_watchpoint (struct target_ops *self,
+ CORE_ADDR addr, int len, int rw,
struct expression *cond)
{
struct lwp_info *lp;
create_watchpoint_request (&p, addr, len, rw, cond, 1);
ALL_LWPS (lp)
- hwdebug_insert_point (&p, TIDGET (lp->ptid));
+ hwdebug_insert_point (&p, ptid_get_lwp (lp->ptid));
ret = 0;
}
saved_dabr_value = dabr_value;
ALL_LWPS (lp)
- if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (lp->ptid), 0,
+ if (ptrace (PTRACE_SET_DEBUGREG, ptid_get_lwp (lp->ptid), 0,
saved_dabr_value) < 0)
return -1;
}
static int
-ppc_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw,
+ppc_linux_remove_watchpoint (struct target_ops *self,
+ CORE_ADDR addr, int len, int rw,
struct expression *cond)
{
struct lwp_info *lp;
create_watchpoint_request (&p, addr, len, rw, cond, 0);
ALL_LWPS (lp)
- hwdebug_remove_point (&p, TIDGET (lp->ptid));
+ hwdebug_remove_point (&p, ptid_get_lwp (lp->ptid));
ret = 0;
}
{
saved_dabr_value = 0;
ALL_LWPS (lp)
- if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (lp->ptid), 0,
+ if (ptrace (PTRACE_SET_DEBUGREG, ptid_get_lwp (lp->ptid), 0,
saved_dabr_value) < 0)
return -1;
static void
ppc_linux_new_thread (struct lwp_info *lp)
{
- int tid = TIDGET (lp->ptid);
+ int tid = ptid_get_lwp (lp->ptid);
if (have_ptrace_hwdebug_interface ())
{
ppc_linux_thread_exit (struct thread_info *tp, int silent)
{
int i;
- int tid = TIDGET (tp->ptid);
+ int tid = ptid_get_lwp (tp->ptid);
struct hw_break_tuple *hw_breaks;
struct thread_points *t = NULL, *p;
/* The index (or slot) of the *point is passed in the si_errno field. */
int slot = siginfo.si_errno;
- t = hwdebug_find_thread_points_by_tid (TIDGET (inferior_ptid), 0);
+ t = hwdebug_find_thread_points_by_tid (ptid_get_lwp (inferior_ptid), 0);
/* Find out if this *point is a hardware breakpoint.
If so, we should return 0. */
}
static int
-ppc_linux_stopped_by_watchpoint (void)
+ppc_linux_stopped_by_watchpoint (struct target_ops *ops)
{
CORE_ADDR addr;
- return ppc_linux_stopped_data_address (¤t_target, &addr);
+ return ppc_linux_stopped_data_address (ops, &addr);
}
static int
struct regcache *regcache, int regno)
{
/* Overload thread id onto process id. */
- int tid = TIDGET (inferior_ptid);
+ int tid = ptid_get_lwp (inferior_ptid);
/* No thread id, just use process id. */
if (tid == 0)
- tid = PIDGET (inferior_ptid);
+ tid = ptid_get_pid (inferior_ptid);
if (regno >= 0)
store_register (regcache, tid, regno);
#ifdef __powerpc64__
long msr;
- int tid = TIDGET (inferior_ptid);
+ int tid = ptid_get_lwp (inferior_ptid);
if (tid == 0)
- tid = PIDGET (inferior_ptid);
+ tid = ptid_get_pid (inferior_ptid);
errno = 0;
msr = (long) ptrace (PTRACE_PEEKUSER, tid, PT_MSR * 8, 0);
- if (errno == 0 && msr < 0)
+ if (errno == 0 && ppc64_64bit_inferior_p (msr))
wordsize = 8;
#endif
int isa205 = 0;
int cell = 0;
- int tid = TIDGET (inferior_ptid);
+ int tid = ptid_get_lwp (inferior_ptid);
if (tid == 0)
- tid = PIDGET (inferior_ptid);
+ tid = ptid_get_pid (inferior_ptid);
if (have_ptrace_getsetevrregs)
{