[RFC] Debuginfo: Add default value support for subprogram arguments

Frédéric Riss friss at apple.com
Thu Aug 14 09:17:43 PDT 2014


Hi,

This is an initial RFC regarding adding support for emitting default value debug information for function/method arguments. Although I’d appreciate initial review comments (patch attached), this is more about getting your feedback on the approach, as it diverges a bit from the standard.

The Dwarf standard reads:

A DW_AT_default_value attribute for a formal parameter entry. The value of this attribute is a reference to the debugging information entry for a variable or subroutine, or the value may be a constant. If the attribute form is of class reference, the default value of the parameter is the value of the referenced variable (which may be constant) or the value returned by the referenced subroutine; a reference value of 0 means that no default value has been specified. If the value is of class constant, that constant is interpreted as a default value of the type of the formal parameter.

For a constant form there is no way to express the absence of a default value. 

As you can see, this text limits us to emitting information about default values being:
 - simple constants (DW_FORM_data*)
 - global variable (DW_FORM_ref*)
 - calls to functions without arguments (DW_FORM_ref*)

I tried to go a bit further and implement a more complete solution that adds:
 - any link time constant (DW_FORM_block*): in this form, the block of data represents the default value as it would be stored in the target memory
 - arbitrary complex expressions (DW_FORM_str*): when no other of the above forms fits, this dumps the default value expression as textual form. The debugger can then evaluate this expression in the context of the declaration if it has this capacity

First of all, would these kind of extensions be welcome? If you agree that they are worthwhile, I’ll submit a request to augment the standard wording.

The attached patches seems to get at least the basics right, but 2 issues are still bothering me:

 - Forward declaration:

int foo();

void bar(int i = foo()) {return i;}

int foo() {return 1;}

the default value references a forward decl of the function. When emitting the debuginfo metadata in CGDebugInfo.cpp:EmitDeclare(), the init function decl isn’t yet in the DeclCache. The current code falls back to emitting the default_value attribute as the “foo()” string. This is part of the basic stuff that could be expressed in standard Dwarf4, thus it would be nicer to have it emitted as a reference to foo’s DIE.

- Relocatable address:

const char *me = “fred”;
void foo(const char *str = me);

the initialiser is a global address (function or data). The generated metadata is alright. If I have clang dump assembly, it looks fine. However, if I have clang emit the object file directly, it fails to relocate the address of the initialiser in the debug information. The ObjectStreamer adds fixups for the entries, but then nothing gets relocated. Any hints on how to debug that kind of failure?


The final version of the patch will of course feature doc update and test(s).

Thoughts?

Thanks,
Fred

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140814/3cdcbc32/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: default-17979567.clang.diff
Type: application/octet-stream
Size: 3366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140814/3cdcbc32/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140814/3cdcbc32/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: default-17979567.llvm.diff
Type: application/octet-stream
Size: 13969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140814/3cdcbc32/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140814/3cdcbc32/attachment-0002.html>


More information about the llvm-commits mailing list