[Lldb-commits] [PATCH] D149213: [lldb] Add basic support to Rust enums in TypeSystemClang

Vladimir Makaev via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 25 16:05:03 PDT 2023


VladimirMakaev created this revision.
VladimirMakaev added reviewers: clayborg, ayermolo, Michael137.
VladimirMakaev added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a reviewer: shafik.
Herald added a project: All.
VladimirMakaev requested review of this revision.
Herald added a subscriber: lldb-commits.

LLDB doesn't yet have a TypeSystemRust implemented however it is used to debug Rust applications. Most of the types map well enough to Clang types and there are python formatters implemented to display those types reasonably well in a debugger. We discussed this with Greg Clayton internally and this approach looks like a reasonable thing to implement and fix one of the major pain points when debugging Rust with LLDB.

However, Rust enums are completely ignored by LLDB as Clang never emits DW_TAG_variant_part inside DW_TAG_structure_type

This diff adds a parser for DW_TAG_variant_part (Rust-only) that creates a matching valid Clang declaration that represents a Rust enum. As long as there is enough information and all fields have correct offsets synthetic/summary providers can be implemented to display it correctly when debugging Rust code

For example given a Rust enum:

  enum EnumOpt2 {
      A(u8),
      B(bool),
  }

The following is a matching Clang declaration:

  struct EnumOpt2 {
      union debugger_test::EnumOpt2$Inner {
          struct A$Variant {
              unsigned char $discr$;
              debugger_test::EnumOpt2::A value : 8;
          };
          debugger_test::EnumOpt2::debugger_test::EnumOpt2$Inner::A$Variant $variant$0;
          struct B$Variant {
              unsigned char $discr$;
              debugger_test::EnumOpt2::B value : 8;
          };
          debugger_test::EnumOpt2::debugger_test::EnumOpt2$Inner::B$Variant $variant$1;
      };
      struct A {
          unsigned char __0;
      };
      struct B {
          bool __0;
      };
      debugger_test::EnumOpt2::debugger_test::EnumOpt2$Inner inner;
  }

Now this declaration contains all the necessary information to interpret the original Rust enum in a Python synthetic formatter and display back on UI as Rust enum.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149213

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/test/API/lang/rust/enum-structs/TestEnumStructsGenerated.py
  lldb/test/API/lang/rust/enum-structs/main.rs
  lldb/test/API/lang/rust/enum-structs/main.yaml



More information about the lldb-commits mailing list