<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 28, 2019, at 4:00 PM, Vadim Chugunov via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi,<div dir="auto" class=""><div dir="auto" class=""><font size="2" class="">Last year there was an effort led by Tom Tromey to add Rust language support into LLDB. He had implemented a fairly complete language plugin, however it was not accepted into mainline because of supportability concerns. I guess these concerns had some merit, because this change <a href="https://github.com/rust-lang/llvm-project/pull/19" target="_blank" class=""><font size="2" class="">did not survive even in Rust's private branch</font></a> due to the difficulty of rebasing on top of LLVM 9.</font></div><div dir="auto" class=""><font size="2" class=""><br class=""></font></div><div class=""><font size="2" class="">I am wondering if there's a more limited version of this, that <i class="">can</i> be merged into mainline:</font></div><div class=""><font size="2" class="">In terms of its memory model, Rust is not that far off from C++, so treating Rust types is if they were C++ types basically works. There is only one major problem: currently LLDB cannot deal with tagged unions, which Rust code uses quite heavily. When such a type is encountered, LLDB just emits an empty struct, which makes it impossible to examine the contents.</font></div><div class=""><font size="2" class=""><br class=""></font></div><div class=""><font size="2" class="">My tentative proposal is to modify LLDB's DWARFASTParserClang to handle DW_TAG_variant et al, and create a C++ approximation of these types, e.g. as a polymorphic class, or just an untagged union. This would provide at least a minimal level of functionality for Rust (and possibly other languages) and be a much lesser maintenance burden on LLDB core team. <br class=""></font></div><div class=""><font size="2" class="">What would y'all say?<br class=""></font></div></div></div></div></blockquote><div><br class=""></div>So if Rust actually uses llvm and clang and Rust is supported by llvm and clang, this shouldn't be an issue and should already work. But if you are having problems, then I am guessing that you have a compiler that isn't based on llvm and clang? If that is the case, the _best_ thing you can do is write a new TypeSystem subclass. Everywhere in LLDB, anytime we want to get type information or run an expression, we grab a TypeSytem for a given language enumeration. When we are stopped in a Rust stack frame, we will ask for the type system for the Rust language and hopefully we get something back. </div><div><br class=""></div><div>For viewing types in a variable view, you _can_ go the route of letting LLDB convert DWARF into clang AST types and letting that infrastructure display those types. But you can often run into issues, like you have seen with your DW_TAG_variant. If a user then types "p foo->bar", it will invoke the clang expression parser and it will then play with the types that you have created. Clang has a lot of asserts and other things that can crash your debug session if you do anything to weird in your clang AST context.</div><div><br class=""></div><div>So if Rust doesn't use clang in its compiler</div><div>- create a new TypeSystem for Rust that would convert DWARF into Rust AST types that are native to your Rust compiler that uses as much of the Rust compiler sources as possible</div><div>- write a native Rust expression parser which hopefully uses your Rust compiler sources to evaluate and run your expression</div><div><br class=""></div><div>It is good to note how the Swift language decided to do things differently. Swift decided that they would have the compiler/linker generate a blob of data that is embedded into the executable or stand alone debug information that contains a serialized AST of the program. The benefit of this approach is that when you debug your program, LLDB will hand this serialized blob back to the compiler. The DWARF information for Swift doesn't need to encode the full type information in this case. It just has mangled names that uniquely identify the types. LLDB can then pass this mangled name to the compiler and say "please give me a type the '_SC3FooS3Bar'". The other benefit if this approach is that the compiler can rapidly change language features and the debugger can keep up by recompiling. Any new language features or types are encoded in the data blob and the compiler can then extract them. The serialized Swift AST contexts are not portable between compiler versions though, and this is the drawback of this approach. The LLDB must be perfectly in sync with the tools that produce the binaries. Another benefit of this approach is that the entire AST of all types gets encoded. Many compilers will limit the amount of DWARF debug info they emit which means that they don't emit every type, they try to only emit the types that are used. DWARF also doesn't have great template support, so any templates that aren't used, or code that is only inlined (std::vector<int>::size() for example) won't be callable in an expression. If you have the entire AST, you can synthesize these inlined functions and use all types that your program knew about when it was compiled. If you convert reduced DWARF into ASTs, you only have the information that is represented by the DWARF itself and nothing more.</div><div><br class=""></div><div>All other languages convert DWARF back into clang AST types and then let the clang compiler evaluate expression using native clang AST types. The C and C++ languages have been pretty stable so this approach works well for C/C++/ObjC and more.</div><div><br class=""></div><div>So the right answer depends on what the Rust community wants. Is the language changing rapidly where the debugger must be in sync to take advantage and use the latest language features? Or is it stable?</div><div><br class=""></div><div>The other nice things about creating a new TypeSystem, is that it is a plugin and you don't need to compile it in. cmake can be taught to conditionally compile in your type system if you want it. It would also allow you to have more than one Rust type system if needed for different Rust language versions that each could be exclusively compiled in. Having your sources be in a new TypeSystem plug-in ensure easy merging when it comes to different repositories.</div><div><br class=""></div><div>Let us know about which approach sounds better to the Rust community and we can proceed from there!</div><div><br class=""></div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div dir="auto" class=""><div class=""><font size="2" class=""><br class=""></font></div></div></div>
_______________________________________________<br class="">lldb-dev mailing list<br class=""><a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev<br class=""></div></blockquote></div><br class=""></body></html>