Debugging the Any trait object in Rust

I’d like to make my first contribution to LLDB. I believe a debugger attached to a Rust program has a unique opportunity to help with interpreting the Rust Any type. After my contribution, on startup if the debugger detects it’s attached to a Rust program, it will find all functions in the executable which are monomorphizations of the TypeId::of<T>() function, and call them in order to build up a hashmap where the keys are TypeId, and the values are the type associated with that id. Then, during debugging if a trait object with trait Any is inspected, this hashmap will be queried with the type id of the trait object. If an entry is found the value will also be annotated with the type that came back in the query. In summary, this will give lldb the ability to report at runtime what type is contained within a trait object of Any.

The kind of improvement you are suggesting would fit naturally into the RustLanguageRuntime plugin, both the C++ & ObjC LanguageRuntime’s do this job under the rubric of “Dynamic Type Detection”. So it would fit naturally into the lldb architecture if we had more support for Rust as a language. At present, lldb really doesn’t know much more about Rust than “it’s type system looks close enough to C99 that we’ll just pretend it is”. There isn’t a Rust TypeSystem or a RustLanguageRuntime plugin.

I think you could do just the dynamic type resolution part while still using the Clang TypeSystem to represent the types, but you will at least need to create & register the RustLanguageRuntime plugin so you’ll have a place to do this work.

1 Like