Re: -file-list-exec-source-files

Bob Rossi
2004-06-28T20:40:35Z

On Sun, Jun 27, 2004 at 08:06:13PM +0200, Andreas Schwab wrote:
> Bob Rossi <bob@brasko.net> writes:
>
> > +/* Finds the fullname that a symtab represents.
> > +
> > + If this functions finds the fullname, it will save it in ps->fullname
> > + and it will also return the value.
> >
> > + If this function fails to find the file that this symtab represents,
> > + NULL will be returned and ps->fullname will be set to NULL. */
>
> This causes gdb to crash in lookup_symtab.
>
> if (full_path != NULL)
> {
> const char *fp = symtab_to_fullname (s);
> if (FILENAME_CMP (full_path, fp) == 0)
> {
> return s;
> }
> }
>
> if (real_path != NULL)
> {
> char *rp = gdb_realpath (symtab_to_fullname (s));
> make_cleanup (xfree, rp);
> if (FILENAME_CMP (real_path, rp) == 0)
> {
> return s;
> }
> }

The patch below checks symtab_to_fullname's return value against NULL.
Even though this is the "trivial" fix, I believe it is the correct
patch. When I added these calls recently, I blindly changed the old call
to symtab_to_fullname, and the old call did not return NULL.

Permission to apply?

2004-06-28 Bob Rossi <bob@brasko.net>

* symtab.c (lookup_symtab): check return value of symtab_to_fullname

Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.133
diff -w -u -r1.133 symtab.c
--- symtab.c 18 Jun 2004 21:36:15 -0000 1.133
+++ symtab.c 28 Jun 2004 20:36:18 -0000
@@ -182,7 +182,7 @@
if (full_path != NULL)
{
const char *fp = symtab_to_fullname (s);
- if (FILENAME_CMP (full_path, fp) == 0)
+ if (fp != NULL && FILENAME_CMP (full_path, fp) == 0)
{
return s;
}
@@ -190,7 +190,10 @@

if (real_path != NULL)
{
- char *rp = gdb_realpath (symtab_to_fullname (s));
+ char *fullname = symtab_to_fullname (s);
+ if (fullname != NULL)
+ {
+ char *rp = gdb_realpath (fullname);
make_cleanup (xfree, rp);
if (FILENAME_CMP (real_path, rp) == 0)
{
@@ -198,6 +201,7 @@
}
}
}
+ }

/* Now, search for a matching tail (only if name doesn't have any dirs) */