#include "gdb_assert.h"
#include "inflow.h"
#include "auxv.h"
+#include "procfs.h"
/*
* PROCFS.C
static void procfs_store_registers (struct target_ops *,
struct regcache *, int);
static void procfs_notice_signals (ptid_t);
-static void procfs_kill_inferior (void);
+static void procfs_kill_inferior (struct target_ops *ops);
static void procfs_mourn_inferior (struct target_ops *ops);
static void procfs_create_inferior (struct target_ops *, char *,
char *, char **, int);
static ptid_t procfs_wait (struct target_ops *,
- ptid_t, struct target_waitstatus *);
+ ptid_t, struct target_waitstatus *, int);
static int procfs_xfer_memory (CORE_ADDR, gdb_byte *, int, int,
struct mem_attrib *attrib,
struct target_ops *);
procfs_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
{
+ enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
gdb_byte *ptr = *readptr;
if (endptr == ptr)
if (endptr - ptr < 8 * 2)
return -1;
- *typep = extract_unsigned_integer (ptr, 4);
+ *typep = extract_unsigned_integer (ptr, 4, byte_order);
ptr += 8;
/* The size of data is always 64-bit. If the application is 32-bit,
it will be zero extended, as expected. */
- *valp = extract_unsigned_integer (ptr, 8);
+ *valp = extract_unsigned_integer (ptr, 8, byte_order);
ptr += 8;
*readptr = ptr;
}
#endif
-static struct target_ops *
+struct target_ops *
procfs_target (void)
{
struct target_ops *t = inf_child_target ();
t->to_has_thread_control = tc_schedlock;
t->to_find_memory_regions = proc_find_memory_regions;
t->to_make_corefile_notes = procfs_make_note_section;
- t->to_can_use_hw_breakpoint = procfs_can_use_hw_breakpoint;
#if defined(PR_MODEL_NATIVE) && (PR_MODEL_NATIVE == PR_MODEL_LP64)
t->to_auxv_parse = procfs_auxv_parse;
/* Use char array to avoid alignment issues. */
char sinfo[sizeof (gdb_siginfo_t)];
} arg;
- gdb_siginfo_t *mysinfo;
+ gdb_siginfo_t mysinfo;
ptid_t wait_ptid;
struct target_waitstatus wait_status;
#endif
/* The pointer is just a type alias. */
- mysinfo = (gdb_siginfo_t *) &arg.sinfo;
get_last_target_status (&wait_ptid, &wait_status);
if (ptid_equal (wait_ptid, inferior_ptid)
&& wait_status.kind == TARGET_WAITKIND_STOPPED
/* Use the siginfo associated with the signal being
redelivered. */
#ifdef NEW_PROC_API
- memcpy (mysinfo, &pi->prstatus.pr_lwp.pr_info, sizeof (gdb_siginfo_t));
+ memcpy (arg.sinfo, &pi->prstatus.pr_lwp.pr_info, sizeof (gdb_siginfo_t));
#else
- memcpy (mysinfo, &pi->prstatus.pr_info, sizeof (gdb_siginfo_t));
+ memcpy (arg.sinfo, &pi->prstatus.pr_info, sizeof (gdb_siginfo_t));
#endif
else
{
- mysinfo->si_signo = signo;
- mysinfo->si_code = 0;
- mysinfo->si_pid = getpid (); /* ?why? */
- mysinfo->si_uid = getuid (); /* ?why? */
+ mysinfo.si_signo = signo;
+ mysinfo.si_code = 0;
+ mysinfo.si_pid = getpid (); /* ?why? */
+ mysinfo.si_uid = getuid (); /* ?why? */
+ memcpy (arg.sinfo, &mysinfo, sizeof (gdb_siginfo_t));
}
#ifdef NEW_PROC_API
/* Use char array to avoid alignment issues. */
char sinfo[sizeof (gdb_siginfo_t)];
} arg;
- gdb_siginfo_t *mysinfo;
+ gdb_siginfo_t mysinfo;
arg.cmd = PCSSIG;
/* The pointer is just a type alias. */
- mysinfo = (gdb_siginfo_t *) &arg.sinfo;
- mysinfo->si_signo = 0;
- mysinfo->si_code = 0;
- mysinfo->si_errno = 0;
- mysinfo->si_pid = getpid (); /* ?why? */
- mysinfo->si_uid = getuid (); /* ?why? */
+ mysinfo.si_signo = 0;
+ mysinfo.si_code = 0;
+ mysinfo.si_errno = 0;
+ mysinfo.si_pid = getpid (); /* ?why? */
+ mysinfo.si_uid = getuid (); /* ?why? */
+ memcpy (arg.sinfo, &mysinfo, sizeof (gdb_siginfo_t));
win = (write (pi->ctl_fd, (void *) &arg, sizeof (arg)) == sizeof (arg));
}
int
proc_set_watchpoint (procinfo *pi, CORE_ADDR addr, int len, int wflags)
{
-#if !defined (TARGET_HAS_HARDWARE_WATCHPOINTS)
+#if !defined (PCWATCH) && !defined (PIOCSWATCH)
+ /* If neither or these is defined, we can't support watchpoints.
+ This just avoids possibly failing to compile the below on such
+ systems. */
return 0;
#else
/* Horrible hack! Detect Solaris 2.5, because this doesn't work on 2.5 */
procfs_ctl_t cmd;
char watch[sizeof (prwatch_t)];
} arg;
- prwatch_t *pwatch;
+ prwatch_t pwatch;
- pwatch = (prwatch_t *) &arg.watch;
/* NOTE: cagney/2003-02-01: Even more horrible hack. Need to
convert a target address into something that can be stored in a
native data structure. */
#ifdef PCAGENT /* Horrible hack: only defined on Solaris 2.6+ */
- pwatch->pr_vaddr = (uintptr_t) procfs_address_to_host_pointer (addr);
+ pwatch.pr_vaddr = (uintptr_t) procfs_address_to_host_pointer (addr);
#else
- pwatch->pr_vaddr = (caddr_t) procfs_address_to_host_pointer (addr);
+ pwatch.pr_vaddr = (caddr_t) procfs_address_to_host_pointer (addr);
#endif
- pwatch->pr_size = len;
- pwatch->pr_wflags = wflags;
+ pwatch.pr_size = len;
+ pwatch.pr_wflags = wflags;
#if defined(NEW_PROC_API) && defined (PCWATCH)
arg.cmd = PCWATCH;
+ memcpy (arg.watch, &pwatch, sizeof (prwatch_t));
return (write (pi->ctl_fd, &arg, sizeof (arg)) == sizeof (arg));
#else
#if defined (PIOCSWATCH)
- return (ioctl (pi->ctl_fd, PIOCSWATCH, pwatch) >= 0);
+ return (ioctl (pi->ctl_fd, PIOCSWATCH, &pwatch) >= 0);
#else
return 0; /* Fail */
#endif
static ptid_t
procfs_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+ ptid_t ptid, struct target_waitstatus *status, int options)
{
/* First cut: loosely based on original version 2.1 */
procinfo *pi;
then remove it. See comments in procfs_init_inferior()
for more details. */
if (dbx_link_bpt_addr != 0
- && dbx_link_bpt_addr == read_pc ())
+ && dbx_link_bpt_addr
+ == regcache_read_pc (get_current_regcache ()))
remove_dbx_link_breakpoint ();
wstat = (SIGTRAP << 8) | 0177;
if (!proc_set_gregs (pi)) /* flush gregs cache */
proc_warn (pi, "target_resume, set_gregs",
__LINE__);
- if (gdbarch_fp0_regnum (current_gdbarch) >= 0)
+ if (gdbarch_fp0_regnum (target_gdbarch) >= 0)
if (pi->fpregs_dirty)
if (parent == NULL ||
proc_get_current_thread (parent) != pi->tid)
static void
procfs_stop (ptid_t ptid)
{
- kill (-inferior_process_group, SIGINT);
+ kill (-inferior_process_group (), SIGINT);
}
/*
*/
static void
-procfs_kill_inferior (void)
+procfs_kill_inferior (struct target_ops *ops)
{
if (!ptid_equal (inferior_ptid, null_ptid)) /* ? */
{
if (dbx_link_bpt != NULL)
{
- deprecated_remove_raw_breakpoint (dbx_link_bpt);
+ deprecated_remove_raw_breakpoint (target_gdbarch, dbx_link_bpt);
dbx_link_bpt_addr = 0;
dbx_link_bpt = NULL;
}
Note: procfs_can_use_hw_breakpoint() is not yet used by all
procfs.c targets due to the fact that some of them still define
- TARGET_CAN_USE_HARDWARE_WATCHPOINT. */
+ target_can_use_hardware_watchpoint. */
static int
procfs_can_use_hw_breakpoint (int type, int cnt, int othertype)
{
-#ifndef TARGET_HAS_HARDWARE_WATCHPOINTS
- return 0;
-#else
/* Due to the way that proc_set_watchpoint() is implemented, host
and target pointers must be of the same size. If they are not,
we can't use hardware watchpoints. This limitation is due to the
/* Other tests here??? */
return 1;
-#endif
}
/*
* else returns zero.
*/
-int
-procfs_stopped_by_watchpoint (ptid_t ptid)
+static int
+procfs_stopped_by_watchpoint (void)
{
procinfo *pi;
- pi = find_procinfo_or_die (PIDGET (ptid) == -1 ?
- PIDGET (inferior_ptid) : PIDGET (ptid), 0);
+ pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
if (!pi) /* If no process, then not stopped by watchpoint! */
return 0;
return 0;
}
+static int
+procfs_insert_watchpoint (CORE_ADDR addr, int len, int type)
+{
+ if (!target_have_steppable_watchpoint
+ && !gdbarch_have_nonsteppable_watchpoint (target_gdbarch))
+ {
+ /* When a hardware watchpoint fires off the PC will be left at
+ the instruction following the one which caused the
+ watchpoint. It will *NOT* be necessary for GDB to step over
+ the watchpoint. */
+ return procfs_set_watchpoint (inferior_ptid, addr, len, type, 1);
+ }
+ else
+ {
+ /* When a hardware watchpoint fires off the PC will be left at
+ the instruction which caused the watchpoint. It will be
+ necessary for GDB to step over the watchpoint. */
+ return procfs_set_watchpoint (inferior_ptid, addr, len, type, 0);
+ }
+}
+
+static int
+procfs_remove_watchpoint (CORE_ADDR addr, int len, int type)
+{
+ return procfs_set_watchpoint (inferior_ptid, addr, 0, 0, 0);
+}
+
+static int
+procfs_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
+{
+ /* The man page for proc(4) on Solaris 2.6 and up says that the
+ system can support "thousands" of hardware watchpoints, but gives
+ no method for finding out how many; It doesn't say anything about
+ the allowed size for the watched area either. So we just tell
+ GDB 'yes'. */
+ return 1;
+}
+
+void
+procfs_use_watchpoints (struct target_ops *t)
+{
+ t->to_stopped_by_watchpoint = procfs_stopped_by_watchpoint;
+ t->to_insert_watchpoint = procfs_insert_watchpoint;
+ t->to_remove_watchpoint = procfs_remove_watchpoint;
+ t->to_region_ok_for_hw_watchpoint = procfs_region_ok_for_hw_watchpoint;
+ t->to_can_use_hw_breakpoint = procfs_can_use_hw_breakpoint;
+}
+
/*
* Memory Mappings Functions:
*/
return (*func) (fd, (CORE_ADDR) map->pr_vaddr);
}
-/*
- * Function: proc_iterate_over_mappings
- *
- * Uses the unified "iterate_over_mappings" function
- * to implement the exported interface to solib-svr4.c.
- *
- * Given a pointer to a function, call that function once for every
- * mapped address space in the process. The callback function
- * receives an open file descriptor for the file corresponding to
- * that mapped address space (if there is one), and the base address
- * of the mapped space. Quit when the callback function returns a
- * nonzero value, or at teh end of the mappings.
- *
- * Returns: the first non-zero return value of the callback function,
- * or zero.
- */
-
-int
-proc_iterate_over_mappings (int (*func) (int, CORE_ADDR))
-{
- procinfo *pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
-
- return iterate_over_mappings (pi, func, pi, solib_mappings_callback);
-}
-
/*
* Function: find_memory_regions_callback
*
if (dbx_link_bpt_addr == 0)
return;
- if (deprecated_remove_raw_breakpoint (dbx_link_bpt) != 0)
+ if (deprecated_remove_raw_breakpoint (target_gdbarch, dbx_link_bpt) != 0)
warning (_("Unable to remove __dbx_link breakpoint."));
dbx_link_bpt_addr = 0;
{
/* Insert the breakpoint. */
dbx_link_bpt_addr = sym_addr;
- dbx_link_bpt = deprecated_insert_raw_breakpoint (sym_addr);
+ dbx_link_bpt = deprecated_insert_raw_breakpoint (target_gdbarch,
+ sym_addr);
if (dbx_link_bpt == NULL)
{
warning (_("Failed to insert dbx_link breakpoint."));
pr_off = map->pr_off;
#endif
- if (gdbarch_addr_bit (current_gdbarch) == 32)
+ if (gdbarch_addr_bit (target_gdbarch) == 32)
printf_filtered ("\t%#10lx %#10lx %#10lx %#10x %7s\n",
(unsigned long) map->pr_vaddr,
(unsigned long) map->pr_vaddr + map->pr_size - 1,
return; /* No output for summary mode. */
printf_filtered (_("Mapped address spaces:\n\n"));
- if (gdbarch_ptr_bit (current_gdbarch) == 32)
+ if (gdbarch_ptr_bit (target_gdbarch) == 32)
printf_filtered ("\t%10s %10s %10s %10s %7s\n",
"Start Addr",
" End Addr",
void
_initialize_procfs (void)
{
- struct target_ops * t;
-
- t = procfs_target ();
-
- add_target (t);
-
add_info ("proc", info_proc_cmd, _("\
Show /proc process information about any running process.\n\
Specify process id, or use the program being debugged by default.\n\