Add basic support for AArch64.
[deliverable/binutils-gdb.git] / gdb / symtab.c
index 68d654db2c97f955e63262572bc9fa576b31b803..57441c1ce5b1bc6e3dd6ea4ee571e8ba8da5a075 100644 (file)
@@ -146,8 +146,8 @@ const struct block *block_found;
 
 /* See whether FILENAME matches SEARCH_NAME using the rule that we
    advertise to the user.  (The manual's description of linespecs
-   describes what we advertise).  We assume that SEARCH_NAME is
-   a relative path.  Returns true if they match, false otherwise.  */
+   describes what we advertise).  Returns true if they match, false
+   otherwise.  */
 
 int
 compare_filenames_for_search (const char *filename, const char *search_name)
@@ -166,12 +166,18 @@ compare_filenames_for_search (const char *filename, const char *search_name)
      preceding the trailing SEARCH_NAME segment of FILENAME must be a
      directory separator.
 
+     The check !IS_ABSOLUTE_PATH ensures SEARCH_NAME "/dir/file.c"
+     cannot match FILENAME "/path//dir/file.c" - as user has requested
+     absolute path.  The sama applies for "c:\file.c" possibly
+     incorrectly hypothetically matching "d:\dir\c:\file.c".
+
      The HAS_DRIVE_SPEC purpose is to make FILENAME "c:file.c"
      compatible with SEARCH_NAME "file.c".  In such case a compiler had
      to put the "c:file.c" name into debug info.  Such compatibility
      works only on GDB built for DOS host.  */
   return (len == search_len
-         || IS_DIR_SEPARATOR (filename[len - search_len - 1])
+         || (!IS_ABSOLUTE_PATH (search_name)
+             && IS_DIR_SEPARATOR (filename[len - search_len - 1]))
          || (HAS_DRIVE_SPEC (filename)
              && STRIP_DRIVE_SPEC (filename) == &filename[len - search_len]));
 }
@@ -179,7 +185,7 @@ compare_filenames_for_search (const char *filename, const char *search_name)
 /* Check for a symtab of a specific name by searching some symtabs.
    This is a helper function for callbacks of iterate_over_symtabs.
 
-   The return value, NAME, FULL_PATH, REAL_PATH, CALLBACK, and DATA
+   The return value, NAME, REAL_PATH, CALLBACK, and DATA
    are identical to the `map_symtabs_matching_filename' method of
    quick_symbol_functions.
 
@@ -189,7 +195,6 @@ compare_filenames_for_search (const char *filename, const char *search_name)
 
 int
 iterate_over_some_symtabs (const char *name,
-                          const char *full_path,
                           const char *real_path,
                           int (*callback) (struct symtab *symtab,
                                            void *data),
@@ -199,18 +204,10 @@ iterate_over_some_symtabs (const char *name,
 {
   struct symtab *s = NULL;
   const char* base_name = lbasename (name);
-  int is_abs = IS_ABSOLUTE_PATH (name);
 
   for (s = first; s != NULL && s != after_last; s = s->next)
     {
-      /* Exact match is always ok.  */
-      if (FILENAME_CMP (name, s->filename) == 0)
-       {
-         if (callback (s, data))
-           return 1;
-       }
-
-      if (!is_abs && compare_filenames_for_search (s->filename, name))
+      if (compare_filenames_for_search (s->filename, name))
        {
          if (callback (s, data))
            return 1;
@@ -222,50 +219,26 @@ iterate_over_some_symtabs (const char *name,
        && FILENAME_CMP (base_name, lbasename (s->filename)) != 0)
       continue;
 
-    /* If the user gave us an absolute path, try to find the file in
-       this symtab and use its absolute path.  */
-
-    if (full_path != NULL)
+    if (compare_filenames_for_search (symtab_to_fullname (s), name))
       {
-        const char *fp = symtab_to_fullname (s);
-
-        if (FILENAME_CMP (full_path, fp) == 0)
-          {
-           if (callback (s, data))
-             return 1;
-          }
-
-       if (!is_abs && compare_filenames_for_search (fp, name))
-         {
-           if (callback (s, data))
-             return 1;
-         }
+       if (callback (s, data))
+         return 1;
       }
 
+    /* If the user gave us an absolute path, try to find the file in
+       this symtab and use its absolute path.  */
+
     if (real_path != NULL)
       {
         const char *fullname = symtab_to_fullname (s);
-       char *rp = gdb_realpath (fullname);
-       struct cleanup *cleanups = make_cleanup (xfree, rp);
 
-       if (FILENAME_CMP (real_path, rp) == 0)
+       gdb_assert (IS_ABSOLUTE_PATH (real_path));
+       gdb_assert (IS_ABSOLUTE_PATH (name));
+       if (FILENAME_CMP (real_path, fullname) == 0)
          {
            if (callback (s, data))
-             {
-               do_cleanups (cleanups);
-               return 1;
-             }
-         }
-
-       if (!is_abs && compare_filenames_for_search (rp, name))
-         {
-           if (callback (s, data))
-             {
-               do_cleanups (cleanups);
-               return 1;
-             }
+             return 1;
          }
-       do_cleanups (cleanups);
       }
     }
 
@@ -285,25 +258,22 @@ iterate_over_symtabs (const char *name,
                                       void *data),
                      void *data)
 {
-  struct symtab *s = NULL;
   struct objfile *objfile;
   char *real_path = NULL;
-  char *full_path = NULL;
   struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
 
   /* Here we are interested in canonicalizing an absolute path, not
      absolutizing a relative path.  */
   if (IS_ABSOLUTE_PATH (name))
     {
-      full_path = xfullpath (name);
-      make_cleanup (xfree, full_path);
       real_path = gdb_realpath (name);
       make_cleanup (xfree, real_path);
+      gdb_assert (IS_ABSOLUTE_PATH (real_path));
     }
 
   ALL_OBJFILES (objfile)
   {
-    if (iterate_over_some_symtabs (name, full_path, real_path, callback, data,
+    if (iterate_over_some_symtabs (name, real_path, callback, data,
                                   objfile->symtabs, NULL))
       {
        do_cleanups (cleanups);
@@ -319,7 +289,6 @@ iterate_over_symtabs (const char *name,
     if (objfile->sf
        && objfile->sf->qf->map_symtabs_matching_filename (objfile,
                                                           name,
-                                                          full_path,
                                                           real_path,
                                                           callback,
                                                           data))
@@ -526,7 +495,7 @@ symbol_set_language (struct general_symbol_info *gsymbol,
 /* Objects of this type are stored in the demangled name hash table.  */
 struct demangled_name_entry
 {
-  char *mangled;
+  const char *mangled;
   char demangled[1];
 };
 
@@ -758,7 +727,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
       linkage_name_copy = linkage_name;
     }
 
-  entry.mangled = (char *) lookup_name;
+  entry.mangled = lookup_name;
   slot = ((struct demangled_name_entry **)
          htab_find_slot (objfile->demangled_names_hash,
                          &entry, INSERT));
@@ -789,10 +758,12 @@ symbol_set_names (struct general_symbol_info *gsymbol,
                                 offsetof (struct demangled_name_entry,
                                           demangled)
                                 + demangled_len + 1);
-         (*slot)->mangled = (char *) lookup_name;
+         (*slot)->mangled = lookup_name;
        }
       else
        {
+         char *mangled_ptr;
+
          /* If we must copy the mangled name, put it directly after
             the demangled name so we can have a single
             allocation.  */
@@ -800,8 +771,9 @@ symbol_set_names (struct general_symbol_info *gsymbol,
                                 offsetof (struct demangled_name_entry,
                                           demangled)
                                 + lookup_len + demangled_len + 2);
-         (*slot)->mangled = &((*slot)->demangled[demangled_len + 1]);
-         strcpy ((*slot)->mangled, lookup_name);
+         mangled_ptr = &((*slot)->demangled[demangled_len + 1]);
+         strcpy (mangled_ptr, lookup_name);
+         (*slot)->mangled = mangled_ptr;
        }
 
       if (demangled_name != NULL)
@@ -1684,7 +1656,7 @@ Internal: %s symbol `%s' found in %s psymtab but not in symtab.\n\
 %s may be an inlined function, or may be a template function\n\
 (if a template, try specifying an instantiation: %s<type>)."),
               kind == GLOBAL_BLOCK ? "global" : "static",
-              name, symtab->filename, name, name);
+              name, symtab_to_filename_for_display (symtab), name, name);
     }
   return fixup_symbol_section (sym, objfile);
 }
@@ -1889,7 +1861,7 @@ basic_lookup_transparent_type_quick (struct objfile *objfile, int kind,
 Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
 %s may be an inlined function, or may be a template function\n\
 (if a template, try specifying an instantiation: %s<type>)."),
-              name, symtab->filename, name, name);
+              name, symtab_to_filename_for_display (symtab), name, name);
     }
   if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
     return SYMBOL_TYPE (sym);
@@ -2100,12 +2072,9 @@ find_pc_sect_symtab (CORE_ADDR pc, struct obj_section *section)
   struct symtab *s = NULL;
   struct symtab *best_s = NULL;
   struct objfile *objfile;
-  struct program_space *pspace;
   CORE_ADDR distance = 0;
   struct minimal_symbol *msymbol;
 
-  pspace = current_program_space;
-
   /* If we know that this is not a text address, return failure.  This is
      necessary because we loop based on the block's high and low code
      addresses, which do not include the data ranges, and because
@@ -2258,7 +2227,6 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
      we will use a line one less than this,
      with a range from the start of that file to the first line's pc.  */
   struct linetable_entry *alt = NULL;
-  struct symtab *alt_symtab = 0;
 
   /* Info on best line seen in this file.  */
 
@@ -2403,10 +2371,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
       /* Is this file's first line closer than the first lines of other files?
          If so, record this file, and its first line, as best alternate.  */
       if (item->pc > pc && (!alt || item->pc < alt->pc))
-       {
-         alt = item;
-         alt_symtab = s;
-       }
+       alt = item;
 
       for (i = 0; i < len; i++, item++)
        {
@@ -2542,8 +2507,8 @@ find_line_symtab (struct symtab *symtab, int line,
       ALL_OBJFILES (objfile)
       {
        if (objfile->sf)
-         objfile->sf->qf->expand_symtabs_with_filename (objfile,
-                                                        symtab->filename);
+         objfile->sf->qf->expand_symtabs_with_fullname (objfile,
+                                                  symtab_to_fullname (symtab));
       }
 
       ALL_SYMTABS (objfile, s)
@@ -2597,8 +2562,7 @@ VEC (CORE_ADDR) *
 find_pcs_for_symtab_line (struct symtab *symtab, int line,
                          struct linetable_entry **best_item)
 {
-  int start = 0, ix;
-  struct symbol *previous_function = NULL;
+  int start = 0;
   VEC (CORE_ADDR) *result = NULL;
 
   /* First, collect all the PCs that are at this line.  */
@@ -3301,8 +3265,11 @@ sources_info (char *ignore, int from_tty)
   do_cleanups (cleanups);
 }
 
+/* Compare FILE against all the NFILES entries of FILES.  If BASENAMES is
+   non-zero compare only lbasename of FILES.  */
+
 static int
-file_matches (const char *file, char *files[], int nfiles)
+file_matches (const char *file, char *files[], int nfiles, int basenames)
 {
   int i;
 
@@ -3310,7 +3277,9 @@ file_matches (const char *file, char *files[], int nfiles)
     {
       for (i = 0; i < nfiles; i++)
        {
-         if (filename_cmp (files[i], lbasename (file)) == 0)
+         if (compare_filenames_for_search (file, (basenames
+                                                  ? lbasename (files[i])
+                                                  : files[i])))
            return 1;
        }
     }
@@ -3410,11 +3379,12 @@ struct search_symbols_data
 /* A callback for expand_symtabs_matching.  */
 
 static int
-search_symbols_file_matches (const char *filename, void *user_data)
+search_symbols_file_matches (const char *filename, void *user_data,
+                            int basenames)
 {
   struct search_symbols_data *data = user_data;
 
-  return file_matches (filename, data->files, data->nfiles);
+  return file_matches (filename, data->files, data->nfiles, basenames);
 }
 
 /* A callback for expand_symtabs_matching.  */
@@ -3623,7 +3593,14 @@ search_symbols (char *regexp, enum search_domain kind,
 
            QUIT;
 
-           if (file_matches (real_symtab->filename, files, nfiles)
+           /* Check first sole REAL_SYMTAB->FILENAME.  It does not need to be
+              a substring of symtab_to_fullname as it may contain "./" etc.  */
+           if ((file_matches (real_symtab->filename, files, nfiles, 0)
+                || ((basenames_may_differ
+                     || file_matches (lbasename (real_symtab->filename),
+                                      files, nfiles, 1))
+                    && file_matches (symtab_to_fullname (real_symtab),
+                                     files, nfiles, 0)))
                && ((!datum.preg_p
                     || regexec (&datum.preg, SYMBOL_NATURAL_NAME (sym), 0,
                                 NULL, 0) == 0)
@@ -3741,12 +3718,14 @@ search_symbols (char *regexp, enum search_domain kind,
 static void
 print_symbol_info (enum search_domain kind,
                   struct symtab *s, struct symbol *sym,
-                  int block, char *last)
+                  int block, const char *last)
 {
-  if (last == NULL || filename_cmp (last, s->filename) != 0)
+  const char *s_filename = symtab_to_filename_for_display (s);
+
+  if (last == NULL || filename_cmp (last, s_filename) != 0)
     {
       fputs_filtered ("\nFile ", gdb_stdout);
-      fputs_filtered (s->filename, gdb_stdout);
+      fputs_filtered (s_filename, gdb_stdout);
       fputs_filtered (":\n", gdb_stdout);
     }
 
@@ -3804,7 +3783,7 @@ symtab_symbol_info (char *regexp, enum search_domain kind, int from_tty)
   struct symbol_search *symbols;
   struct symbol_search *p;
   struct cleanup *old_chain;
-  char *last_filename = NULL;
+  const char *last_filename = NULL;
   int first = 1;
 
   gdb_assert (kind <= TYPES_DOMAIN);
@@ -3839,7 +3818,7 @@ symtab_symbol_info (char *regexp, enum search_domain kind, int from_tty)
                             p->symbol,
                             p->block,
                             last_filename);
-         last_filename = p->symtab->filename;
+         last_filename = symtab_to_filename_for_display (p->symtab);
        }
     }
 
@@ -3923,7 +3902,9 @@ rbreak_command (char *regexp, int from_tty)
     {
       if (p->msymbol == NULL)
        {
-         int newlen = (strlen (p->symtab->filename)
+         const char *fullname = symtab_to_fullname (p->symtab);
+
+         int newlen = (strlen (fullname)
                        + strlen (SYMBOL_LINKAGE_NAME (p->symbol))
                        + 4);
 
@@ -3932,7 +3913,7 @@ rbreak_command (char *regexp, int from_tty)
              string = xrealloc (string, newlen);
              len = newlen;
            }
-         strcpy (string, p->symtab->filename);
+         strcpy (string, fullname);
          strcat (string, ":'");
          strcat (string, SYMBOL_LINKAGE_NAME (p->symbol));
          strcat (string, "'");
@@ -3941,7 +3922,7 @@ rbreak_command (char *regexp, int from_tty)
                             p->symtab,
                             p->symbol,
                             p->block,
-                            p->symtab->filename);
+                            symtab_to_filename_for_display (p->symtab));
        }
       else
        {
@@ -4038,8 +4019,6 @@ completion_list_add_name (const char *symname,
                          const char *sym_text, int sym_text_len,
                          const char *text, const char *word)
 {
-  int newsize;
-
   /* Clip symbols that cannot match.  */
   if (!compare_symbol_name (symname, sym_text, sym_text_len))
     return;
@@ -4902,6 +4881,10 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
             line mark the prologue -> body transition.  */
          if (sal.line >= prologue_sal.line)
            break;
+         /* Likewise if we are in a different symtab altogether
+            (e.g. within a file included via #include).  */
+         if (sal.symtab != prologue_sal.symtab)
+           break;
 
          /* The line number is smaller.  Check that it's from the
             same function, not something inlined.  If it's inlined,
This page took 0.031273 seconds and 4 git commands to generate.