GDB (API)
/home/stan/gdb/src/gdb/remote-sim.c
Go to the documentation of this file.
00001 /* Generic remote debugging interface for simulators.
00002 
00003    Copyright (C) 1993-2013 Free Software Foundation, Inc.
00004 
00005    Contributed by Cygnus Support.
00006    Steve Chamberlain (sac@cygnus.com).
00007 
00008    This file is part of GDB.
00009 
00010    This program is free software; you can redistribute it and/or modify
00011    it under the terms of the GNU General Public License as published by
00012    the Free Software Foundation; either version 3 of the License, or
00013    (at your option) any later version.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License
00021    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00022 
00023 #include "defs.h"
00024 #include "inferior.h"
00025 #include "value.h"
00026 #include "gdb_string.h"
00027 #include <ctype.h>
00028 #include <fcntl.h>
00029 #include <signal.h>
00030 #include <setjmp.h>
00031 #include <errno.h>
00032 #include "terminal.h"
00033 #include "target.h"
00034 #include "gdbcore.h"
00035 #include "gdb/callback.h"
00036 #include "gdb/remote-sim.h"
00037 #include "command.h"
00038 #include "regcache.h"
00039 #include "gdb_assert.h"
00040 #include "sim-regno.h"
00041 #include "arch-utils.h"
00042 #include "readline/readline.h"
00043 #include "gdbthread.h"
00044 
00045 /* Prototypes */
00046 
00047 extern void _initialize_remote_sim (void);
00048 
00049 static void init_callbacks (void);
00050 
00051 static void end_callbacks (void);
00052 
00053 static int gdb_os_write_stdout (host_callback *, const char *, int);
00054 
00055 static void gdb_os_flush_stdout (host_callback *);
00056 
00057 static int gdb_os_write_stderr (host_callback *, const char *, int);
00058 
00059 static void gdb_os_flush_stderr (host_callback *);
00060 
00061 static int gdb_os_poll_quit (host_callback *);
00062 
00063 /* printf_filtered is depreciated.  */
00064 static void gdb_os_printf_filtered (host_callback *, const char *, ...);
00065 
00066 static void gdb_os_vprintf_filtered (host_callback *, const char *, va_list);
00067 
00068 static void gdb_os_evprintf_filtered (host_callback *, const char *, va_list);
00069 
00070 static void gdb_os_error (host_callback *, const char *, ...)
00071      ATTRIBUTE_NORETURN;
00072 
00073 static void gdbsim_kill (struct target_ops *);
00074 
00075 static void gdbsim_load (char *prog, int fromtty);
00076 
00077 static void gdbsim_open (char *args, int from_tty);
00078 
00079 static void gdbsim_close (void);
00080 
00081 static void gdbsim_detach (struct target_ops *ops, char *args, int from_tty);
00082 
00083 static void gdbsim_prepare_to_store (struct regcache *regcache);
00084 
00085 static void gdbsim_files_info (struct target_ops *target);
00086 
00087 static void gdbsim_mourn_inferior (struct target_ops *target);
00088 
00089 static void gdbsim_stop (ptid_t ptid);
00090 
00091 void simulator_command (char *args, int from_tty);
00092 
00093 /* Naming convention:
00094 
00095    sim_* are the interface to the simulator (see remote-sim.h).
00096    gdbsim_* are stuff which is internal to gdb.  */
00097 
00098 /* Forward data declarations */
00099 extern struct target_ops gdbsim_ops;
00100 
00101 static const struct inferior_data *sim_inferior_data_key;
00102 
00103 /* Simulator-specific, per-inferior state.  */
00104 struct sim_inferior_data {
00105   /* Flag which indicates whether or not the program has been loaded.  */
00106   int program_loaded;
00107 
00108   /* Simulator descriptor for this inferior.  */
00109   SIM_DESC gdbsim_desc;
00110 
00111   /* This is the ptid we use for this particular simulator instance.  Its
00112      value is somewhat arbitrary, as the simulator target don't have a
00113      notion of tasks or threads, but we need something non-null to place
00114      in inferior_ptid.  For simulators which permit multiple instances,
00115      we also need a unique identifier to use for each inferior.  */
00116   ptid_t remote_sim_ptid;
00117 
00118   /* Signal with which to resume.  */
00119   enum gdb_signal resume_siggnal;
00120 
00121   /* Flag which indicates whether resume should step or not.  */
00122   int resume_step;
00123 };
00124 
00125 /* Flag indicating the "open" status of this module.  It's set to 1
00126    in gdbsim_open() and 0 in gdbsim_close().  */
00127 static int gdbsim_is_open = 0;
00128 
00129 /* Value of the next pid to allocate for an inferior.  As indicated
00130    elsewhere, its initial value is somewhat arbitrary; it's critical
00131    though that it's not zero or negative.  */
00132 static int next_pid;
00133 #define INITIAL_PID 42000
00134 
00135 /* Argument list to pass to sim_open().  It is allocated in gdbsim_open()
00136    and deallocated in gdbsim_close().  The lifetime needs to extend beyond
00137    the call to gdbsim_open() due to the fact that other sim instances other
00138    than the first will be allocated after the gdbsim_open() call.  */
00139 static char **sim_argv = NULL;
00140 
00141 /* OS-level callback functions for write, flush, etc.  */
00142 static host_callback gdb_callback;
00143 static int callbacks_initialized = 0;
00144 
00145 /* Callback for iterate_over_inferiors.  It checks to see if the sim
00146    descriptor passed via ARG is the same as that for the inferior
00147    designated by INF.  Return true if so; false otherwise.  */
00148 
00149 static int
00150 check_for_duplicate_sim_descriptor (struct inferior *inf, void *arg)
00151 {
00152   struct sim_inferior_data *sim_data;
00153   SIM_DESC new_sim_desc = arg;
00154 
00155   sim_data = inferior_data (inf, sim_inferior_data_key);
00156 
00157   return (sim_data != NULL && sim_data->gdbsim_desc == new_sim_desc);
00158 }
00159 
00160 /* Flags indicating whether or not a sim instance is needed.  One of these
00161    flags should be passed to get_sim_inferior_data().  */
00162 
00163 enum {SIM_INSTANCE_NOT_NEEDED = 0, SIM_INSTANCE_NEEDED = 1};
00164 
00165 /* Obtain pointer to per-inferior simulator data, allocating it if necessary.
00166    Attempt to open the sim if SIM_INSTANCE_NEEDED is true.  */
00167 
00168 static struct sim_inferior_data *
00169 get_sim_inferior_data (struct inferior *inf, int sim_instance_needed)
00170 {
00171   SIM_DESC sim_desc = NULL;
00172   struct sim_inferior_data *sim_data
00173     = inferior_data (inf, sim_inferior_data_key);
00174 
00175   /* Try to allocate a new sim instance, if needed.  We do this ahead of
00176      a potential allocation of a sim_inferior_data struct in order to
00177      avoid needlessly allocating that struct in the event that the sim
00178      instance allocation fails.  */
00179   if (sim_instance_needed == SIM_INSTANCE_NEEDED 
00180       && (sim_data == NULL || sim_data->gdbsim_desc == NULL))
00181     {
00182       struct inferior *idup;
00183       sim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback, exec_bfd, sim_argv);
00184       if (sim_desc == NULL)
00185         error (_("Unable to create simulator instance for inferior %d."),
00186                inf->num);
00187 
00188       idup = iterate_over_inferiors (check_for_duplicate_sim_descriptor,
00189                                      sim_desc);
00190       if (idup != NULL)
00191         {
00192           /* We don't close the descriptor due to the fact that it's
00193              shared with some other inferior.  If we were to close it,
00194              that might needlessly muck up the other inferior.  Of
00195              course, it's possible that the damage has already been
00196              done...  Note that it *will* ultimately be closed during
00197              cleanup of the other inferior.  */
00198           sim_desc = NULL;
00199           error (
00200  _("Inferior %d and inferior %d would have identical simulator state.\n"
00201    "(This simulator does not support the running of more than one inferior.)"),
00202                  inf->num, idup->num); 
00203         }
00204     }
00205 
00206   if (sim_data == NULL)
00207     {
00208       sim_data = XZALLOC(struct sim_inferior_data);
00209       set_inferior_data (inf, sim_inferior_data_key, sim_data);
00210 
00211       /* Allocate a ptid for this inferior.  */
00212       sim_data->remote_sim_ptid = ptid_build (next_pid, 0, next_pid);
00213       next_pid++;
00214 
00215       /* Initialize the other instance variables.  */
00216       sim_data->program_loaded = 0;
00217       sim_data->gdbsim_desc = sim_desc;
00218       sim_data->resume_siggnal = GDB_SIGNAL_0;
00219       sim_data->resume_step = 0;
00220     }
00221   else if (sim_desc)
00222     {
00223       /* This handles the case where sim_data was allocated prior to
00224          needing a sim instance.  */
00225       sim_data->gdbsim_desc = sim_desc;
00226     }
00227 
00228 
00229   return sim_data;
00230 }
00231 
00232 /* Return pointer to per-inferior simulator data using PTID to find the
00233    inferior in question.  Return NULL when no inferior is found or
00234    when ptid has a zero or negative pid component.  */
00235 
00236 static struct sim_inferior_data *
00237 get_sim_inferior_data_by_ptid (ptid_t ptid, int sim_instance_needed)
00238 {
00239   struct inferior *inf;
00240   int pid = ptid_get_pid (ptid);
00241 
00242   if (pid <= 0)
00243     return NULL;
00244   
00245   inf = find_inferior_pid (pid);
00246 
00247   if (inf)
00248     return get_sim_inferior_data (inf, sim_instance_needed);
00249   else
00250     return NULL;
00251 }
00252 
00253 /* Free the per-inferior simulator data.  */
00254 
00255 static void
00256 sim_inferior_data_cleanup (struct inferior *inf, void *data)
00257 {
00258   struct sim_inferior_data *sim_data = data;
00259 
00260   if (sim_data != NULL)
00261     {
00262       if (sim_data->gdbsim_desc)
00263         {
00264           sim_close (sim_data->gdbsim_desc, 0);
00265           sim_data->gdbsim_desc = NULL;
00266         }
00267       xfree (sim_data);
00268     }
00269 }
00270 
00271 static void
00272 dump_mem (const gdb_byte *buf, int len)
00273 {
00274   fputs_unfiltered ("\t", gdb_stdlog);
00275 
00276   if (len == 8 || len == 4)
00277     {
00278       uint32_t l[2];
00279 
00280       memcpy (l, buf, len);
00281       fprintf_unfiltered (gdb_stdlog, "0x%08x", l[0]);
00282       if (len == 8)
00283         fprintf_unfiltered (gdb_stdlog, " 0x%08x", l[1]);
00284     }
00285   else
00286     {
00287       int i;
00288 
00289       for (i = 0; i < len; i++)
00290         fprintf_unfiltered (gdb_stdlog, "0x%02x ", buf[i]);
00291     }
00292 
00293   fputs_unfiltered ("\n", gdb_stdlog);
00294 }
00295 
00296 /* Initialize gdb_callback.  */
00297 
00298 static void
00299 init_callbacks (void)
00300 {
00301   if (!callbacks_initialized)
00302     {
00303       gdb_callback = default_callback;
00304       gdb_callback.init (&gdb_callback);
00305       gdb_callback.write_stdout = gdb_os_write_stdout;
00306       gdb_callback.flush_stdout = gdb_os_flush_stdout;
00307       gdb_callback.write_stderr = gdb_os_write_stderr;
00308       gdb_callback.flush_stderr = gdb_os_flush_stderr;
00309       gdb_callback.printf_filtered = gdb_os_printf_filtered;
00310       gdb_callback.vprintf_filtered = gdb_os_vprintf_filtered;
00311       gdb_callback.evprintf_filtered = gdb_os_evprintf_filtered;
00312       gdb_callback.error = gdb_os_error;
00313       gdb_callback.poll_quit = gdb_os_poll_quit;
00314       gdb_callback.magic = HOST_CALLBACK_MAGIC;
00315       callbacks_initialized = 1;
00316     }
00317 }
00318 
00319 /* Release callbacks (free resources used by them).  */
00320 
00321 static void
00322 end_callbacks (void)
00323 {
00324   if (callbacks_initialized)
00325     {
00326       gdb_callback.shutdown (&gdb_callback);
00327       callbacks_initialized = 0;
00328     }
00329 }
00330 
00331 /* GDB version of os_write_stdout callback.  */
00332 
00333 static int
00334 gdb_os_write_stdout (host_callback *p, const char *buf, int len)
00335 {
00336   int i;
00337   char b[2];
00338 
00339   ui_file_write (gdb_stdtarg, buf, len);
00340   return len;
00341 }
00342 
00343 /* GDB version of os_flush_stdout callback.  */
00344 
00345 static void
00346 gdb_os_flush_stdout (host_callback *p)
00347 {
00348   gdb_flush (gdb_stdtarg);
00349 }
00350 
00351 /* GDB version of os_write_stderr callback.  */
00352 
00353 static int
00354 gdb_os_write_stderr (host_callback *p, const char *buf, int len)
00355 {
00356   int i;
00357   char b[2];
00358 
00359   for (i = 0; i < len; i++)
00360     {
00361       b[0] = buf[i];
00362       b[1] = 0;
00363       fputs_unfiltered (b, gdb_stdtargerr);
00364     }
00365   return len;
00366 }
00367 
00368 /* GDB version of os_flush_stderr callback.  */
00369 
00370 static void
00371 gdb_os_flush_stderr (host_callback *p)
00372 {
00373   gdb_flush (gdb_stdtargerr);
00374 }
00375 
00376 /* GDB version of printf_filtered callback.  */
00377 
00378 static void
00379 gdb_os_printf_filtered (host_callback * p, const char *format,...)
00380 {
00381   va_list args;
00382 
00383   va_start (args, format);
00384   vfprintf_filtered (gdb_stdout, format, args);
00385   va_end (args);
00386 }
00387 
00388 /* GDB version of error vprintf_filtered.  */
00389 
00390 static void
00391 gdb_os_vprintf_filtered (host_callback * p, const char *format, va_list ap)
00392 {
00393   vfprintf_filtered (gdb_stdout, format, ap);
00394 }
00395 
00396 /* GDB version of error evprintf_filtered.  */
00397 
00398 static void
00399 gdb_os_evprintf_filtered (host_callback * p, const char *format, va_list ap)
00400 {
00401   vfprintf_filtered (gdb_stderr, format, ap);
00402 }
00403 
00404 /* GDB version of error callback.  */
00405 
00406 static void
00407 gdb_os_error (host_callback * p, const char *format, ...)
00408 {
00409   va_list args;
00410 
00411   va_start (args, format);
00412   verror (format, args);
00413   va_end (args);
00414 }
00415 
00416 int
00417 one2one_register_sim_regno (struct gdbarch *gdbarch, int regnum)
00418 {
00419   /* Only makes sense to supply raw registers.  */
00420   gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
00421   return regnum;
00422 }
00423 
00424 static void
00425 gdbsim_fetch_register (struct target_ops *ops,
00426                        struct regcache *regcache, int regno)
00427 {
00428   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00429   struct sim_inferior_data *sim_data
00430     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
00431 
00432   if (regno == -1)
00433     {
00434       for (regno = 0; regno < gdbarch_num_regs (gdbarch); regno++)
00435         gdbsim_fetch_register (ops, regcache, regno);
00436       return;
00437     }
00438 
00439   switch (gdbarch_register_sim_regno (gdbarch, regno))
00440     {
00441     case LEGACY_SIM_REGNO_IGNORE:
00442       break;
00443     case SIM_REGNO_DOES_NOT_EXIST:
00444       {
00445         /* For moment treat a `does not exist' register the same way
00446            as an ``unavailable'' register.  */
00447         gdb_byte buf[MAX_REGISTER_SIZE];
00448         int nr_bytes;
00449 
00450         memset (buf, 0, MAX_REGISTER_SIZE);
00451         regcache_raw_supply (regcache, regno, buf);
00452         break;
00453       }
00454       
00455     default:
00456       {
00457         static int warn_user = 1;
00458         gdb_byte buf[MAX_REGISTER_SIZE];
00459         int nr_bytes;
00460 
00461         gdb_assert (regno >= 0 && regno < gdbarch_num_regs (gdbarch));
00462         memset (buf, 0, MAX_REGISTER_SIZE);
00463         nr_bytes = sim_fetch_register (sim_data->gdbsim_desc,
00464                                        gdbarch_register_sim_regno
00465                                          (gdbarch, regno),
00466                                        buf,
00467                                        register_size (gdbarch, regno));
00468         if (nr_bytes > 0
00469             && nr_bytes != register_size (gdbarch, regno) && warn_user)
00470           {
00471             fprintf_unfiltered (gdb_stderr,
00472                                 "Size of register %s (%d/%d) "
00473                                 "incorrect (%d instead of %d))",
00474                                 gdbarch_register_name (gdbarch, regno),
00475                                 regno,
00476                                 gdbarch_register_sim_regno
00477                                   (gdbarch, regno),
00478                                 nr_bytes, register_size (gdbarch, regno));
00479             warn_user = 0;
00480           }
00481         /* FIXME: cagney/2002-05-27: Should check `nr_bytes == 0'
00482            indicating that GDB and the SIM have different ideas about
00483            which registers are fetchable.  */
00484         /* Else if (nr_bytes < 0): an old simulator, that doesn't
00485            think to return the register size.  Just assume all is ok.  */
00486         regcache_raw_supply (regcache, regno, buf);
00487         if (remote_debug)
00488           {
00489             fprintf_unfiltered (gdb_stdlog,
00490                                 "gdbsim_fetch_register: %d", regno);
00491             /* FIXME: We could print something more intelligible.  */
00492             dump_mem (buf, register_size (gdbarch, regno));
00493           }
00494         break;
00495       }
00496     }
00497 }
00498 
00499 
00500 static void
00501 gdbsim_store_register (struct target_ops *ops,
00502                        struct regcache *regcache, int regno)
00503 {
00504   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00505   struct sim_inferior_data *sim_data
00506     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
00507 
00508   if (regno == -1)
00509     {
00510       for (regno = 0; regno < gdbarch_num_regs (gdbarch); regno++)
00511         gdbsim_store_register (ops, regcache, regno);
00512       return;
00513     }
00514   else if (gdbarch_register_sim_regno (gdbarch, regno) >= 0)
00515     {
00516       gdb_byte tmp[MAX_REGISTER_SIZE];
00517       int nr_bytes;
00518 
00519       regcache_cooked_read (regcache, regno, tmp);
00520       nr_bytes = sim_store_register (sim_data->gdbsim_desc,
00521                                      gdbarch_register_sim_regno
00522                                        (gdbarch, regno),
00523                                      tmp, register_size (gdbarch, regno));
00524       if (nr_bytes > 0 && nr_bytes != register_size (gdbarch, regno))
00525         internal_error (__FILE__, __LINE__,
00526                         _("Register size different to expected"));
00527       if (nr_bytes < 0)
00528         internal_error (__FILE__, __LINE__,
00529                         _("Register %d not updated"), regno);
00530       if (nr_bytes == 0)
00531         warning (_("Register %s not updated"),
00532                  gdbarch_register_name (gdbarch, regno));
00533 
00534       if (remote_debug)
00535         {
00536           fprintf_unfiltered (gdb_stdlog, "gdbsim_store_register: %d", regno);
00537           /* FIXME: We could print something more intelligible.  */
00538           dump_mem (tmp, register_size (gdbarch, regno));
00539         }
00540     }
00541 }
00542 
00543 /* Kill the running program.  This may involve closing any open files
00544    and releasing other resources acquired by the simulated program.  */
00545 
00546 static void
00547 gdbsim_kill (struct target_ops *ops)
00548 {
00549   if (remote_debug)
00550     fprintf_unfiltered (gdb_stdlog, "gdbsim_kill\n");
00551 
00552   /* There is no need to `kill' running simulator - the simulator is
00553      not running.  Mourning it is enough.  */
00554   target_mourn_inferior ();
00555 }
00556 
00557 /* Load an executable file into the target process.  This is expected to
00558    not only bring new code into the target process, but also to update
00559    GDB's symbol tables to match.  */
00560 
00561 static void
00562 gdbsim_load (char *args, int fromtty)
00563 {
00564   char **argv;
00565   char *prog;
00566   struct sim_inferior_data *sim_data
00567     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
00568 
00569   if (args == NULL)
00570       error_no_arg (_("program to load"));
00571 
00572   argv = gdb_buildargv (args);
00573   make_cleanup_freeargv (argv);
00574 
00575   prog = tilde_expand (argv[0]);
00576 
00577   if (argv[1] != NULL)
00578     error (_("GDB sim does not yet support a load offset."));
00579 
00580   if (remote_debug)
00581     fprintf_unfiltered (gdb_stdlog, "gdbsim_load: prog \"%s\"\n", prog);
00582 
00583   /* FIXME: We will print two messages on error.
00584      Need error to either not print anything if passed NULL or need
00585      another routine that doesn't take any arguments.  */
00586   if (sim_load (sim_data->gdbsim_desc, prog, NULL, fromtty) == SIM_RC_FAIL)
00587     error (_("unable to load program"));
00588 
00589   /* FIXME: If a load command should reset the targets registers then
00590      a call to sim_create_inferior() should go here.  */
00591 
00592   sim_data->program_loaded = 1;
00593 }
00594 
00595 
00596 /* Start an inferior process and set inferior_ptid to its pid.
00597    EXEC_FILE is the file to run.
00598    ARGS is a string containing the arguments to the program.
00599    ENV is the environment vector to pass.  Errors reported with error().
00600    On VxWorks and various standalone systems, we ignore exec_file.  */
00601 /* This is called not only when we first attach, but also when the
00602    user types "run" after having attached.  */
00603 
00604 static void
00605 gdbsim_create_inferior (struct target_ops *target, char *exec_file, char *args,
00606                         char **env, int from_tty)
00607 {
00608   struct sim_inferior_data *sim_data
00609     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
00610   int len;
00611   char *arg_buf, **argv;
00612 
00613   if (exec_file == 0 || exec_bfd == 0)
00614     warning (_("No executable file specified."));
00615   if (!sim_data->program_loaded)
00616     warning (_("No program loaded."));
00617 
00618   if (remote_debug)
00619     fprintf_unfiltered (gdb_stdlog,
00620                         "gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n",
00621                         (exec_file ? exec_file : "(NULL)"),
00622                         args);
00623 
00624   if (ptid_equal (inferior_ptid, sim_data->remote_sim_ptid))
00625     gdbsim_kill (target);
00626   remove_breakpoints ();
00627   init_wait_for_inferior ();
00628 
00629   if (exec_file != NULL)
00630     {
00631       len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10;
00632       arg_buf = (char *) alloca (len);
00633       arg_buf[0] = '\0';
00634       strcat (arg_buf, exec_file);
00635       strcat (arg_buf, " ");
00636       strcat (arg_buf, args);
00637       argv = gdb_buildargv (arg_buf);
00638       make_cleanup_freeargv (argv);
00639     }
00640   else
00641     argv = NULL;
00642 
00643   if (!have_inferiors ())
00644     init_thread_list ();
00645 
00646   if (sim_create_inferior (sim_data->gdbsim_desc, exec_bfd, argv, env)
00647       != SIM_RC_OK)
00648     error (_("Unable to create sim inferior."));
00649 
00650   inferior_ptid = sim_data->remote_sim_ptid;
00651   inferior_appeared (current_inferior (), ptid_get_pid (inferior_ptid));
00652   add_thread_silent (inferior_ptid);
00653 
00654   insert_breakpoints ();        /* Needed to get correct instruction
00655                                    in cache.  */
00656 
00657   clear_proceed_status ();
00658 }
00659 
00660 /* The open routine takes the rest of the parameters from the command,
00661    and (if successful) pushes a new target onto the stack.
00662    Targets should supply this routine, if only to provide an error message.  */
00663 /* Called when selecting the simulator.  E.g. (gdb) target sim name.  */
00664 
00665 static void
00666 gdbsim_open (char *args, int from_tty)
00667 {
00668   int len;
00669   char *arg_buf;
00670   struct sim_inferior_data *sim_data;
00671   SIM_DESC gdbsim_desc;
00672 
00673   if (remote_debug)
00674     fprintf_unfiltered (gdb_stdlog,
00675                         "gdbsim_open: args \"%s\"\n", args ? args : "(null)");
00676 
00677   /* Ensure that the sim target is not on the target stack.  This is
00678      necessary, because if it is on the target stack, the call to
00679      push_target below will invoke sim_close(), thus freeing various
00680      state (including a sim instance) that we allocate prior to
00681      invoking push_target().  We want to delay the push_target()
00682      operation until after we complete those operations which could
00683      error out.  */
00684   if (gdbsim_is_open)
00685     unpush_target (&gdbsim_ops);
00686 
00687   len = (7 + 1                  /* gdbsim */
00688          + strlen (" -E little")
00689          + strlen (" --architecture=xxxxxxxxxx")
00690          + strlen (" --sysroot=") + strlen (gdb_sysroot) +
00691          + (args ? strlen (args) : 0)
00692          + 50) /* slack */ ;
00693   arg_buf = (char *) alloca (len);
00694   strcpy (arg_buf, "gdbsim");   /* 7 */
00695   /* Specify the byte order for the target when it is explicitly
00696      specified by the user (not auto detected).  */
00697   switch (selected_byte_order ())
00698     {
00699     case BFD_ENDIAN_BIG:
00700       strcat (arg_buf, " -E big");
00701       break;
00702     case BFD_ENDIAN_LITTLE:
00703       strcat (arg_buf, " -E little");
00704       break;
00705     case BFD_ENDIAN_UNKNOWN:
00706       break;
00707     }
00708   /* Specify the architecture of the target when it has been
00709      explicitly specified */
00710   if (selected_architecture_name () != NULL)
00711     {
00712       strcat (arg_buf, " --architecture=");
00713       strcat (arg_buf, selected_architecture_name ());
00714     }
00715   /* Pass along gdb's concept of the sysroot.  */
00716   strcat (arg_buf, " --sysroot=");
00717   strcat (arg_buf, gdb_sysroot);
00718   /* finally, any explicit args */
00719   if (args)
00720     {
00721       strcat (arg_buf, " ");    /* 1 */
00722       strcat (arg_buf, args);
00723     }
00724   sim_argv = gdb_buildargv (arg_buf);
00725 
00726   init_callbacks ();
00727   gdbsim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback, exec_bfd, sim_argv);
00728 
00729   if (gdbsim_desc == 0)
00730     {
00731       freeargv (sim_argv);
00732       sim_argv = NULL;
00733       error (_("unable to create simulator instance"));
00734     }
00735 
00736   /* Reset the pid numberings for this batch of sim instances.  */
00737   next_pid = INITIAL_PID;
00738 
00739   /* Allocate the inferior data, but do not allocate a sim instance
00740      since we've already just done that.  */
00741   sim_data = get_sim_inferior_data (current_inferior (),
00742                                     SIM_INSTANCE_NOT_NEEDED);
00743 
00744   sim_data->gdbsim_desc = gdbsim_desc;
00745 
00746   push_target (&gdbsim_ops);
00747   printf_filtered ("Connected to the simulator.\n");
00748 
00749   /* There's nothing running after "target sim" or "load"; not until
00750      "run".  */
00751   inferior_ptid = null_ptid;
00752 
00753   gdbsim_is_open = 1;
00754 }
00755 
00756 /* Callback for iterate_over_inferiors.  Called (indirectly) by
00757    gdbsim_close().  */
00758 
00759 static int
00760 gdbsim_close_inferior (struct inferior *inf, void *arg)
00761 {
00762   struct sim_inferior_data *sim_data = inferior_data (inf,
00763                                                       sim_inferior_data_key);
00764   if (sim_data != NULL)
00765     {
00766       ptid_t ptid = sim_data->remote_sim_ptid;
00767 
00768       sim_inferior_data_cleanup (inf, sim_data);
00769       set_inferior_data (inf, sim_inferior_data_key, NULL);
00770 
00771       /* Having a ptid allocated and stored in remote_sim_ptid does
00772          not mean that a corresponding inferior was ever created.
00773          Thus we need to verify the existence of an inferior using the
00774          pid in question before setting inferior_ptid via
00775          switch_to_thread() or mourning the inferior.  */
00776       if (find_inferior_pid (ptid_get_pid (ptid)) != NULL)
00777         {
00778           switch_to_thread (ptid);
00779           generic_mourn_inferior ();
00780         }
00781     }
00782 
00783   return 0;
00784 }
00785 
00786 /* Close out all files and local state before this target loses control.  */
00787 
00788 static void
00789 gdbsim_close (void)
00790 {
00791   struct sim_inferior_data *sim_data
00792     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
00793 
00794   if (remote_debug)
00795     fprintf_unfiltered (gdb_stdlog, "gdbsim_close\n");
00796 
00797   iterate_over_inferiors (gdbsim_close_inferior, NULL);
00798 
00799   if (sim_argv != NULL)
00800     {
00801       freeargv (sim_argv);
00802       sim_argv = NULL;
00803     }
00804 
00805   end_callbacks ();
00806 
00807   gdbsim_is_open = 0;
00808 }
00809 
00810 /* Takes a program previously attached to and detaches it.
00811    The program may resume execution (some targets do, some don't) and will
00812    no longer stop on signals, etc.  We better not have left any breakpoints
00813    in the program or it'll die when it hits one.  ARGS is arguments
00814    typed by the user (e.g. a signal to send the process).  FROM_TTY
00815    says whether to be verbose or not.  */
00816 /* Terminate the open connection to the remote debugger.
00817    Use this when you want to detach and do something else with your gdb.  */
00818 
00819 static void
00820 gdbsim_detach (struct target_ops *ops, char *args, int from_tty)
00821 {
00822   if (remote_debug)
00823     fprintf_unfiltered (gdb_stdlog, "gdbsim_detach: args \"%s\"\n", args);
00824 
00825   unpush_target (ops);          /* calls gdbsim_close to do the real work */
00826   if (from_tty)
00827     printf_filtered ("Ending simulator %s debugging\n", target_shortname);
00828 }
00829 
00830 /* Resume execution of the target process.  STEP says whether to single-step
00831    or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
00832    to the target, or zero for no signal.  */
00833 
00834 struct resume_data
00835 {
00836   enum gdb_signal siggnal;
00837   int step;
00838 };
00839 
00840 static int
00841 gdbsim_resume_inferior (struct inferior *inf, void *arg)
00842 {
00843   struct sim_inferior_data *sim_data
00844     = get_sim_inferior_data (inf, SIM_INSTANCE_NOT_NEEDED);
00845   struct resume_data *rd = arg;
00846 
00847   if (sim_data)
00848     {
00849       sim_data->resume_siggnal = rd->siggnal;
00850       sim_data->resume_step = rd->step;
00851 
00852       if (remote_debug)
00853         fprintf_unfiltered (gdb_stdlog,
00854                             _("gdbsim_resume: pid %d, step %d, signal %d\n"),
00855                             inf->pid, rd->step, rd->siggnal);
00856     }
00857 
00858   /* When called from iterate_over_inferiors, a zero return causes the
00859      iteration process to proceed until there are no more inferiors to
00860      consider.  */
00861   return 0;
00862 }
00863 
00864 static void
00865 gdbsim_resume (struct target_ops *ops,
00866                ptid_t ptid, int step, enum gdb_signal siggnal)
00867 {
00868   struct resume_data rd;
00869   struct sim_inferior_data *sim_data
00870     = get_sim_inferior_data_by_ptid (ptid, SIM_INSTANCE_NOT_NEEDED);
00871 
00872   rd.siggnal = siggnal;
00873   rd.step = step;
00874 
00875   /* We don't access any sim_data members within this function.
00876      What's of interest is whether or not the call to
00877      get_sim_inferior_data_by_ptid(), above, is able to obtain a
00878      non-NULL pointer.  If it managed to obtain a non-NULL pointer, we
00879      know we have a single inferior to consider.  If it's NULL, we
00880      either have multiple inferiors to resume or an error condition.  */
00881 
00882   if (sim_data)
00883     gdbsim_resume_inferior (find_inferior_pid (ptid_get_pid (ptid)), &rd);
00884   else if (ptid_equal (ptid, minus_one_ptid))
00885     iterate_over_inferiors (gdbsim_resume_inferior, &rd);
00886   else
00887     error (_("The program is not being run."));
00888 }
00889 
00890 /* Notify the simulator of an asynchronous request to stop.
00891 
00892    The simulator shall ensure that the stop request is eventually
00893    delivered to the simulator.  If the call is made while the
00894    simulator is not running then the stop request is processed when
00895    the simulator is next resumed.
00896 
00897    For simulators that do not support this operation, just abort.  */
00898 
00899 static int
00900 gdbsim_stop_inferior (struct inferior *inf, void *arg)
00901 {
00902   struct sim_inferior_data *sim_data
00903     = get_sim_inferior_data (inf, SIM_INSTANCE_NEEDED);
00904 
00905   if (sim_data)
00906     {
00907       if (!sim_stop (sim_data->gdbsim_desc))
00908         {
00909           quit ();
00910         }
00911     }
00912 
00913   /* When called from iterate_over_inferiors, a zero return causes the
00914      iteration process to proceed until there are no more inferiors to
00915      consider.  */
00916   return 0;
00917 }
00918 
00919 static void
00920 gdbsim_stop (ptid_t ptid)
00921 {
00922   struct sim_inferior_data *sim_data;
00923 
00924   if (ptid_equal (ptid, minus_one_ptid))
00925     {
00926       iterate_over_inferiors (gdbsim_stop_inferior, NULL);
00927     }
00928   else
00929     {
00930       struct inferior *inf = find_inferior_pid (ptid_get_pid (ptid));
00931 
00932       if (inf == NULL)
00933         error (_("Can't stop pid %d.  No inferior found."),
00934                ptid_get_pid (ptid));
00935 
00936       gdbsim_stop_inferior (inf, NULL);
00937     }
00938 }
00939 
00940 /* GDB version of os_poll_quit callback.
00941    Taken from gdb/util.c - should be in a library.  */
00942 
00943 static int
00944 gdb_os_poll_quit (host_callback *p)
00945 {
00946   if (deprecated_ui_loop_hook != NULL)
00947     deprecated_ui_loop_hook (0);
00948 
00949   if (check_quit_flag ())       /* gdb's idea of quit */
00950     {
00951       clear_quit_flag ();       /* we've stolen it */
00952       return 1;
00953     }
00954   return 0;
00955 }
00956 
00957 /* Wait for inferior process to do something.  Return pid of child,
00958    or -1 in case of error; store status through argument pointer STATUS,
00959    just as `wait' would.  */
00960 
00961 static void
00962 gdbsim_cntrl_c (int signo)
00963 {
00964   gdbsim_stop (minus_one_ptid);
00965 }
00966 
00967 static ptid_t
00968 gdbsim_wait (struct target_ops *ops,
00969              ptid_t ptid, struct target_waitstatus *status, int options)
00970 {
00971   struct sim_inferior_data *sim_data;
00972   static RETSIGTYPE (*prev_sigint) ();
00973   int sigrc = 0;
00974   enum sim_stop reason = sim_running;
00975 
00976   /* This target isn't able to (yet) resume more than one inferior at a time.
00977      When ptid is minus_one_ptid, just use the current inferior.  If we're
00978      given an explicit pid, we'll try to find it and use that instead.  */
00979   if (ptid_equal (ptid, minus_one_ptid))
00980     sim_data = get_sim_inferior_data (current_inferior (),
00981                                       SIM_INSTANCE_NEEDED);
00982   else
00983     {
00984       sim_data = get_sim_inferior_data_by_ptid (ptid, SIM_INSTANCE_NEEDED);
00985       if (sim_data == NULL)
00986         error (_("Unable to wait for pid %d.  Inferior not found."),
00987                ptid_get_pid (ptid));
00988       inferior_ptid = ptid;
00989     }
00990 
00991   if (remote_debug)
00992     fprintf_unfiltered (gdb_stdlog, "gdbsim_wait\n");
00993 
00994 #if defined (HAVE_SIGACTION) && defined (SA_RESTART)
00995   {
00996     struct sigaction sa, osa;
00997     sa.sa_handler = gdbsim_cntrl_c;
00998     sigemptyset (&sa.sa_mask);
00999     sa.sa_flags = 0;
01000     sigaction (SIGINT, &sa, &osa);
01001     prev_sigint = osa.sa_handler;
01002   }
01003 #else
01004   prev_sigint = signal (SIGINT, gdbsim_cntrl_c);
01005 #endif
01006   sim_resume (sim_data->gdbsim_desc, sim_data->resume_step,
01007               sim_data->resume_siggnal);
01008 
01009   signal (SIGINT, prev_sigint);
01010   sim_data->resume_step = 0;
01011 
01012   sim_stop_reason (sim_data->gdbsim_desc, &reason, &sigrc);
01013 
01014   switch (reason)
01015     {
01016     case sim_exited:
01017       status->kind = TARGET_WAITKIND_EXITED;
01018       status->value.integer = sigrc;
01019       break;
01020     case sim_stopped:
01021       switch (sigrc)
01022         {
01023         case GDB_SIGNAL_ABRT:
01024           quit ();
01025           break;
01026         case GDB_SIGNAL_INT:
01027         case GDB_SIGNAL_TRAP:
01028         default:
01029           status->kind = TARGET_WAITKIND_STOPPED;
01030           status->value.sig = sigrc;
01031           break;
01032         }
01033       break;
01034     case sim_signalled:
01035       status->kind = TARGET_WAITKIND_SIGNALLED;
01036       status->value.sig = sigrc;
01037       break;
01038     case sim_running:
01039     case sim_polling:
01040       /* FIXME: Is this correct?  */
01041       break;
01042     }
01043 
01044   return inferior_ptid;
01045 }
01046 
01047 /* Get ready to modify the registers array.  On machines which store
01048    individual registers, this doesn't need to do anything.  On machines
01049    which store all the registers in one fell swoop, this makes sure
01050    that registers contains all the registers from the program being
01051    debugged.  */
01052 
01053 static void
01054 gdbsim_prepare_to_store (struct regcache *regcache)
01055 {
01056   /* Do nothing, since we can store individual regs.  */
01057 }
01058 
01059 /* Helper for gdbsim_xfer_partial that handles memory transfers.
01060    Arguments are like target_xfer_partial.  */
01061 
01062 static LONGEST
01063 gdbsim_xfer_memory (struct target_ops *target,
01064                     gdb_byte *readbuf, const gdb_byte *writebuf,
01065                     ULONGEST memaddr, LONGEST len)
01066 {
01067   struct sim_inferior_data *sim_data
01068     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
01069 
01070   /* If this target doesn't have memory yet, return 0 causing the
01071      request to be passed to a lower target, hopefully an exec
01072      file.  */
01073   if (!target->to_has_memory (target))
01074     return 0;
01075 
01076   if (!sim_data->program_loaded)
01077     error (_("No program loaded."));
01078 
01079   /* Note that we obtained the sim_data pointer above using
01080      SIM_INSTANCE_NOT_NEEDED.  We do this so that we don't needlessly
01081      allocate a sim instance prior to loading a program.   If we
01082      get to this point in the code though, gdbsim_desc should be
01083      non-NULL.  (Note that a sim instance is needed in order to load
01084      the program...)  */
01085   gdb_assert (sim_data->gdbsim_desc != NULL);
01086 
01087   if (remote_debug)
01088     fprintf_unfiltered (gdb_stdlog,
01089                         "gdbsim_xfer_memory: readbuf %s, writebuf %s, "
01090                         "memaddr %s, len %s\n",
01091                         host_address_to_string (readbuf),
01092                         host_address_to_string (writebuf),
01093                         paddress (target_gdbarch (), memaddr),
01094                         plongest (len));
01095 
01096   if (writebuf)
01097     {
01098       if (remote_debug && len > 0)
01099         dump_mem (writebuf, len);
01100       len = sim_write (sim_data->gdbsim_desc, memaddr, writebuf, len);
01101     }
01102   else
01103     {
01104       len = sim_read (sim_data->gdbsim_desc, memaddr, readbuf, len);
01105       if (remote_debug && len > 0)
01106         dump_mem (readbuf, len);
01107     }
01108   return len;
01109 }
01110 
01111 /* Target to_xfer_partial implementation.  */
01112 
01113 static LONGEST
01114 gdbsim_xfer_partial (struct target_ops *ops, enum target_object object,
01115                      const char *annex, gdb_byte *readbuf,
01116                      const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
01117 {
01118   switch (object)
01119     {
01120     case TARGET_OBJECT_MEMORY:
01121       return gdbsim_xfer_memory (ops, readbuf, writebuf, offset, len);
01122 
01123     default:
01124       return -1;
01125     }
01126 }
01127 
01128 static void
01129 gdbsim_files_info (struct target_ops *target)
01130 {
01131   struct sim_inferior_data *sim_data
01132     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
01133   const char *file = "nothing";
01134 
01135   if (exec_bfd)
01136     file = bfd_get_filename (exec_bfd);
01137 
01138   if (remote_debug)
01139     fprintf_unfiltered (gdb_stdlog, "gdbsim_files_info: file \"%s\"\n", file);
01140 
01141   if (exec_bfd)
01142     {
01143       fprintf_unfiltered (gdb_stdlog, "\tAttached to %s running program %s\n",
01144                           target_shortname, file);
01145       sim_info (sim_data->gdbsim_desc, 0);
01146     }
01147 }
01148 
01149 /* Clear the simulator's notion of what the break points are.  */
01150 
01151 static void
01152 gdbsim_mourn_inferior (struct target_ops *target)
01153 {
01154   struct sim_inferior_data *sim_data
01155     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
01156 
01157   if (remote_debug)
01158     fprintf_unfiltered (gdb_stdlog, "gdbsim_mourn_inferior:\n");
01159 
01160   remove_breakpoints ();
01161   generic_mourn_inferior ();
01162   delete_thread_silent (sim_data->remote_sim_ptid);
01163 }
01164 
01165 /* Pass the command argument through to the simulator verbatim.  The
01166    simulator must do any command interpretation work.  */
01167 
01168 void
01169 simulator_command (char *args, int from_tty)
01170 {
01171   struct sim_inferior_data *sim_data;
01172 
01173   /* We use inferior_data() instead of get_sim_inferior_data() here in
01174      order to avoid attaching a sim_inferior_data struct to an
01175      inferior unnecessarily.  The reason we take such care here is due
01176      to the fact that this function, simulator_command(), may be called
01177      even when the sim target is not active.  If we were to use
01178      get_sim_inferior_data() here, it is possible that this call would
01179      be made either prior to gdbsim_open() or after gdbsim_close(),
01180      thus allocating memory that would not be garbage collected until
01181      the ultimate destruction of the associated inferior.  */
01182 
01183   sim_data  = inferior_data (current_inferior (), sim_inferior_data_key);
01184   if (sim_data == NULL || sim_data->gdbsim_desc == NULL)
01185     {
01186 
01187       /* PREVIOUSLY: The user may give a command before the simulator
01188          is opened. [...] (??? assuming of course one wishes to
01189          continue to allow commands to be sent to unopened simulators,
01190          which isn't entirely unreasonable).  */
01191 
01192       /* The simulator is a builtin abstraction of a remote target.
01193          Consistent with that model, access to the simulator, via sim
01194          commands, is restricted to the period when the channel to the
01195          simulator is open.  */
01196 
01197       error (_("Not connected to the simulator target"));
01198     }
01199 
01200   sim_do_command (sim_data->gdbsim_desc, args);
01201 
01202   /* Invalidate the register cache, in case the simulator command does
01203      something funny.  */
01204   registers_changed ();
01205 }
01206 
01207 static VEC (char_ptr) *
01208 sim_command_completer (struct cmd_list_element *ignore, const char *text,
01209                        const char *word)
01210 {
01211   struct sim_inferior_data *sim_data;
01212   char **tmp;
01213   int i;
01214   VEC (char_ptr) *result = NULL;
01215 
01216   sim_data = inferior_data (current_inferior (), sim_inferior_data_key);
01217   if (sim_data == NULL || sim_data->gdbsim_desc == NULL)
01218     return NULL;
01219 
01220   tmp = sim_complete_command (sim_data->gdbsim_desc, text, word);
01221   if (tmp == NULL)
01222     return NULL;
01223 
01224   /* Transform the array into a VEC, and then free the array.  */
01225   for (i = 0; tmp[i] != NULL; i++)
01226     VEC_safe_push (char_ptr, result, tmp[i]);
01227   xfree (tmp);
01228 
01229   return result;
01230 }
01231 
01232 /* Check to see if a thread is still alive.  */
01233 
01234 static int
01235 gdbsim_thread_alive (struct target_ops *ops, ptid_t ptid)
01236 {
01237   struct sim_inferior_data *sim_data
01238     = get_sim_inferior_data_by_ptid (ptid, SIM_INSTANCE_NOT_NEEDED);
01239 
01240   if (sim_data == NULL)
01241     return 0;
01242 
01243   if (ptid_equal (ptid, sim_data->remote_sim_ptid))
01244     /* The simulators' task is always alive.  */
01245     return 1;
01246 
01247   return 0;
01248 }
01249 
01250 /* Convert a thread ID to a string.  Returns the string in a static
01251    buffer.  */
01252 
01253 static char *
01254 gdbsim_pid_to_str (struct target_ops *ops, ptid_t ptid)
01255 {
01256   return normal_pid_to_str (ptid);
01257 }
01258 
01259 /* Simulator memory may be accessed after the program has been loaded.  */
01260 
01261 static int
01262 gdbsim_has_all_memory (struct target_ops *ops)
01263 {
01264   struct sim_inferior_data *sim_data
01265     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
01266 
01267   if (!sim_data->program_loaded)
01268     return 0;
01269 
01270   return 1;
01271 }
01272 
01273 static int
01274 gdbsim_has_memory (struct target_ops *ops)
01275 {
01276   struct sim_inferior_data *sim_data
01277     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
01278 
01279   if (!sim_data->program_loaded)
01280     return 0;
01281 
01282   return 1;
01283 }
01284 
01285 /* Define the target subroutine names.  */
01286 
01287 struct target_ops gdbsim_ops;
01288 
01289 static void
01290 init_gdbsim_ops (void)
01291 {
01292   gdbsim_ops.to_shortname = "sim";
01293   gdbsim_ops.to_longname = "simulator";
01294   gdbsim_ops.to_doc = "Use the compiled-in simulator.";
01295   gdbsim_ops.to_open = gdbsim_open;
01296   gdbsim_ops.to_close = gdbsim_close;
01297   gdbsim_ops.to_detach = gdbsim_detach;
01298   gdbsim_ops.to_resume = gdbsim_resume;
01299   gdbsim_ops.to_wait = gdbsim_wait;
01300   gdbsim_ops.to_fetch_registers = gdbsim_fetch_register;
01301   gdbsim_ops.to_store_registers = gdbsim_store_register;
01302   gdbsim_ops.to_prepare_to_store = gdbsim_prepare_to_store;
01303   gdbsim_ops.to_xfer_partial = gdbsim_xfer_partial;
01304   gdbsim_ops.to_files_info = gdbsim_files_info;
01305   gdbsim_ops.to_insert_breakpoint = memory_insert_breakpoint;
01306   gdbsim_ops.to_remove_breakpoint = memory_remove_breakpoint;
01307   gdbsim_ops.to_kill = gdbsim_kill;
01308   gdbsim_ops.to_load = gdbsim_load;
01309   gdbsim_ops.to_create_inferior = gdbsim_create_inferior;
01310   gdbsim_ops.to_mourn_inferior = gdbsim_mourn_inferior;
01311   gdbsim_ops.to_stop = gdbsim_stop;
01312   gdbsim_ops.to_thread_alive = gdbsim_thread_alive;
01313   gdbsim_ops.to_pid_to_str = gdbsim_pid_to_str;
01314   gdbsim_ops.to_stratum = process_stratum;
01315   gdbsim_ops.to_has_all_memory = gdbsim_has_all_memory;
01316   gdbsim_ops.to_has_memory = gdbsim_has_memory;
01317   gdbsim_ops.to_has_stack = default_child_has_stack;
01318   gdbsim_ops.to_has_registers = default_child_has_registers;
01319   gdbsim_ops.to_has_execution = default_child_has_execution;
01320   gdbsim_ops.to_magic = OPS_MAGIC;
01321 }
01322 
01323 void
01324 _initialize_remote_sim (void)
01325 {
01326   struct cmd_list_element *c;
01327 
01328   init_gdbsim_ops ();
01329   add_target (&gdbsim_ops);
01330 
01331   c = add_com ("sim", class_obscure, simulator_command,
01332                _("Send a command to the simulator."));
01333   set_cmd_completer (c, sim_command_completer);
01334 
01335   sim_inferior_data_key
01336     = register_inferior_data_with_cleanup (NULL, sim_inferior_data_cleanup);
01337 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines