Fix crash when exiting TUI with gdb -tui
[deliverable/binutils-gdb.git] / sim / cris / sim-if.c
index 71afbff31df2a6bc88a5f95b4177e8dcc4eca5cb..67e8d691591ca8606ec12f8b3e4463447963a7e2 100644 (file)
@@ -1,5 +1,5 @@
 /* Main simulator entry points specific to the CRIS.
-   Copyright (C) 2004-2015 Free Software Foundation, Inc.
+   Copyright (C) 2004-2020 Free Software Foundation, Inc.
    Contributed by Axis Communications.
 
 This file is part of the GNU simulators.
@@ -81,10 +81,6 @@ static int cris_program_offset = 0;
 enum cris_unknown_syscall_action_type cris_unknown_syscall_action
   = CRIS_USYSC_MSG_STOP;
 
-/* Records simulator descriptor so utilities like cris_dump_regs can be
-   called from gdb.  */
-SIM_DESC current_state;
-
 /* CRIS-specific options.  */
 typedef enum {
   OPTION_CRIS_STATS = OPTION_START,
@@ -233,32 +229,6 @@ cris_option_handler (SIM_DESC sd, sim_cpu *cpu ATTRIBUTE_UNUSED, int opt,
   return sim_profile_set_option (sd, "-model", PROFILE_MODEL_IDX, "on");
 }
 
-/* FIXME: Remove these, globalize those in sim-load.c, move elsewhere.  */
-
-static void
-xprintf  (host_callback *callback, const char *fmt, ...)
-{
-  va_list ap;
-
-  va_start (ap, fmt);
-
-  (*callback->vprintf_filtered) (callback, fmt, ap);
-
-  va_end (ap);
-}
-
-static void
-eprintf (host_callback *callback, const char *fmt, ...)
-{
-  va_list ap;
-
-  va_start (ap, fmt);
-
-  (*callback->evprintf_filtered) (callback, fmt, ap);
-
-  va_end (ap);
-}
-
 /* An ELF-specific simplified ../common/sim-load.c:sim_load_file,
    using the program headers, not sections, in order to make sure that
    the program headers themeselves are also loaded.  The caller is
@@ -271,7 +241,6 @@ cris_load_elf_file (SIM_DESC sd, struct bfd *abfd, sim_write_fn do_write)
   int n_hdrs;
   int i;
   bfd_boolean verbose = STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG;
-  host_callback *callback = STATE_CALLBACK (sd);
 
   phdr = elf_tdata (abfd)->phdr;
   n_hdrs = elf_elfheader (abfd)->e_phnum;
@@ -290,24 +259,24 @@ cris_load_elf_file (SIM_DESC sd, struct bfd *abfd, sim_write_fn do_write)
       buf = xmalloc (phdr[i].p_filesz);
 
       if (verbose)
-       xprintf (callback, "Loading segment at 0x%lx, size 0x%lx\n",
-                lma, phdr[i].p_filesz);
+       sim_io_printf (sd, "Loading segment at 0x%lx, size 0x%lx\n",
+                      lma, phdr[i].p_filesz);
 
       if (bfd_seek (abfd, phdr[i].p_offset, SEEK_SET) != 0
          || (bfd_bread (buf, phdr[i].p_filesz, abfd) != phdr[i].p_filesz))
        {
-         eprintf (callback,
-                  "%s: could not read segment at 0x%lx, size 0x%lx\n",
-                  STATE_MY_NAME (sd), lma, phdr[i].p_filesz);
+         sim_io_eprintf (sd,
+                         "%s: could not read segment at 0x%lx, size 0x%lx\n",
+                         STATE_MY_NAME (sd), lma, phdr[i].p_filesz);
          free (buf);
          return FALSE;
        }
 
       if (do_write (sd, lma, buf, phdr[i].p_filesz) != phdr[i].p_filesz)
        {
-         eprintf (callback,
-                  "%s: could not load segment at 0x%lx, size 0x%lx\n",
-                  STATE_MY_NAME (sd), lma, phdr[i].p_filesz);
+         sim_io_eprintf (sd,
+                         "%s: could not load segment at 0x%lx, size 0x%lx\n",
+                         STATE_MY_NAME (sd), lma, phdr[i].p_filesz);
          free (buf);
          return FALSE;
        }
@@ -346,17 +315,17 @@ cris_set_section_offset_iterator (bfd *abfd, asection *s, void *vp)
   SIM_DESC sd = p->sd;
   int offset = p->offset;
 
-  if ((bfd_get_section_flags (abfd, s) & SEC_ALLOC))
+  if ((bfd_section_flags (s) & SEC_ALLOC))
     {
-      bfd_vma vma = bfd_get_section_vma (abfd, s);
+      bfd_vma vma = bfd_section_vma (s);
       
-      bfd_set_section_vma (abfd, s, vma + offset);
+      bfd_set_section_vma (s, vma + offset);
     }
 
   /* This seems clumsy and inaccurate, but let's stick to doing it the
      same way as sim_analyze_program for consistency.  */
-  if (strcmp (bfd_get_section_name (abfd, s), ".text") == 0)
-    STATE_TEXT_START (sd) = bfd_get_section_vma (abfd, s);
+  if (strcmp (bfd_section_name (s), ".text") == 0)
+    STATE_TEXT_START (sd) = bfd_section_vma (s);
 }
 
 /* Adjust the start-address, LMA and VMA of a SD.  Must be called
@@ -391,10 +360,10 @@ get_progbounds_iterator (bfd *abfd ATTRIBUTE_UNUSED, asection *s, void *vp)
 {
   struct progbounds *pbp = (struct progbounds *) vp;
 
-  if ((bfd_get_section_flags (abfd, s) & SEC_ALLOC))
+  if ((bfd_section_flags (s) & SEC_ALLOC))
     {
-      bfd_size_type sec_size = bfd_get_section_size (s);
-      bfd_size_type sec_start = bfd_get_section_vma (abfd, s);
+      bfd_size_type sec_size = bfd_section_size (s);
+      bfd_size_type sec_start = bfd_section_vma (s);
       bfd_size_type sec_end = sec_start + sec_size;
 
       if (sec_end > pbp->endmem)
@@ -403,7 +372,7 @@ get_progbounds_iterator (bfd *abfd ATTRIBUTE_UNUSED, asection *s, void *vp)
       if (sec_start < pbp->startmem)
        pbp->startmem = sec_start;
 
-      if ((bfd_get_section_flags (abfd, s) & SEC_LOAD))
+      if ((bfd_section_flags (s) & SEC_LOAD))
        {
          if (sec_end > pbp->end_loadmem)
            pbp->end_loadmem = sec_end;
@@ -648,7 +617,7 @@ cris_handle_interpreter (SIM_DESC sd, struct bfd *abfd)
 
 SIM_DESC
 sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
-         char **argv)
+         char * const *argv)
 {
   char c;
   int i;
@@ -711,9 +680,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
       return 0;
     }
 
-  /* getopt will print the error message so we just have to exit if this fails.
-     FIXME: Hmmm...  in the case of gdb we need getopt to call
-     print_filtered.  */
+  /* The parser will print an error message for us, so we silently return.  */
   if (sim_parse_args (sd, argv) != SIM_RC_OK)
     {
       free_state (sd);
@@ -779,7 +746,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
      specified.  */
   if (abfd != NULL && !cris_bare_iron)
     {
-      char *name = bfd_get_filename (abfd);
+      const char *name = bfd_get_filename (abfd);
       char **my_environ = GET_ENVIRON ();
       /* We use these maps to give the same behavior as the old xsim
         simulator.  */
@@ -819,7 +786,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
       /* Note that the linux kernel does not correctly compute the storage
         needs for the static-exe AUX vector.  */
 
-      csp -= sizeof (auxv_entries) / sizeof (auxv_entries[0]) * 4 * 2;
+      csp -= ARRAY_SIZE (auxv_entries) * 4 * 2;
 
       csp -= (envc + 1) * 4;
       csp -= (my_argc + 1) * 4;
@@ -907,7 +874,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
        goto abandon_chip;
 
       if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
-       for (i = 0; i < sizeof (auxv_entries) / sizeof (auxv_entries[0]); i++)
+       for (i = 0; i < ARRAY_SIZE (auxv_entries); i++)
          {
            write_dword (csp, auxv_entries[i].id);
            write_dword (csp + 4,
@@ -985,10 +952,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
      Must be done after cris_cgen_cpu_open.  */
   cgen_init (sd);
 
-  /* Store in a global so things like cris_dump_regs can be invoked
-     from the gdb command line.  */
-  current_state = sd;
-
   cris_set_callbacks (callback);
 
   return sd;
@@ -996,8 +959,8 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 \f
 SIM_RC
 sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
-                    char **argv ATTRIBUTE_UNUSED,
-                    char **envp ATTRIBUTE_UNUSED)
+                    char * const *argv ATTRIBUTE_UNUSED,
+                    char * const *envp ATTRIBUTE_UNUSED)
 {
   SIM_CPU *current_cpu = STATE_CPU (sd, 0);
   SIM_ADDR addr;
This page took 0.025931 seconds and 4 git commands to generate.