* x86-64-tdep.h: Tewak comment.
[deliverable/binutils-gdb.git] / gdb / symtab.c
index fa8b3e7c287d5c87b0ba72b021066481355dacb9..6995891b5ae3ad3074e5c1795ea94eb0659de865 100644 (file)
@@ -485,7 +485,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
 
 /* Set both the mangled and demangled (if any) names for GSYMBOL based
    on LINKAGE_NAME and LEN.  The hash table corresponding to OBJFILE
-   is used, and the memory comes from that objfile's symbol_obstack.
+   is used, and the memory comes from that objfile's objfile_obstack.
    LINKAGE_NAME is copied, so the pointer can be discarded after
    calling this function.  */
 
@@ -572,7 +572,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
       /* If there is a demangled name, place it right after the mangled name.
         Otherwise, just place a second zero byte after the end of the mangled
         name.  */
-      *slot = obstack_alloc (&objfile->symbol_obstack,
+      *slot = obstack_alloc (&objfile->objfile_obstack,
                             lookup_len + demangled_len + 2);
       memcpy (*slot, lookup_name, lookup_len + 1);
       if (demangled_name != NULL)
@@ -672,8 +672,10 @@ init_sal (struct symtab_and_line *sal)
 \f
 
 
-/* Find which partial symtab on contains PC and SECTION.  Return 0 if none.  */
-
+/* Find which partial symtab contains PC and SECTION.  Return 0 if
+   none.  We return the psymtab that contains a symbol whose address
+   exactly matches PC, or, if we cannot find an exact match, the
+   psymtab that contains a symbol whose address is closest to PC.  */
 struct partial_symtab *
 find_pc_sect_psymtab (CORE_ADDR pc, asection *section)
 {
@@ -698,6 +700,8 @@ find_pc_sect_psymtab (CORE_ADDR pc, asection *section)
     if (pc >= pst->textlow && pc < pst->texthigh)
       {
        struct partial_symtab *tpst;
+       struct partial_symtab *best_pst = pst;
+       struct partial_symbol *best_psym = NULL;
 
        /* An objfile that has its functions reordered might have
           many partial symbol tables containing the PC, but
@@ -710,6 +714,13 @@ find_pc_sect_psymtab (CORE_ADDR pc, asection *section)
        if (msymbol == NULL)
          return (pst);
 
+       /* The code range of partial symtabs sometimes overlap, so, in
+          the loop below, we need to check all partial symtabs and
+          find the one that fits better for the given PC address. We
+          select the partial symtab that contains a symbol whose
+          address is closest to the PC address.  By closest we mean
+          that find_pc_sect_symbol returns the symbol with address
+          that is closest and still less than the given PC.  */
        for (tpst = pst; tpst != NULL; tpst = tpst->next)
          {
            if (pc >= tpst->textlow && pc < tpst->texthigh)
@@ -721,9 +732,33 @@ find_pc_sect_psymtab (CORE_ADDR pc, asection *section)
                    && SYMBOL_VALUE_ADDRESS (p)
                    == SYMBOL_VALUE_ADDRESS (msymbol))
                  return (tpst);
+               if (p != NULL)
+                 {
+                   /* We found a symbol in this partial symtab which
+                      matches (or is closest to) PC, check whether it
+                      is closer than our current BEST_PSYM.  Since
+                      this symbol address is necessarily lower or
+                      equal to PC, the symbol closer to PC is the
+                      symbol which address is the highest.  */
+                   /* This way we return the psymtab which contains
+                      such best match symbol. This can help in cases
+                      where the symbol information/debuginfo is not
+                      complete, like for instance on IRIX6 with gcc,
+                      where no debug info is emitted for
+                      statics. (See also the nodebug.exp
+                      testcase.)  */
+                   if (best_psym == NULL
+                       || SYMBOL_VALUE_ADDRESS (p)
+                       > SYMBOL_VALUE_ADDRESS (best_psym))
+                     {
+                       best_psym = p;
+                       best_pst = tpst;
+                     }
+                 }
+
              }
          }
-       return (pst);
+       return (best_pst);
       }
   }
   return (NULL);
@@ -3860,6 +3895,60 @@ in_prologue (CORE_ADDR pc, CORE_ADDR func_start)
   return func_addr <= pc && pc < sal.end;
 }
 
+/* Given PC at the function's start address, attempt to find the
+   prologue end using SAL information.  Return zero if the skip fails.
+
+   A non-optimized prologue traditionally has one SAL for the function
+   and a second for the function body.  A single line function has
+   them both pointing at the same line.
+
+   An optimized prologue is similar but the prologue may contain
+   instructions (SALs) from the instruction body.  Need to skip those
+   while not getting into the function body.
+
+   The functions end point and an increasing SAL line are used as
+   indicators of the prologue's endpoint.
+
+   This code is based on the function refine_prologue_limit (versions
+   found in both ia64 and ppc).  */
+
+CORE_ADDR
+skip_prologue_using_sal (CORE_ADDR func_addr)
+{
+  struct symtab_and_line prologue_sal;
+  CORE_ADDR start_pc;
+  CORE_ADDR end_pc;
+
+  /* Get an initial range for the function.  */
+  find_pc_partial_function (func_addr, NULL, &start_pc, &end_pc);
+  start_pc += FUNCTION_START_OFFSET;
+
+  prologue_sal = find_pc_line (start_pc, 0);
+  if (prologue_sal.line != 0)
+    {
+      while (prologue_sal.end < end_pc)
+       {
+         struct symtab_and_line sal;
+
+         sal = find_pc_line (prologue_sal.end, 0);
+         if (sal.line == 0)
+           break;
+         /* Assume that a consecutive SAL for the same (or larger)
+            line mark the prologue -> body transition.  */
+         if (sal.line >= prologue_sal.line)
+           break;
+         /* The case in which compiler's optimizer/scheduler has
+            moved instructions into the prologue.  We look ahead in
+            the function looking for address ranges whose
+            corresponding line number is less the first one that we
+            found for the function.  This is more conservative then
+            refine_prologue_limit which scans a large number of SALs
+            looking for any in the prologue */
+         prologue_sal = sal;
+       }
+    }
+  return prologue_sal.end;
+}
 \f
 struct symtabs_and_lines
 decode_line_spec (char *string, int funfirstline)
This page took 0.035045 seconds and 4 git commands to generate.