* target.h: Add enum target_waitkind, enum target_signal, and
[deliverable/binutils-gdb.git] / gdb / xcoffexec.c
index 7a57f9c854f0042b994291e0ab36459ff8a966be..cb20bc30c08adc3c7745d75dcb2c6731412867d7 100644 (file)
@@ -81,6 +81,7 @@ exec_close(quitting)
 {
   register struct vmap *vp, *nxt;
   struct objfile *obj;
+  int need_symtab_cleanup = 0;
   
   for (nxt = vmap; vp = nxt; )
     {
@@ -90,7 +91,10 @@ exec_close(quitting)
         free_objfile() will do proper cleanup of objfile *and* bfd. */
                   
       if (vp->objfile)
-       free_objfile (vp->objfile);
+       {
+         free_objfile (vp->objfile);
+         need_symtab_cleanup = 1;
+       }
       else
        bfd_close(vp->bfd);
 
@@ -111,6 +115,9 @@ exec_close(quitting)
     exec_ops.to_sections = NULL;
     exec_ops.to_sections_end = NULL;
   }
+
+  if (need_symtab_cleanup)
+    clear_symtab_users ();
 }
 
 /*
@@ -140,7 +147,7 @@ char *filename;
        if (scratch_chan < 0)
          perror_with_name(filename);
 
-       exec_bfd = bfd_fdopenr(scratch_pathname, NULL, scratch_chan);
+       exec_bfd = bfd_fdopenr(scratch_pathname, gnutarget, scratch_chan);
        if (!exec_bfd)
          error("Could not open `%s' as an executable file: %s"
                      , scratch_pathname, bfd_errmsg(bfd_error));
@@ -177,7 +184,7 @@ char *filename;
   else {
        exec_close(0);  /* just in case */
        if (from_tty)
-         printf("No exec file now.\n");
+         printf_unfiltered("No exec file now.\n");
   }
 }
 
@@ -228,21 +235,22 @@ build_section_table (some_bfd, start, end)
 
   count = bfd_count_sections (some_bfd);
   if (count == 0)
-    abort();   /* return 1? */
+    fatal ("aborting");        /* return 1? */
   if (*start)
     free (*start);
   *start = (struct section_table *) xmalloc (count * sizeof (**start));
   *end = *start;
   bfd_map_over_sections (some_bfd, add_to_section_table, (char *)end);
   if (*end > *start + count)
-    abort();
+    fatal ("aborting");
   /* We could realloc the table, but it probably loses for most files.  */
   return 0;
 }
 \f
 void
-sex_to_vmap(bfd *bf, sec_ptr sex, struct vmap_and_bfd *vmap_bfd
+sex_to_vmap(bfd *bf, sec_ptr sex, PTR arg3
 {
+  struct vmap_and_bfd *vmap_bfd = (struct vmap_and_bfd *)arg3;
   register struct vmap *vp, **vpp;
   register struct symtab *syms;
   bfd *arch = vmap_bfd->pbfd;
@@ -269,7 +277,7 @@ sex_to_vmap(bfd *bf, sec_ptr sex, struct vmap_and_bfd *vmap_bfd)
   }
 
   else if (STREQ(bfd_section_name(bf, sex), ".bss"))   /* FIXMEmgo */
-    printf ("bss section in exec! Don't know what the heck to do!\n");
+    printf_unfiltered ("bss section in exec! Don't know what the heck to do!\n");
 }
 
 /* Make a vmap for the BFD "bf", which might be a member of the archive
@@ -282,7 +290,7 @@ map_vmap (bfd *bf, bfd *arch)
   struct objfile *obj;
 
   vp = (void*) xmalloc (sizeof (*vp));
-  bzero (vp, sizeof (*vp));
+  memset (vp, '\0', sizeof (*vp));
   vp->nxt = 0;
   vp->bfd = bf;
   vp->name = bfd_get_filename(arch ? arch : bf);
@@ -301,21 +309,21 @@ map_vmap (bfd *bf, bfd *arch)
 }
 
 
-/* true, if symbol table and minimal symbol table are relocated. */
-
-int symtab_relocated = 0;
-
-
 /*  vmap_symtab -      handle symbol translation on vmapping */
 
-vmap_symtab(vp, old_start, vip)
-register struct vmap *vp;
-CORE_ADDR old_start;
-struct stat *vip; 
+static void
+vmap_symtab (vp)
+     register struct vmap *vp;
 {
-  register struct symtab *s;
   register struct objfile *objfile;
-  register struct minimal_symbol *msymbol;
+  asection *textsec;
+  asection *datasec;
+  asection *bsssec;
+  CORE_ADDR text_delta;
+  CORE_ADDR data_delta;
+  CORE_ADDR bss_delta;
+  struct section_offsets *new_offsets;
+  int i;
   
   objfile = vp->objfile;
   if (objfile == NULL)
@@ -328,140 +336,55 @@ struct stat *vip;
       objfile = symfile_objfile;
     }
 
-  s = objfile->symtabs;
-
-       if (vp->tstart != old_start) {
-
-         /* Once we find a relocation base address for one of the symtabs
-            in this objfile, it will be the same for all symtabs in this
-            objfile. Clean this algorithm. FIXME. */
-
-         for (; s; s = s->next)
-           if (!s->nonreloc || LINETABLE(s))
-               vmap_symtab_1(s, vp, old_start);
-
-#if 1
-         /* I believe trampoline entries now have a name like
-            <trampoline>.  In any event, if something needs to be changed,
-            it should be changed in ALL_MSYMBOLS, so it works everywhere.  */
-         /*
-         Himm.., recently we nullified trampoline entry names in order not
-         to confuse them with real symbols.  Appearently this turned into a
-         problem, and msymbol vector did not get relocated properly.  If
-         msymbols have to have non-null names, then we should name
-         trampoline entries with empty strings. */
+  new_offsets = alloca
+    (sizeof (struct section_offsets)
+     + sizeof (new_offsets->offsets) * objfile->num_sections);
 
-         ALL_MSYMBOLS (objfile, msymbol)
-#else
-         for (msymbol = objfile->msymbols;
-              SYMBOL_NAME (msymbol) || SYMBOL_VALUE_ADDRESS (msymbol);
-              (msymbol)++)
-#endif
-             if (SYMBOL_VALUE_ADDRESS (msymbol) < TEXT_SEGMENT_BASE)
-               SYMBOL_VALUE_ADDRESS (msymbol) += vp->tstart - old_start;
-
-       }
-
-  if (vp->tstart != old_start) {
-    /* breakpoints need to be relocated as well. */
-    fixup_breakpoints (0, TEXT_SEGMENT_BASE, vp->tstart - old_start);
+  for (i = 0; i < objfile->num_sections; ++i)
+    ANOFFSET (new_offsets, i) = ANOFFSET (objfile->section_offsets, i);
+  
+  textsec = bfd_get_section_by_name (vp->bfd, ".text");
+  text_delta =
+    vp->tstart - ANOFFSET (objfile->section_offsets, textsec->target_index);
+  ANOFFSET (new_offsets, textsec->target_index) = vp->tstart;
+
+  datasec = bfd_get_section_by_name (vp->bfd, ".data");
+  data_delta =
+    vp->dstart - ANOFFSET (objfile->section_offsets, datasec->target_index);
+  ANOFFSET (new_offsets, datasec->target_index) = vp->dstart;
+  
+  bsssec = bfd_get_section_by_name (vp->bfd, ".bss");
+  bss_delta =
+    vp->dstart - ANOFFSET (objfile->section_offsets, bsssec->target_index);
+  ANOFFSET (new_offsets, bsssec->target_index) = vp->dstart;
+
+  objfile_relocate (objfile, new_offsets);
+
+  {
+    struct obj_section *s;
+    for (s = objfile->sections; s < objfile->sections_end; ++s)
+      {
+       if (s->sec_ptr->target_index == textsec->target_index)
+         {
+           s->addr += text_delta;
+           s->endaddr += text_delta;
+         }
+       else if (s->sec_ptr->target_index == datasec->target_index)
+         {
+           s->addr += data_delta;
+           s->endaddr += data_delta;
+         }
+       else if (s->sec_ptr->target_index == bsssec->target_index)
+         {
+           s->addr += bss_delta;
+           s->endaddr += bss_delta;
+         }
+      }
   }
   
-  symtab_relocated = 1;
-}
-
-
-vmap_symtab_1(s, vp, old_start)
-register struct symtab *s;
-register struct vmap *vp;
-CORE_ADDR old_start; 
-{
-    register int i, j;
-    int len, blen;
-    register struct linetable *l;
-    struct blockvector *bv;
-    register struct block *b;
-    int depth;
-    register ulong reloc, dreloc;
-    
-    if ((reloc = vp->tstart - old_start) == 0)
-       return;
-
-    dreloc = vp->dstart;                       /* data relocation */
-
-    /*
-     * The line table must be relocated.  This is only present for
-     * .text sections, so only vp->text type maps need be considered.
-     */
-    l = LINETABLE (s);
-    if (l) {
-      len = l->nitems;
-      for (i = 0; i < len; i++)
-       l->item[i].pc += reloc;
-    }
-
-    /* if this symbol table is not relocatable, only line table should
-       be relocated and the rest ignored. */
-    if (s->nonreloc)
-      return;
-    
-    bv  = BLOCKVECTOR(s);
-    len = BLOCKVECTOR_NBLOCKS(bv);
-    
-    for (i = 0; i < len; i++) {
-       b = BLOCKVECTOR_BLOCK(bv, i);
-       
-       BLOCK_START(b) += reloc;
-       BLOCK_END(b)   += reloc;
-       
-       blen = BLOCK_NSYMS(b);
-       for (j = 0; j < blen; j++) {
-           register struct symbol *sym;
-           
-           sym = BLOCK_SYM(b, j);
-           switch (SYMBOL_NAMESPACE(sym)) {
-             case STRUCT_NAMESPACE:
-             case UNDEF_NAMESPACE:
-               continue;
-               
-             case LABEL_NAMESPACE:
-             case VAR_NAMESPACE:
-               break;
-           }
-           
-           switch (SYMBOL_CLASS(sym)) {
-             case LOC_CONST:
-             case LOC_CONST_BYTES:
-             case LOC_LOCAL:
-             case LOC_REGISTER:
-             case LOC_ARG:
-             case LOC_LOCAL_ARG:
-             case LOC_REF_ARG:
-             case LOC_REGPARM:
-             case LOC_TYPEDEF:
-               continue;
-               
-#ifdef FIXME
-             case LOC_EXTERNAL:
-#endif
-             case LOC_LABEL:
-               SYMBOL_VALUE_ADDRESS(sym) += reloc;
-               break;
-
-             case LOC_STATIC:
-               SYMBOL_VALUE_ADDRESS(sym) += dreloc;
-               break;
-
-             case LOC_BLOCK:
-               break;
-               
-             default:
-               fatal("botched symbol class %x"
-                     , SYMBOL_CLASS(sym));
-               break;
-           }
-       }
-    }
+  if (text_delta != 0)
+    /* breakpoints need to be relocated as well. */
+    fixup_breakpoints (0, TEXT_SEGMENT_BASE, text_delta);
 }
 
 /* Add symbols for an objfile.  */
@@ -487,7 +410,7 @@ static struct vmap *
 add_vmap(ldi)
      register struct ld_info *ldi; 
 {
-       bfd *bfd, *last;
+       bfd *abfd, *last;
        register char *mem, *objname;
        struct objfile *obj;
        struct vmap *vp;
@@ -503,32 +426,32 @@ add_vmap(ldi)
        if (ldi->ldinfo_fd < 0)
          /* Note that this opens it once for every member; a possible
             enhancement would be to only open it once for every object.  */
-         bfd = bfd_openr (objname, NULL);
+         abfd = bfd_openr (objname, gnutarget);
        else
-         bfd = bfd_fdopenr(objname, NULL, ldi->ldinfo_fd);
-       if (!bfd)
+         abfd = bfd_fdopenr(objname, gnutarget, ldi->ldinfo_fd);
+       if (!abfd)
          error("Could not open `%s' as an executable file: %s",
                                        objname, bfd_errmsg(bfd_error));
 
 
        /* make sure we have an object file */
 
-       if (bfd_check_format(bfd, bfd_object))
-         vp = map_vmap (bfd, 0);
+       if (bfd_check_format(abfd, bfd_object))
+         vp = map_vmap (abfd, 0);
 
-       else if (bfd_check_format(bfd, bfd_archive)) {
+       else if (bfd_check_format(abfd, bfd_archive)) {
                last = 0;
                /*
                 * FIXME??? am I tossing BFDs?  bfd?
                 */
-               while (last = bfd_openr_next_archived_file(bfd, last))
+               while (last = bfd_openr_next_archived_file(abfd, last))
                        if (STREQ(mem, last->filename))
                                break;
 
                if (!last) {
-                 bfd_close(bfd);
+                 bfd_close(abfd);
                  /* FIXME -- should be error */
-                 warning("\"%s\": member \"%s\" missing.", bfd->filename, mem);
+                 warning("\"%s\": member \"%s\" missing.", abfd->filename, mem);
                  return;
                }
 
@@ -537,11 +460,11 @@ add_vmap(ldi)
                        goto obj_err;
                }
 
-               vp = map_vmap (last, bfd);
+               vp = map_vmap (last, abfd);
        }
        else {
            obj_err:
-               bfd_close(bfd);
+               bfd_close(abfd);
                error ("\"%s\": not in executable format: %s.",
                       objname, bfd_errmsg(bfd_error));
                /*NOTREACHED*/
@@ -551,10 +474,11 @@ add_vmap(ldi)
 
 #ifndef SOLIB_SYMBOLS_MANUAL
        if (catch_errors (objfile_symbol_add, (char *)obj,
-                         "Error while reading shared library symbols:\n"))
+                         "Error while reading shared library symbols:\n",
+                         RETURN_MASK_ALL))
          {
            /* Note this is only done if symbol reading was successful.  */
-           vmap_symtab (vp, 0, 0);
+           vmap_symtab (vp);
            vp->loaded = 1;
          }
 #endif
@@ -687,9 +611,10 @@ retry:
          /* found a corresponding VMAP. remap! */
          ostart = vp->tstart;
 
-         vp->tstart = ldi->ldinfo_textorg;
+         /* We can assume pointer == CORE_ADDR, this code is native only.  */
+         vp->tstart = (CORE_ADDR) ldi->ldinfo_textorg;
          vp->tend   = vp->tstart + ldi->ldinfo_textsize;
-         vp->dstart = ldi->ldinfo_dataorg;
+         vp->dstart = (CORE_ADDR) ldi->ldinfo_dataorg;
          vp->dend   = vp->dstart + ldi->ldinfo_datasize;
 
          if (vp->tadj) {
@@ -698,7 +623,7 @@ retry:
          }
 
          /* relocate symbol table(s). */
-         vmap_symtab(vp, ostart, &vi);
+         vmap_symtab (vp);
 
          /* there may be more, so we don't break out of the loop. */
        }
@@ -758,7 +683,7 @@ xfer_memory (memaddr, myaddr, len, write, target)
   boolean (*xfer_fn) PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type));
 
   if (len <= 0)
-    abort();
+    fatal ("aborting");
 
   memend = memaddr + len;
   xfer_fn = write? bfd_set_section_contents: bfd_get_section_contents;
@@ -807,11 +732,13 @@ print_section_info (t, abfd)
   printf_filtered ("file type %s.\n", bfd_get_target(abfd));
 
   for (p = t->to_sections; p < t->to_sections_end; p++) {
-    printf_filtered ("\t%s", local_hex_string_custom (p->addr, "08"));
-    printf_filtered (" - %s", local_hex_string_custom (p->endaddr, "08"));
+    printf_filtered ("\t%s",
+                    local_hex_string_custom ((unsigned long) p->addr, "08l"));
+    printf_filtered (" - %s",
+                    local_hex_string_custom ((unsigned long) p->endaddr, "08l"));
     if (info_verbose)
       printf_filtered (" @ %s",
-                      local_hex_string_custom (p->sec_ptr->filepos, "08"));
+                      local_hex_string_custom ((unsigned long) p->sec_ptr->filepos, "08l"));
     printf_filtered (" is %s", bfd_section_name (p->bfd, p->sec_ptr));
     if (p->bfd != abfd) {
       printf_filtered (" in %s", bfd_get_filename (p->bfd));
@@ -832,13 +759,13 @@ exec_files_info (t)
   if (!vp)
     return;
 
-  printf("\tMapping info for file `%s'.\n", vp->name);
+  printf_unfiltered("\tMapping info for file `%s'.\n", vp->name);
 
-  printf("\t  %8.8s   %8.8s   %8.8s   %8.8s %8.8s %s\n",
+  printf_unfiltered("\t  %8.8s   %8.8s   %8.8s   %8.8s %8.8s %s\n",
     "tstart", "tend", "dstart", "dend", "section", "file(member)");
 
   for (; vp; vp = vp->nxt)
-     printf("\t0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x %s%s%s%s\n",
+     printf_unfiltered("\t0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x %s%s%s%s\n",
        vp->tstart,
        vp->tend,
        vp->dstart,
@@ -982,17 +909,23 @@ xcoff_relocate_core ()
   int offset = 0;
   struct ld_info *ldip;
   struct vmap *vp;
-  
+
   /* Allocated size of buffer.  */
   int buffer_size = LDINFO_SIZE;
   char *buffer = xmalloc (buffer_size);
   struct cleanup *old = make_cleanup (free_current_contents, &buffer);
     
+  /* FIXME, this restriction should not exist.  For now, though I'll
+     avoid coredumps with error() pending a real fix.  */
+  if (vmap == NULL)
+    error
+      ("Can't debug a core file without an executable file (on the RS/6000)");
+  
   ldinfo_sec = bfd_get_section_by_name (core_bfd, ".ldinfo");
   if (ldinfo_sec == NULL)
     {
 bfd_err:
-      fprintf_filtered (stderr, "Couldn't get ldinfo from core file: %s\n",
+      fprintf_filtered (gdb_stderr, "Couldn't get ldinfo from core file: %s\n",
                        bfd_errmsg (bfd_error));
       do_cleanups (old);
       return;
@@ -1036,9 +969,10 @@ bfd_err:
 
       offset += ldip->ldinfo_next;
 
-      vp->tstart = ldip->ldinfo_textorg;
+      /* We can assume pointer == CORE_ADDR, this code is native only.  */
+      vp->tstart = (CORE_ADDR) ldip->ldinfo_textorg;
       vp->tend = vp->tstart + ldip->ldinfo_textsize;
-      vp->dstart = ldip->ldinfo_dataorg;
+      vp->dstart = (CORE_ADDR) ldip->ldinfo_dataorg;
       vp->dend = vp->dstart + ldip->ldinfo_datasize;
 
       if (vp->tadj != 0) {
@@ -1079,9 +1013,10 @@ bfd_err:
          stp->endaddr = bfd_section_vma (stp->bfd, stp->sec_ptr) + vp->dend;
        }
 
-      vmap_symtab (vp, 0, 0);
+      vmap_symtab (vp);
 
-      add_text_to_loadinfo (ldip->ldinfo_textorg, ldip->ldinfo_dataorg);
+      add_text_to_loadinfo ((CORE_ADDR)ldip->ldinfo_textorg,
+                           (CORE_ADDR)ldip->ldinfo_dataorg);
     } while (ldip->ldinfo_next != 0);
   vmap_exec ();
   do_cleanups (old);
This page took 0.029159 seconds and 4 git commands to generate.