struct gdbarch *core_gdbarch = NULL;
+/* Per-core data. Currently, only the section table. Note that these
+ target sections are *not* mapped in the current address spaces' set
+ of target sections --- those should come only from pure executable
+ or shared library bfds. The core bfd sections are an
+ implementation detail of the core target, just like ptrace is for
+ unix child targets. */
+static struct target_section_table *core_data;
+
static void core_files_info (struct target_ops *);
static struct core_fns *sniff_core_bfd (bfd *);
static void core_close_cleanup (void *ignore);
-static void get_core_registers (struct regcache *, int);
-
static void add_to_thread_list (bfd *, asection *, void *);
-static int core_file_thread_alive (ptid_t tid);
-
static void init_core_ops (void);
void _initialize_corelow (void);
comments in clear_solib in solib.c. */
clear_solib ();
+ xfree (core_data->sections);
+ xfree (core_data);
+ core_data = NULL;
+
name = bfd_get_filename (core_bfd);
if (!bfd_close (core_bfd))
warning (_("cannot close \"%s\": %s"),
name, bfd_errmsg (bfd_get_error ()));
xfree (name);
core_bfd = NULL;
- if (core_ops.to_sections)
- {
- xfree (core_ops.to_sections);
- core_ops.to_sections = NULL;
- core_ops.to_sections_end = NULL;
- }
}
core_vec = NULL;
core_gdbarch = NULL;
if (temp_bfd == NULL)
perror_with_name (filename);
- if (!bfd_check_format (temp_bfd, bfd_core) &&
- !gdb_check_format (temp_bfd))
+ if (!bfd_check_format (temp_bfd, bfd_core)
+ && !gdb_check_format (temp_bfd))
{
/* Do it after the err msg */
/* FIXME: should be checking for errors from bfd_close (for one thing,
validate_files ();
+ core_data = XZALLOC (struct target_section_table);
+
/* Find the data section */
- if (build_section_table (core_bfd, &core_ops.to_sections,
- &core_ops.to_sections_end))
+ if (build_section_table (core_bfd,
+ &core_data->sections, &core_data->sections_end))
error (_("\"%s\": Can't find sections: %s"),
bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
from ST to MT. */
add_thread_silent (inferior_ptid);
+ /* Need to flush the register cache (and the frame cache) from a
+ previous debug session. If inferior_ptid ends up the same as the
+ last debug session --- e.g., b foo; run; gcore core1; step; gcore
+ core2; core core1; core core2 --- then there's potential for
+ get_current_regcache to return the cached regcache of the
+ previous session, and the frame cache being stale. */
+ registers_changed ();
+
/* Build up thread list from BFD sections, and possibly set the
current thread to the .reg/NN section matching the .reg
section. */
name ..._from_host(). */
printf_filtered (_("Program terminated with signal %d, %s.\n"), siggy,
target_signal_to_string (
- gdbarch_target_signal_from_host (core_gdbarch, siggy)));
+ (core_gdbarch != NULL) ?
+ gdbarch_target_signal_from_host (core_gdbarch, siggy)
+ : siggy));
/* Fetch all registers from core file. */
target_fetch_registers (get_current_regcache (), -1);
printf_filtered (_("No core file now.\n"));
}
+#ifdef DEPRECATED_IBM6000_TARGET
+
+/* Resize the core memory's section table, by NUM_ADDED. Returns a
+ pointer into the first new slot. This will not be necessary when
+ the rs6000 target is converted to use the standard solib
+ framework. */
+
+struct target_section *
+deprecated_core_resize_section_table (int num_added)
+{
+ int old_count;
+
+ old_count = resize_section_table (core_data, num_added);
+ return core_data->sections + old_count;
+}
+
+#endif
/* Try to retrieve registers from a section in core_bfd, and supply
them to core_vec->core_read_registers, as the register set numbered
/* We just get all the registers, so we don't use regno. */
static void
-get_core_registers (struct regcache *regcache, int regno)
+get_core_registers (struct target_ops *ops,
+ struct regcache *regcache, int regno)
{
int i;
static void
core_files_info (struct target_ops *t)
{
- print_section_info (t, core_bfd);
+ print_section_info (core_data, core_bfd);
}
\f
+struct spuid_list
+{
+ gdb_byte *buf;
+ ULONGEST offset;
+ LONGEST len;
+ ULONGEST pos;
+ ULONGEST written;
+};
+
+static void
+add_to_spuid_list (bfd *abfd, asection *asect, void *list_p)
+{
+ struct spuid_list *list = list_p;
+ enum bfd_endian byte_order
+ = bfd_big_endian (abfd)? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
+ int fd, pos = 0;
+
+ sscanf (bfd_section_name (abfd, asect), "SPU/%d/regs%n", &fd, &pos);
+ if (pos == 0)
+ return;
+
+ if (list->pos >= list->offset && list->pos + 4 <= list->offset + list->len)
+ {
+ store_unsigned_integer (list->buf + list->pos - list->offset,
+ 4, byte_order, fd);
+ list->written += 4;
+ }
+ list->pos += 4;
+}
+
static LONGEST
core_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
switch (object)
{
case TARGET_OBJECT_MEMORY:
- if (readbuf)
- return (*ops->deprecated_xfer_memory) (offset, readbuf,
- len, 0/*read*/, NULL, ops);
- if (writebuf)
- return (*ops->deprecated_xfer_memory) (offset, (gdb_byte *) writebuf,
- len, 1/*write*/, NULL, ops);
- return -1;
+ return section_table_xfer_memory_partial (readbuf, writebuf,
+ offset, len,
+ core_data->sections,
+ core_data->sections_end,
+ NULL);
case TARGET_OBJECT_AUXV:
if (readbuf)
}
/* FALL THROUGH */
+ case TARGET_OBJECT_SPU:
+ if (readbuf && annex)
+ {
+ /* When the SPU contexts are stored in a core file, BFD
+ represents this with a fake section called "SPU/<annex>". */
+
+ struct bfd_section *section;
+ bfd_size_type size;
+ char *contents;
+
+ char sectionstr[100];
+ xsnprintf (sectionstr, sizeof sectionstr, "SPU/%s", annex);
+
+ section = bfd_get_section_by_name (core_bfd, sectionstr);
+ if (section == NULL)
+ return -1;
+
+ size = bfd_section_size (core_bfd, section);
+ if (offset >= size)
+ return 0;
+ size -= offset;
+ if (size > len)
+ size = len;
+ if (size > 0
+ && !bfd_get_section_contents (core_bfd, section, readbuf,
+ (file_ptr) offset, size))
+ {
+ warning (_("Couldn't read SPU section in core file."));
+ return -1;
+ }
+
+ return size;
+ }
+ else if (readbuf)
+ {
+ /* NULL annex requests list of all present spuids. */
+ struct spuid_list list;
+ list.buf = readbuf;
+ list.offset = offset;
+ list.len = len;
+ list.pos = 0;
+ list.written = 0;
+ bfd_map_over_sections (core_bfd, add_to_spuid_list, &list);
+ return list.written;
+ }
+ return -1;
+
default:
if (ops->beneath != NULL)
return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
`gdb internal error' (since generic_mourn calls breakpoint_init_inferior). */
static int
-ignore (struct bp_target_info *bp_tgt)
+ignore (struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
{
return 0;
}
behaviour.
*/
static int
-core_file_thread_alive (ptid_t tid)
+core_thread_alive (struct target_ops *ops, ptid_t ptid)
{
return 1;
}
static const struct target_desc *
core_read_description (struct target_ops *target)
{
- if (gdbarch_core_read_description_p (current_gdbarch))
- return gdbarch_core_read_description (current_gdbarch, target, core_bfd);
+ if (core_gdbarch && gdbarch_core_read_description_p (core_gdbarch))
+ return gdbarch_core_read_description (core_gdbarch, target, core_bfd);
return NULL;
}
{
static char buf[64];
+ if (core_gdbarch
+ && gdbarch_core_pid_to_str_p (core_gdbarch))
+ {
+ char *ret = gdbarch_core_pid_to_str (core_gdbarch, ptid);
+ if (ret != NULL)
+ return ret;
+ }
+
if (ptid_get_lwp (ptid) == 0)
xsnprintf (buf, sizeof buf, "<main task>");
else
return buf;
}
+static int
+core_has_memory (struct target_ops *ops)
+{
+ return (core_bfd != NULL);
+}
+
+static int
+core_has_stack (struct target_ops *ops)
+{
+ return (core_bfd != NULL);
+}
+
+static int
+core_has_registers (struct target_ops *ops)
+{
+ return (core_bfd != NULL);
+}
+
/* Fill in core_ops with its defined operations and properties. */
static void
core_ops.to_detach = core_detach;
core_ops.to_fetch_registers = get_core_registers;
core_ops.to_xfer_partial = core_xfer_partial;
- core_ops.deprecated_xfer_memory = xfer_memory;
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_file_thread_alive;
+ 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;
core_ops.to_stratum = core_stratum;
- core_ops.to_has_memory = 1;
- core_ops.to_has_stack = 1;
- core_ops.to_has_registers = 1;
+ core_ops.to_has_memory = core_has_memory;
+ core_ops.to_has_stack = core_has_stack;
+ core_ops.to_has_registers = core_has_registers;
core_ops.to_magic = OPS_MAGIC;
}
-/* non-zero if we should not do the add_target call in
- _initialize_corelow; not initialized (i.e., bss) so that
- the target can initialize it (i.e., data) if appropriate.
- This needs to be set at compile time because we don't know
- for sure whether the target's initialize routine is called
- before us or after us. */
-int coreops_suppress_target;
-
void
_initialize_corelow (void)
{
init_core_ops ();
- if (!coreops_suppress_target)
- add_target (&core_ops);
+ add_target (&core_ops);
}