[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
Sat May 17 07:05:32 PDT 2025
================
@@ -64,6 +67,22 @@ using LVElementKindSet = std::set<LVElementKind>;
using LVElementDispatch = std::map<LVElementKind, LVElementGetFunction>;
using LVElementRequest = std::vector<LVElementGetFunction>;
+/// A source language supported by any of the debug info representations.
+struct LVSourceLanguage {
+ LVSourceLanguage() = default;
+ LVSourceLanguage(llvm::dwarf::SourceLanguage SL) : Language(SL) {}
+ LVSourceLanguage(llvm::codeview::SourceLanguage SL) : Language(SL) {}
+
+ bool isValid() const { return Language.index() != 0; }
+ template <typename T> T getAs() { return std::get<T>(Language); }
+ StringRef getName() const;
+
+private:
+ std::variant<std::monostate, llvm::dwarf::SourceLanguage,
+ llvm::codeview::SourceLanguage>
+ Language;
+};
+
----------------
jalopezg-git wrote:
I thought about this a bit and came to the conclusion that we could, either
- (1) Leave as-is, using `std::variant<Ts...>`, perhaps with some additional improvement.
- (2) Make `LVSourceLanguage` essentially an `enum` which contains enumerators for every language supported by any of the readers. We could use the most-significant bits to store the format that defines such language (e.g. DWARF, CodeView, etc.). This may be simple, as we can do something similar to
```c++
static constexpr unsigned LVTagDwarf = 0x01;
static constexpr unsigned LVTagCodeView = 0x02;
enum LVSourceLanguage : uint32_t {
/* DWARF */
#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
DW_LANG_##NAME = LVTagDwarf | ID,
#include "llvm/BinaryFormat/Dwarf.def"
/* Codeview */
...
};
```
Then, the SourceLanguage becomes just a `uint32_t`. Essentially, this tries to represent the same as above, but without using `std::variant<Ts...>`, and possibly being more space-efficient.
- Relying on `StringPool`, as you suggested. Then, it may be a bit uncomfortable for `debuginfologicalview` library users to do something conditionally on the source language of a compile unit.
https://github.com/llvm/llvm-project/pull/137223
More information about the llvm-commits
mailing list