/* Native-dependent code for GNU/Linux i386.
- Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
- Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+ 2009, 2010 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 2 of the License, or
+ 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,
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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
+#include "i386-nat.h"
#include "inferior.h"
#include "gdbcore.h"
#include "regcache.h"
errno = 0;
val = ptrace (PTRACE_PEEKUSER, tid, 4 * regmap[regno], 0);
if (errno != 0)
- error (_("Couldn't read register %s (#%d): %s."), REGISTER_NAME (regno),
+ error (_("Couldn't read register %s (#%d): %s."),
+ gdbarch_register_name (get_regcache_arch (regcache), regno),
regno, safe_strerror (errno));
regcache_raw_supply (regcache, regno, &val);
regcache_raw_collect (regcache, regno, &val);
ptrace (PTRACE_POKEUSER, tid, 4 * regmap[regno], val);
if (errno != 0)
- error (_("Couldn't write register %s (#%d): %s."), REGISTER_NAME (regno),
+ error (_("Couldn't write register %s (#%d): %s."),
+ gdbarch_register_name (get_regcache_arch (regcache), regno),
regno, safe_strerror (errno));
}
\f
for (i = 0; i < I386_NUM_GREGS; i++)
regcache_raw_supply (regcache, i, regp + regmap[i]);
- if (I386_LINUX_ORIG_EAX_REGNUM < gdbarch_num_regs (current_gdbarch))
+ if (I386_LINUX_ORIG_EAX_REGNUM
+ < gdbarch_num_regs (get_regcache_arch (regcache)))
regcache_raw_supply (regcache, I386_LINUX_ORIG_EAX_REGNUM,
regp + ORIG_EAX);
}
regcache_raw_collect (regcache, i, regp + regmap[i]);
if ((regno == -1 || regno == I386_LINUX_ORIG_EAX_REGNUM)
- && I386_LINUX_ORIG_EAX_REGNUM < gdbarch_num_regs (current_gdbarch))
+ && I386_LINUX_ORIG_EAX_REGNUM
+ < gdbarch_num_regs (get_regcache_arch (regcache)))
regcache_raw_collect (regcache, I386_LINUX_ORIG_EAX_REGNUM,
regp + ORIG_EAX);
}
fetch_regs (struct regcache *regcache, int tid)
{
elf_gregset_t regs;
+ elf_gregset_t *regs_p = ®s;
if (ptrace (PTRACE_GETREGS, tid, 0, (int) ®s) < 0)
{
perror_with_name (_("Couldn't get registers"));
}
- supply_gregset (regcache, (const elf_gregset_t *) ®s);
+ supply_gregset (regcache, (const elf_gregset_t *) regs_p);
}
/* Store all valid general-purpose registers in GDB's register array
registers). */
static void
-i386_linux_fetch_inferior_registers (struct regcache *regcache, int regno)
+i386_linux_fetch_inferior_registers (struct target_ops *ops,
+ struct regcache *regcache, int regno)
{
int tid;
{
int i;
- for (i = 0; i < gdbarch_num_regs (current_gdbarch); i++)
+ for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
if (regno == -1 || regno == i)
fetch_register (regcache, i);
/* The call above might reset `have_ptrace_getregs'. */
if (!have_ptrace_getregs)
{
- i386_linux_fetch_inferior_registers (regcache, regno);
+ i386_linux_fetch_inferior_registers (ops, regcache, regno);
return;
}
do this for all registers (including the floating point and SSE
registers). */
static void
-i386_linux_store_inferior_registers (struct regcache *regcache, int regno)
+i386_linux_store_inferior_registers (struct target_ops *ops,
+ struct regcache *regcache, int regno)
{
int tid;
{
int i;
- for (i = 0; i < gdbarch_num_regs (current_gdbarch); i++)
+ for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
if (regno == -1 || regno == i)
store_register (regcache, i);
/* Support for debug registers. */
+static unsigned long i386_linux_dr[DR_CONTROL + 1];
+
+/* Get debug register REGNUM value from only the one LWP of PTID. */
+
static unsigned long
-i386_linux_dr_get (int regnum)
+i386_linux_dr_get (ptid_t ptid, int regnum)
{
int tid;
unsigned long value;
- /* FIXME: kettenis/2001-01-29: It's not clear what we should do with
- multi-threaded processes here. For now, pretend there is just
- one thread. */
- tid = PIDGET (inferior_ptid);
+ tid = TIDGET (ptid);
+ if (tid == 0)
+ tid = PIDGET (ptid);
/* FIXME: kettenis/2001-03-27: Calling perror_with_name if the
ptrace call fails breaks debugging remote targets. The correct
return value;
}
+/* Set debug register REGNUM to VALUE in only the one LWP of PTID. */
+
static void
-i386_linux_dr_set (int regnum, unsigned long value)
+i386_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
{
int tid;
- /* FIXME: kettenis/2001-01-29: It's not clear what we should do with
- multi-threaded processes here. For now, pretend there is just
- one thread. */
- tid = PIDGET (inferior_ptid);
+ tid = TIDGET (ptid);
+ if (tid == 0)
+ tid = PIDGET (ptid);
errno = 0;
ptrace (PTRACE_POKEUSER, tid,
perror_with_name (_("Couldn't write debug register"));
}
-void
+/* Set DR_CONTROL to ADDR in all LWPs of LWP_LIST. */
+
+static void
i386_linux_dr_set_control (unsigned long control)
{
- i386_linux_dr_set (DR_CONTROL, control);
+ struct lwp_info *lp;
+ ptid_t ptid;
+
+ i386_linux_dr[DR_CONTROL] = control;
+ ALL_LWPS (lp, ptid)
+ i386_linux_dr_set (ptid, DR_CONTROL, control);
}
-void
+/* Set address REGNUM (zero based) to ADDR in all LWPs of LWP_LIST. */
+
+static void
i386_linux_dr_set_addr (int regnum, CORE_ADDR addr)
{
+ struct lwp_info *lp;
+ ptid_t ptid;
+
gdb_assert (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR);
- i386_linux_dr_set (DR_FIRSTADDR + regnum, addr);
+ i386_linux_dr[DR_FIRSTADDR + regnum] = addr;
+ ALL_LWPS (lp, ptid)
+ i386_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr);
}
-void
+/* Set address REGNUM (zero based) to zero in all LWPs of LWP_LIST. */
+
+static void
i386_linux_dr_reset_addr (int regnum)
{
- gdb_assert (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR);
-
- i386_linux_dr_set (DR_FIRSTADDR + regnum, 0L);
+ i386_linux_dr_set_addr (regnum, 0);
}
-unsigned long
+/* Get DR_STATUS from only the one LWP of INFERIOR_PTID. */
+
+static unsigned long
i386_linux_dr_get_status (void)
{
- return i386_linux_dr_get (DR_STATUS);
+ return i386_linux_dr_get (inferior_ptid, DR_STATUS);
+}
+
+/* Unset MASK bits in DR_STATUS in all LWPs of LWP_LIST. */
+
+static void
+i386_linux_dr_unset_status (unsigned long mask)
+{
+ struct lwp_info *lp;
+ ptid_t ptid;
+
+ ALL_LWPS (lp, ptid)
+ {
+ unsigned long value;
+
+ value = i386_linux_dr_get (ptid, DR_STATUS);
+ value &= ~mask;
+ i386_linux_dr_set (ptid, DR_STATUS, value);
+ }
+}
+
+static void
+i386_linux_new_thread (ptid_t ptid)
+{
+ int i;
+
+ for (i = DR_FIRSTADDR; i <= DR_LASTADDR; i++)
+ i386_linux_dr_set (ptid, i, i386_linux_dr[i]);
+
+ i386_linux_dr_set (ptid, DR_CONTROL, i386_linux_dr[DR_CONTROL]);
}
\f
If SIGNAL is nonzero, give it that signal. */
static void
-i386_linux_resume (ptid_t ptid, int step, enum target_signal signal)
+i386_linux_resume (struct target_ops *ops,
+ ptid_t ptid, int step, enum target_signal signal)
{
int pid = PIDGET (ptid);
- int request = PTRACE_CONT;
+ int request;
- if (pid == -1)
- /* Resume all threads. */
- /* I think this only gets used in the non-threaded case, where "resume
- all threads" and "resume inferior_ptid" are the same. */
- pid = PIDGET (inferior_ptid);
+ if (catch_syscall_enabled () > 0)
+ request = PTRACE_SYSCALL;
+ else
+ request = PTRACE_CONT;
if (step)
{
- struct cleanup *old_chain = save_inferior_ptid ();
- struct regcache *regcache = current_regcache;
+ struct regcache *regcache = get_thread_regcache (pid_to_ptid (pid));
+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
ULONGEST pc;
gdb_byte buf[LINUX_SYSCALL_LEN];
request = PTRACE_SINGLESTEP;
- inferior_ptid = pid_to_ptid (pid);
- regcache_cooked_read_unsigned (regcache, PC_REGNUM, &pc);
+ regcache_cooked_read_unsigned (regcache,
+ gdbarch_pc_regnum (gdbarch), &pc);
/* Returning from a signal trampoline is done by calling a
special system call (sigreturn or rt_sigreturn, see
that's about to be restored, and set the trace flag there. */
/* First check if PC is at a system call. */
- if (read_memory_nobpt (pc, buf, LINUX_SYSCALL_LEN) == 0
+ if (target_read_memory (pc, buf, LINUX_SYSCALL_LEN) == 0
&& memcmp (buf, linux_syscall, LINUX_SYSCALL_LEN) == 0)
{
ULONGEST syscall;
regcache_cooked_read_unsigned (regcache, I386_ESP_REGNUM, &sp);
if (syscall == SYS_rt_sigreturn)
- addr = read_memory_integer (sp + 8, 4) + 20;
+ addr = read_memory_integer (sp + 8, 4, byte_order) + 20;
else
addr = sp;
write_memory (addr, (gdb_byte *) &eflags, 4);
}
}
-
- do_cleanups (old_chain);
}
if (ptrace (request, pid, 0, target_signal_to_host (signal)) == -1)
/* Fill in the generic GNU/Linux methods. */
t = linux_target ();
+ i386_use_watchpoints (t);
+
+ i386_dr_low.set_control = i386_linux_dr_set_control;
+ i386_dr_low.set_addr = i386_linux_dr_set_addr;
+ i386_dr_low.reset_addr = i386_linux_dr_reset_addr;
+ i386_dr_low.get_status = i386_linux_dr_get_status;
+ i386_dr_low.unset_status = i386_linux_dr_unset_status;
+ i386_set_debug_register_length (4);
+
/* Override the default ptrace resume method. */
t->to_resume = i386_linux_resume;
/* Register the target. */
linux_nat_add_target (t);
+ linux_nat_set_new_thread (t, i386_linux_new_thread);
}