[llvm] [llvm-debuginfo-analyzer] Add support for parsing DWARF / CodeView SourceLanguage (PR #137223)

Javier Lopez-Gomez via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 4 09:30:49 PDT 2025


================
@@ -70,6 +70,48 @@ using LVElementRequest = std::vector<LVElementGetFunction>;
 // lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp.
 constexpr unsigned int DWARF_CHAR_BIT = 8u;
 
+/// A source language supported by any of the debug info representations.
+struct LVSourceLanguage {
+  static constexpr unsigned TagDwarf = 0x00;
+  static constexpr unsigned TagCodeView = 0x01;
+
+  enum TaggedLanguage : uint32_t {
+    Invalid = -1U,
+
+  // DWARF
+#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR)                 \
+  DW_LANG_##NAME = (TagDwarf << 16) | ID,
+#include "llvm/BinaryFormat/Dwarf.def"
+  // CodeView
+#define CV_LANGUAGE(NAME, ID) CV_LANG_##NAME = (TagCodeView << 16) | ID,
+#include "llvm/DebugInfo/CodeView/CodeViewLanguages.def"
+  };
+
+  LVSourceLanguage() = default;
+  LVSourceLanguage(llvm::dwarf::SourceLanguage SL)
+      : LVSourceLanguage(TagDwarf, SL) {}
+  LVSourceLanguage(llvm::codeview::SourceLanguage SL)
+      : LVSourceLanguage(TagCodeView, SL) {}
+  bool operator==(const LVSourceLanguage &SL) const {
+    return get() == SL.get();
+  }
+  bool operator==(const LVSourceLanguage::TaggedLanguage &TL) const {
+    return get() == TL;
+  }
+
+  bool isValid() const { return Language != Invalid; }
+  TaggedLanguage get() const { return Language; }
+  StringRef getName() const;
+
+private:
+  TaggedLanguage Language = Invalid;
+
+  LVSourceLanguage(unsigned Tag, unsigned Lang)
+      : Language(static_cast<TaggedLanguage>((Tag << 16) | Lang)) {}
+  unsigned getTag() const { return Language >> 16; }
+  unsigned getLang() const { return Language & 0xffff; }
+};
+
----------------
jalopezg-git wrote:

> With the nice abstraction of the CodeView enums, may be LVSourceLanguage can be on its own file LVSourceLanguage.cpp[h] in the Core directory of the tool?

Done; thank you for the review!  Given that we agreed on using `LVSourceLanguage`, I have closed all the comments above (that were suggesting exploring the use of `StringPool`).

> My understanding is:
> DWARF language ID --> LVSourceLanguage --> Language String
> CodeView language ID --> LVSourceLanguage --> Language String

Yes, that is the idea :+1:.  In addition to to-string conversion, having `LVSourceLanguage` enumerator value enables simple comparison, e.g. as part of a `if` / `switch` statement.

https://github.com/llvm/llvm-project/pull/137223


More information about the llvm-commits mailing list