[PATCH] D82139: [DWARFYAML][debug_info] Fix array index out of bounds error. NFC.

Xing GUO via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 19 05:53:31 PDT 2020


Higuoxing updated this revision to Diff 272029.
Higuoxing marked 2 inline comments as done.
Higuoxing added a comment.

Use `--match-full-lines`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82139/new/

https://reviews.llvm.org/D82139

Files:
  llvm/lib/ObjectYAML/DWARFVisitor.cpp
  llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml


Index: llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
===================================================================
--- llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
+++ llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
@@ -548,3 +548,30 @@
       Entries:
         - AbbrCode: 0
           Values:   []
+
+## h) Test that yaml2obj doesn't crash when the 'Entries' of a compilation unit is empty.
+
+# RUN: yaml2obj --docnum=8 %s -o %t8.o
+# RUN: llvm-readelf --hex-dump=.debug_info %t8.o | \
+# RUN:   FileCheck %s --check-prefix=EMPTY-ENTRIES --match-full-lines
+
+#       EMPTY-ENTRIES: Hex dump of section '.debug_info':
+#  EMPTY-ENTRIES-NEXT: 0x00000000 34120000 05000204 34120000 4.......4...
+# EMPTY-ENTRIES-EMPTY:
+##                                ^- 'Entries' is empty
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+DWARF:
+  debug_info:
+    - Length:
+        TotalLength: 0x1234
+      Version:    5
+      UnitType:   DW_UT_type
+      AbbrOffset: 0x1234
+      AddrSize:   4
+      Entries:    []
Index: llvm/lib/ObjectYAML/DWARFVisitor.cpp
===================================================================
--- llvm/lib/ObjectYAML/DWARFVisitor.cpp
+++ llvm/lib/ObjectYAML/DWARFVisitor.cpp
@@ -46,6 +46,8 @@
 template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
   for (auto &Unit : DebugInfo.CompileUnits) {
     onStartCompileUnit(Unit);
+    if (Unit.Entries.size() == 0)
+      continue;
     auto FirstAbbrevCode = Unit.Entries[0].AbbrCode;
 
     for (auto &Entry : Unit.Entries) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82139.272029.patch
Type: text/x-patch
Size: 1613 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200619/37e30aad/attachment.bin>


More information about the llvm-commits mailing list