* config/tc-mips.c (macro_build_jalr): Reverse a negative
[deliverable/binutils-gdb.git] / gdb / symtab.c
index 9447bd91772474cab7dcce0fc067d63f27a1eb32..3d94e6b9a3367fc5dfab3cb54a00c35fa24bc763 100644 (file)
@@ -112,6 +112,11 @@ void _initialize_symtab (void);
 
 /* */
 
+/* Non-zero if a file may be known by two different basenames.
+   This is the uncommon case, and significantly slows down gdb.
+   Default set to "off" to not slow down the common case.  */
+int basenames_may_differ = 0;
+
 /* Allow the user to configure the debugger behavior with respect
    to multiple-choice menus when more than one symbol matches during
    a symbol lookup.  */
@@ -155,6 +160,7 @@ lookup_symtab (const char *name)
   char *real_path = NULL;
   char *full_path = NULL;
   struct cleanup *cleanup;
+  const char* base_name = lbasename (name);
 
   cleanup = make_cleanup (null_cleanup, NULL);
 
@@ -180,6 +186,12 @@ got_symtab:
        return s;
       }
 
+    /* Before we invoke realpath, which can get expensive when many
+       files are involved, do a quick comparison of the basenames.  */
+    if (! basenames_may_differ
+       && 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.  */
 
@@ -2549,8 +2561,8 @@ skip_prologue_sal (struct symtab_and_line *sal)
       /* Check if gdbarch_skip_prologue left us in mid-line, and the next
         line is still part of the same function.  */
       if (skip && start_sal.pc != pc
-         && (sym? (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= start_sal.end
-                   && start_sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
+         && (sym ? (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= start_sal.end
+                    && start_sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
              : (lookup_minimal_symbol_by_pc_section (start_sal.end, section)
                 == lookup_minimal_symbol_by_pc_section (pc, section))))
        {
@@ -2881,7 +2893,8 @@ sources_info (char *ignore, int from_tty)
                   "will be read in on demand:\n\n");
 
   first = 1;
-  map_partial_symbol_filenames (output_partial_symbol_filename, &first);
+  map_partial_symbol_filenames (output_partial_symbol_filename, &first,
+                               1 /*need_fullname*/);
   printf_filtered ("\n");
 }
 
@@ -3573,6 +3586,30 @@ compare_symbol_name (const char *name, const char *sym_text, int sym_text_len)
   return 1;
 }
 
+/* Free any memory associated with a completion list.  */
+
+static void
+free_completion_list (char ***list_ptr)
+{
+  int i = 0;
+  char **list = *list_ptr;
+
+  while (list[i] != NULL)
+    {
+      xfree (list[i]);
+      i++;
+    }
+  xfree (list);
+}
+
+/* Callback for make_cleanup.  */
+
+static void
+do_free_completion_list (void *list)
+{
+  free_completion_list (list);
+}
+
 /* Helper routine for make_symbol_completion_list.  */
 
 static int return_val_size;
@@ -3810,6 +3847,7 @@ default_make_symbol_completion_list_break_on (char *text, char *word,
   /* Length of sym_text.  */
   int sym_text_len;
   struct add_name_data datum;
+  struct cleanup *back_to;
 
   /* Now look for the symbol we are supposed to complete on.  */
   {
@@ -3886,6 +3924,7 @@ default_make_symbol_completion_list_break_on (char *text, char *word,
   return_val_index = 0;
   return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
   return_val[0] = NULL;
+  back_to = make_cleanup (do_free_completion_list, &return_val);
 
   datum.sym_text = sym_text;
   datum.sym_text_len = sym_text_len;
@@ -3995,6 +4034,7 @@ default_make_symbol_completion_list_break_on (char *text, char *word,
       macro_for_each (macro_user_macros, add_macro_name, &datum);
     }
 
+  discard_cleanups (back_to);
   return (return_val);
 }
 
@@ -4244,12 +4284,15 @@ make_source_files_completion_list (char *text, char *word)
   char **list = (char **) xmalloc (list_alloced * sizeof (char *));
   const char *base_name;
   struct add_partial_filename_data datum;
+  struct cleanup *back_to;
 
   list[0] = NULL;
 
   if (!have_full_symbols () && !have_partial_symbols ())
     return list;
 
+  back_to = make_cleanup (do_free_completion_list, &list);
+
   ALL_SYMTABS (objfile, s)
     {
       if (not_interesting_fname (s->filename))
@@ -4284,7 +4327,9 @@ make_source_files_completion_list (char *text, char *word)
   datum.list = &list;
   datum.list_used = &list_used;
   datum.list_alloced = &list_alloced;
-  map_partial_symbol_filenames (maybe_add_partial_symtab_filename, &datum);
+  map_partial_symbol_filenames (maybe_add_partial_symtab_filename, &datum,
+                               0 /*need_fullname*/);
+  discard_cleanups (back_to);
 
   return list;
 }
@@ -4852,5 +4897,19 @@ Show how the debugger handles ambiguities in expressions."), _("\
 Valid values are \"ask\", \"all\", \"cancel\", and the default is \"all\"."),
                         NULL, NULL, &setlist, &showlist);
 
+  add_setshow_boolean_cmd ("basenames-may-differ", class_obscure,
+                          &basenames_may_differ, _("\
+Set whether a source file may have multiple base names."), _("\
+Show whether a source file may have multiple base names."), _("\
+(A \"base name\" is the name of a file with the directory part removed.\n\
+Example: The base name of \"/home/user/hello.c\" is \"hello.c\".)\n\
+If set, GDB will canonicalize file names (e.g., expand symlinks)\n\
+before comparing them.  Canonicalization is an expensive operation,\n\
+but it allows the same file be known by more than one base name.\n\
+If not set (the default), all source files are assumed to have just\n\
+one base name, and gdb will do file name comparisons more efficiently."),
+                          NULL, NULL,
+                          &setlist, &showlist);
+
   observer_attach_executable_changed (symtab_observer_executable_changed);
 }
This page took 0.02575 seconds and 4 git commands to generate.