aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog15
-rw-r--r--gdb/Makefile.in2
-rw-r--r--gdb/remote-sim.c53
3 files changed, 66 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0a991f0..9bcadff 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,20 @@
2008-07-09 Pedro Alves <pedro@codesourcery.com>
+ * remote-sim.c: Include gdbthread.h.
+ (remote_sim_ptid): New global.
+ (gdbsim_create_inferior): Silently add the main task to GDB's
+ thread list.
+ (gdbsim_close, gdbsim_mourn_inferior): Silently delete the main
+ task from GDB's thread list.
+ (gdbsim_resume): Adjust to use remote_sim_ptid.
+ (gdbsim_thread_alive, gdbsim_pid_to_str): New.
+ (init_gdbsim_ops): Register gdbsim_thread_alive and
+ gdbsim_pid_to_str.
+ (_initialize_remote_sim): Initialize remote_sim_ptid.
+ * Makefile.in (remote-sim.o): Depend on $(gdbthread_h).
+
+2008-07-09 Pedro Alves <pedro@codesourcery.com>
+
* monitor (monitor_ptid): New global.
(monitor_open): Silently add the main task to GDB's thread list.
(monitor_close, monitor_mourn_inferior): Silently delete the main
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 055a759..d4b1297 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -2671,7 +2671,7 @@ remote-sim.o: remote-sim.c $(defs_h) $(inferior_h) $(value_h) \
$(gdb_string_h) $(terminal_h) $(target_h) $(gdbcore_h) \
$(gdb_callback_h) $(gdb_remote_sim_h) $(command_h) \
$(regcache_h) $(gdb_assert_h) $(sim_regno_h) $(arch_utils_h) \
- $(readline_h)
+ $(readline_h) $(gdbthread_h)
rs6000-nat.o: rs6000-nat.c $(defs_h) $(inferior_h) $(target_h) $(gdbcore_h) \
$(xcoffsolib_h) $(symfile_h) $(objfiles_h) $(libbfd_h) $(bfd_h) \
$(exceptions_h) $(gdb_stabs_h) $(regcache_h) $(arch_utils_h) \
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 918eab8..de5e7de 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -41,6 +41,7 @@
#include "sim-regno.h"
#include "arch-utils.h"
#include "readline/readline.h"
+#include "gdbthread.h"
/* Prototypes */
@@ -115,6 +116,12 @@ static int program_loaded = 0;
back to the other sim_foo routines. */
static SIM_DESC gdbsim_desc = 0;
+/* This is the ptid we use while we're connected to the simulator.
+ Its value is arbitrary, as the simulator target don't have a notion
+ or processes or threads, but we need something non-null to place in
+ inferior_ptid. */
+static ptid_t remote_sim_ptid;
+
static void
dump_mem (char *buf, int len)
{
@@ -452,7 +459,8 @@ gdbsim_create_inferior (char *exec_file, char *args, char **env, int from_tty)
(exec_file ? exec_file : "(NULL)"),
args);
- gdbsim_kill ();
+ if (ptid_equal (inferior_ptid, remote_sim_ptid))
+ gdbsim_kill ();
remove_breakpoints ();
init_wait_for_inferior ();
@@ -471,7 +479,9 @@ gdbsim_create_inferior (char *exec_file, char *args, char **env, int from_tty)
argv = NULL;
sim_create_inferior (gdbsim_desc, exec_bfd, argv, env);
- inferior_ptid = pid_to_ptid (42);
+ inferior_ptid = remote_sim_ptid;
+ add_thread_silent (inferior_ptid);
+
target_mark_running (&gdbsim_ops);
insert_breakpoints (); /* Needed to get correct instruction in cache */
@@ -580,6 +590,7 @@ gdbsim_close (int quitting)
end_callbacks ();
generic_mourn_inferior ();
+ delete_thread_silent (remote_sim_ptid);
}
/* Takes a program previously attached to and detaches it.
@@ -612,7 +623,7 @@ static int resume_step;
static void
gdbsim_resume (ptid_t ptid, int step, enum target_signal siggnal)
{
- if (PIDGET (inferior_ptid) != 42)
+ if (!ptid_equal (inferior_ptid, remote_sim_ptid))
error (_("The program is not being run."));
if (remote_debug)
@@ -818,6 +829,7 @@ gdbsim_mourn_inferior (void)
remove_breakpoints ();
target_mark_exited (&gdbsim_ops);
generic_mourn_inferior ();
+ delete_thread_silent (remote_sim_ptid);
}
/* Pass the command argument through to the simulator verbatim. The
@@ -849,6 +861,35 @@ simulator_command (char *args, int from_tty)
registers_changed ();
}
+/* Check to see if a thread is still alive. */
+
+static int
+gdbsim_thread_alive (ptid_t ptid)
+{
+ if (ptid_equal (ptid, remote_sim_ptid))
+ /* The simulators' task is always alive. */
+ return 1;
+
+ return 0;
+}
+
+/* Convert a thread ID to a string. Returns the string in a static
+ buffer. */
+
+static char *
+gdbsim_pid_to_str (ptid_t ptid)
+{
+ static char buf[64];
+
+ if (ptid_equal (remote_sim_ptid, ptid))
+ {
+ xsnprintf (buf, sizeof buf, "Thread <main>");
+ return buf;
+ }
+
+ return normal_pid_to_str (ptid);
+}
+
/* Define the target subroutine names */
struct target_ops gdbsim_ops;
@@ -876,6 +917,8 @@ init_gdbsim_ops (void)
gdbsim_ops.to_create_inferior = gdbsim_create_inferior;
gdbsim_ops.to_mourn_inferior = gdbsim_mourn_inferior;
gdbsim_ops.to_stop = gdbsim_stop;
+ gdbsim_ops.to_thread_alive = gdbsim_thread_alive;
+ gdbsim_ops.to_pid_to_str = gdbsim_pid_to_str;
gdbsim_ops.to_stratum = process_stratum;
gdbsim_ops.to_has_all_memory = 1;
gdbsim_ops.to_has_memory = 1;
@@ -897,4 +940,8 @@ _initialize_remote_sim (void)
add_com ("sim", class_obscure, simulator_command,
_("Send a command to the simulator."));
+
+ /* Yes, 42000 is arbitrary. The only sense out of it, is that it
+ isn't 0. */
+ remote_sim_ptid = ptid_build (42000, 0, 42000);
}