use and meaning of DW_AT_location

瘦欲@ 提交于 2020-01-16 05:26:32

问题


I wanted to know the use of the attribute DW_AT_location for debugging. It is one of the attributes specified by dwarf for debugging, but could not really understand what exactly it represents. And also when should this attribute be emitted when we compile a code.


回答1:


From the DWARF 3 spec (http://dwarfstd.org/doc/Dwarf3.pdf):

2.16 Data Locations Any debugging information entry describing a data object, which includes variables, parameters, common blocks and the like, may have a DW_AT_location attribute, whose value is a location description (see Section 2.6).

The value of the DW_AT_location attribute is a location expression. Location expressions are fairly complex, I'd advise you to read the DWARF spec referenced above to learn more. In summary, a location expression can be a simple address with the location of the variable, or a mini-program that must be evaluated at run-time by the debugger to determine the location of the variable. Here are some example location expressions, from the DWARF spec:

Ideally, your compiler should emit a location list for a variable describing its location at all points in the program. Tracking a variable's location through registers is not trivial, that is why some compilers when producing debug information disable optimizations like moving variables into registers.




回答2:


Please check the chapter 7 of DWARF 3 spec, DATA REPRESENTATION.

For example, if the value of DW_AT_location is 0x91 0x68, from the table in chapter 7, we can know that the 0x91 indicates the DWARF Debugging Information Format which is DW_OP_fbreg, and 0x68 is a SLEB128 offset, we can get its real value: -24.



来源:https://stackoverflow.com/questions/9719266/use-and-meaning-of-dw-at-location

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!