/* Core dump and executable file functions below target vector, for GDB.
Copyright (C) 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
- 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008
+ 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009
Free Software Foundation, Inc.
This file is part of GDB.
static void core_open (char *, int);
-static void core_detach (char *, int);
+static void core_detach (struct target_ops *ops, char *, int);
static void core_close (int);
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);
struct target_ops core_ops;
+/* An arbitrary identifier for the core inferior. */
+#define CORELOW_PID 1
+
/* Link a new core_fns into the global core_file_fns list. Called on gdb
startup by the _initialize routine in each core file register reader, to
register information about each format the the reader is prepared to
if (core_bfd)
{
+ int pid = ptid_get_pid (inferior_ptid);
inferior_ptid = null_ptid; /* Avoid confusion from thread stuff */
+ delete_inferior_silent (pid);
/* Clear out solib state while the bfd is still open. See
comments in clear_solib in solib.c. */
thread_id = atoi (bfd_section_name (abfd, asect) + 5);
- ptid = ptid_build (ptid_get_pid (inferior_ptid), thread_id, 0);
+ if (core_gdbarch
+ && gdbarch_core_reg_section_encodes_pid (core_gdbarch))
+ {
+ uint32_t merged_pid = thread_id;
+ ptid = ptid_build (merged_pid & 0xffff,
+ merged_pid >> 16, 0);
+ }
+ else
+ ptid = ptid_build (ptid_get_pid (inferior_ptid), thread_id, 0);
if (ptid_get_lwp (inferior_ptid) == 0)
/* The main thread has already been added before getting here, and
bfd *temp_bfd;
int scratch_chan;
int flags;
- /* An arbitrary identifier for the core inferior. */
- int corelow_pid = 1;
+ int corelow_pid = CORELOW_PID;
target_preopen (from_tty);
if (!filename)
push_target (&core_ops);
discard_cleanups (old_chain);
+ add_inferior_silent (corelow_pid);
+
/* Do this before acknowledging the inferior, so if
post_create_inferior throws (can happen easilly if you're loading
a core file with the wrong exec), we aren't left with threads
from ST to MT. */
add_thread_silent (inferior_ptid);
- /* This is done first, before anything has a chance to query the
- inferior for information such as symbols. */
- post_create_inferior (&core_ops, from_tty);
+ /* 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
bfd_map_over_sections (core_bfd, add_to_thread_list,
bfd_get_section_by_name (core_bfd, ".reg"));
+ post_create_inferior (&core_ops, from_tty);
+
/* Now go through the target stack looking for threads since there
may be a thread_stratum target loaded on top of target core by
now. The layer above should claim threads found in the BFD
}
static void
-core_detach (char *args, int from_tty)
+core_detach (struct target_ops *ops, char *args, int from_tty)
{
if (args)
error (_("Too many arguments"));
- unpush_target (&core_ops);
+ unpush_target (ops);
reinit_frame_cache ();
if (from_tty)
printf_filtered (_("No core file now.\n"));
char *contents;
xfree (section_name);
- if (ptid_get_lwp (inferior_ptid))
+
+ if (core_gdbarch
+ && gdbarch_core_reg_section_encodes_pid (core_gdbarch))
+ {
+ uint32_t merged_pid;
+
+ merged_pid = ptid_get_lwp (inferior_ptid);
+ merged_pid = merged_pid << 16 | ptid_get_pid (inferior_ptid);
+
+ section_name = xstrprintf ("%s/%s", name, plongest (merged_pid));
+ }
+ else if (ptid_get_lwp (inferior_ptid))
section_name = xstrprintf ("%s/%ld", name, ptid_get_lwp (inferior_ptid));
else
section_name = xstrdup (name);
/* 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;
behaviour.
*/
static int
-core_file_thread_alive (ptid_t tid)
+core_thread_alive (struct target_ops *ops, ptid_t ptid)
{
return 1;
}
}
static char *
-core_pid_to_str (ptid_t ptid)
+core_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
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
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_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);
}