From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30267 invoked by alias); 18 Dec 2010 20:17:43 -0000 Received: (qmail 30257 invoked by uid 22791); 18 Dec 2010 20:17:42 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,TW_GD,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp3.ugent.be (HELO smtp3.UGent.be) (157.193.49.127) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 18 Dec 2010 20:17:36 +0000 Received: from localhost (mcheck2.ugent.be [157.193.49.249]) by smtp3.UGent.be (Postfix) with ESMTP id D0782148129 for ; Sat, 18 Dec 2010 21:17:33 +0100 (CET) Received: from smtp3.UGent.be ([157.193.49.127]) by localhost (mcheck2.ugent.be [157.193.43.11]) (amavisd-new, port 10024) with ESMTP id myw+3uXbT+le for ; Sat, 18 Dec 2010 21:17:33 +0100 (CET) Received: from [192.168.1.2] (unknown [91.182.105.225]) (Authenticated sender: jmaebe) by smtp3.UGent.be (Postfix) with ESMTPSA id 2E5CD14811C for ; Sat, 18 Dec 2010 21:17:33 +0100 (CET) From: Jonas Maebe Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: Symbolic constants inside classes Date: Sat, 18 Dec 2010 20:17:00 -0000 Message-Id: <1DD38938-E7BD-491F-905C-FCA963E5E941@elis.ugent.be> To: gdb@sourceware.org Mime-Version: 1.0 (Apple Message framework v1082) X-j-chkmail-Enveloppe: 4D0D16D8.000/91.182.105.225/[91.182.105.225]/[192.168.1.2]/ X-j-chkmail-Score: MSGID : 4D0D16D8.000 on smtp3.UGent.be : j-chkmail score : . : R=. U=. O=. B=0.000 -> S=0.000 X-j-chkmail-Status: Ham X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2010-12/txt/msg00056.txt.bz2 Hi, Consider this C++ program: *** class Xyz { public: static const int MAGIC_NUM =3D 42; private: char mArray[MAGIC_NUM]; }; class Xyz2 { public: static const int MAGIC_NUM =3D 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 t= he 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 : =20=20=20 DW_AT_name : Xyz=20=20=20=20 DW_AT_byte_size : 42=20=20=20=20=20 DW_AT_decl_file : 1=20=20=20=20=20=20 DW_AT_decl_line : 1=20=20=20=20=20=20 <2><84>: Abbrev Number: 3 (DW_TAG_variable) -- MAGIC_NUM field DW_AT_name : (indirect string, offset: 0x14): MAGIC_NUM=20=20= =20=20=20 DW_AT_decl_file : 1=20=20=20=20=20=20 DW_AT_decl_line : 3=20=20=20=20=20=20 DW_AT_MIPS_linkage_name: (indirect string, offset: 0x1e): _ZN3Xyz9MAGI= C_NUME=20=20=20=20=20=20=20 DW_AT_type : =20=20=20 DW_AT_external : 1=20=20=20=20=20=20 DW_AT_declaration : 1=20=20=20=20=20=20 DW_AT_const_value : 42=20=20=20=20=20 ... in the global namespace: <1><146>: Abbrev Number: 10 (DW_TAG_namespace) -- global namespace DW_AT_sibling : <168>=20=20 DW_AT_name : ::=20=20=20=20=20 DW_AT_decl_file : 2=20=20=20=20=20=20 DW_AT_decl_line : 0=20=20=20=20=20=20 ... <1><168>: Abbrev Number: 12 (DW_TAG_variable) -- "C" global variable DW_AT_specification: <150>=20 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>=20 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=20=20= =20=20=20 DW_AT_decl_file : 1=20=20=20=20=20=20 DW_AT_decl_line : 3=20=20=20=20=20=20 DW_AT_MIPS_linkage_name: (indirect string, offset: 0x1e): _ZN3Xyz9MAGI= C_NUME=20=20=20=20=20=20=20 DW_AT_type : =20=20=20 DW_AT_external : 1=20=20=20=20=20=20 DW_AT_declaration : 1=20=20=20=20=20=20 DW_AT_const_value : 42=20=20=20=20=20 <1><198>: Abbrev Number: 3 (DW_TAG_variable) -- Xyz2::MAGIC_NUM DW_AT_name : (indirect string, offset: 0x14): MAGIC_NUM=20=20= =20=20=20 DW_AT_decl_file : 1=20=20=20=20=20=20 DW_AT_decl_line : 10=20=20=20=20=20 DW_AT_MIPS_linkage_name: (indirect string, offset: 0x0): _ZN4Xyz29MAGI= C_NUME=20=20=20=20=20=20=20 DW_AT_type : =20=20=20 DW_AT_external : 1=20=20=20=20=20=20 DW_AT_declaration : 1=20=20=20=20=20=20 DW_AT_const_value : 43=20=20=20=20=20 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 nonexiste= nt or has been optimised out" 4) ptype Xyz returns: type =3D 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 cann= ot 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 rul= e I missed? Jonas