202001-10-15 Jim Ingham <jingham@inghji.apple.com>
[deliverable/binutils-gdb.git] / gdb / partial-stab.h
index f627c8e3232a355d0d87ed4a0b24fb4c18d34410..e18cabbba097f0e6221562eaa2f40794fa38461c 100644 (file)
@@ -1,5 +1,6 @@
 /* Shared code to pre-read a stab (dbx-style), when building a psymtab.
-   Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+   1996, 1997, 1998, 1999, 2000, 2001
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -24,7 +25,6 @@
    CUR_SYMBOL_TYPE --Type code of current symbol.
    CUR_SYMBOL_VALUE --Value field of current symbol.  May be adjusted here.
    namestring - variable pointing to the name of the stab.
-   section_offsets - variable pointing to the section offsets.
    pst - the partial symbol table being built.
 
    psymtab_include_list, includes_used, includes_allocated - list of include
@@ -40,6 +40,9 @@
 
 switch (CUR_SYMBOL_TYPE)
   {
+    static struct complaint function_outside_compilation_unit = {
+      "function `%s' appears to be defined outside of all compilation units", 0, 0
+    };
     char *p;
     /*
      * Standard, external, non-debugger, symbols
@@ -47,19 +50,19 @@ switch (CUR_SYMBOL_TYPE)
 
   case N_TEXT | N_EXT:
   case N_NBTEXT | N_EXT:
-    CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
+    CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
     goto record_it;
 
   case N_DATA | N_EXT:
   case N_NBDATA | N_EXT:
-    CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
+    CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
     goto record_it;
 
   case N_BSS:
   case N_BSS | N_EXT:
   case N_NBBSS | N_EXT:
   case N_SETV | N_EXT:         /* FIXME, is this in BSS? */
-    CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_BSS);
+    CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
     goto record_it;
 
   case N_ABS | N_EXT:
@@ -86,7 +89,7 @@ switch (CUR_SYMBOL_TYPE)
   case N_FN_SEQ:
   case N_TEXT:
 #ifdef DBXREAD_ONLY
-    CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
+    CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
     SET_NAMESTRING ();
     if ((namestring[0] == '-' && namestring[1] == 'l')
        || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
@@ -122,7 +125,7 @@ switch (CUR_SYMBOL_TYPE)
     continue;
 
   case N_DATA:
-    CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
+    CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
     goto record_it;
 
   case N_UNDF | N_EXT:
@@ -198,13 +201,13 @@ switch (CUR_SYMBOL_TYPE)
 
   case N_SO:
     {
-      unsigned long valu;
+      CORE_ADDR valu;
       static int prev_so_symnum = -10;
       static int first_so_symnum;
       char *p;
       int prev_textlow_not_set;
 
-      valu = CUR_SYMBOL_VALUE + ANOFFSET (section_offsets, SECT_OFF_TEXT);
+      valu = CUR_SYMBOL_VALUE + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
       prev_textlow_not_set = textlow_not_set;
 
@@ -266,7 +269,7 @@ switch (CUR_SYMBOL_TYPE)
          immediately follow the first.  */
 
       if (!pst)
-       pst = START_PSYMTAB (objfile, section_offsets,
+       pst = START_PSYMTAB (objfile,
                             namestring, valu,
                             first_so_symnum * symbol_size,
                             objfile->global_psymbols.next,
@@ -394,9 +397,9 @@ switch (CUR_SYMBOL_TYPE)
 
 #ifdef DBXREAD_ONLY
     /* See if this is an end of function stab.  */
-    if (CUR_SYMBOL_TYPE == N_FUN && *namestring == '\000')
+    if (pst && CUR_SYMBOL_TYPE == N_FUN && *namestring == '\000')
       {
-       unsigned long valu;
+       CORE_ADDR valu;
 
        /* It's value is the size (in bytes) of the function for
           function relative stabs, or the address of the function's
@@ -424,7 +427,7 @@ switch (CUR_SYMBOL_TYPE)
     switch (p[1])
       {
       case 'S':
-       CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
+       CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
 #ifdef STATIC_TRANSFORM_NAME
        namestring = STATIC_TRANSFORM_NAME (namestring);
 #endif
@@ -435,7 +438,7 @@ switch (CUR_SYMBOL_TYPE)
                             psymtab_language, objfile);
        continue;
       case 'G':
-       CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
+       CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
        /* The addresses in these entries are reported to be
           wrong.  See the code that reads 'G's for symtabs. */
        add_psymbol_to_list (namestring, p - namestring,
@@ -576,33 +579,57 @@ switch (CUR_SYMBOL_TYPE)
        continue;
 
       case 'f':
-       CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
+        if (! pst)
+          {
+            int name_len = p - namestring;
+            char *name = xmalloc (name_len + 1);
+            memcpy (name, namestring, name_len);
+            name[name_len] = '\0';
+            complain (&function_outside_compilation_unit, name);
+            xfree (name);
+          }
+       CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 #ifdef DBXREAD_ONLY
-       /* Keep track of the start of the last function so we
-          can handle end of function symbols.  */
-       last_function_start = CUR_SYMBOL_VALUE;
        /* Kludges for ELF/STABS with Sun ACC */
        last_function_name = namestring;
 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
        /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
           value for the bottom of the text seg in those cases. */
+       if (CUR_SYMBOL_VALUE == ANOFFSET (objfile->section_offsets, 
+                                         SECT_OFF_TEXT (objfile)))
+         {
+           CORE_ADDR minsym_valu = 
+             find_stab_function_addr (namestring, pst->filename, objfile);
+           /* find_stab_function_addr will return 0 if the minimal
+              symbol wasn't found.  (Unfortunately, this might also
+              be a valid address.)  Anyway, if it *does* return 0,
+              it is likely that the value was set correctly to begin
+              with... */
+           if (minsym_valu != 0)
+             CUR_SYMBOL_VALUE = minsym_valu;
+         }
        if (pst && textlow_not_set)
          {
-           pst->textlow =
-             find_stab_function_addr (namestring, pst, objfile);
+           pst->textlow = CUR_SYMBOL_VALUE;
            textlow_not_set = 0;
          }
 #endif
        /* End kludge.  */
 
+       /* Keep track of the start of the last function so we
+          can handle end of function symbols.  */
+       last_function_start = CUR_SYMBOL_VALUE;
+
        /* In reordered executables this function may lie outside
           the bounds created by N_SO symbols.  If that's the case
           use the address of this function as the low bound for
           the partial symbol table.  */
-       if (textlow_not_set
-           || (CUR_SYMBOL_VALUE < pst->textlow
-               && CUR_SYMBOL_VALUE
-               != ANOFFSET (section_offsets, SECT_OFF_TEXT)))
+       if (pst
+            && (textlow_not_set
+                || (CUR_SYMBOL_VALUE < pst->textlow
+                    && (CUR_SYMBOL_VALUE
+                        != ANOFFSET (objfile->section_offsets,
+                                     SECT_OFF_TEXT (objfile))))))
          {
            pst->textlow = CUR_SYMBOL_VALUE;
            textlow_not_set = 0;
@@ -619,32 +646,57 @@ switch (CUR_SYMBOL_TYPE)
           are put into the global psymtab like one would expect.
           They're also in the minimal symbol table.  */
       case 'F':
-       CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
+        if (! pst)
+          {
+            int name_len = p - namestring;
+            char *name = xmalloc (name_len + 1);
+            memcpy (name, namestring, name_len);
+            name[name_len] = '\0';
+            complain (&function_outside_compilation_unit, name);
+            xfree (name);
+          }
+       CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 #ifdef DBXREAD_ONLY
-       /* Keep track of the start of the last function so we
-          can handle end of function symbols.  */
-       last_function_start = CUR_SYMBOL_VALUE;
        /* Kludges for ELF/STABS with Sun ACC */
        last_function_name = namestring;
 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
        /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
           value for the bottom of the text seg in those cases. */
+       if (CUR_SYMBOL_VALUE == ANOFFSET (objfile->section_offsets, 
+                                         SECT_OFF_TEXT (objfile)))
+         {
+           CORE_ADDR minsym_valu = 
+             find_stab_function_addr (namestring, pst->filename, objfile);
+           /* find_stab_function_addr will return 0 if the minimal
+              symbol wasn't found.  (Unfortunately, this might also
+              be a valid address.)  Anyway, if it *does* return 0,
+              it is likely that the value was set correctly to begin
+              with... */
+           if (minsym_valu != 0)
+             CUR_SYMBOL_VALUE = minsym_valu;
+         }
        if (pst && textlow_not_set)
          {
-           pst->textlow =
-             find_stab_function_addr (namestring, pst, objfile);
+           pst->textlow = CUR_SYMBOL_VALUE;
            textlow_not_set = 0;
          }
 #endif
        /* End kludge.  */
+
+       /* Keep track of the start of the last function so we
+          can handle end of function symbols.  */
+       last_function_start = CUR_SYMBOL_VALUE;
+
        /* In reordered executables this function may lie outside
           the bounds created by N_SO symbols.  If that's the case
           use the address of this function as the low bound for
           the partial symbol table.  */
-       if (textlow_not_set
-           || (CUR_SYMBOL_VALUE < pst->textlow
-               && CUR_SYMBOL_VALUE
-               != ANOFFSET (section_offsets, SECT_OFF_TEXT)))
+       if (pst
+            && (textlow_not_set
+                || (CUR_SYMBOL_VALUE < pst->textlow
+                    && (CUR_SYMBOL_VALUE
+                        != ANOFFSET (objfile->section_offsets,
+                                     SECT_OFF_TEXT (objfile))))))
          {
            pst->textlow = CUR_SYMBOL_VALUE;
            textlow_not_set = 0;
This page took 0.028784 seconds and 4 git commands to generate.