This is the mail archive of the gdb-prs@sourceware.org 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]

[Bug exp/14093] New: Wrong type found by check_typedef


http://sourceware.org/bugzilla/show_bug.cgi?id=14093

             Bug #: 14093
           Summary: Wrong type found by check_typedef
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: exp
        AssignedTo: unassigned@sourceware.org
        ReportedBy: brobecker@gnat.com
    Classification: Unclassified


Created attachment 6404
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6404
Text files containing all sources needed to reproduce.

Reproduced on x86_64-linux, using GNU gdb (GDB) 7.4.50.20120509-cvs.

The sources are filed as an attachement. To compile the sources, do:

  % gcc -o libfoo.so -g -shared -fPIC lib-foo.c lib-if.c
  % gcc -o main -g foo.c foo-if.c main.c -lfoo -L.

The sources create a scenario where two source files use an opaque type
(foo-if.c and lib-if.c). The opaque type in each file has the same name
(struct some_data), but the actual definition is different.

When trying to print the value of a variable of that type, check_typedef
needs to be called in order to resolve the variable's type. The resolution
is performed regardless of context, and thus results in the same type
being returned each time.  This means that one of the times, the variable
value is printed wrong, as demonstrated in the GDB transcript below.

One way to mitigate the problem in this example is to enhance check_typedef
to search the same objfile as the objfile where the variable is defined. But
the testcase can be tweaked into a single executable, and reveal the same
problem. Just compile the sources using:

  % gcc -o main-single -g *.c

In that case, the heuristics of searching the current objfile first isn't going
to be sufficient.  Not sure if there is a solution to that problem...

GDB session transcript:

(gdb) b foo-if.c:9
Breakpoint 1 at 0x4004f3: file foo-if.c, line 9.
(gdb) b lib-if.c:9
Breakpoint 2 at 0x400581: file lib-if.c, line 9.
(gdb) run
Starting program: /[...]/main 

Breakpoint 1, do_something_in_foo () at foo-if.c:9
9         return data != NULL;
(gdb) p *data
$1 = {a = 11, b = 21}
(gdb) c
Continuing.

Breakpoint 2, do_something_in_lib () at lib-if.c:9
9         return data != NULL;
(gdb) p *data
$2 = {a = 1684234849, b = 0}

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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