-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add debug representation of trait objects #1563
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
What would a debug representation of a Trait be? I think of a Trait as a purely compile-time entity that is erased by the time you get to runtime. @jdm Is this specifically for @trait objects (in which case, yes, I agree we would want to expose the vtable to the debugger?) If so, then I'll clear up the bug title and description. |
Yes, I think scoping this to cover trait objects (of the ~ and @ variety) would be fine. |
According to i.e. this is still valid, properly tagged and milestoned, 2013-06-19. |
Triage visit; deferring to @michaelwoerister. |
It is still NYI but should be tackled some time this month. |
Update:As of PR #9168 there is some basic support for trait objects. A trait object pointer is described as a struct with the correct size (two pointers) and the correct name ({sigil}{mutability}{trait name}) and is placed in the correct namespace. The interior of this "fat pointer" is not described any further yet. What is missing is the description of the trait's methods. I don't know enough about how they are actually implemented to say much about that. |
Not 1.0, but high |
@michaelwoerister: By the way, the new vtable layout is |
This has got more complicated with DST since you can have objects like |
Triage bump: unsure what the status is of this today. |
still needs doing |
We could do the following: (2) Describe trait pointers ( (3) Implement custom GDB/LLDB commands in Python that, given a fat pointer, use the pointer value and type information to print the vtable. That's not perfect but could be done with the current means available. The symbol names of the functions pointed to by the vtable should also indicate the actual runtime type of the trait object. |
Only in builds with debug info (i.e., not release builds) and only by a pretty tiny amount |
Triage: still needs doing. cc @Manishearth @tromey P-low |
This is both |
Removing P-medium |
I looked into this a bit recently. What I hope to do is:
Then a debugger can do the following to print a trait object pointer: if a value's type has a vtable, fetch the vtable from the inferior, look up the vtable's address in the DWARF to find the vtable type, and then use the concrete type to decode the payload pointer. |
I'm working on this. I have an LLVM patch to let rustc emit a small DWARF extension (the |
First success today:
|
Exciting! |
LLVM patch is here: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20171016/495458.html |
Moved to phabricator; might be simpler to follow there as well: https://reviews.llvm.org/D39503 |
Emit better debugging information for a trait object pointer. In particular, now: * The fields are explicitly represented in the DWARF; * DWARF for the vtable itself is emitted; and * The DWARF for the vtable's type has a DW_AT_containing_type which points to the concrete type for which the vtable was emitted. This is a small DWARF extension, that allows debuggers to determine the real type of the object to which a trait object points. I'll submit the gdb patch to take advantage of this new debuginfo once this lands. The vtable type is not currently complete -- it doesn't include members for the pointers it contains. This information was not needed for this feature. This addresses part 1 of rust-lang#1563.
gdb patch for printing trait objects is here: https://sourceware.org/ml/gdb-patches/2017-11/msg00289.html |
Part 2 can be done by describing the fields of the vtable. I haven't looked at the rustc bits to see how difficult this is yet. The |
Version 2 of the gdb patch is here: https://sourceware.org/ml/gdb-patches/2017-11/msg00369.html |
The gdb patch is in now, but I think this issue should be left open, as there's still the other vtable task to implement. |
@tromey does the "vtable task" require gdb changes or just rustc changes? |
Ideally I think it would require both; however just doing the rustc bits would be a good start (and this has to come first anyhow). The task here is to have rustc emit a full description of the vtable in the DWARF -- so, the type and name of each member. |
Visited during wg-debugging triage. As far as we're aware, @tromey's update above is still correct and the next step is to update rustc to generate full descriptions of the vtable in DWARF. |
This is actually almost entirely complete. The only issue that remains is that the emitted vtable struct has names like |
Using the actual method name inside vtable debuginfo is only blocked on coming up with a clean way for handling multiple methods of the same name, I think. For example, a vtable might contain methods of traits |
The same problem probably exists with C++. How is it solved there? |
vtables in C++ aren't "flattened" the way they are in Rust. In the multiple inheritance case the object actually contains multiple vtable pointers, and in the single inheritance case a method with the same (mangled) name overrides an earlier one. So this problem doesn't actually exist in C++. |
That's good to know. Is this possible with Rust too? Or is it maybe possible to add a mapping of Foo:: method to _method3?
Sorry, I know nothing about compilers and debuggers so these may are ignorant questions. In my mind there should be a some kind of mapping from unmangled to mangled. Like in the .map in JavaScript that's generated after minifying the code.
|
Looks awful (yet there are different crate versions - look how compiler encodes symbols) but it depends on how debuggers resolve the vtable debug info: if there's a way to link the symbol name "crate_foo::foo::Foo::quux" to its function body |
Updated descrption
Trait objects (
~T
and@T
whereT
is a trait) are objects that hide their implementation and carry a virtual method dispatch table (i.e. vtable).So, two things:
info vtbl
or perhapsinfo vtable
). It would be cool if we could massage our debug info so that gdb can just print out our vtables too, the same way.Original description
There is none.
The text was updated successfully, but these errors were encountered: