llvm-project/lldb/source/Core
Alexander Mols 0a2d4f3f24 [lldb] Enable Rust v0 symbol demangling
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 = 0x00000000000076a4
(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: 0x000055555555b6a4 main`main::main at main.rs:2:5
   1    fn main() {
-> 2        println!("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: 0x000055555555b6a4 main`main::main at main.rs:2:5
    frame #1: 0x000055555555b78b main`<fn() as core::ops::function::FnOnce<()>>::call_once((null)=(main`main::main at main.rs:1), (null)=<unavailable>) at function.rs:227:5
    frame #2: 0x000055555555b66e main`std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>(f=(main`main::main at main.rs:1)) at backtrace.rs:125:18
    frame #3: 0x000055555555b851 main`std::rt::lang_start::<()>::{closure#0} at rt.rs:49:18
    frame #4: 0x000055555556c9f9 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: 0x000055555556c9f2 main`std::rt::lang_start_internal::hc51399759a90501a [inlined] std::panicking::try::do_call::hb8da45704d5cfbbf at panicking.rs:401:40
    frame #6: 0x000055555556c9f2 main`std::rt::lang_start_internal::hc51399759a90501a [inlined] std::panicking::try::h4beadc19a78fec52 at panicking.rs:365:19
    frame #7: 0x000055555556c9f2 main`std::rt::lang_start_internal::hc51399759a90501a [inlined] std::panic::catch_unwind::hc58016cd36ba81a4 at panic.rs:433:14
    frame #8: 0x000055555556c9f2 main`std::rt::lang_start_internal::hc51399759a90501a at rt.rs:34:21
    frame #9: 0x000055555555b830 main`std::rt::lang_start::<()>(main=(main`main::main at main.rs:1), argc=1, argv=0x00007fffffffcb18) at rt.rs:48:5
    frame #10: 0x000055555555b6fc main`main + 28
    frame #11: 0x00007ffff73f2493 libc.so.6`__libc_start_main + 243
    frame #12: 0x000055555555b59e main`_start + 46
(lldb)
```

[1]: https://github.com/rust-lang/rust/issues/60705

Reviewed By: clayborg, teemperor

Differential Revision: https://reviews.llvm.org/D104054
2021-06-21 18:20:15 +02:00
..
Address.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
AddressRange.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
AddressResolver.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
AddressResolverFileLine.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
CMakeLists.txt [lldb/Core] Add SourceLocationSpec class (NFC) 2021-05-04 16:34:45 +00:00
Communication.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
CoreProperties.td [lldb] Document ctrl-f for completing show-autosuggestion 2021-05-17 12:52:20 -07:00
Debugger.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
Declaration.cpp [lldb] Move and clean-up the Declaration class (NFC) 2021-05-04 16:34:44 +00:00
Disassembler.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
DumpDataExtractor.cpp Fix extraneous ')' error. 2021-06-11 14:50:22 +01:00
DumpRegisterValue.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
DynamicLoader.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
EmulateInstruction.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
FileLineResolver.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
FileSpecList.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
FormatEntity.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
Highlighter.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
IOHandler.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
IOHandlerCursesGUI.cpp [lldb] vwprintw -> vw_printw in IOHandlerCursesGUI 2021-06-16 13:14:08 +02:00
Mangled.cpp [lldb] Enable Rust v0 symbol demangling 2021-06-21 18:20:15 +02:00
Module.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
ModuleChild.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
ModuleList.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
Opcode.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
PluginManager.cpp Add a corefile style option to process save-core; skinny corefiles 2021-06-20 12:26:54 -07:00
Progress.cpp Add a progress class that can track long running operations in LLDB. 2021-03-24 12:58:13 -07:00
RichManglingContext.cpp [lldb] Fix RichManglingContext::FromCxxMethodName() leak 2021-04-21 12:32:08 -07:00
SearchFilter.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
Section.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
SourceLocationSpec.cpp [lldb/Core] Add SourceLocationSpec class (NFC) 2021-05-04 16:34:45 +00:00
SourceManager.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
StreamAsynchronousIO.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
StreamFile.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
UserSettingsController.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
Value.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
ValueObject.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
ValueObjectCast.cpp Unify the return value of GetByteSize to an llvm::Optional<uint64_t> (NFC-ish) 2020-07-27 13:26:35 -07:00
ValueObjectChild.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
ValueObjectConstResult.cpp Make the error condition in Value::ValueType explicit (NFC) 2021-02-12 16:12:31 -08:00
ValueObjectConstResultCast.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
ValueObjectConstResultChild.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
ValueObjectConstResultImpl.cpp Make the error condition in Value::ValueType explicit (NFC) 2021-02-12 16:12:31 -08:00
ValueObjectDynamicValue.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
ValueObjectList.cpp [lldb] Delete the SharingPtr class 2020-02-11 13:23:18 +01:00
ValueObjectMemory.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
ValueObjectRegister.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
ValueObjectSyntheticFilter.cpp [lldb][NFC] Cleanup ValueObject construction code 2021-02-23 09:39:18 +01:00
ValueObjectUpdater.cpp [lldb][NFC] Rename the second ValueObjectManager to ValueObjectUpdater and remove the dead code 2021-02-24 13:58:01 +01:00
ValueObjectVariable.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00