/* 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)
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]));
}
/* 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.
int
iterate_over_some_symtabs (const char *name,
- const char *full_path,
const char *real_path,
int (*callback) (struct symtab *symtab,
void *data),
{
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;
&& 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);
}
}
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);
if (objfile->sf
&& objfile->sf->qf->map_symtabs_matching_filename (objfile,
name,
- full_path,
real_path,
callback,
data))
/* Objects of this type are stored in the demangled name hash table. */
struct demangled_name_entry
{
- char *mangled;
+ const char *mangled;
char demangled[1];
};
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));
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. */
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)
%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);
}
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);
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
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. */
/* 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++)
{
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)
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. */
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;
{
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;
}
}
/* 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. */
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)
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);
}
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);
p->symbol,
p->block,
last_filename);
- last_filename = p->symtab->filename;
+ last_filename = symtab_to_filename_for_display (p->symtab);
}
}
{
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);
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, "'");
p->symtab,
p->symbol,
p->block,
- p->symtab->filename);
+ symtab_to_filename_for_display (p->symtab));
}
else
{
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;
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,