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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With