Bug 11702

Summary: static const member is not printed
Product: gdb Reporter: Jan Kratochvil <jan>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: dje, gdb-prs
Priority: P2    
Version: unknown   
Target Milestone: 7.1   
Host: Target:
Build: Last reconfirmed:

Description Jan Kratochvil 2010-06-13 20:49:20 UTC
class C { static const int i = 1; } c;

 <2><37>: Abbrev Number: 3 (DW_TAG_member)
    <38>   DW_AT_name        : i	
    <40>   DW_AT_type        : <0x49>	
    <44>   DW_AT_external    : 1	
    <45>   DW_AT_accessibility: 3	(private)
    <46>   DW_AT_declaration : 1	
    <47>   DW_AT_const_value : 1	

(gdb) ptype c
type = class C {
    static const int i;
}

(gdb) p c
$2 = {static i = <optimized out>}
(gdb) p c.i
field i is nonexistent or has been optimised out

But GDB should print the constant value 1.

enum field_loc_kind
  {
    FIELD_LOC_KIND_BITPOS,      /* bitpos */
    FIELD_LOC_KIND_PHYSADDR,    /* physaddr */
    FIELD_LOC_KIND_PHYSNAME,    /* physname */
    FIELD_LOC_KIND_DWARF_BLOCK  /* dwarf_block */
  };
Some FIELD_LOC_KIND_CONST or an assembled dwarf block is needed in
dwarf2_add_field().
Comment 1 Sourceware Commits 2010-06-29 16:53:22 UTC
Subject: Bug 11702

CVSROOT:	/cvs/src
Module name:	src
Changes by:	devans@sourceware.org	2010-06-29 16:53:10

Modified files:
	gdb            : ChangeLog NEWS dwarf2read.c gdbtypes.c symtab.c 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.cp: m-static.exp m-static.h 

Log message:
	PR c++/11702
	* NEWS: Add entry.
	* dwarf2read.c (dwarf2_add_field): If DW_AT_const_value is present,
	create a symbol for the field and record the value.
	(new_symbol): Handle DW_TAG_member.
	* gdbtypes.c (field_is_static): Remove FIXME.
	* symtab.c (search_symbols): When searching for VARIABLES_DOMAIN,
	only ignore LOC_CONST symbols that are enums.
	
	testsuite/
	Test PR c++/11702.
	* gdb.cp/m-static.exp: Add testcase.
	* gdb.cp/m-static.h (gnu_obj_4): Add initialized static const member.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.11950&r2=1.11951
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/NEWS.diff?cvsroot=src&r1=1.388&r2=1.389
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/dwarf2read.c.diff?cvsroot=src&r1=1.407&r2=1.408
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbtypes.c.diff?cvsroot=src&r1=1.193&r2=1.194
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/symtab.c.diff?cvsroot=src&r1=1.239&r2=1.240
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2363&r2=1.2364
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/m-static.exp.diff?cvsroot=src&r1=1.12&r2=1.13
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/m-static.h.diff?cvsroot=src&r1=1.2&r2=1.3

Comment 2 dje 2010-06-29 17:09:58 UTC
Fixed with this patch:
http://sourceware.org/ml/gdb-patches/2010-06/msg00677.html
Comment 3 Sourceware Commits 2010-06-30 05:39:50 UTC
Subject: Bug 11702

CVSROOT:	/cvs/src
Module name:	src
Changes by:	devans@sourceware.org	2010-06-30 05:39:24

Modified files:
	gdb            : ChangeLog dwarf2read.c 

Log message:
	PR gdb/11702
	* dwarf2read.c (dwarf2_add_field): Only create a symbol if
	DW_AT_external is present.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.11951&r2=1.11952
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/dwarf2read.c.diff?cvsroot=src&r1=1.408&r2=1.409