Fix breakpoints when several source files have the same name

Joel Brobecker brobecker@adacore.com
Tue Sep 29 22:20:00 GMT 2009


Sebastien,

Really really sorry for taking so long before reviewing this patch.
Please don't hesitate to send pings on the list to remind us of a patch
that is sitting unreviewed for more than a week or two.

> There is in gdb 6.8 a new bug that makes breakpoints inserted at the  
> wrong place when a program has several files with the same base name (in  
> different directories).
[...]
> I have found it using the mi interface but it appears in the same way  
> with the other commands.

For the record, here is how I reproduced the issue on my side:
I have two small files a/foo.c and b/foo.c, each containing an empty
function called foo_a and foo_b (resp). Then a file main.c:

     extern void foo_a (void);
     extern void foo_b (void);
     
     int
     main (void)
     {
       foo_a ();
       foo_b ();
     
       return 0;
     }

To build, I did:

    % (cd a && gcc -c -g foo.c)
    % (cd b && gcc -c -g foo.c)
    % gcc -o main main.c a/foo.o b/foo.o

The important part here, is to compile both foo.c files from
within the directory where these files are located, at least
with GCC.

Trying to break on either location, using the filename's fullname,
results in 2 breakpoints being inserted instead of just one:

    (gdb) b /t.a/brobecke/ex/break/a/foo.c:3
    Breakpoint 1 at 0x400480: file foo.c, line 4. (2 locations)
    (gdb) b /t.a/brobecke/ex/break/b/foo.c:3
    Note: breakpoint 1 also set at pc 0x400480.
    Note: breakpoint 1 also set at pc 0x400478.
    Breakpoint 2 at 0x400480: file foo.c, line 4. (2 locations)

> 2009-05-24  Sebastien Granjoux <seb.sfo@free.fr>
> 
> 	PR mi/9583:
> 	* symtab.c (find_line_symtab): Use full filename if available

My concern with your approach is with performance: symtab_to_fullname
and psymtab_to_fullname are actually a bit expensive to call, as they
involve locating the file on the local host disk, taking into account
debugging info as well as the source path (see the "dir" command) and
then opening/closing that file if found.

How about changing the patch to only do the fullname matching iff
(if and only iff) the simple filename matches first.  In other words,
compute the symtab/psymtab fullname only if the filename matches.

-- 
Joel



More information about the Gdb-patches mailing list