#include "defs.h"
#include "arch-utils.h"
-#include <string.h>
-#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#ifdef HAVE_SYS_FILE_H
#endif
#include "frame.h" /* required by inferior.h */
#include "inferior.h"
+#include "infrun.h"
#include "symtab.h"
#include "command.h"
#include "bfd.h"
#include "symfile.h"
#include "exec.h"
#include "readline/readline.h"
-#include "gdb_assert.h"
#include "exceptions.h"
#include "solib.h"
#include "filenames.h"
static int gdb_check_format (bfd *);
-static void core_open (char *, int);
-
-static void core_close (void);
+static void core_close (struct target_ops *self);
static void core_close_cleanup (void *ignore);
stack spaces as empty. */
static void
-core_close (void)
+core_close (struct target_ops *self)
{
if (core_bfd)
{
static void
core_close_cleanup (void *ignore)
{
- core_close ();
+ core_close (NULL);
}
/* Look for sections whose names start with `.reg/' so that we can
/* This routine opens and sets up the core file bfd. */
static void
-core_open (char *filename, int from_tty)
+core_open (const char *arg, int from_tty)
{
const char *p;
int siggy;
int scratch_chan;
int flags;
volatile struct gdb_exception except;
+ char *filename;
target_preopen (from_tty);
- if (!filename)
+ if (!arg)
{
if (core_bfd)
error (_("No core file specified. (Use `detach' "
error (_("No core file specified."));
}
- filename = tilde_expand (filename);
+ filename = tilde_expand (arg);
if (!IS_ABSOLUTE_PATH (filename))
{
temp = concat (current_directory, "/",
bfd_section_vma (core_bfd, section)));
}
+/* Callback for get_core_registers that handles a single core file
+ register note section. */
+
+static void
+get_core_registers_cb (const char *sect_name, int size,
+ const char *human_name, void *cb_data)
+{
+ struct regcache *regcache = (struct regcache *) cb_data;
+
+ if (strcmp (sect_name, ".reg") == 0)
+ get_core_register_section (regcache, sect_name, 0, human_name, 1);
+ else if (strcmp (sect_name, ".reg2") == 0)
+ get_core_register_section (regcache, sect_name, 2, human_name, 0);
+ else
+ get_core_register_section (regcache, sect_name, 3, human_name, 0);
+}
/* Get the registers out of a core file. This is the machine-
independent part. Fetch_core_registers is the machine-dependent
get_core_registers (struct target_ops *ops,
struct regcache *regcache, int regno)
{
- struct core_regset_section *sect_list;
int i;
+ struct gdbarch *gdbarch;
if (!(core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
&& (core_vec == NULL || core_vec->core_read_registers == NULL))
return;
}
- sect_list = gdbarch_core_regset_sections (get_regcache_arch (regcache));
- if (sect_list)
- while (sect_list->sect_name != NULL)
- {
- if (strcmp (sect_list->sect_name, ".reg") == 0)
- get_core_register_section (regcache, sect_list->sect_name,
- 0, sect_list->human_name, 1);
- else if (strcmp (sect_list->sect_name, ".reg2") == 0)
- get_core_register_section (regcache, sect_list->sect_name,
- 2, sect_list->human_name, 0);
- else
- get_core_register_section (regcache, sect_list->sect_name,
- 3, sect_list->human_name, 0);
-
- sect_list++;
- }
-
+ gdbarch = get_regcache_arch (regcache);
+ if (gdbarch_iterate_over_regset_sections_p (gdbarch))
+ gdbarch_iterate_over_regset_sections (gdbarch,
+ get_core_registers_cb,
+ (void *) regcache, NULL);
else
{
get_core_register_section (regcache,
return len;
}
-static LONGEST
+static enum target_xfer_status
core_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
const gdb_byte *writebuf, ULONGEST offset,
- ULONGEST len)
+ ULONGEST len, ULONGEST *xfered_len)
{
switch (object)
{
case TARGET_OBJECT_MEMORY:
return section_table_xfer_memory_partial (readbuf, writebuf,
- offset, len,
+ offset, len, xfered_len,
core_data->sections,
core_data->sections_end,
NULL);
size = bfd_section_size (core_bfd, section);
if (offset >= size)
- return 0;
+ return TARGET_XFER_EOF;
size -= offset;
if (size > len)
size = len;
- if (size > 0
- && !bfd_get_section_contents (core_bfd, section, readbuf,
- (file_ptr) offset, size))
+
+ if (size == 0)
+ return TARGET_XFER_EOF;
+ if (!bfd_get_section_contents (core_bfd, section, readbuf,
+ (file_ptr) offset, size))
{
warning (_("Couldn't read NT_AUXV note in core file."));
return TARGET_XFER_E_IO;
}
- return size;
+ *xfered_len = (ULONGEST) size;
+ return TARGET_XFER_OK;
}
return TARGET_XFER_E_IO;
size = bfd_section_size (core_bfd, section);
if (offset >= size)
- return 0;
+ return TARGET_XFER_EOF;
size -= offset;
if (size > len)
size = len;
- if (size > 0
- && !bfd_get_section_contents (core_bfd, section, readbuf,
- (file_ptr) offset, size))
+
+ if (size == 0)
+ return TARGET_XFER_EOF;
+ if (!bfd_get_section_contents (core_bfd, section, readbuf,
+ (file_ptr) offset, size))
{
warning (_("Couldn't read StackGhost cookie in core file."));
return TARGET_XFER_E_IO;
}
- return size;
+ *xfered_len = (ULONGEST) size;
+ return TARGET_XFER_OK;
+
}
return TARGET_XFER_E_IO;
{
if (writebuf)
return TARGET_XFER_E_IO;
- return
- gdbarch_core_xfer_shared_libraries (core_gdbarch,
- readbuf, offset, len);
+ else
+ {
+ *xfered_len = gdbarch_core_xfer_shared_libraries (core_gdbarch,
+ readbuf,
+ offset, len);
+
+ if (*xfered_len == 0)
+ return TARGET_XFER_EOF;
+ else
+ return TARGET_XFER_OK;
+ }
}
/* FALL THROUGH */
{
if (writebuf)
return TARGET_XFER_E_IO;
- return
- gdbarch_core_xfer_shared_libraries_aix (core_gdbarch,
- readbuf, offset, len);
+ else
+ {
+ *xfered_len
+ = gdbarch_core_xfer_shared_libraries_aix (core_gdbarch,
+ readbuf, offset,
+ len);
+
+ if (*xfered_len == 0)
+ return TARGET_XFER_EOF;
+ else
+ return TARGET_XFER_OK;
+ }
}
/* FALL THROUGH */
size = bfd_section_size (core_bfd, section);
if (offset >= size)
- return 0;
+ return TARGET_XFER_EOF;
size -= offset;
if (size > len)
size = len;
- if (size > 0
- && !bfd_get_section_contents (core_bfd, section, readbuf,
- (file_ptr) offset, size))
+
+ if (size == 0)
+ return TARGET_XFER_EOF;
+ if (!bfd_get_section_contents (core_bfd, section, readbuf,
+ (file_ptr) offset, size))
{
warning (_("Couldn't read SPU section in core file."));
return TARGET_XFER_E_IO;
}
- return size;
+ *xfered_len = (ULONGEST) size;
+ return TARGET_XFER_OK;
}
else if (readbuf)
{
list.pos = 0;
list.written = 0;
bfd_map_over_sections (core_bfd, add_to_spuid_list, &list);
- return list.written;
+
+ if (list.written == 0)
+ return TARGET_XFER_EOF;
+ else
+ {
+ *xfered_len = (ULONGEST) list.written;
+ return TARGET_XFER_OK;
+ }
}
return TARGET_XFER_E_IO;
case TARGET_OBJECT_SIGNAL_INFO:
if (readbuf)
- return get_core_siginfo (core_bfd, readbuf, offset, len);
+ {
+ LONGEST l = get_core_siginfo (core_bfd, readbuf, offset, len);
+
+ if (l > 0)
+ {
+ *xfered_len = len;
+ return TARGET_XFER_OK;
+ }
+ }
return TARGET_XFER_E_IO;
default:
- if (ops->beneath != NULL)
- return ops->beneath->to_xfer_partial (ops->beneath, object,
- annex, readbuf,
- writebuf, offset, len);
- return TARGET_XFER_E_IO;
+ return ops->beneath->to_xfer_partial (ops->beneath, object,
+ annex, readbuf,
+ writebuf, offset, len,
+ xfered_len);
}
}
core_read_description (struct target_ops *target)
{
if (core_gdbarch && gdbarch_core_read_description_p (core_gdbarch))
- return gdbarch_core_read_description (core_gdbarch,
- target, core_bfd);
+ {
+ const struct target_desc *result;
+
+ result = gdbarch_core_read_description (core_gdbarch,
+ target, core_bfd);
+ if (result != NULL)
+ return result;
+ }
- return NULL;
+ return target->beneath->to_read_description (target->beneath);
}
static char *
/* Implement the to_info_proc method. */
static void
-core_info_proc (struct target_ops *ops, char *args, enum info_proc_what request)
+core_info_proc (struct target_ops *ops, const char *args,
+ enum info_proc_what request)
{
struct gdbarch *gdbarch = get_current_arch ();
"Use a core file as a target. Specify the filename of the core file.";
core_ops.to_open = core_open;
core_ops.to_close = core_close;
- core_ops.to_attach = find_default_attach;
core_ops.to_detach = core_detach;
core_ops.to_fetch_registers = get_core_registers;
core_ops.to_xfer_partial = core_xfer_partial;
core_ops.to_files_info = core_files_info;
core_ops.to_insert_breakpoint = ignore;
core_ops.to_remove_breakpoint = ignore;
- core_ops.to_create_inferior = find_default_create_inferior;
core_ops.to_thread_alive = core_thread_alive;
core_ops.to_read_description = core_read_description;
core_ops.to_pid_to_str = core_pid_to_str;