[llvm] [DWARFYAML] Implement debug_names support (PR #79666)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 01:05:59 PST 2024


================
@@ -46,4 +47,164 @@ TEST(DWARFDebugNames, TooSmallForDWARF64) {
                         "data at offset 0x2b while reading [0x28, 0x2c)"));
 }
 
+TEST(DWARFDebugNames, BasicTestEntries) {
+  const char *Yamldata = R"(
+--- !ELF
+  debug_str:
+    - 'NameType1'
+    - 'NameType2'
+
+  debug_names:
+    Abbreviations:
+    - Code:   0x1
+      Tag: DW_TAG_namespace
+      Indices:
+        - Idx:   DW_IDX_compile_unit
+          Form:  DW_FORM_data4
+        - Idx:   DW_IDX_die_offset
+          Form:  DW_FORM_ref4
+    Entries:
+    - Name:   0x0  # strp to NameType1
+      Code:   0x1
+      Values:
+        - 0x0      # Compile unit
+        - 0x0      # DIE Offset
+    - Name:   0xa  # strp to NameType2
+      Code:   0x1
+      Values:
+        - 0x1      # Compile unit
+        - 0x1      # DIE Offset
+    - Name:   0x0  # strp to NameType1
+      Code:   0x1
+      Values:
+        - 0x2     # Compile unit
+        - 0x2     # DIE Offset
+
+)";
+
+  Expected<StringMap<std::unique_ptr<MemoryBuffer>>> Sections =
+      DWARFYAML::emitDebugSections(StringRef(Yamldata),
----------------
jh7370 wrote:

Yep, being `explicit` would inhibit one of the main purposes of `StringRef`, which is to be essentially a drop-in replacement for `const std::string &` in function signatures (which is of course implicitly constructible from `std::string` or `const char *`). It's the same as the C++17 `std::string_view` class (but I believe we haven't switched because `StringRef` has some additional functionality that we've implemented).

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


More information about the llvm-commits mailing list