From happyfrank3d@web.de  Mon Apr  4 07:08:12 2011
From: happyfrank3d@web.de (=?utf-8?B?aGFwcHlmcmFuazNkQHdlYi5kZQ==?=)
Date: Mon, 04 Apr 2011 09:08:12 +0200
Subject: [Dwarf-Discuss] =?utf-8?q?Problems_understanding_attribute_DW=5FA?=
	=?utf-8?q?T=5Flocation_of_global_variables_=28Form_DW=5FFORM=5FBLO?=
	=?utf-8?b?Q0sp?=
Message-ID: <E1Q6duJ-0004mL-00@smtp08.web.de>

Hi, 

I have some problems understanding the attribute DW_AT_location of global variables. 
My small C++ application has the following DWARF output: (version 2) 

[?] 

<1><11f>: Abbrev Number: 12 (DW_TAG_variable) 
??? <120>?? DW_AT_name??????? : (indirect string, offset: 0x15a): global01????? 
??? <124>?? DW_AT_decl_file?? : 1?????? 
??? <125>?? DW_AT_decl_line?? : 5?????? 
??? <126>?? DW_AT_type??????? : <0x4f>? 
??? <12a>?? DW_AT_external??? : 1?????? 
??? <12b>?? DW_AT_location??? : 5 byte block: 3 0 0 0 0 ??????? (DW_OP_addr: 0) 
?<1><131>: Abbrev Number: 12 (DW_TAG_variable) 
??? <132>?? DW_AT_name??????? : (indirect string, offset: 0x163): global02????? 
??? <136>?? DW_AT_decl_file?? : 1?????? 
??? <137>?? DW_AT_decl_line?? : 6?????? 
??? <138>?? DW_AT_type??????? : <0x4f>? 
??? <13c>?? DW_AT_external??? : 1?????? 
??? <13d>?? DW_AT_location??? : 5 byte block: 3 4 0 0 0 ??????? (DW_OP_addr: 4) 
?<1><143>: Abbrev Number: 12 (DW_TAG_variable) 
??? <144>?? DW_AT_name??????? : (indirect string, offset: 0x16c): global03????? 
??? <148>?? DW_AT_decl_file?? : 1?????? 
??? <149>?? DW_AT_decl_line?? : 7?????? 
??? <14a>?? DW_AT_type??????? : <0x4f>? 
??? <14e>?? DW_AT_external??? : 1?????? 
??? <14f>?? DW_AT_location??? : 5 byte block: 3 8 0 0 0 ??????? (DW_OP_addr: 8) 

[?] 

?<1><275>: Abbrev Number: 12 (DW_TAG_variable) 
??? <276>?? DW_AT_name??????? : (indirect string, offset: 0x96): global20?????? 
??? <27a>?? DW_AT_decl_file?? : 1?????? 
??? <27b>?? DW_AT_decl_line?? : 24????? 
??? <27c>?? DW_AT_type??????? : <0x4f>? 
??? <280>?? DW_AT_external??? : 1?????? 
??? <281>?? DW_AT_location??? : 5 byte block: 3 4c 0 0 0 ?????? (DW_OP_addr: 4c) 

All variables are of type int(4 byte). 

1. What does the value "5 byte block: 3 0 0 0 0" in this special case mean? 
2. What does the value "3" stand for? 
3. Is the virtual address of variable "global01" 0x0000? 
4. What does the offset in the section .debug_pubtypes of the global variables mean? 

Thank you for your help. 

Best regards, 
Frank

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dwarfstd.org/private.cgi/dwarf-discuss-dwarfstd.org/attachments/20110404/b83fcaa3/attachment.htm>


From jakub@redhat.com  Mon Apr  4 07:23:13 2011
From: jakub@redhat.com (Jakub Jelinek)
Date: Mon, 4 Apr 2011 09:23:13 +0200
Subject: [Dwarf-Discuss] Problems understanding attribute DW_AT_location
 of global variables (Form DW_FORM_BLOCK)
In-Reply-To: <E1Q6duJ-0004mL-00@smtp08.web.de>
References: <E1Q6duJ-0004mL-00@smtp08.web.de>
Message-ID: <20110404072313.GI18914@tyan-ft48-01.lab.bos.redhat.com>

On Mon, Apr 04, 2011 at 09:08:12AM +0200, happyfrank3d at web.de wrote:
> ?<1><275>: Abbrev Number: 12 (DW_TAG_variable) 
> ??? <276>?? DW_AT_name??????? : (indirect string, offset: 0x96): global20?????? 
> ??? <27a>?? DW_AT_decl_file?? : 1?????? 
> ??? <27b>?? DW_AT_decl_line?? : 24????? 
> ??? <27c>?? DW_AT_type??????? : <0x4f>? 
> ??? <280>?? DW_AT_external??? : 1?????? 
> ??? <281>?? DW_AT_location??? : 5 byte block: 3 4c 0 0 0 ?????? (DW_OP_addr: 4c) 
> 
> All variables are of type int(4 byte). 
> 
> 1. What does the value "5 byte block: 3 0 0 0 0" in this special case mean? 

It dumps the content of the block for the DW_AT_location attribute, then
interprets it.

> 2. What does the value "3" stand for? 

DW_OP_addr.

> 3. Is the virtual address of variable "global01" 0x0000? 

Most likely you are looking at ET_REL file, thus the value you are seeing in
the 4 bytes after DW_OP_addr opcode is (for 32-bit REL targets) just addend,
you need to look up the relocation against .debug_info+0x282.

> 4. What does the offset in the section .debug_pubtypes of the global variables mean? 

See DWARF 4 standard, 7.19 - the offsets are the relative DIE offsets within
the compilation unit referenced from the preceeding .debug_pubtypes header.

	Jakub



From jan.kratochvil@redhat.com  Sun Apr 10 19:56:56 2011
From: jan.kratochvil@redhat.com (Jan Kratochvil)
Date: Sun, 10 Apr 2011 21:56:56 +0200
Subject: [Dwarf-Discuss] DW_AT_low_pc/DW_AT_high_pc for empty compilation
	units
Message-ID: <20110410195656.GA1665@host1.jankratochvil.net>

Hi,

for the 'int x;' compilation unit there exists no code.

echo 'int x;' | cc -c -x c - -g; echo 'main(){}' | cc 1.o -x c -; readelf -wi a.out
->
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    < c>   DW_AT_producer    : (indirect string, offset: 0x11): GNU C 4.5.1 20100924 (Red Hat 4.5.1-4)	
[...]
    <19>   DW_AT_low_pc      : 0x400454	
    <21>   DW_AT_high_pc     : 0x400454	

Should be DW_AT_low_pc == DW_AT_high_pc as is with GCC or should be both
attributes omitted at all?

Appendix A states the list of tag-attribute pairs is not binding in any way.

Some my interpretations of DWARF-4 statements can be found in:
	[patch] Fix empty PC range psymtab<->symtab discrepancy
	http://sourceware.org/ml/gdb-patches/2011-03/msg00739.html


There is a related issue with both attributes being 0 by the GNU toolchain for
functions discarded during linking.  I guess the whole DIE(s) should have been
also discarded instead as it violates DWARF this way:

 <1><12ff>: Abbrev Number: 58 (DW_TAG_subprogram)
    <1300>   DW_AT_external    : 1
    <1301>   DW_AT_name        : (indirect string, offset: 0x381): bus_activation_ref
[...]
    <130d>   DW_AT_low_pc      : 0x0
    <1315>   DW_AT_high_pc     : 0x0
[...]


Thanks,
Jan



From mjw@redhat.com  Sun Apr 10 20:33:24 2011
From: mjw@redhat.com (Mark Wielaard)
Date: Sun, 10 Apr 2011 22:33:24 +0200
Subject: [Dwarf-Discuss] DW_AT_low_pc/DW_AT_high_pc for empty
 compilation units
In-Reply-To: <20110410195656.GA1665@host1.jankratochvil.net>
References: <20110410195656.GA1665@host1.jankratochvil.net>
Message-ID: <1302467604.5256.15.camel@springer.wildebeest.org>

Hi Jan,

On Sun, 2011-04-10 at 21:56 +0200, Jan Kratochvil wrote:
> for the 'int x;' compilation unit there exists no code.
> 
> echo 'int x;' | cc -c -x c - -g; echo 'main(){}' | cc 1.o -x c -; readelf -wi a.out
> ->
>  <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
>     < c>   DW_AT_producer    : (indirect string, offset: 0x11): GNU C 4.5.1 20100924 (Red Hat 4.5.1-4)	
> [...]
>     <19>   DW_AT_low_pc      : 0x400454	
>     <21>   DW_AT_high_pc     : 0x400454	
> 
> Should be DW_AT_low_pc == DW_AT_high_pc as is with GCC or should be both
> attributes omitted at all?

I interpreted this as both attributes should be omitted based on the
sentence "If an entity has no associated machine code, none of these
attributes are specified." in "2.17 Code Addresses and Ranges". I have
submitted a patch for GCC to no longer emit them for the CU in that
case: http://gcc.gnu.org/ml/gcc-patches/2011-03/msg02286.html

DWARF section [26] '.debug_info' at offset 0x83d:
 [Offset]
 Compilation unit at offset 0:
 Version: 2, Abbreviation section offset: 0, Address size: 8, Offset size: 4
 [     b]  compile_unit
           producer             (strp) "GNU C 4.7.0 20110407 (experimental)"
           language             (data1) ISO C89 (1)
           comp_dir             (strp) "/home/mark"
           stmt_list            (data4) 0
 [    19]    variable
             name                 (string) "x"
             decl_file            (data1) 1
             decl_line            (data1) 1
             type                 (ref4) [    2d]
             external             (flag) Yes
             location             (block1)               [   0] addr 0x6007f8 <x>
 [    2d]    base_type
             byte_size            (data1) 4
             encoding             (data1) signed (5)
             name                 (string) "int"

Cheers,

Mark




From ron.brender@charter.net  Sun Apr 10 20:54:11 2011
From: ron.brender@charter.net (Ron Brender)
Date: Sun, 10 Apr 2011 16:54:11 -0400
Subject: [Dwarf-Discuss] DW_AT_low_pc/DW_AT_high_pc for empty
 compilation units
In-Reply-To: <20110410195656.GA1665@host1.jankratochvil.net>
References: <20110410195656.GA1665@host1.jankratochvil.net>
Message-ID: <4DA218F3.1050900@charter.net>

DWARF V4, 2.17, page 37 is rather explicit:

    "If an entity has no associated machine code, none of these
     attributes are specified."

This suggests that the presence of a DW_AT_low_pc/_high_pc pair that 
indicates a zero length range (same low and high values) should be 
considered inappropriate.

OTOH, it seems like an explicit zero length range is a perfectly natural 
extension that has little, if any, potential for being misunderstood by 
a consumer--even it not checked for. Further, there are numerous cases 
in DWARF where an implicit and an explicit representation of the same 
information is allowed and defined to mean the same thing. This would be 
reasonable here.

Finally, the committee has been loath to adopt rules which might require 
a "normal" linkage editor to be able to understand and be able to 
rewrite DWARF sections (adding/removing DIEs and/or attributes, etc) 
related to "simple" linkage optimizations. Yet another reason to not be 
strict about disallowing a DW_AT_low_pc/_high_pc pair that indicates a 
zero length range.

Bottom line: while the current wording does seem to preclude an explicit 
zero length code range, I  would support a change to make it clearly 
allowed, and equivalent to the absence of any code address attribute(s).

Ron

p.s. Whether the _low_pc and _high_pc values are both (absolute) zero or 
the same relocated value should make no difference.

-------------------------------------------
On 4/10/2011 3:56 PM, Jan Kratochvil wrote:
> Hi,
>
> for the 'int x;' compilation unit there exists no code.
>
> echo 'int x;' | cc -c -x c - -g; echo 'main(){}' | cc 1.o -x c -; readelf -wi a.out
> ->
>   <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
>      <  c>    DW_AT_producer    : (indirect string, offset: 0x11): GNU C 4.5.1 20100924 (Red Hat 4.5.1-4)	
> [...]
>      <19>    DW_AT_low_pc      : 0x400454	
>      <21>    DW_AT_high_pc     : 0x400454	
>
> Should be DW_AT_low_pc == DW_AT_high_pc as is with GCC or should be both
> attributes omitted at all?
>
> Appendix A states the list of tag-attribute pairs is not binding in any way.
>
> Some my interpretations of DWARF-4 statements can be found in:
> 	[patch] Fix empty PC range psymtab<->symtab discrepancy
> 	http://sourceware.org/ml/gdb-patches/2011-03/msg00739.html
>
>
> There is a related issue with both attributes being 0 by the GNU toolchain for
> functions discarded during linking.  I guess the whole DIE(s) should have been
> also discarded instead as it violates DWARF this way:
>
>   <1><12ff>: Abbrev Number: 58 (DW_TAG_subprogram)
>      <1300>    DW_AT_external    : 1
>      <1301>    DW_AT_name        : (indirect string, offset: 0x381): bus_activation_ref
> [...]
>      <130d>    DW_AT_low_pc      : 0x0
>      <1315>    DW_AT_high_pc     : 0x0
> [...]
>
>
> Thanks,
> Jan
> _______________________________________________
> Dwarf-Discuss mailing list
> Dwarf-Discuss at lists.dwarfstd.org
> http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org
>
>





From jan.kratochvil@redhat.com  Sun Apr 10 20:54:24 2011
From: jan.kratochvil@redhat.com (Jan Kratochvil)
Date: Sun, 10 Apr 2011 22:54:24 +0200
Subject: [Dwarf-Discuss] DW_AT_low_pc/DW_AT_high_pc for empty
 compilation units
In-Reply-To: <1302467604.5256.15.camel@springer.wildebeest.org>
References: <20110410195656.GA1665@host1.jankratochvil.net>
	<1302467604.5256.15.camel@springer.wildebeest.org>
Message-ID: <20110410205424.GA5275@host1.jankratochvil.net>

Hi Mark,

On Sun, 10 Apr 2011 22:33:24 +0200, Mark Wielaard wrote:
> I interpreted this as both attributes should be omitted based on the
> sentence "If an entity has no associated machine code, none of these
> attributes are specified." in "2.17 Code Addresses and Ranges".

I missed this sentence, it looks clear now, I have no more questions.


Thanks,
Jan



From Richard.Relph@amd.com  Thu Apr 28 14:04:40 2011
From: Richard.Relph@amd.com (Relph, Richard)
Date: Thu, 28 Apr 2011 09:04:40 -0500
Subject: [Dwarf-Discuss] Windows DWARF dumper?
Message-ID: <7691DC9FC60C9E4F88A0BBCA628F55FF0471DABF76@sausexmbp02.amd.com>

We're cross-compiling for our target from Windows, producing DWARF as a debug format.
Can anyone recommend DWARF dump utilities that work well under Windows? I've been using readelf -w, and that's pretty good, but I'm looking for alternatives.

Thanks,

Richard Relph
MTS | Stream Compute SW | AMD
o. 408.749.6659

[cid:image001.jpg at 01CC0572.8B24D800]


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dwarfstd.org/private.cgi/dwarf-discuss-dwarfstd.org/attachments/20110428/c98e8a84/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 6743 bytes
Desc: image001.jpg
URL: <http://lists.dwarfstd.org/private.cgi/dwarf-discuss-dwarfstd.org/attachments/20110428/c98e8a84/attachment.jpg>


