Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse and format default function arguments #82

Open
Tracked by #328
osandov opened this issue Jan 9, 2021 · 0 comments
Open
Tracked by #328

Parse and format default function arguments #82

osandov opened this issue Jan 9, 2021 · 0 comments
Labels
C++ Support for C++ debugging enhancement New feature or request

Comments

@osandov
Copy link
Owner

osandov commented Jan 9, 2021

d35243b added a representation for default function arguments in the drgn API, but we don't actually parse them from DWARF. As of this writing, neither GCC nor Clang actually emits the required DWARF, but we should prepare for it if we can.

Parsing

Section 4.1 in the DWARF 5 spec defines how default arguments are represented:

A DW_AT_default_value attribute for a formal parameter entry. The value of this attribute may be a constant, or a reference to the debugging information entry for a variable, or a reference to a debugging information entry containing a DWARF procedure. If the attribute form is of class constant, that constant is interpreted as a value whose type is the same as the type of the formal parameter. If the attribute form is of class reference, and the referenced entry is for a variable, the default value of the parameter is the value of the referenced variable. If the reference value is 0, no default value has been specified. Otherwise, the attribute represents an implicit DW_OP_call_ref to the referenced debugging information entry, and the default value of the parameter is the value returned by that DWARF procedure, interpreted as a value of the type of the formal parameter.

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

The constant form is easy. The variable reference form is also relatively easy, except it doesn't specify how the type of the variable is related to the type of the parameter: are they supposed to be the same type, or are we supposed to convert it to the parameter type if the variable type differs? It's hard to tell without real producers. A reference to a DWARF procedure is obviously going to require DWARF expression support.

Formatting

We also currently don't include the default arguments when printing a function type. We can probably reuse the struct/array initializer formatting code to format parameters with default arguments.

@osandov osandov added enhancement New feature or request C++ Support for C++ debugging labels Jan 9, 2021
osandov added a commit that referenced this issue Feb 17, 2021
TypeParameter.default_argument is currently basically a placeholder
because we don't parse it from DWARF and compilers don't emit it, so
document that. See #82.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ Support for C++ debugging enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant