/* Machine independent support for QNX Neutrino /proc (process file system)
for GDB. Written by Colin Burgess at QNX Software Systems Limited.
- Copyright (C) 2003-2016 Free Software Foundation, Inc.
+ Copyright (C) 2003-2018 Free Software Foundation, Inc.
Contributed by QNX Software Systems Ltd.
#include "solib.h"
#include "inf-child.h"
#include "common/filestuff.h"
+#include "common/scoped_fd.h"
#define NULL_PID 0
#define _DEBUG_FLAG_TRACE (_DEBUG_FLAG_TRACE_EXEC|_DEBUG_FLAG_TRACE_RD|\
{
char *endstr;
char buffer[50];
- int fd, total_size;
+ int total_size;
procfs_sysinfo *sysinfo;
- struct cleanup *cleanups;
char nto_procfs_path[PATH_MAX];
/* Offer to kill previous inferiors before opening this target. */
snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s",
(nodestr != NULL) ? nodestr : "", "/proc");
- fd = open (nto_procfs_path, O_RDONLY);
- if (fd == -1)
+ scoped_fd fd (open (nto_procfs_path, O_RDONLY));
+ if (fd.get () == -1)
{
printf_filtered ("Error opening %s : %d (%s)\n", nto_procfs_path, errno,
safe_strerror (errno));
error (_("Invalid procfs arg"));
}
- cleanups = make_cleanup_close (fd);
sysinfo = (void *) buffer;
- if (devctl (fd, DCMD_PROC_SYSINFO, sysinfo, sizeof buffer, 0) != EOK)
+ if (devctl (fd.get (), DCMD_PROC_SYSINFO, sysinfo, sizeof buffer, 0) != EOK)
{
printf_filtered ("Error getting size: %d (%s)\n", errno,
safe_strerror (errno));
}
else
{
- if (devctl (fd, DCMD_PROC_SYSINFO, sysinfo, total_size, 0) != EOK)
+ if (devctl (fd.get (), DCMD_PROC_SYSINFO, sysinfo, total_size, 0)
+ != EOK)
{
printf_filtered ("Error getting sysinfo: %d (%s)\n", errno,
safe_strerror (errno));
}
}
}
- do_cleanups (cleanups);
inf_child_open_target (ops, arg, from_tty);
printf_filtered ("Debugging using %s\n", nto_procfs_path);
update_thread_private_data_name (struct thread_info *new_thread,
const char *newname)
{
- int newnamelen;
- struct private_thread_info *pti;
+ nto_thread_info *pti = get_nto_thread_info (new_thread);
gdb_assert (newname != NULL);
gdb_assert (new_thread != NULL);
- newnamelen = strlen (newname);
- if (!new_thread->priv)
- {
- new_thread->priv = xmalloc (offsetof (struct private_thread_info,
- name)
- + newnamelen + 1);
- memcpy (new_thread->priv->name, newname, newnamelen + 1);
- }
- else if (strcmp (newname, new_thread->priv->name) != 0)
+
+ if (pti)
{
- /* Reallocate if neccessary. */
- int oldnamelen = strlen (new_thread->priv->name);
-
- if (oldnamelen < newnamelen)
- new_thread->priv = xrealloc (new_thread->priv,
- offsetof (struct private_thread_info,
- name)
- + newnamelen + 1);
- memcpy (new_thread->priv->name, newname, newnamelen + 1);
+ pti = new nto_thread_info;
+ new_thread->priv.reset (pti);
}
+
+ pti->name = newname;
}
static void
update_thread_private_data (struct thread_info *new_thread,
pthread_t tid, int state, int flags)
{
- struct private_thread_info *pti;
procfs_info pidinfo;
struct _thread_name *tn;
procfs_threadctl tctl;
update_thread_private_data_name (new_thread, tn->name_buf);
- pti = (struct private_thread_info *) new_thread->priv;
+ nto_thread_info *pti = get_nto_thread_info (new_thread);
pti->tid = tid;
pti->state = state;
pti->flags = flags;
}
static void
-procfs_pidlist (char *args, int from_tty)
+procfs_pidlist (const char *args, int from_tty)
{
DIR *dp = NULL;
struct dirent *dirp = NULL;
do
{
- int fd;
- struct cleanup *inner_cleanup;
-
/* Get the right pid and procfs path for the pid. */
do
{
while (pid == 0);
/* Open the procfs path. */
- fd = open (buf, O_RDONLY);
- if (fd == -1)
+ scoped_fd fd (open (buf, O_RDONLY));
+ if (fd.get () == -1)
{
fprintf_unfiltered (gdb_stderr, "failed to open %s - %d (%s)\n",
buf, errno, safe_strerror (errno));
continue;
}
- inner_cleanup = make_cleanup_close (fd);
pidinfo = (procfs_info *) buf;
- if (devctl (fd, DCMD_PROC_INFO, pidinfo, sizeof (buf), 0) != EOK)
+ if (devctl (fd.get (), DCMD_PROC_INFO, pidinfo, sizeof (buf), 0) != EOK)
{
fprintf_unfiltered (gdb_stderr,
"devctl DCMD_PROC_INFO failed - %d (%s)\n",
num_threads = pidinfo->num_threads;
info = (procfs_debuginfo *) buf;
- if (devctl (fd, DCMD_PROC_MAPDEBUG_BASE, info, sizeof (buf), 0) != EOK)
+ if (devctl (fd.get (), DCMD_PROC_MAPDEBUG_BASE, info, sizeof (buf), 0)
+ != EOK)
strcpy (name, "unavailable");
else
strcpy (name, info->path);
for (status->tid = 1; status->tid <= num_threads; status->tid++)
{
const int err
- = devctl (fd, DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0);
+ = devctl (fd.get (), DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0);
printf_filtered ("%s - %d", name, pid);
if (err == EOK && status->tid != 0)
printf_filtered ("/%d\n", status->tid);
break;
}
}
-
- do_cleanups (inner_cleanup);
}
while (dirp != NULL);
}
static void
-procfs_meminfo (char *args, int from_tty)
+procfs_meminfo (const char *args, int from_tty)
{
procfs_mapinfo *mapinfos = NULL;
static int num_mapinfos = 0;
/* If this doesn't work, try more severe steps. */
signal (signo, nto_handle_sigint_twice);
- target_interrupt (inferior_ptid);
+ target_interrupt ();
}
static ptid_t
reg;
int regsize;
- procfs_set_thread (inferior_ptid);
+ procfs_set_thread (regcache_get_ptid (regcache));
if (devctl (ctl_fd, DCMD_PROC_GETGREG, ®, sizeof (reg), ®size) == EOK)
nto_supply_gregset (regcache, (char *) ®.greg);
if (devctl (ctl_fd, DCMD_PROC_GETFPREG, ®, sizeof (reg), ®size)
on signals, etc. We'd better not have left any breakpoints
in the program or it'll die when it hits one. */
static void
-procfs_detach (struct target_ops *ops, const char *args, int from_tty)
+procfs_detach (struct target_ops *ops, inferior *inf, int from_tty)
{
- int siggnal = 0;
int pid;
target_announce_detach ();
- if (args)
- siggnal = atoi (args);
-
if (siggnal)
- SignalKill (nto_node (), ptid_get_pid (inferior_ptid), 0, siggnal, 0, 0);
+ SignalKill (nto_node (), ptid_get_pid (inferior_ptid), 0, 0, 0, 0);
close (ctl_fd);
ctl_fd = -1;
}
static void
-procfs_create_inferior (struct target_ops *ops, char *exec_file,
- char *allargs, char **env, int from_tty)
+procfs_create_inferior (struct target_ops *ops, const char *exec_file,
+ const std::string &allargs,
+ char **env, int from_tty)
{
struct inheritance inherit;
pid_t pid;
const char *inferior_io_terminal = get_inferior_io_terminal ();
struct inferior *inf;
- argv = xmalloc (((strlen (allargs) + 1) / (unsigned) 2 + 2) *
+ argv = xmalloc ((allargs.size () / (unsigned) 2 + 2) *
sizeof (*argv));
argv[0] = get_exec_file (1);
if (!argv[0])
return;
}
- args = xstrdup (allargs);
+ args = xstrdup (allargs.c_str ());
breakup_args (args, (exec_file != NULL) ? &argv[1] : &argv[0]);
argv = nto_parse_redirection (argv, &in, &out, &err);
}
if (!target_is_pushed (ops))
push_target (ops);
- target_terminal_init ();
+ target_terminal::init ();
if (exec_bfd != NULL
|| (symfile_objfile != NULL && symfile_objfile->obfd != NULL))
}
static void
-procfs_interrupt (struct target_ops *self, ptid_t ptid)
+procfs_interrupt (struct target_ops *self)
{
devctl (ctl_fd, DCMD_PROC_STOP, NULL, 0, 0);
}
unsigned off;
int len, regset, regsize, dev_set, err;
char *data;
+ ptid_t ptid = regcache_get_ptid (regcache);
- if (ptid_equal (inferior_ptid, null_ptid))
+ if (ptid_equal (ptid, null_ptid))
return;
- procfs_set_thread (inferior_ptid);
+ procfs_set_thread (ptid);
if (regno == -1)
{
if (dev_set == -1)
return;
- len = nto_register_area (get_regcache_arch (regcache),
+ len = nto_register_area (regcache->arch (),
regno, regset, &off);
if (len < 1)
#define OSTYPE_NTO 1
-extern initialize_file_ftype _initialize_procfs;
-
void
_initialize_procfs (void)
{