From: Jonas Maebe <jonas.maebe@elis.ugent.be>
To: gdb@sourceware.org
Subject: Symbolic constants inside classes
Date: Sat, 18 Dec 2010 20:17:00 -0000 [thread overview]
Message-ID: <1DD38938-E7BD-491F-905C-FCA963E5E941@elis.ugent.be> (raw)
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
next reply other threads:[~2010-12-18 20:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-18 20:17 Jonas Maebe [this message]
2010-12-20 21:23 ` Tom Tromey
2010-12-20 22:56 ` Jonas Maebe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1DD38938-E7BD-491F-905C-FCA963E5E941@elis.ugent.be \
--to=jonas.maebe@elis.ugent.be \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox