This is the mail archive of the
gdb-prs@sources.redhat.com
mailing list for the GDB project.
symtab/1537: anonymous union at function scope, gcc 3.4
- From: mec dot gnu at mindspring dot com
- To: gdb-gnats at sources dot redhat dot com
- Date: 30 Jan 2004 06:06:08 -0000
- Subject: symtab/1537: anonymous union at function scope, gcc 3.4
- Reply-to: mec dot gnu at mindspring dot com
>Number: 1537
>Category: symtab
>Synopsis: anonymous union at function scope, gcc 3.4
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Fri Jan 30 06:08:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator: mec.gnu@mindspring.com
>Release: gdb 6.0
>Organization:
>Environment:
target = native, host = i686-pc-linux-gnu, osversion=red-hat-8.0
gdb = 6.0
gcc = gcc HEAD 2004-01-27
binutils = 2.14
glibc = 2.2.93-5-rh
gformat = dwarf-2, glevel = 2
>Description:
gcc changed its debug information for anonymous unions and gdb can't cope. This happens only for anonymous unions which are variables; anonymous unions which are nested inside other structures are fine.
Here is a test program:
int sum;
void f2 (int *pi)
{
sum += *pi;
}
void f1 ()
{
union
{
int alpha;
int beta;
};
alpha = 1;
f2 (&alpha);
beta = 2;
f2 (&beta);
}
int main ()
{
f1 ();
}
With gcc 3.3.2 -gdwarf-2, the DIE's look like this:
<2><ca0>: Abbrev Number: 6 (DW_TAG_variable)
DW_AT_name : (indirect string, offset: 0x98a): alpha
DW_AT_decl_file : 1
DW_AT_decl_line : 14
DW_AT_type : <c80>
DW_AT_location : 2 byte block: 91 7c (DW_OP_fbreg: -4; )
<2><cae>: Abbrev Number: 6 (DW_TAG_variable)
DW_AT_name : (indirect string, offset: 0x9ba): beta
DW_AT_decl_file : 1
DW_AT_decl_line : 14
DW_AT_type : <c80>
DW_AT_location : 2 byte block: 91 7c (DW_OP_fbreg: -4; )
But with gcc HEAD or gcc gcc-3_4-branch, the DIEs look like this:
<3><d04>: Abbrev Number: 7 (DW_TAG_union_type)
DW_AT_sibling : <d26>
DW_AT_byte_size : 4
DW_AT_decl_file : 1
DW_AT_decl_line : 11
<4><d0c>: Abbrev Number: 8 (DW_TAG_member)
DW_AT_name : alpha
DW_AT_decl_file : 1
DW_AT_decl_line : 12
DW_AT_type : <cd8>
<4><d19>: Abbrev Number: 8 (DW_TAG_member)
DW_AT_name : beta
DW_AT_decl_file : 1
DW_AT_decl_line : 13
DW_AT_type : <cd8>
<3><d26>: Abbrev Number: 9 (DW_TAG_variable)
DW_AT_type : <d04>
DW_AT_location : 2 byte block: 91 7c (DW_OP_fbreg: -4; )
The new compiler is more accurate, but gdb does not understand the DW_TAG_variable with no name and appears to discard it.
Compare:
# gcc 3.3.2
(gdb) info locals
alpha = 1
beta = 1
# gcc gcc-3_4-branch or gcc HEAD
(gdb) info locals
No locals.
This happens with both dwarf-2 and stabs+.
>How-To-Repeat:
Compile the sample program with gcc HEAD or gcc gcc-3_4-branch
Break on f1.
Run two lines into f1.
type "print alpha" or "print beta" or "info locals".
You can also see the problem with gdb.cp/anon-union.exp. See the "print w *" and "print z *" tests.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: