* gdb.texinfo (Command Files): Mention -x, use @enumerate for
[deliverable/binutils-gdb.git] / gdb / symfile.c
index 5b2a2ff56579a8123e0b70f6ea22ece686c1d3b0..108695a338e6cf825649e6e8decfe58e5eff389b 100644 (file)
@@ -461,6 +461,51 @@ find_lowest_section (abfd, sect, obj)
     *lowest = sect;
 }
 
+
+/* Build (allocate and populate) a section_addr_info struct from
+   an existing section table. */
+
+extern struct section_addr_info *
+build_section_addr_info_from_section_table (const struct section_table *start,
+                                            const struct section_table *end)
+{
+  struct section_addr_info *sap;
+  const struct section_table *stp;
+  int oidx;
+
+  sap = xmalloc (sizeof (struct section_addr_info));
+  memset (sap, 0, sizeof (struct section_addr_info));
+
+  for (stp = start, oidx = 0; stp != end; stp++)
+    {
+      if (stp->the_bfd_section->flags & (SEC_ALLOC | SEC_LOAD)
+         && oidx < MAX_SECTIONS)
+       {
+         sap->other[oidx].addr = stp->addr;
+         sap->other[oidx].name = xstrdup (stp->the_bfd_section->name);
+         sap->other[oidx].sectindex = stp->the_bfd_section->index;
+         oidx++;
+       }
+    }
+
+  return sap;
+}
+
+
+/* Free all memory allocated by build_section_addr_info_from_section_table. */
+
+extern void
+free_section_addr_info (struct section_addr_info *sap)
+{
+  int idx;
+
+  for (idx = 0; idx < MAX_SECTIONS; idx++)
+    if (sap->other[idx].name)
+      free (sap->other[idx].name);
+  free (sap);
+}
+
+
 /* Parse the user's idea of an offset for dynamic linking, into our idea
    of how to represent it for fast symbol reading.  This is the default 
    version of the sym_fns.sym_offsets function for symbol readers that
@@ -479,15 +524,6 @@ default_symfile_offsets (objfile, addrs)
     obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
   memset (objfile->section_offsets, 0, SIZEOF_SECTION_OFFSETS);
 
-  /* If user explicitly specified values for data and bss, set them here. */
-  
-  if (addrs->text_addr)
-    ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT) = addrs->text_addr;
-  if (addrs->data_addr)
-    ANOFFSET (objfile->section_offsets, SECT_OFF_DATA) = addrs->data_addr;
-  if (addrs->bss_addr)
-    ANOFFSET (objfile->section_offsets, SECT_OFF_BSS)  = addrs->bss_addr;
-    
   /* Now calculate offsets for other sections. */
   for (i = 0; i < MAX_SECTIONS && addrs->other[i].name; i++)
     {
@@ -531,7 +567,6 @@ syms_from_objfile (objfile, addrs, mainline, verbo)
      int mainline;
      int verbo;
 {
-  struct section_offsets *section_offsets;
   asection *lower_sect;
   asection *sect;
   CORE_ADDR lower_offset;
@@ -584,14 +619,7 @@ syms_from_objfile (objfile, addrs, mainline, verbo)
 
      We no longer warn if the lowest section is not a text segment (as
      happens for the PA64 port.  */
-  if (mainline)
-    {
-      /* No offset from objfile addresses.  */
-      addrs -> text_addr = 0;
-      addrs -> data_addr = 0;
-      addrs -> bss_addr = 0;
-    }
-  else
+  if (!mainline)
     {
       /* Find lowest loadable section to be used as starting point for 
          continguous sections. FIXME!! won't work without call to find
@@ -624,57 +652,17 @@ syms_from_objfile (objfile, addrs, mainline, verbo)
         (the loadable section directly below it in memory).
         this_offset = lower_offset = lower_addr - lower_orig_addr */
 
-      /* FIXME: These sections will not need special treatment because ALL
-        sections are in the other sections table */
-      if (addrs->text_addr != 0)
-       {
-         sect = bfd_get_section_by_name (objfile->obfd, ".text");
-         if (sect)
-           {
-             addrs->text_addr -= bfd_section_vma (objfile->obfd, sect);
-             lower_offset = addrs->text_addr;
-           }
-       }
-      else 
-       /* ??? who's below me? */
-       addrs->text_addr = lower_offset;
-      if (addrs->data_addr != 0)
-       {
-         sect = bfd_get_section_by_name (objfile->obfd, ".data");
-         if (sect)
-           {
-             addrs->data_addr -= bfd_section_vma (objfile->obfd, sect);
-             lower_offset = addrs->data_addr;
-           }
-       }
-      else
-       addrs->data_addr = lower_offset;
-      if (addrs->bss_addr != 0)
-       {
-         sect = bfd_get_section_by_name (objfile->obfd, ".bss");
-         if (sect)
-           {
-             addrs->bss_addr -= bfd_section_vma (objfile->obfd, sect);
-             lower_offset = addrs->bss_addr;
-           }
-       }
-      else
-       addrs->bss_addr = lower_offset;
-  
-       /* Now calculate offsets for other sections. */
+       /* Calculate offsets for sections. */
       for (i=0 ; i < MAX_SECTIONS && addrs->other[i].name; i++)
        {
-        
-         if (addrs->other[i].addr != 0)
+         if (addrs->other[i].addr != 0)
            {
-             sect=bfd_get_section_by_name(objfile->obfd, addrs->other[i].name);
+             sect = bfd_get_section_by_name (objfile->obfd, addrs->other[i].name);
              if (sect)
                {
                  addrs->other[i].addr -= bfd_section_vma (objfile->obfd, sect);
                  lower_offset = addrs->other[i].addr;
+                 /* This is the index used by BFD. */
                  addrs->other[i].sectindex = sect->index ;
                }
              else
@@ -731,14 +719,9 @@ syms_from_objfile (objfile, addrs, mainline, verbo)
          CORE_ADDR s_addr = 0;
          int i;
 
-         if (strcmp (s->the_bfd_section->name, ".text") == 0)
-           s_addr = addrs->text_addr;
-         else if (strcmp (s->the_bfd_section->name, ".data") == 0)
-           s_addr = addrs->data_addr;
-         else if (strcmp (s->the_bfd_section->name, ".bss") == 0)
-           s_addr = addrs->bss_addr;
-         else 
-           for (i = 0; !s_addr && addrs->other[i].name; i++)
+           for (i = 0; 
+                !s_addr && i < MAX_SECTIONS && addrs->other[i].name;
+                i++)
              if (strcmp (s->the_bfd_section->name, addrs->other[i].name) == 0)
                s_addr = addrs->other[i].addr; /* end added for gdb/13815 */
  
@@ -940,6 +923,10 @@ symbol_file_add (name, from_tty, addrs, mainline, flags)
    used in GDB (perhaps "set mapped on", "set readnow on" would be
    better), (3) the order of options matters, which is contrary to GNU
    conventions (because it is confusing and inconvenient).  */
+/* Note: ezannoni 2000-04-17. This function used to have support for
+   rombug (see remote-os9k.c). It consisted of a call to target_link()
+   (target.c) to get the address of the text segment from the target,
+   and pass that to symbol_file_add(). This is no longer supported. */
 
 void
 symbol_file_command (args, from_tty)
@@ -948,7 +935,6 @@ symbol_file_command (args, from_tty)
 {
   char **argv;
   char *name = NULL;
-  CORE_ADDR text_relocation = 0;       /* text_relocation */
   struct cleanup *cleanups;
   int flags = OBJF_USERLOADED;
 
@@ -973,9 +959,7 @@ symbol_file_command (args, from_tty)
 
       symfile_objfile = NULL;
       if (from_tty)
-       {
          printf_unfiltered ("No symbol file now.\n");
-       }
 #ifdef HPUXHPPA
       RESET_HP_UX_GLOBALS ();
 #endif
@@ -990,56 +974,26 @@ symbol_file_command (args, from_tty)
       while (*argv != NULL)
        {
          if (STREQ (*argv, "-mapped"))
-           {
-             flags |= OBJF_MAPPED;
-           }
-         else if (STREQ (*argv, "-readnow"))
-           {
+           flags |= OBJF_MAPPED;
+         else 
+           if (STREQ (*argv, "-readnow"))
              flags |= OBJF_READNOW;
-           }
-         else if (**argv == '-')
-           {
-             error ("unknown option `%s'", *argv);
-           }
-         else
-           {
-             char *p;
-
-             name = *argv;
-
-             /* this is for rombug remote only, to get the text relocation by
-                using link command */
-             p = strrchr (name, '/');
-             if (p != NULL)
-               p++;
+           else 
+             if (**argv == '-')
+               error ("unknown option `%s'", *argv);
              else
-               p = name;
-
-             target_link (p, &text_relocation);
-
-             if (text_relocation == (CORE_ADDR) 0)
-               return;
-             else if (text_relocation == (CORE_ADDR) -1)
                {
+                  name = *argv;
                  symbol_file_add (name, from_tty, NULL, 1, flags);
 #ifdef HPUXHPPA
                  RESET_HP_UX_GLOBALS ();
 #endif
-               }
-             else
-               {
-                 struct section_addr_info section_addrs;
-                 memset (&section_addrs, 0, sizeof (section_addrs));
-                 section_addrs.text_addr = (CORE_ADDR) text_relocation;
-                 symbol_file_add (name, from_tty, &section_addrs, 0, flags);
-               }
+                 /* Getting new symbols may change our opinion about
+                    what is frameless.  */
+                 reinit_frame_cache ();
 
-             /* Getting new symbols may change our opinion about what is
-                frameless.  */
-             reinit_frame_cache ();
-
-             set_initial_language ();
-           }
+                 set_initial_language ();
+               }
          argv++;
        }
 
@@ -1452,6 +1406,12 @@ print_transfer_performance (struct ui_file *stream,
 
 /* This function allows the addition of incrementally linked object files.
    It does not modify any state in the target, only in the debugger.  */
+/* Note: ezannoni 2000-04-13 This function/command used to have a
+   special case syntax for the rombug target (Rombug is the boot
+   monitor for Microware's OS-9 / OS-9000, see remote-os9k.c). In the
+   rombug case, the user doesn't need to supply a text address,
+   instead a call to target_link() (in target.c) would supply the
+   value to use. We are now discontinuing this type of ad hoc syntax. */
 
 /* ARGSUSED */
 static void
@@ -1459,199 +1419,157 @@ add_symbol_file_command (args, from_tty)
      char *args;
      int from_tty;
 {
-  char *name = NULL;
-  CORE_ADDR text_addr;
+  char *filename = NULL;
   int flags = OBJF_USERLOADED;
   char *arg;
   int expecting_option = 0;
-  int option_index = 0;
+  int section_index = 0;
   int argcnt = 0;
   int sec_num = 0;
   int i;
+  int expecting_sec_name = 0;
+  int expecting_sec_addr = 0;
+
   struct
   {
-    enum { OPT_SECTION } type;
     char *name;
     char *value;
-  } opt[SECT_OFF_MAX];
+  } sect_opts[SECT_OFF_MAX];
+
   struct section_addr_info section_addrs;
+  struct cleanup *my_cleanups;
 
   dont_repeat ();
 
   if (args == NULL)
-    {
-      error ("add-symbol-file takes a file name and an address");
-    }
+    error ("add-symbol-file takes a file name and an address");
 
   /* Make a copy of the string that we can safely write into. */
-
   args = xstrdup (args);
-  make_cleanup (free, args);
 
   /* Ensure section_addrs is initialized */
   memset (&section_addrs, 0, sizeof (section_addrs));
 
-  /* Pick off any -option args and the file name. */
-
   while (*args != '\000')
     {
+      /* Any leading spaces? */
       while (isspace (*args))
-       {
-         args++;
-       }
+       args++;
+
+      /* Point arg to the beginning of the argument. */
       arg = args;
+
+      /* Move args pointer over the argument. */
       while ((*args != '\000') && !isspace (*args))
-       {
-         args++;
-       }
+       args++;
+
+      /* If there are more arguments, terminate arg and
+         proceed past it. */
       if (*args != '\000')
+       *args++ = '\000';
+
+      /* Now process the argument. */
+      if (argcnt == 0)
        {
-         *args++ = '\000';
-       }
-      if (*arg != '-')
-       {
-         if (expecting_option)
-           {
-             opt[option_index++].value = arg;
-             expecting_option = 0;
-           }
-         else
-           {
-             switch (argcnt)
-               {
-               case 0:
-                 name = arg;
-                 break;
-               case 1: 
-                 opt[option_index].type = OPT_SECTION;
-                 opt[option_index].name = ".text";
-                 opt[option_index++].value = arg;
-                 break;
-               case 2: 
-                 opt[option_index].type = OPT_SECTION;
-                 opt[option_index].name = ".data";
-                 opt[option_index++].value = arg;
-                 break;
-               case 3: 
-                 opt[option_index].type = OPT_SECTION;
-                 opt[option_index].name = ".bss";
-                 opt[option_index++].value = arg;
-                 break;
-               default:
-                 warning ("Too many arguments entered; see \"help add-symbol-file\" for command syntax.");
-               }
-             argcnt++;
-           }
-       }
-      else if (STREQ (arg, "-mapped"))
-       {
-         flags |= OBJF_MAPPED;
-       }
-      else if (STREQ (arg, "-readnow"))
-       {
-         flags |= OBJF_READNOW;
+         /* The first argument is the file name. */
+         filename = tilde_expand (arg);
+         my_cleanups = make_cleanup (free, filename);
        }
-      else if (STREQN (arg, "-T", 2))
-       {
-         if (option_index >= SECT_OFF_MAX)
-           {
-             warning ("Number of options exceeds maximum allowed.");
-           }
-         else
-           {
-             expecting_option = 1;
-             opt[option_index].type = OPT_SECTION;
-             opt[option_index].name = arg + 2;
-           }
-       }
-      else 
-        {
-         error ("Unknown option `%s'", arg);
-        }
-    }
+      else
+       if (argcnt == 1)
+         {
+           /* The second argument is always the text address at which
+               to load the program. */
+           sect_opts[section_index].name = ".text";
+           sect_opts[section_index].value = arg;
+           section_index++;              
+         }
+       else
+         {
+           /* It's an option (starting with '-') or it's an argument
+              to an option */
 
-  if (name == NULL)
-    {
-      error ("add-symbol-file takes a file name");
+           if (*arg == '-')
+             {
+               if (strcmp (arg, "-mapped") == 0)
+                 flags |= OBJF_MAPPED;
+               else 
+                 if (strcmp (arg, "-readnow") == 0)
+                   flags |= OBJF_READNOW;
+                 else 
+                   if (strcmp (arg, "-s") == 0)
+                     {
+                       if (section_index >= SECT_OFF_MAX)
+                         error ("Too many sections specified.");
+                       expecting_sec_name = 1;
+                       expecting_sec_addr = 1;
+                     }
+             }
+           else
+             {
+               if (expecting_sec_name)
+                 {
+                   sect_opts[section_index].name = arg;
+                   expecting_sec_name = 0;
+                 }
+               else
+                 if (expecting_sec_addr)
+                   {
+                     sect_opts[section_index].value = arg;
+                     expecting_sec_addr = 0;
+                     section_index++;            
+                   }
+                 else
+                   error ("USAGE: add-symbol-file <filename> <textaddress> [-mapped] [-readnow] [-s <secname> <addr>]*");
+             }
+         }
+      argcnt++;
     }
-  name = tilde_expand (name);
-  make_cleanup (free, name);
 
-  if (option_index > 0)
-    {
-      /* Print the prompt for the query below.
-        We have to split this up into 3 print statements because
-        local_hex_string returns a local static string. */
+  /* Print the prompt for the query below. And save the arguments into
+     a sect_addr_info structure to be passed around to other
+     functions.  We have to split this up into separate print
+     statements because local_hex_string returns a local static
+     string. */
  
-      printf_filtered ("add symbol table from file \"%s\" at\n", name);
-      for (i = 0; i < option_index; i++)
-       {
-         switch (opt[i].type)
-           {
-           case OPT_SECTION:
-             {
-                CORE_ADDR addr;
-                char *val = opt[i].value;
-                char *sec = opt[i].name;
-                val = opt[i].value;
-                if (val[0] == '0' && val[1] == 'x')
-                  addr = strtoul (val+2, NULL, 16);
-                else
-                  addr = strtoul (val, NULL, 10);
-                if (strcmp (sec, ".text") == 0)
-                  section_addrs.text_addr = addr;
-                else if (strcmp (sec, ".data") == 0)
-                  section_addrs.data_addr = addr;
-                else if (strcmp (sec, ".bss") == 0)
-                  section_addrs.bss_addr = addr;
-                /* Add the section to the others even if it is a
-                   text data or bss section. This is redundent but
-                   eventually, none will be given special treatment */
-               {
-                 section_addrs.other[sec_num].name = xstrdup (sec);
-                 make_cleanup (free, section_addrs.other[sec_num].name);
-                 section_addrs.other[sec_num++].addr = addr;
-                 printf_filtered ("\t%s_addr = %s\n",
-                                  sec, 
-                                  local_hex_string ((unsigned long)addr));
-               }
-                /* The object's sections are initialized when a 
-                   call is made to build_objfile_section_table (objfile).
-                   This happens in reread_symbols. 
-                   At this point, we don't know what file type this is,
-                   so we can't determine what section names are valid.  */
-              }
-              break;
-            default:
-              complain (&unknown_option_complaint, opt[i].name);
-           }
-       }
-      /* Eventually, these hard coded names will be obsolete */
-      /* All the addresses will be on the others section */
-    }
-  else
+  printf_filtered ("add symbol table from file \"%s\" at\n", filename);
+  for (i = 0; i < section_index; i++)
     {
-      CORE_ADDR text_addr;
-      target_link (name, &text_addr);  
-      if (text_addr == (CORE_ADDR) -1)
-       error("Don't know how to get text start location for this file");
-      section_addrs.text_addr = text_addr;
-      section_addrs.data_addr = 0;
-      section_addrs.bss_addr = 0;
-      printf_filtered("add symbol table from file \"%s\" at text_addr = %s?\n",
-                     name, local_hex_string ((unsigned long)text_addr));
+      CORE_ADDR addr;
+      char *val = sect_opts[i].value;
+      char *sec = sect_opts[i].name;
+      val = sect_opts[i].value;
+      if (val[0] == '0' && val[1] == 'x')
+       addr = strtoul (val+2, NULL, 16);
+      else
+       addr = strtoul (val, NULL, 10);
+
+      /* Here we store the section offsets in the order they were
+         entered on the command line. */
+      section_addrs.other[sec_num].name = sec;
+      section_addrs.other[sec_num].addr = addr;
+      printf_filtered ("\t%s_addr = %s\n",
+                      sec, 
+                      local_hex_string ((unsigned long)addr));
+      sec_num++;
+
+      /* The object's sections are initialized when a 
+        call is made to build_objfile_section_table (objfile).
+        This happens in reread_symbols. 
+        At this point, we don't know what file type this is,
+        so we can't determine what section names are valid.  */
     }
+
   if (from_tty && (!query ("%s", "")))
     error ("Not confirmed.");
 
-  symbol_file_add (name, from_tty, &section_addrs, 0, flags);
+  symbol_file_add (filename, from_tty, &section_addrs, 0, flags);
 
   /* Getting new symbols may change our opinion about what is
      frameless.  */
   reinit_frame_cache ();
+  do_cleanups (my_cleanups);
 }
 \f
 static void
@@ -1775,6 +1693,10 @@ reread_symbols ()
              objfile->free_psymtabs = NULL;
              objfile->msymbols = NULL;
              objfile->minimal_symbol_count = 0;
+             memset (&objfile->msymbol_hash, 0,
+                     sizeof (objfile->msymbol_hash));
+             memset (&objfile->msymbol_demangled_hash, 0,
+                     sizeof (objfile->msymbol_demangled_hash));
              objfile->fundamental_types = NULL;
              if (objfile->sf != NULL)
                {
@@ -2912,7 +2834,9 @@ map_overlay_command (args, from_tty)
   asection *bfdsec;
 
   if (!overlay_debugging)
-    error ("Overlay debugging not enabled.  Use the 'OVERLAY ON' command.");
+    error ("\
+Overlay debugging not enabled.  Use either the 'overlay auto' or\n\
+the 'overlay manual' command.");
 
   if (args == 0 || *args == 0)
     error ("Argument required: name of an overlay section");
@@ -2962,7 +2886,9 @@ unmap_overlay_command (args, from_tty)
   struct obj_section *sec;
 
   if (!overlay_debugging)
-    error ("Overlay debugging not enabled.  Use the 'OVERLAY ON' command.");
+    error ("\
+Overlay debugging not enabled.  Use either the 'overlay auto' or\n\
+the 'overlay manual' command.");
 
   if (args == 0 || *args == 0)
     error ("Argument required: name of an overlay section");
@@ -3310,13 +3236,12 @@ to execute.", &cmdlist);
   c->completer = filename_completer;
 
   c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command,
-              "Usage: add-symbol-file FILE ADDR [DATA_ADDR [BSS_ADDR]]\n\
-or:    add-symbol-file FILE -T<SECT> <SECT_ADDR> -T<SECT> <SECT_ADDR> ...\n\
+              "Usage: add-symbol-file FILE ADDR [-s <SECT> <SECT_ADDR> -s <SECT> <SECT_ADDR> ...]\n\
 Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
 ADDR is the starting address of the file's text.\n\
-The optional arguments, DATA_ADDR and BSS_ADDR, should be specified\n\
-if the data and bss segments are not contiguous with the text.\n\
-For complicated cases, SECT is a section name to be loaded at SECT_ADDR.",
+The optional arguments are section-name section-address pairs and\n\
+should be specified if the data and bss segments are not contiguous\n\
+with the text. SECT is a section name to be loaded at SECT_ADDR.",
               &cmdlist);
   c->completer = filename_completer;
 
This page took 0.036542 seconds and 4 git commands to generate.