Source: class myclass { public: static void func(const int aa) {}; }; int main (int argc, char *argv[]) { myclass::func (42); } Example: (gdb) break myclass::func the class myclass does not have any method named func Hint: try 'myclass::func<TAB> or 'myclass::func<ESC-?> (Note leading single quote.) Make breakpoint pending on future shared library load? (y or [n]) n
This happens because of the constant scalar parameter for "func". Gdb thinks it is really "int" (not "const int"), and when it goes to lookup "myclass::func(int)", it does not find anything. The DIEs pertaining to "myclass" and "func": <1><31>: Abbrev Number: 2 (DW_TAG_class_type) <32> DW_AT_name : (indirect string, offset: 0x71): myclass <36> DW_AT_byte_size : 1 <37> DW_AT_decl_file : 1 <38> DW_AT_decl_line : 2 <39> DW_AT_sibling : <0x51> <2><3d>: Abbrev Number: 3 (DW_TAG_subprogram) <3e> DW_AT_external : 1 <3f> DW_AT_name : (indirect string, offset: 0x0): func <43> DW_AT_decl_file : 1 <44> DW_AT_decl_line : 4 <45> DW_AT_MIPS_linkage_name: (indirect string, offset: 0x59): _ZN7myclass4funcEi <49> DW_AT_declaration : 1 <3><4a>: Abbrev Number: 4 (DW_TAG_formal_parameter) <4b> DW_AT_type : <0x51> <1><51>: Abbrev Number: 5 (DW_TAG_base_type) <52> DW_AT_byte_size : 4 <53> DW_AT_encoding : 5 (signed) <54> DW_AT_name : int <1><58>: Abbrev Number: 6 (DW_TAG_subprogram) <59> DW_AT_specification: <0x3d> <5d> DW_AT_low_pc : 0x400574 <65> DW_AT_high_pc : 0x40057d <6d> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa) <6f> DW_AT_sibling : <0x81> <2><73>: Abbrev Number: 7 (DW_TAG_formal_parameter) <74> DW_AT_name : aa <77> DW_AT_decl_file : 1 <78> DW_AT_decl_line : 4 <79> DW_AT_type : <0x81> <7d> DW_AT_location : 2 byte block: 91 6c (DW_OP_fbreg: -20) <1><81>: Abbrev Number: 8 (DW_TAG_const_type) <82> DW_AT_type : <0x51> As you can see, when reading the fieldlists for "myclass", we add an entry for "func" with parameter "int" NOT "const int". Later when the function definition is seen, we correctly get "const int". IMO, this is a compiler bug. I see no reason why the class definition and the function definition should conflict. However, this might be relatively painless to add something to gdb to ignore
(Comment #1 continued) > However, this might be relatively painless to add something to gdb to ignore DW_AT_const for non-pointer/reference scalar types.
I have tried g++-3.3, g++-4.3 and g++-4.4 on debian and they all have the same error with gdb 7.2. When using gdb_7.0.1-2+b1_i386.deb it is working fine and the breakpoint can be set.
(In reply to comment #3) > I have tried g++-3.3, g++-4.3 and g++-4.4 on debian and they all have the > same error with gdb 7.2. > When using gdb_7.0.1-2+b1_i386.deb it is working fine and the breakpoint > can be set. That's happens because prior to 7.1, GDB used DW_AT_MIPS_linkage_name. Nowadays, we compute a canonicalized physical name based on the debug information. MIPS_linkage_name was too unreliable (and often "wrong" for GDB consumption). I just built GCC 3.4.6, and it also contains the same bug: the class declaration and function declaration DIEs contain different types ("int" vs "const int").
I have not found a GCC Bug filed for this claimed GCC problem. But it is a GDB-only regression: C++ working draft: 13.1 Overloadable declarations point 3, item: - Parameter declarations that differ only in the presence or absence of const and/or volatile are equivalent. class C { void m(const int a) {} void m(int a) {} }; g++ (GCC) 4.6.0 20110117 (experimental) classC.C:3:8: error: ‘void C::m(int)’ cannot be overloaded classC.C:2:8: error: with ‘void C::m(int)’ The debug info looks weird but it is irrelevant to this case as both `(const int aa)' and `(int aa)' DIEs must generate the same linkage name.
GDB fix: [patch 1/2] Fix physname regression: c/v types quals (PR c++/12328) http://sourceware.org/ml/gdb-patches/2011-02/msg00112.html
CVSROOT: /cvs/src Module name: src Changes by: jkratoch@sourceware.org 2011-02-13 09:15:54 Modified files: gdb : ChangeLog c-typeprint.c gdb/testsuite : ChangeLog Added files: gdb/testsuite/gdb.cp: overload-const.cc overload-const.exp Log message: gdb/ Fix const/volatile qualifiers of C++ types, PR c++/12328. * c-typeprint.c (c_type_print_args): Update the function comment. New variable param_type, initialize it. Remove const/volatile qualifiers for language_cplus and !show_artificial. Use param_type. gdb/testsuite/ Fix const/volatile qualifiers of C++ types, PR c++/12328. * gdb.cp/overload-const.exp: New file. * gdb.cp/overload-const.cc: New file. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.12558&r2=1.12559 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/c-typeprint.c.diff?cvsroot=src&r1=1.68&r2=1.69 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2576&r2=1.2577 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/overload-const.cc.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/overload-const.exp.diff?cvsroot=src&r1=NONE&r2=1.1
Checked in.