for (j = 0; j < file_data->num_file_names; ++j)
{
const char *this_name = file_data->file_names[j];
+ const char *this_real_name;
if (compare_filenames_for_search (this_name, name))
{
&& FILENAME_CMP (lbasename (this_name), name_basename) != 0)
continue;
- if (real_path != NULL)
+ this_real_name = dw2_get_real_path (objfile, file_data, j);
+ if (compare_filenames_for_search (this_real_name, name))
{
- const char *this_real_name = dw2_get_real_path (objfile,
- file_data, j);
+ if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
+ callback, data))
+ return 1;
+ }
+ if (real_path != NULL)
+ {
gdb_assert (IS_ABSOLUTE_PATH (real_path));
gdb_assert (IS_ABSOLUTE_PATH (name));
if (this_real_name != NULL
static void
dw2_expand_symtabs_matching
(struct objfile *objfile,
- int (*file_matcher) (const char *, void *),
+ int (*file_matcher) (const char *, void *, int basenames),
int (*name_matcher) (const char *, void *),
enum search_domain kind,
void *data)
for (j = 0; j < file_data->num_file_names; ++j)
{
- if (file_matcher (file_data->file_names[j], data))
+ const char *this_real_name;
+
+ if (file_matcher (file_data->file_names[j], data, 0))
+ {
+ per_cu->v.quick->mark = 1;
+ break;
+ }
+
+ /* Before we invoke realpath, which can get expensive when many
+ files are involved, do a quick comparison of the basenames. */
+ if (!basenames_may_differ
+ && !file_matcher (lbasename (file_data->file_names[j]),
+ data, 1))
+ continue;
+
+ this_real_name = dw2_get_real_path (objfile, file_data, j);
+ if (file_matcher (this_real_name, data, 0))
{
per_cu->v.quick->mark = 1;
break;
{
struct partial_symtab *subpst = allocate_psymtab (name, objfile);
+ if (!IS_ABSOLUTE_PATH (subpst->filename))
+ {
+ /* It shares objfile->objfile_obstack. */
+ subpst->dirname = pst->dirname;
+ }
+
subpst->section_offsets = pst->section_offsets;
subpst->textlow = 0;
subpst->texthigh = 0;
\f
/* Macro support. */
-/* Return the full name of file number I in *LH's file name table.
- Use COMP_DIR as the name of the current directory of the
- compilation. The result is allocated using xmalloc; the caller is
+/* Return file name relative to the compilation directory of file number I in
+ *LH's file name table. The result is allocated using xmalloc; the caller is
responsible for freeing it. */
+
static char *
-file_full_name (int file, struct line_header *lh, const char *comp_dir)
+file_file_name (int file, struct line_header *lh)
{
/* Is the file number a valid index into the line header's file name
table? Remember that file numbers start with one, not zero. */
{
struct file_entry *fe = &lh->file_names[file - 1];
- if (IS_ABSOLUTE_PATH (fe->name))
+ if (IS_ABSOLUTE_PATH (fe->name) || fe->dir_index == 0)
return xstrdup (fe->name);
- else
- {
- const char *dir;
- int dir_len;
- char *full_name;
-
- if (fe->dir_index)
- dir = lh->include_dirs[fe->dir_index - 1];
- else
- dir = comp_dir;
-
- if (dir)
- {
- dir_len = strlen (dir);
- full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
- strcpy (full_name, dir);
- full_name[dir_len] = '/';
- strcpy (full_name + dir_len + 1, fe->name);
- return full_name;
- }
- else
- return xstrdup (fe->name);
- }
+ return concat (lh->include_dirs[fe->dir_index - 1], SLASH_STRING,
+ fe->name, NULL);
}
else
{
}
}
+/* Return the full name of file number I in *LH's file name table.
+ Use COMP_DIR as the name of the current directory of the
+ compilation. The result is allocated using xmalloc; the caller is
+ responsible for freeing it. */
+static char *
+file_full_name (int file, struct line_header *lh, const char *comp_dir)
+{
+ /* Is the file number a valid index into the line header's file name
+ table? Remember that file numbers start with one, not zero. */
+ if (1 <= file && file <= lh->num_file_names)
+ {
+ char *relative = file_file_name (file, lh);
+
+ if (IS_ABSOLUTE_PATH (relative) || comp_dir == NULL)
+ return relative;
+ return reconcat (relative, comp_dir, SLASH_STRING, relative, NULL);
+ }
+ else
+ return file_file_name (file, lh);
+}
+
static struct macro_source_file *
macro_start_file (int file, int line,
const char *comp_dir,
struct line_header *lh, struct objfile *objfile)
{
- /* The full name of this source file. */
- char *full_name = file_full_name (file, lh, comp_dir);
+ /* File name relative to the compilation directory of this source file. */
+ char *file_name = file_file_name (file, lh);
/* We don't create a macro table for this compilation unit
at all until we actually get a filename. */
if (! pending_macros)
pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
- objfile->per_bfd->macro_cache);
+ objfile->per_bfd->macro_cache,
+ comp_dir);
if (! current_file)
{
/* If we have no current file, then this must be the start_file
directive for the compilation unit's main source file. */
- current_file = macro_set_main (pending_macros, full_name);
+ current_file = macro_set_main (pending_macros, file_name);
macro_define_special (pending_macros);
}
else
- current_file = macro_include (current_file, line, full_name);
+ current_file = macro_include (current_file, line, file_name);
- xfree (full_name);
+ xfree (file_name);
return current_file;
}