#include "inf-ptrace.h"
#include "inf-child.h"
#include "gdbthread.h"
+#include "nat/fork-inferior.h"
+#include "utils.h"
\f
static void
inf_ptrace_create_inferior (struct target_ops *ops,
- char *exec_file, char *allargs, char **env,
- int from_tty)
+ const char *exec_file, const std::string &allargs,
+ char **env, int from_tty)
{
- int pid;
+ pid_t pid;
+ ptid_t ptid;
/* Do not change either targets above or the same target if already present.
The reason is the target stack is shared across multiple inferiors. */
pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL,
NULL, NULL, NULL);
+ ptid = pid_to_ptid (pid);
+ /* We have something that executes now. We'll be running through
+ the shell at this point (if startup-with-shell is true), but the
+ pid shouldn't change. */
+ add_thread_silent (ptid);
+
discard_cleanups (back_to);
- startup_inferior (START_INFERIOR_TRAPS_EXPECTED);
+ gdb_startup_inferior (pid, START_INFERIOR_TRAPS_EXPECTED);
/* On some targets, there must be some explicit actions taken after
the inferior has been started up. */
- target_post_startup_inferior (pid_to_ptid (pid));
+ target_post_startup_inferior (ptid);
}
#ifdef PT_GET_PROCESS_STATE
/* We transfer aligned words. Thus align ADDR down to a word
boundary and determine how many bytes to skip at the
beginning. */
- unsigned int skip = addr & (sizeof (PTRACE_TYPE_RET) - 1);
+ ULONGEST skip = addr & (sizeof (PTRACE_TYPE_RET) - 1);
addr -= skip;
for (n = 0;
const gdb_byte *writebuf,
ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
{
- pid_t pid = ptid_get_pid (inferior_ptid);
+ pid_t pid = get_ptrace_pid (inferior_ptid);
switch (object)
{
target_pid_to_str (inferior_ptid));
}
-static char *
+static const char *
inf_ptrace_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
return normal_pid_to_str (ptid);
static void
inf_ptrace_fetch_register (struct regcache *regcache, int regnum)
{
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
CORE_ADDR addr;
size_t size;
PTRACE_TYPE_RET *buf;
- int pid, i;
+ pid_t pid;
+ int i;
/* This isn't really an address, but ptrace thinks of it as one. */
addr = inf_ptrace_register_u_offset (gdbarch, regnum, 0);
return;
}
- /* Cater for systems like GNU/Linux, that implement threads as
- separate processes. */
- pid = ptid_get_lwp (inferior_ptid);
- if (pid == 0)
- pid = ptid_get_pid (inferior_ptid);
+ pid = get_ptrace_pid (regcache_get_ptid (regcache));
size = register_size (gdbarch, regnum);
gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0);
{
if (regnum == -1)
for (regnum = 0;
- regnum < gdbarch_num_regs (get_regcache_arch (regcache));
+ regnum < gdbarch_num_regs (regcache->arch ());
regnum++)
inf_ptrace_fetch_register (regcache, regnum);
else
static void
inf_ptrace_store_register (const struct regcache *regcache, int regnum)
{
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
CORE_ADDR addr;
size_t size;
PTRACE_TYPE_RET *buf;
- int pid, i;
+ pid_t pid;
+ int i;
/* This isn't really an address, but ptrace thinks of it as one. */
addr = inf_ptrace_register_u_offset (gdbarch, regnum, 1);
|| gdbarch_cannot_store_register (gdbarch, regnum))
return;
- /* Cater for systems like GNU/Linux, that implement threads as
- separate processes. */
- pid = ptid_get_lwp (inferior_ptid);
- if (pid == 0)
- pid = ptid_get_pid (inferior_ptid);
+ pid = get_ptrace_pid (regcache_get_ptid (regcache));
size = register_size (gdbarch, regnum);
gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0);
{
if (regnum == -1)
for (regnum = 0;
- regnum < gdbarch_num_regs (get_regcache_arch (regcache));
+ regnum < gdbarch_num_regs (regcache->arch ());
regnum++)
inf_ptrace_store_register (regcache, regnum);
else