-
Notifications
You must be signed in to change notification settings - Fork 13.3k
debuginfo: Generate debugging information for global variables. #9227
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
Comments
Here is a little guide on how this could be implemented. Maybe someone is interested in giving it a try.
Bonus points for also handling static variables within a function. |
This sounds interesting, I'm going to start looking into it. Thanks for the guide here @michaelwoerister. |
I've taken a look at this again some time ago and found that it would be better to use If you have any questions or run into a dead-end just ask here and I'll be happy to help you out :) |
A little update since it's been a while - I have an implementation for this and have started writing tests. Questions and/or a pull request should follow shortly once I've worked through some test cases. |
Great. If you do a pull request, be sure to cc me, so I see it in time. |
Will do. I'm not handling mutable statics properly at the moment so I need to fix that, but immutable static globals are working with the exception of floating point types. Floating point constants can be inspected with GDB and the @michaelwoerister do you have any idea what would cause this in the underlying debug info? |
Alright, so looking at the DWARF information with objdump reveals that the float types aren't getting the DW_AT_const_value attribute that is generated for the other variables. The presence of this tag on mutable statics is also why they can't be debugged properly, since it indicates that the described variable doesn't exist in the address space of the program and can never change. I'm still perplexed as to why float constants aren't being handled properly, but I have some ideas on how to fix the issue with mutable statics at least. |
If cmacknz@032e206 still represents the code you are testing, the problem might be that you pass |
Right, taking a closer look at the code it makes sense why using Using
While using
The referenced DW_AT_type describes a single byte encoded as a bool in both cases. The difference in specifying the DW_AT_MIPS_linkage_name in the 2nd case is the obvious suspect, although I'm not sure what specifically the problem is. The DWARF specification also only seems to describe DW_AT_linkage_name and not DW_AT_MIPS_linkage_name. |
Dumping the symbol table I get the following, where This suggests that the linkage name in the DWARF info is incorrect. Is
|
The linkage name in DWARF does not actually correspond to the name of the symbol (which in Rust is not only a mangled name like in C++, but also contains some hash-value, see https://github.com/mozilla/rust/blob/master/src/librustc/back/link.rs#L454 for more info). The DWARF linkage name has just one purpose: to be printed nicely in GDB (which would not handle namespaces very well otherwise).
|
|
Comparing the DWARF information with that generated for a local variable indicates that the DW_AT_location attribute is missing, which would explain why GDB can't access it. |
I often find it helpful in such a case to take a look at the DWARF generated by gcc and clang. |
Yeah, looking at the equivalent case with GCC confirms that the DW_AT_location attribute is missing. From my understanding this means that llvm doesn't have information to figure where the variable exists in the address space of the program when it generates the DWARF information. My preliminary suspicion is that the scope metadata provided to |
Alright, so I can see that If that seems like a sensible reason for llvm not being able to figure out where the global variables are defined, then it looks like I would similarly need to walk the AST looking for decl's within a crate (i.e. outside of any functions). If the above doesn't make sense, then at least it looks like updating |
For As for the missing |
It turns out things work just fine, but you have to access the variables using the filename as a namespace. So for example, The location in the DWARF information is present, but it is specified using the DW_AT_declaration and DW_AT_specification attributes instead of being associated with the reset of the variable's information (name, type, etc.). |
If you use In your example above, what happens if you have a file like the following: // file name: some_bool.rs
static B: bool = true;
mod nested {
static C: bool = false;
} Is My guess would be that it's not the file name that one needs to prefix but the module path. |
The single quotes are only necessary to escape the "-" in file names at the GDB prompt. Looks like
|
This seems to be a known issue with GDB: Great work so far! |
Good find, I've now started looking into adding debug info for statics within functions, and am stuck trying track down the source of a segmentation fault that occurs after passing the scope metadata for a function level static into If you could take a look at the code below and see if you can spot anything it'd be appreciated, as attempting to build |
Sure, I'll take a look at it tomorrow. |
The FunctionContext you pass to However, that isn't the cause of the segfault. It seems that LLVM just doesn't fully support debuginfo for function static variables yet. In theory you do the right thing, but in practice the scope of a static variable mustn't be a lexical scope DIE. If you always assign the function DIE as scope for the static, the crash goes away. Of course we loose information this way. Clang does so too, at the moment: #include<stdio.h>
int main() {
static int X = 10;
{
static bool X = false;
printf("...");
}
printf("...");
} If you compile this with clang 3.4 and break at the So it seems we are out of luck with this, at the moment. My suggestion would be to file a bug report with LLVM and fall back to just always assigning function scope to statics for now. |
Thanks, good find. I'll take a look at the LLVM bugzilla and if this isn't in there I'll file a new issue. Since getting function statics working looks like its going to take a fair chunk of work, I think I'd rather polish off what I have so far for crate level statics and capture what we've discovered for functions in another bug. |
Sounds like a plan |
Only supports crate level statics. No debug info is generated for function level statics. Closes #9227. As discussed at the end of the comments for #9227, I took an initial stab at adding support for function level statics and decided it would be enough work to warrant being split into a separate issue. See #13144 for the new issue describing the need to add support for function level static variables.
There is no description of global variables yet. This will involve using
llvm::DIBuilder::createGlobalVariable()
. The implementation will be similar to those for other kinds of variables.The text was updated successfully, but these errors were encountered: