[DWARFYAML][debug_info] Make the 'Values' field optional.
authorXing GUO <higuoxing@gmail.com>
Thu, 6 Aug 2020 12:41:12 +0000 (20:41 +0800)
committerXing GUO <higuoxing@gmail.com>
Thu, 6 Aug 2020 12:43:52 +0000 (20:43 +0800)
This patch makes the 'Values' field optional. This is useful when we
handcraft the terminating entry of DIEs.

```
debug_info:
  - Version:  4
    ...
    Entries:
      - AbbrCode: 1
        Values:
          - Value: 0x1234
      - AbbrCode: 0 ## Termination
```

Reviewed By: jhenderson, grimar

Differential Revision: https://reviews.llvm.org/D85397

llvm/lib/ObjectYAML/DWARFYAML.cpp
llvm/test/ObjectYAML/MachO/DWARF-debug_info.yaml
llvm/test/ObjectYAML/MachO/DWARF5-debug_info.yaml
llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml

index a31df94..467127a 100644 (file)
@@ -156,7 +156,7 @@ void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
 
 void MappingTraits<DWARFYAML::Entry>::mapping(IO &IO, DWARFYAML::Entry &Entry) {
   IO.mapRequired("AbbrCode", Entry.AbbrCode);
-  IO.mapRequired("Values", Entry.Values);
+  IO.mapOptional("Values", Entry.Values);
 }
 
 void MappingTraits<DWARFYAML::FormValue>::mapping(
index 937c84b..f260c24 100644 (file)
@@ -438,7 +438,6 @@ DWARF:
             - Value:           0x0000000000000003
             - Value:           0x0000000000000067
         - AbbrCode:        0x00000000
-          Values:          
         - AbbrCode:        0x00000004
           Values:          
             - Value:           0x0000000000000085
@@ -456,7 +455,6 @@ DWARF:
             - Value:           0x0000000000000006
             - Value:           0x0000000000000001
         - AbbrCode:        0x00000000
-          Values:          
   debug_line:      
     - Length:          65
       Version:         2
@@ -556,7 +554,6 @@ DWARF:
 # DWARF32-NEXT:             - Value: 0x0000000000000003
 # DWARF32-NEXT:             - Value: 0x0000000000000067
 # DWARF32-NEXT:         - AbbrCode: 0x00000000
-# DWARF32-NEXT:           Values:
 # DWARF32-NEXT:         - AbbrCode: 0x00000004
 # DWARF32-NEXT:           Values:
 # DWARF32-NEXT:             - Value: 0x0000000000000085
@@ -574,7 +571,6 @@ DWARF:
 # DWARF32-NEXT:             - Value: 0x0000000000000006
 # DWARF32-NEXT:             - Value: 0x0000000000000001
 # DWARF32-NEXT:         - AbbrCode: 0x00000000
-# DWARF32-NEXT:           Values:
 
 ## b) Test that yaml2obj emits a correct unit header and obj2yaml is able to convert it back.
 
index c413484..f832782 100644 (file)
@@ -439,7 +439,6 @@ DWARF:
             - Value:           0x0000000000000003
             - Value:           0x0000000000000067
         - AbbrCode:        0x00000000
-          Values:          
         - AbbrCode:        0x00000004
           Values:          
             - Value:           0x0000000000000085
@@ -457,7 +456,6 @@ DWARF:
             - Value:           0x0000000000000006
             - Value:           0x0000000000000001
         - AbbrCode:        0x00000000
-          Values:          
   debug_line:      
     - Length:          65
       Version:         2
@@ -557,7 +555,6 @@ DWARF:
 # DWARF32-NEXT:             - Value:           0x0000000000000003
 # DWARF32-NEXT:             - Value:           0x0000000000000067
 # DWARF32-NEXT:         - AbbrCode:        0x00000000
-# DWARF32-NEXT:           Values:          
 # DWARF32-NEXT:         - AbbrCode:        0x00000004
 # DWARF32-NEXT:           Values:          
 # DWARF32-NEXT:             - Value:           0x0000000000000085
@@ -575,7 +572,6 @@ DWARF:
 # DWARF32-NEXT:             - Value:           0x0000000000000006
 # DWARF32-NEXT:             - Value:           0x0000000000000001
 # DWARF32-NEXT:         - AbbrCode:        0x00000000
-# DWARF32-NEXT:           Values:          
 
 ## b) Test that yaml2obj emits a correct unit header and obj2yaml is able to convert it back.
 
index 5cd2bca..25b5a88 100644 (file)
@@ -842,3 +842,35 @@ DWARF:
             - Value: 0x1120 ## DW_AT_low_pc [DW_FORM_addr]
             - Value: 0x06   ## DW_AT_high_pc [DW_FORM_data4]
             - Value: 0x38   ## DW_AT_name [DW_FORM_strp]
+
+## l) Test that if we don't specify the 'Values' key for an entry, yaml2obj will only emit the abbrev_code.
+
+# RUN: yaml2obj --docnum=14 %s -o %t14.o
+# RUN: llvm-readelf --hex-dump=.debug_info %t14.o | \
+# RUN:   FileCheck %s --check-prefix=NO-VALUES
+
+#      NO-VALUES: Hex dump of section '.debug_info':
+# NO-VALUES-NEXT: 0x00000000 0a000000 04000000 00000801 0002     ..............
+##                           ^-------                            unit_length (4-byte)
+##                                    ^---                       version (2-byte)
+##                                        ^--------              debug_abbrev_offset (4-byte)
+##                                                 ^-            address_size (1-byte)
+##                                                   ^-          abbrev_code (ULEB128) 0x01
+##                                                      ^-       abbrev_code (ULEB128) 0x00
+##                                                        ^-     abbrev_code (ULEB128) 0x02
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+DWARF:
+  debug_info:
+    - Version:    4
+      AbbrOffset: 0x00
+      AddrSize:   0x08
+      Entries:
+        - AbbrCode: 1
+        - AbbrCode: 0
+        - AbbrCode: 2