* Symbolic constants inside classes
@ 2010-12-18 20:17 Jonas Maebe
2010-12-20 21:23 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Jonas Maebe @ 2010-12-18 20:17 UTC (permalink / raw)
To: gdb
Hi,
Consider this C++ program:
***
class Xyz {
public:
static const int MAGIC_NUM = 42;
private:
char mArray[MAGIC_NUM];
};
class Xyz2 {
public:
static const int MAGIC_NUM = 43;
private:
char mArray2[MAGIC_NUM];
};
Xyz C;
Xyz2 C2;
int main()
{
return 0;
}
***
g++ -gdwarf-2 generates a definition for both MAGIC_NUM constants both in the respective class scopes, and also in the global namespace:
in the class:
<1><78>: Abbrev Number: 2 (DW_TAG_class_type) -- Xyz declaration
DW_AT_sibling : <a9>
DW_AT_name : Xyz
DW_AT_byte_size : 42
DW_AT_decl_file : 1
DW_AT_decl_line : 1
<2><84>: Abbrev Number: 3 (DW_TAG_variable) -- MAGIC_NUM field
DW_AT_name : (indirect string, offset: 0x14): MAGIC_NUM
DW_AT_decl_file : 1
DW_AT_decl_line : 3
DW_AT_MIPS_linkage_name: (indirect string, offset: 0x1e): _ZN3Xyz9MAGIC_NUME
DW_AT_type : <a9>
DW_AT_external : 1
DW_AT_declaration : 1
DW_AT_const_value : 42
...
in the global namespace:
<1><146>: Abbrev Number: 10 (DW_TAG_namespace) -- global namespace
DW_AT_sibling : <168>
DW_AT_name : ::
DW_AT_decl_file : 2
DW_AT_decl_line : 0
...
<1><168>: Abbrev Number: 12 (DW_TAG_variable) -- "C" global variable
DW_AT_specification: <150>
DW_AT_location : 9 byte block: 3 0 0 0 0 0 0 0 0 (DW_OP_addr: 0)
<1><177>: Abbrev Number: 12 (DW_TAG_variable) -- "C2" global variable
DW_AT_specification: <15b>
DW_AT_location : 9 byte block: 3 0 0 0 0 0 0 0 0 (DW_OP_addr: 0)
<1><186>: Abbrev Number: 3 (DW_TAG_variable) -- Xyz::MAGIC_NUM
DW_AT_name : (indirect string, offset: 0x14): MAGIC_NUM
DW_AT_decl_file : 1
DW_AT_decl_line : 3
DW_AT_MIPS_linkage_name: (indirect string, offset: 0x1e): _ZN3Xyz9MAGIC_NUME
DW_AT_type : <a9>
DW_AT_external : 1
DW_AT_declaration : 1
DW_AT_const_value : 42
<1><198>: Abbrev Number: 3 (DW_TAG_variable) -- Xyz2::MAGIC_NUM
DW_AT_name : (indirect string, offset: 0x14): MAGIC_NUM
DW_AT_decl_file : 1
DW_AT_decl_line : 10
DW_AT_MIPS_linkage_name: (indirect string, offset: 0x0): _ZN4Xyz29MAGIC_NUME
DW_AT_type : <a9>
DW_AT_external : 1
DW_AT_declaration : 1
DW_AT_const_value : 43
In gdb (7.0),
1) p MAGIC_NUM prints 42
2) "p Xyz::MAGIC_NUM" and "p Xyz2::MAGIC_NUM" print "static field MAGIC_NUM has been optimized out"
3) "p C.MAGIC_NUM" and "p C2.MAGIC_NUM" print "field MAGIC_NUM is nonexistent or has been optimised out"
4) ptype Xyz returns:
type = class Xyz {
public:
static const int MAGIC_NUM;
private:
char mArray[42];
}
My questions:
a) why does GDB not know the value of MAGIC_NUM inside the class scope? It is there in the debug info (see above)
b) does g++ possibly add the constants to the global scope because gdb cannot show them in the class scope (although it obviously can still only show one of them in case of a name conflict), or is this required by a DWARF rule I missed?
Jonas
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Symbolic constants inside classes
2010-12-18 20:17 Symbolic constants inside classes Jonas Maebe
@ 2010-12-20 21:23 ` Tom Tromey
2010-12-20 22:56 ` Jonas Maebe
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2010-12-20 21:23 UTC (permalink / raw)
To: Jonas Maebe; +Cc: gdb
>>>>> "Jonas" == Jonas Maebe <jonas.maebe@elis.ugent.be> writes:
Jonas> Consider this C++ program:
[...]
Jonas> g++ -gdwarf-2 generates a definition for both MAGIC_NUM constants
Jonas> both in the respective class scopes, and also in the global
Jonas> namespace:
What version of g++?
Jonas> In gdb (7.0),
Jonas> 1) p MAGIC_NUM prints 42
Jonas> 2) "p Xyz::MAGIC_NUM" and "p Xyz2::MAGIC_NUM" print "static field MAGIC_NUM has been optimized out"
Jonas> 3) "p C.MAGIC_NUM" and "p C2.MAGIC_NUM" print "field MAGIC_NUM is nonexistent or has been optimised out"
I tried this example with svn trunk gcc and CVS head gdb, and it worked.
I didn't try to find out whether the fix was in gcc or gdb.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-12-20 22:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-18 20:17 Symbolic constants inside classes Jonas Maebe
2010-12-20 21:23 ` Tom Tromey
2010-12-20 22:56 ` Jonas Maebe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox