+2015-06-10 Gary Benson <gbenson@redhat.com>
+
+ * target.h (struct inferior): New forward declaration.
+ (struct target_ops) <to_filesystem_is_local>: Update comment.
+ (struct target_ops) <to_fileio_open>: New argument inf.
+ Update comment. All implementations updated.
+ (struct target_ops) <to_fileio_unlink>: Likewise.
+ (struct target_ops) <to_fileio_readlink>: Likewise.
+ (target_filesystem_is_local): Update comment.
+ (target_fileio_open): New argument inf. Update comment.
+ (target_fileio_unlink): Likewise.
+ (target_fileio_readlink): Likewise.
+ (target_fileio_read_alloc): Likewise.
+ (target_fileio_read_stralloc): Likewise.
+ * target.c (target_fileio_open): New argument inf.
+ Pass inf to implementation. Update debug printing.
+ (target_fileio_unlink): Likewise.
+ (target_fileio_readlink): Likewise.
+ (target_fileio_read_alloc_1): New argument inf. Pass inf
+ to target_fileio_open.
+ (target_fileio_read_alloc): New argument inf. Pass inf to
+ target_fileio_read_alloc_1.
+ (target_fileio_read_stralloc): Likewise.
+ * gdb_bfd.c (inferior.h): New include.
+ (gdb_bfd_iovec_fileio_open): Replace unused "open_closure"
+ argument with new argument "inferior". Pass inferior to
+ target_fileio_open.
+ (gdb_bfd_open): Supply inferior argument to
+ gdb_bfd_iovec_fileio_open.
+ * linux-tdep.c (linux_info_proc): Supply inf argument to
+ relevant target_fileio calls.
+ (linux_find_memory_regions_full): Likewise.
+ (linux_fill_prpsinfo): Likewise.
+ * remote.c (remote_filesystem_is_local): Supply inf
+ argument to remote_hostio_open.
+ (remote_file_put): Likewise.
+ (remote_file_get): Likewise.
+ (remote_file_delete): Supply inf argument to
+ remote_hostio_unlink.
+
2015-06-10 Gary Benson <gbenson@redhat.com>
* inf-child.c (inf_child_fileio_open): Replace comment.
#endif
#include "target.h"
#include "gdb/fileio.h"
+#include "inferior.h"
typedef bfd *bfdp;
DEF_VEC_P (bfdp);
OPEN_CLOSURE is unused. */
static void *
-gdb_bfd_iovec_fileio_open (struct bfd *abfd, void *open_closure)
+gdb_bfd_iovec_fileio_open (struct bfd *abfd, void *inferior)
{
const char *filename = bfd_get_filename (abfd);
int fd, target_errno;
gdb_assert (is_target_filename (filename));
- fd = target_fileio_open (filename + strlen (TARGET_SYSROOT_PREFIX),
+ fd = target_fileio_open ((struct inferior *) inferior,
+ filename + strlen (TARGET_SYSROOT_PREFIX),
FILEIO_O_RDONLY, 0,
&target_errno);
if (fd == -1)
gdb_assert (fd == -1);
return gdb_bfd_openr_iovec (name, target,
- gdb_bfd_iovec_fileio_open, NULL,
+ gdb_bfd_iovec_fileio_open,
+ current_inferior (),
gdb_bfd_iovec_fileio_pread,
gdb_bfd_iovec_fileio_close,
gdb_bfd_iovec_fileio_fstat);
static int
inf_child_fileio_open (struct target_ops *self,
- const char *filename, int flags, int mode,
- int *target_errno)
+ struct inferior *inf, const char *filename,
+ int flags, int mode, int *target_errno)
{
int nat_flags;
mode_t nat_mode;
static int
inf_child_fileio_unlink (struct target_ops *self,
- const char *filename, int *target_errno)
+ struct inferior *inf, const char *filename,
+ int *target_errno)
{
int ret;
static char *
inf_child_fileio_readlink (struct target_ops *self,
- const char *filename, int *target_errno)
+ struct inferior *inf, const char *filename,
+ int *target_errno)
{
/* We support readlink only on systems that also provide a compile-time
maximum path length (PATH_MAX), at least for now. */
if (cmdline_f)
{
xsnprintf (filename, sizeof filename, "/proc/%ld/cmdline", pid);
- data = target_fileio_read_stralloc (filename);
+ data = target_fileio_read_stralloc (NULL, filename);
if (data)
{
struct cleanup *cleanup = make_cleanup (xfree, data);
if (cwd_f)
{
xsnprintf (filename, sizeof filename, "/proc/%ld/cwd", pid);
- data = target_fileio_readlink (filename, &target_errno);
+ data = target_fileio_readlink (NULL, filename, &target_errno);
if (data)
{
struct cleanup *cleanup = make_cleanup (xfree, data);
if (exe_f)
{
xsnprintf (filename, sizeof filename, "/proc/%ld/exe", pid);
- data = target_fileio_readlink (filename, &target_errno);
+ data = target_fileio_readlink (NULL, filename, &target_errno);
if (data)
{
struct cleanup *cleanup = make_cleanup (xfree, data);
if (mappings_f)
{
xsnprintf (filename, sizeof filename, "/proc/%ld/maps", pid);
- data = target_fileio_read_stralloc (filename);
+ data = target_fileio_read_stralloc (NULL, filename);
if (data)
{
struct cleanup *cleanup = make_cleanup (xfree, data);
if (status_f)
{
xsnprintf (filename, sizeof filename, "/proc/%ld/status", pid);
- data = target_fileio_read_stralloc (filename);
+ data = target_fileio_read_stralloc (NULL, filename);
if (data)
{
struct cleanup *cleanup = make_cleanup (xfree, data);
if (stat_f)
{
xsnprintf (filename, sizeof filename, "/proc/%ld/stat", pid);
- data = target_fileio_read_stralloc (filename);
+ data = target_fileio_read_stralloc (NULL, filename);
if (data)
{
struct cleanup *cleanup = make_cleanup (xfree, data);
{
xsnprintf (coredumpfilter_name, sizeof (coredumpfilter_name),
"/proc/%d/coredump_filter", pid);
- coredumpfilterdata = target_fileio_read_stralloc (coredumpfilter_name);
+ coredumpfilterdata = target_fileio_read_stralloc (NULL,
+ coredumpfilter_name);
if (coredumpfilterdata != NULL)
{
sscanf (coredumpfilterdata, "%x", &filterflags);
}
xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/smaps", pid);
- data = target_fileio_read_stralloc (mapsfilename);
+ data = target_fileio_read_stralloc (NULL, mapsfilename);
if (data == NULL)
{
/* Older Linux kernels did not support /proc/PID/smaps. */
xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/maps", pid);
- data = target_fileio_read_stralloc (mapsfilename);
+ data = target_fileio_read_stralloc (NULL, mapsfilename);
}
if (data != NULL)
/* Obtaining PID and filename. */
pid = ptid_get_pid (inferior_ptid);
xsnprintf (filename, sizeof (filename), "/proc/%d/cmdline", (int) pid);
- fname = target_fileio_read_stralloc (filename);
+ fname = target_fileio_read_stralloc (NULL, filename);
if (fname == NULL || *fname == '\0')
{
p->pr_psargs[sizeof (p->pr_psargs) - 1] = '\0';
xsnprintf (filename, sizeof (filename), "/proc/%d/stat", (int) pid);
- proc_stat = target_fileio_read_stralloc (filename);
+ proc_stat = target_fileio_read_stralloc (NULL, filename);
make_cleanup (xfree, proc_stat);
if (proc_stat == NULL || *proc_stat == '\0')
/* Finally, obtaining the UID and GID. For that, we read and parse the
contents of the `/proc/PID/status' file. */
xsnprintf (filename, sizeof (filename), "/proc/%d/status", (int) pid);
- proc_status = target_fileio_read_stralloc (filename);
+ proc_status = target_fileio_read_stralloc (NULL, filename);
make_cleanup (xfree, proc_status);
if (proc_status == NULL || *proc_status == '\0')
static int
remote_hostio_open (struct target_ops *self,
- const char *filename, int flags, int mode,
- int *remote_errno)
+ struct inferior *inf, const char *filename,
+ int flags, int mode, int *remote_errno)
{
struct remote_state *rs = get_remote_state ();
char *p = rs->buf;
static int
remote_hostio_unlink (struct target_ops *self,
- const char *filename, int *remote_errno)
+ struct inferior *inf, const char *filename,
+ int *remote_errno)
{
struct remote_state *rs = get_remote_state ();
char *p = rs->buf;
static char *
remote_hostio_readlink (struct target_ops *self,
- const char *filename, int *remote_errno)
+ struct inferior *inf, const char *filename,
+ int *remote_errno)
{
struct remote_state *rs = get_remote_state ();
char *p = rs->buf;
/* Try opening a file to probe support. The supplied
filename is irrelevant, we only care about whether
the stub recognizes the packet or not. */
- fd = remote_hostio_open (self, "just probing",
+ fd = remote_hostio_open (self, NULL, "just probing",
FILEIO_O_RDONLY, 0700,
&remote_errno);
perror_with_name (local_file);
back_to = make_cleanup_fclose (file);
- fd = remote_hostio_open (find_target_at (process_stratum),
+ fd = remote_hostio_open (find_target_at (process_stratum), NULL,
remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT
| FILEIO_O_TRUNC),
0700, &remote_errno);
if (!rs->remote_desc)
error (_("command can only be used with remote target"));
- fd = remote_hostio_open (find_target_at (process_stratum),
+ fd = remote_hostio_open (find_target_at (process_stratum), NULL,
remote_file, FILEIO_O_RDONLY, 0, &remote_errno);
if (fd == -1)
remote_hostio_error (remote_errno);
error (_("command can only be used with remote target"));
retcode = remote_hostio_unlink (find_target_at (process_stratum),
- remote_file, &remote_errno);
+ NULL, remote_file, &remote_errno);
if (retcode == -1)
remote_hostio_error (remote_errno);
/* See target.h. */
int
-target_fileio_open (const char *filename, int flags, int mode,
- int *target_errno)
+target_fileio_open (struct inferior *inf, const char *filename,
+ int flags, int mode, int *target_errno)
{
struct target_ops *t;
{
if (t->to_fileio_open != NULL)
{
- int fd = t->to_fileio_open (t, filename, flags, mode, target_errno);
+ int fd = t->to_fileio_open (t, inf, filename, flags, mode,
+ target_errno);
if (fd < 0)
fd = -1;
if (targetdebug)
fprintf_unfiltered (gdb_stdlog,
- "target_fileio_open (%s,0x%x,0%o) = %d (%d)\n",
+ "target_fileio_open (%d,%s,0x%x,0%o)"
+ " = %d (%d)\n",
+ inf == NULL ? 0 : inf->num,
filename, flags, mode,
fd, fd != -1 ? 0 : *target_errno);
return fd;
/* See target.h. */
int
-target_fileio_unlink (const char *filename, int *target_errno)
+target_fileio_unlink (struct inferior *inf, const char *filename,
+ int *target_errno)
{
struct target_ops *t;
{
if (t->to_fileio_unlink != NULL)
{
- int ret = t->to_fileio_unlink (t, filename, target_errno);
+ int ret = t->to_fileio_unlink (t, inf, filename,
+ target_errno);
if (targetdebug)
fprintf_unfiltered (gdb_stdlog,
- "target_fileio_unlink (%s) = %d (%d)\n",
- filename, ret, ret != -1 ? 0 : *target_errno);
+ "target_fileio_unlink (%d,%s)"
+ " = %d (%d)\n",
+ inf == NULL ? 0 : inf->num, filename,
+ ret, ret != -1 ? 0 : *target_errno);
return ret;
}
}
/* See target.h. */
char *
-target_fileio_readlink (const char *filename, int *target_errno)
+target_fileio_readlink (struct inferior *inf, const char *filename,
+ int *target_errno)
{
struct target_ops *t;
{
if (t->to_fileio_readlink != NULL)
{
- char *ret = t->to_fileio_readlink (t, filename, target_errno);
+ char *ret = t->to_fileio_readlink (t, inf, filename,
+ target_errno);
if (targetdebug)
fprintf_unfiltered (gdb_stdlog,
- "target_fileio_readlink (%s) = %s (%d)\n",
+ "target_fileio_readlink (%d,%s)"
+ " = %s (%d)\n",
+ inf == NULL ? 0 : inf->num,
filename, ret? ret : "(nil)",
ret? 0 : *target_errno);
return ret;
target_fileio_close (fd, &target_errno);
}
-/* Read target file FILENAME. Store the result in *BUF_P and
- return the size of the transferred data. PADDING additional bytes are
- available in *BUF_P. This is a helper function for
- target_fileio_read_alloc; see the declaration of that function for more
- information. */
+/* Read target file FILENAME, in the filesystem as seen by INF. If
+ INF is NULL, use the filesystem seen by the debugger (GDB or, for
+ remote targets, the remote stub). Store the result in *BUF_P and
+ return the size of the transferred data. PADDING additional bytes
+ are available in *BUF_P. This is a helper function for
+ target_fileio_read_alloc; see the declaration of that function for
+ more information. */
static LONGEST
-target_fileio_read_alloc_1 (const char *filename,
+target_fileio_read_alloc_1 (struct inferior *inf, const char *filename,
gdb_byte **buf_p, int padding)
{
struct cleanup *close_cleanup;
int fd;
int target_errno;
- fd = target_fileio_open (filename, FILEIO_O_RDONLY, 0700, &target_errno);
+ fd = target_fileio_open (inf, filename, FILEIO_O_RDONLY, 0700,
+ &target_errno);
if (fd == -1)
return -1;
/* See target.h. */
LONGEST
-target_fileio_read_alloc (const char *filename, gdb_byte **buf_p)
+target_fileio_read_alloc (struct inferior *inf, const char *filename,
+ gdb_byte **buf_p)
{
- return target_fileio_read_alloc_1 (filename, buf_p, 0);
+ return target_fileio_read_alloc_1 (inf, filename, buf_p, 0);
}
/* See target.h. */
char *
-target_fileio_read_stralloc (const char *filename)
+target_fileio_read_stralloc (struct inferior *inf, const char *filename)
{
gdb_byte *buffer;
char *bufstr;
LONGEST i, transferred;
- transferred = target_fileio_read_alloc_1 (filename, &buffer, 1);
+ transferred = target_fileio_read_alloc_1 (inf, filename, &buffer, 1);
bufstr = (char *) buffer;
if (transferred < 0)
struct traceframe_info;
struct expression;
struct dcache_struct;
+struct inferior;
#include "infrun.h" /* For enum exec_direction_kind. */
/* Target file operations. */
- /* Return nonzero if the filesystem accessed by the
- target_fileio_* methods is the local filesystem,
- zero otherwise. */
+ /* Return nonzero if the filesystem seen by the current inferior
+ is the local filesystem, zero otherwise. */
int (*to_filesystem_is_local) (struct target_ops *)
TARGET_DEFAULT_RETURN (1);
- /* Open FILENAME on the target, using FLAGS and MODE. Return a
- target file descriptor, or -1 if an error occurs (and set
- *TARGET_ERRNO). */
+ /* Open FILENAME on the target, in the filesystem as seen by INF,
+ using FLAGS and MODE. If INF is NULL, use the filesystem seen
+ by the debugger (GDB or, for remote targets, the remote stub).
+ Return a target file descriptor, or -1 if an error occurs (and
+ set *TARGET_ERRNO). */
int (*to_fileio_open) (struct target_ops *,
- const char *filename, int flags, int mode,
- int *target_errno);
+ struct inferior *inf, const char *filename,
+ int flags, int mode, int *target_errno);
/* Write up to LEN bytes from WRITE_BUF to FD on the target.
Return the number of bytes written, or -1 if an error occurs
(and set *TARGET_ERRNO). */
int (*to_fileio_close) (struct target_ops *, int fd, int *target_errno);
- /* Unlink FILENAME on the target. Return 0, or -1 if an error
- occurs (and set *TARGET_ERRNO). */
+ /* Unlink FILENAME on the target, in the filesystem as seen by
+ INF. If INF is NULL, use the filesystem seen by the debugger
+ (GDB or, for remote targets, the remote stub). Return 0, or
+ -1 if an error occurs (and set *TARGET_ERRNO). */
int (*to_fileio_unlink) (struct target_ops *,
- const char *filename, int *target_errno);
-
- /* Read value of symbolic link FILENAME on the target. Return a
- null-terminated string allocated via xmalloc, or NULL if an error
- occurs (and set *TARGET_ERRNO). */
+ struct inferior *inf,
+ const char *filename,
+ int *target_errno);
+
+ /* Read value of symbolic link FILENAME on the target, in the
+ filesystem as seen by INF. If INF is NULL, use the filesystem
+ seen by the debugger (GDB or, for remote targets, the remote
+ stub). Return a null-terminated string allocated via xmalloc,
+ or NULL if an error occurs (and set *TARGET_ERRNO). */
char *(*to_fileio_readlink) (struct target_ops *,
- const char *filename, int *target_errno);
+ struct inferior *inf,
+ const char *filename,
+ int *target_errno);
/* Implement the "info proc" command. */
/* Target file operations. */
-/* Return nonzero if the filesystem accessed by the target_fileio_*
- methods is the local filesystem, zero otherwise. */
+/* Return nonzero if the filesystem seen by the current inferior
+ is the local filesystem, zero otherwise. */
#define target_filesystem_is_local() \
current_target.to_filesystem_is_local (¤t_target)
-/* Open FILENAME on the target, using FLAGS and MODE. Return a
- target file descriptor, or -1 if an error occurs (and set
- *TARGET_ERRNO). */
-extern int target_fileio_open (const char *filename, int flags, int mode,
- int *target_errno);
+/* Open FILENAME on the target, in the filesystem as seen by INF,
+ using FLAGS and MODE. If INF is NULL, use the filesystem seen
+ by the debugger (GDB or, for remote targets, the remote stub).
+ Return a target file descriptor, or -1 if an error occurs (and
+ set *TARGET_ERRNO). */
+extern int target_fileio_open (struct inferior *inf,
+ const char *filename, int flags,
+ int mode, int *target_errno);
/* Write up to LEN bytes from WRITE_BUF to FD on the target.
Return the number of bytes written, or -1 if an error occurs
(and set *TARGET_ERRNO). */
extern int target_fileio_close (int fd, int *target_errno);
-/* Unlink FILENAME on the target. Return 0, or -1 if an error
+/* Unlink FILENAME on the target, in the filesystem as seen by INF.
+ If INF is NULL, use the filesystem seen by the debugger (GDB or,
+ for remote targets, the remote stub). Return 0, or -1 if an error
occurs (and set *TARGET_ERRNO). */
-extern int target_fileio_unlink (const char *filename, int *target_errno);
-
-/* Read value of symbolic link FILENAME on the target. Return a
- null-terminated string allocated via xmalloc, or NULL if an error
- occurs (and set *TARGET_ERRNO). */
-extern char *target_fileio_readlink (const char *filename, int *target_errno);
-
-/* Read target file FILENAME. The return value will be -1 if the transfer
- fails or is not supported; 0 if the object is empty; or the length
- of the object otherwise. If a positive value is returned, a
- sufficiently large buffer will be allocated using xmalloc and
- returned in *BUF_P containing the contents of the object.
+extern int target_fileio_unlink (struct inferior *inf,
+ const char *filename,
+ int *target_errno);
+
+/* Read value of symbolic link FILENAME on the target, in the
+ filesystem as seen by INF. If INF is NULL, use the filesystem seen
+ by the debugger (GDB or, for remote targets, the remote stub).
+ Return a null-terminated string allocated via xmalloc, or NULL if
+ an error occurs (and set *TARGET_ERRNO). */
+extern char *target_fileio_readlink (struct inferior *inf,
+ const char *filename,
+ int *target_errno);
+
+/* Read target file FILENAME, in the filesystem as seen by INF. If
+ INF is NULL, use the filesystem seen by the debugger (GDB or, for
+ remote targets, the remote stub). The return value will be -1 if
+ the transfer fails or is not supported; 0 if the object is empty;
+ or the length of the object otherwise. If a positive value is
+ returned, a sufficiently large buffer will be allocated using
+ xmalloc and returned in *BUF_P containing the contents of the
+ object.
This method should be used for objects sufficiently small to store
in a single xmalloc'd buffer, when no fixed bound on the object's
size is known in advance. */
-extern LONGEST target_fileio_read_alloc (const char *filename,
+extern LONGEST target_fileio_read_alloc (struct inferior *inf,
+ const char *filename,
gdb_byte **buf_p);
-/* Read target file FILENAME. The result is NUL-terminated and
+/* Read target file FILENAME, in the filesystem as seen by INF. If
+ INF is NULL, use the filesystem seen by the debugger (GDB or, for
+ remote targets, the remote stub). The result is NUL-terminated and
returned as a string, allocated using xmalloc. If an error occurs
or the transfer is unsupported, NULL is returned. Empty objects
are returned as allocated but empty strings. A warning is issued
if the result contains any embedded NUL bytes. */
-extern char *target_fileio_read_stralloc (const char *filename);
+extern char *target_fileio_read_stralloc (struct inferior *inf,
+ const char *filename);
/* Tracepoint-related operations. */