/* List lines of source files for GDB, the GNU debugger.
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
- 2009 Free Software Foundation, Inc.
+ 2009, 2010 Free Software Foundation, Inc.
This file is part of GDB.
static int current_source_line;
+static struct program_space *current_source_pspace;
+
/* Default number of lines to print with commands like "list".
This is based on guessing how many long (i.e. more than chars_per_line
characters) lines there will be. To be completely correct, "list"
{
struct symtab_and_line cursal = { 0 };
+ cursal.pspace = current_source_pspace;
cursal.symtab = current_source_symtab;
cursal.line = current_source_line;
cursal.pc = 0;
set_current_source_symtab_and_line (const struct symtab_and_line *sal)
{
struct symtab_and_line cursal = { 0 };
-
+
+ cursal.pspace = current_source_pspace;
cursal.symtab = current_source_symtab;
cursal.line = current_source_line;
+ cursal.pc = 0;
+ cursal.end = 0;
+ current_source_pspace = sal->pspace;
current_source_symtab = sal->symtab;
current_source_line = sal->line;
- cursal.pc = 0;
- cursal.end = 0;
-
+
return cursal;
}
{
current_source_symtab = s;
current_source_line = 1;
+ current_source_pspace = SYMTAB_PSPACE (s);
return;
}
sals = decode_line_spec (main_name (), 1);
sal = sals.sals[0];
xfree (sals.sals);
+ current_source_pspace = sal.pspace;
current_source_symtab = sal.symtab;
current_source_line = max (sal.line - (lines_to_list - 1), 1);
if (current_source_symtab)
current_source_line = 1;
- for (ofp = object_files; ofp != NULL; ofp = ofp->next)
+ ALL_OBJFILES (ofp)
{
for (s = ofp->symtabs; s; s = s->next)
{
int len = strlen (name);
if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
|| strcmp (name, "<<C++-namespaces>>") == 0)))
- current_source_symtab = s;
+ {
+ current_source_pspace = current_program_space;
+ current_source_symtab = s;
+ }
}
}
+
if (current_source_symtab)
return;
/* How about the partial symbol tables? */
- for (ofp = object_files; ofp != NULL; ofp = ofp->next)
+ ALL_OBJFILES (ofp)
{
for (ps = ofp->psymtabs; ps != NULL; ps = ps->next)
{
}
else
{
+ current_source_pspace = current_program_space;
current_source_symtab = PSYMTAB_TO_SYMTAB (cs_pst);
}
}
void
forget_cached_source_info (void)
{
+ struct program_space *pspace;
struct symtab *s;
struct objfile *objfile;
struct partial_symtab *pst;
- for (objfile = object_files; objfile != NULL; objfile = objfile->next)
+ ALL_PSPACES (pspace)
+ ALL_PSPACE_OBJFILES (pspace, objfile)
{
for (s = objfile->symtabs; s != NULL; s = s->next)
{
}
}
}
+
+ last_source_visited = NULL;
}
void
forget_cached_source_info ();
}
-void
-init_last_source_visited (void)
-{
- last_source_visited = NULL;
-}
-
/* Add zero or more directories to the front of the source path. */
void
else
{
mod_path (dirname, &source_path);
- last_source_visited = NULL;
+ forget_cached_source_info ();
}
if (from_tty)
show_directories ((char *) 0, from_tty);
- forget_cached_source_info ();
}
/* Add a path given with the -d command line switch.
/* The open syscall MODE parameter is not specified. */
gdb_assert ((mode & O_CREAT) == 0);
+ gdb_assert (string != NULL);
+
+ /* A file with an empty name cannot possibly exist. Report a failure
+ without further checking.
+
+ This is an optimization which also defends us against buggy
+ implementations of the "stat" function. For instance, we have
+ noticed that a MinGW debugger built on Windows XP 32bits crashes
+ when the debugger is started with an empty argument. */
+ if (string[0] == '\0')
+ {
+ errno = ENOENT;
+ return -1;
+ }
if (!path)
path = ".";
}
/* This function is capable of finding the absolute path to a
- source file, and opening it, provided you give it an
- OBJFILE and FILENAME. Both the DIRNAME and FULLNAME are only
- added suggestions on where to find the file.
+ source file, and opening it, provided you give it a FILENAME. Both the
+ DIRNAME and FULLNAME are only added suggestions on where to find the file.
- OBJFILE should be the objfile associated with a psymtab or symtab.
FILENAME should be the filename to open.
DIRNAME is the compilation directory of a particular source file.
Only some debug formats provide this info.
FULLNAME is set to NULL. */
static int
-find_and_open_source (struct objfile *objfile,
- const char *filename,
+find_and_open_source (const char *filename,
const char *dirname,
char **fullname)
{
if (!s)
return -1;
- return find_and_open_source (s->objfile, s->filename, s->dirname,
- &s->fullname);
+ return find_and_open_source (s->filename, s->dirname, &s->fullname);
}
/* Finds the fullname that a symtab represents.
/* Don't check s->fullname here, the file could have been
deleted/moved/..., look for it again */
- r = find_and_open_source (s->objfile, s->filename, s->dirname,
- &s->fullname);
+ r = find_and_open_source (s->filename, s->dirname, &s->fullname);
if (r >= 0)
{
/* Don't check ps->fullname here, the file could have been
deleted/moved/..., look for it again */
- r = find_and_open_source (ps->objfile, ps->filename, ps->dirname,
- &ps->fullname);
+ r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
if (r >= 0)
{
if (re_exec (buf) > 0)
{
/* Match! */
- fclose (stream);
+ do_cleanups (cleanups);
print_source_lines (current_source_symtab, line, line + 1, 0);
set_internalvar_integer (lookup_internalvar ("_"), line);
current_source_line = max (line - lines_to_list / 2, 1);
if (re_exec (buf) > 0)
{
/* Match! */
- fclose (stream);
+ do_cleanups (cleanups);
print_source_lines (current_source_symtab, line, line + 1, 0);
set_internalvar_integer (lookup_internalvar ("_"), line);
current_source_line = max (line - lines_to_list / 2, 1);
line--;
if (fseek (stream, current_source_symtab->line_charpos[line - 1], 0) < 0)
{
- fclose (stream);
+ do_cleanups (cleanups);
perror_with_name (current_source_symtab->filename);
}
}
if (from != NULL && !rule_found)
error (_("No substitution rule defined for `%s'"), from);
+
+ forget_cached_source_info ();
}
/* Add a new source path substitution rule. */
/* Insert the new substitution rule. */
add_substitute_path_rule (argv[0], argv[1]);
+ forget_cached_source_info ();
}
\f