[Lldb-commits] [PATCH] D104054: [lldb] Enable Rust v0 symbol demangling
asm created this revision. asm added reviewers: clayborg, wallace. Herald added subscribers: pengfei, JDevlieghere. asm requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits. Rust's v0 name mangling scheme [1] is easy to disambiguate from other name mangling schemes because symbols always start with `_R`. The llvm Demangle library supports demangling the Rust v0 scheme. Use it to demangle Rust symbols. Added unit tests that check simple symbols. Ran LLDB built with this patch to debug some Rust programs compiled with the v0 name mangling scheme. Confirmed symbol names were demangled as expected. Note: enabling the new name mangling scheme requires a nightly toolchain: $ cat main.rs fn main() { println!("Hello world!"); } $ $(rustup which --toolchain nightly rustc) -Z symbol-mangling-version=v0 main.rs -g $ /home/asm/hacking/llvm/build/bin/lldb ./main --one-line 'b main.rs:2' (lldb) target create "./main" Current executable set to '/home/asm/hacking/llvm/rust/main' (x86_64). (lldb) b main.rs:2 Breakpoint 1: where = main`main::main + 4 at main.rs:2:5, address = 0x76a4 (lldb) r Process 948449 launched: '/home/asm/hacking/llvm/rust/main' (x86_64) warning: (x86_64) /lib64/libgcc_s.so.1 No LZMA support found for reading .gnu_debugdata section Process 948449 stopped * thread #1, name = 'main', stop reason = breakpoint 1.1 frame #0: 0xb6a4 main`main::main at main.rs:2:5 1fn main() { -> 2println!("Hello world!"); 3} (lldb) bt error: need to add support for DW_TAG_base_type '()' encoded with DW_ATE = 0x7, bit_size = 0 * thread #1, name = 'main', stop reason = breakpoint 1.1 * frame #0: 0xb6a4 main`main::main at main.rs:2:5 frame #1: 0xb78b main`>::call_once((null)=(main`main::main at main.rs:1), (null)=) at function.rs:227:5 frame #2: 0xb66e main`std::sys_common::backtrace::__rust_begin_short_backtrace::(f=(main`main::main at main.rs:1)) at backtrace.rs:125:18 frame #3: 0xb851 main`std::rt::lang_start::<()>::{closure#0} at rt.rs:49:18 frame #4: 0x5556c9f9 main`std::rt::lang_start_internal::hc51399759a90501a [inlined] core::ops::function::impls::_$LT$impl$u20$core..ops..function..FnOnce$LT$A$GT$$u20$for$u20$$RF$F$GT$::call_once::h04259e4a34d07c2f at function.rs:259:13 frame #5: 0x5556c9f2 main`std::rt::lang_start_internal::hc51399759a90501a [inlined] std::panicking::try::do_call::hb8da45704d5cfbbf at panicking.rs:401:40 frame #6: 0x5556c9f2 main`std::rt::lang_start_internal::hc51399759a90501a [inlined] std::panicking::try::h4beadc19a78fec52 at panicking.rs:365:19 frame #7: 0x5556c9f2 main`std::rt::lang_start_internal::hc51399759a90501a [inlined] std::panic::catch_unwind::hc58016cd36ba81a4 at panic.rs:433:14 frame #8: 0x5556c9f2 main`std::rt::lang_start_internal::hc51399759a90501a at rt.rs:34:21 frame #9: 0xb830 main`std::rt::lang_start::<()>(main=(main`main::main at main.rs:1), argc=1, argv=0x7fffcb18) at rt.rs:48:5 frame #10: 0xb6fc main`main + 28 frame #11: 0x773f2493 libc.so.6`__libc_start_main + 243 frame #12: 0xb59e main`_start + 46 (lldb) [1]: https://github.com/rust-lang/rust/issues/60705 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D104054 Files: lldb/include/lldb/Core/Mangled.h lldb/source/Core/Mangled.cpp lldb/source/Symbol/Symtab.cpp lldb/unittests/Core/MangledTest.cpp Index: lldb/unittests/Core/MangledTest.cpp === --- lldb/unittests/Core/MangledTest.cpp +++ lldb/unittests/Core/MangledTest.cpp @@ -55,6 +55,23 @@ EXPECT_STREQ("", TheDemangled.GetCString()); } +TEST(MangledTest, ResultForValidRustV0Name) { + ConstString MangledName("_RNvC1a4main"); + Mangled TheMangled(MangledName); + ConstString TheDemangled = TheMangled.GetDemangledName(); + + ConstString ExpectedResult("a::main"); + EXPECT_STREQ(ExpectedResult.GetCString(), TheDemangled.GetCString()); +} + +TEST(MangledTest, EmptyForInvalidRustV0Name) { + ConstString MangledName("_RRR"); + Mangled TheMangled(MangledName); + ConstString TheDemangled = TheMangled.GetDemangledName(); + + EXPECT_STREQ("", TheDemangled.GetCString()); +} + TEST(MangledTest, NameIndexes_FindFunctionSymbols) { SubsystemRAII subsystems; Index: lldb/source/Symbol/Symtab.cpp === --- lldb/source/Symbol/Symtab.cpp +++ lldb/source/Symbol/Symtab.cpp @@ -240,6 +240,10 @@ case Mangled::eManglingSchemeMSVC: return false; + // No filters for this scheme yet. Include all names in indexing. + case Mangled::eManglingSchemeRustV0: +return false; + // Don't try and demangle things we can't categorize. case Ma
[Lldb-commits] [PATCH] D104054: [lldb] Enable Rust v0 symbol demangling
asm added inline comments. Comment at: lldb/unittests/Core/MangledTest.cpp:72 + + EXPECT_STREQ("", TheDemangled.GetCString()); +} teemperor wrote: > Could you do me a favour and change your test functions to LLDB's code style, > so `mangled_name` as a variable name instead of `MangledName` and so on. > > I'm aware the rest of the file is already using LLVM code style, but I think > that's was just an oversight. I'll probably change the code style in this > file to LLDB's and it would keep the git history a bit simpler. Sure no problem. This is my first contribution to LLVM. I just mimicked the code around. Just to check I understand. You're looking for something like this? ``` ConstString manged_lname("_RRR"); Mangled the_mangled(mangled_name); ConstString the_demangled = the_mangled.GetDemangledName(); EXPECT_STREQ("", the_demangled.GetCString()); ``` Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D104054/new/ https://reviews.llvm.org/D104054 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D104054: [lldb] Enable Rust v0 symbol demangling
asm updated this revision to Diff 351481. asm marked an inline comment as done. asm added a comment. code style fixes, use modern log Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D104054/new/ https://reviews.llvm.org/D104054 Files: lldb/include/lldb/Core/Mangled.h lldb/source/Core/Mangled.cpp lldb/source/Symbol/Symtab.cpp lldb/unittests/Core/MangledTest.cpp Index: lldb/unittests/Core/MangledTest.cpp === --- lldb/unittests/Core/MangledTest.cpp +++ lldb/unittests/Core/MangledTest.cpp @@ -55,6 +55,23 @@ EXPECT_STREQ("", TheDemangled.GetCString()); } +TEST(MangledTest, ResultForValidRustV0Name) { + ConstString mangled_name("_RNvC1a4main"); + Mangled the_mangled(mangled_name); + ConstString the_demangled = the_mangled.GetDemangledName(); + + ConstString expected_result("a::main"); + EXPECT_STREQ(expected_result.GetCString(), the_demangled.GetCString()); +} + +TEST(MangledTest, EmptyForInvalidRustV0Name) { + ConstString mangled_name("_RRR"); + Mangled the_mangled(mangled_name); + ConstString the_demangled = the_mangled.GetDemangledName(); + + EXPECT_STREQ("", the_demangled.GetCString()); +} + TEST(MangledTest, NameIndexes_FindFunctionSymbols) { SubsystemRAII subsystems; Index: lldb/source/Symbol/Symtab.cpp === --- lldb/source/Symbol/Symtab.cpp +++ lldb/source/Symbol/Symtab.cpp @@ -240,6 +240,10 @@ case Mangled::eManglingSchemeMSVC: return false; + // No filters for this scheme yet. Include all names in indexing. + case Mangled::eManglingSchemeRustV0: +return false; + // Don't try and demangle things we can't categorize. case Mangled::eManglingSchemeNone: return true; Index: lldb/source/Core/Mangled.cpp === --- lldb/source/Core/Mangled.cpp +++ lldb/source/Core/Mangled.cpp @@ -72,6 +72,9 @@ if (name.startswith("?")) return Mangled::eManglingSchemeMSVC; + if (name.startswith("_R")) +return Mangled::eManglingSchemeRustV0; + if (name.startswith("_Z")) return Mangled::eManglingSchemeItanium; @@ -199,6 +202,19 @@ return demangled_cstr; } +static char *GetRustV0DemangledStr(const char *M) { + char *demangled_cstr = llvm::rustDemangle(M, nullptr, nullptr, nullptr); + + if (Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DEMANGLE)) { +if (demangled_cstr && demangled_cstr[0]) + LLDB_LOG(log, "demangled rustv0: {0} -> \"{1}\"", M, demangled_cstr); +else + LLDB_LOG(log, "demangled rustv0: {0} -> error: failed to demangle", M); + } + + return demangled_cstr; +} + // Explicit demangling for scheduled requests during batch processing. This // makes use of ItaniumPartialDemangler's rich demangle info bool Mangled::DemangleWithRichManglingInfo( @@ -256,6 +272,10 @@ return context.FromCxxMethodName(m_demangled); } } + + case eManglingSchemeRustV0: +// Rich demangling scheme is not supported for Rust +return false; } llvm_unreachable("Fully covered switch above!"); } @@ -284,6 +304,9 @@ demangled_name = GetItaniumDemangledStr(mangled_name); break; } + case eManglingSchemeRustV0: +demangled_name = GetRustV0DemangledStr(mangled_name); +break; case eManglingSchemeNone: llvm_unreachable("eManglingSchemeNone was handled already"); } Index: lldb/include/lldb/Core/Mangled.h === --- lldb/include/lldb/Core/Mangled.h +++ lldb/include/lldb/Core/Mangled.h @@ -43,7 +43,8 @@ enum ManglingScheme { eManglingSchemeNone = 0, eManglingSchemeMSVC, -eManglingSchemeItanium +eManglingSchemeItanium, +eManglingSchemeRustV0 }; /// Default constructor. ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D104054: [lldb] Enable Rust v0 symbol demangling
asm added a comment. And thank you for the quick review! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D104054/new/ https://reviews.llvm.org/D104054 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D104054: [lldb] Enable Rust v0 symbol demangling
asm added a comment. @teemperor @clayborg Is this good to go? :) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D104054/new/ https://reviews.llvm.org/D104054 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits