This is the mail archive of the gdb-prs@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gdb/555: GDB scopes macros incorrectly in multiply-#included files



>Number:         555
>Category:       gdb
>Synopsis:       GDB scopes macros incorrectly in multiply-#included files
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 20 15:58:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jim Blandy
>Release:        unknown-1.0
>Organization:
>Environment:

>Description:
If a source file is #included more than once, GDB is unable to distinguish between the multiple inclusions, and is thus unable to see which macros were in scope in each.
>How-To-Repeat:
In the transcript below, note that although listing `first_func' and `second_func' unambiguously identifies one of the two #inclusions of `m2.h', GDB is still unable to distinguish between the two; it recognizes only the second inclusion.

After listing `first_func', GDB should say that FIRST_INCLUSION is #defined, and that SECOND_INCLUSION is not; and after listing `second_func', it should say the reverse.

$ cat m1.c
#include <stdio.h>

#define FIRST_INCLUSION
#include "m2.h"
#undef FIRST_INCLUSION

#define SECOND_INCLUSION
#include "m2.h"
#undef SECOND_INCLUSION

main () { }
$ cat m2.h
#ifdef FIRST_INCLUSION
void first_func () {}
#endif

#ifdef SECOND_INCLUSION
void second_func () {}
#endif
$ gcc -gdwarf-2 -g3 m1.c -o m1
$ $D6/gdb/gdb -nw m1
GNU gdb 2002-05-17-cvs
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) list first_func
During symbol reading, macro `__ELF__' redefined at /home/jimb/play/m1.c:1;original definition at /home/jimb/play/m1.c:1.
During symbol reading, macro `__gnu_linux__' redefined at /home/jimb/play/m1.c:1;original definition at /home/jimb/play/m1.c:1.
1       #ifdef FIRST_INCLUSION
2       void first_func () {}
3       #endif
4
5       #ifdef SECOND_INCLUSION
6       void second_func () {}
7       #endif
(gdb) show macro FIRST_INCLUSION
The symbol `FIRST_INCLUSION' has no definition as a C/C++ preprocessor macro
at /home/jimb/play/m2.h:8
  included at /home/jimb/play/m1.c:8
(gdb) show macro SECOND_INCLUSION
Defined at /home/jimb/play/m1.c:7
#define SECOND_INCLUSION 
(gdb) list second_func
1       #ifdef FIRST_INCLUSION
2       void first_func () {}
3       #endif
4
5       #ifdef SECOND_INCLUSION
6       void second_func () {}
7       #endif
(gdb) show macro FIRST_INCLUSION
The symbol `FIRST_INCLUSION' has no definition as a C/C++ preprocessor macro
at /home/jimb/play/m2.h:8
  included at /home/jimb/play/m1.c:8
(gdb) show macro SECOND_INCLUSION
Defined at /home/jimb/play/m1.c:7
#define SECOND_INCLUSION 
(gdb) 
>Fix:
The problem here is that, although GDB can map a PC value (such as that obtained by looking up a function by name, like `first_func' or `second_func') to a source file and line number, it cannot map a PC value to a *particular inclusion* of a source file, and a line number.  So after the `list first_func' command, GDB knows that the macros in scope at line 8 in m2.h are visible --- but not *which inclusion* of m2.h.

This is a limitation of GDB's symtab structures.  The macro code itself is able to distinguish multiple #inclusions of the same file, but the intermediate form (symtab and line) is not, so the macro code hasn't enough information to get the right answer.
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]