[PATCH] D87346: [elf2yaml] Fix dumping a debug section whose name is not recognized.

Xing GUO via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 23:14:18 PDT 2020


Higuoxing created this revision.
Higuoxing added reviewers: jhenderson, grimar, MaskRay.
Herald added subscribers: llvm-commits, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Higuoxing requested review of this revision.

If the debug section's name isn't recognized, the variable 'Err' should
be in the error state. Or the content of the section will not be dumped.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87346

Files:
  llvm/test/tools/obj2yaml/ELF/DWARF/unrecognized-debug-section.yaml
  llvm/tools/obj2yaml/elf2yaml.cpp


Index: llvm/tools/obj2yaml/elf2yaml.cpp
===================================================================
--- llvm/tools/obj2yaml/elf2yaml.cpp
+++ llvm/tools/obj2yaml/elf2yaml.cpp
@@ -15,6 +15,7 @@
 #include "llvm/ObjectYAML/DWARFYAML.h"
 #include "llvm/ObjectYAML/ELFYAML.h"
 #include "llvm/Support/DataExtractor.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/YAMLTraits.h"
 
@@ -416,6 +417,11 @@
         Err = dumpDebugARanges(*DWARFCtx.get(), DWARF);
       else if (RawSec->Name == ".debug_str")
         Err = dumpDebugStrings(*DWARFCtx.get(), DWARF);
+      else
+        Err =
+            createStringError(errc::not_supported,
+                              "the parser for the %s section is not supported",
+                              RawSec->Name.str().c_str());
 
       // If the DWARF section cannot be successfully parsed, emit raw content
       // instead of an entry in the DWARF section of the YAML.
Index: llvm/test/tools/obj2yaml/ELF/DWARF/unrecognized-debug-section.yaml
===================================================================
--- /dev/null
+++ llvm/test/tools/obj2yaml/ELF/DWARF/unrecognized-debug-section.yaml
@@ -0,0 +1,19 @@
+## Test dumping a debug section that its name is not recognized by yaml2obj.
+
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s --check-prefix=UNRECOGNIZED
+
+#      UNRECOGNIZED: Sections:
+# UNRECOGNIZED-NEXT:   - Name:    .debug_foo
+# UNRECOGNIZED-NEXT:     Type:    SHT_PROGBITS
+# UNRECOGNIZED-NEXT:     Content: '01020304'
+# UNRECOGNIZED-NEXT: ...
+
+--- !ELF
+FileHeader:
+  Class: ELFCLASS64
+  Data:  ELFDATA2LSB
+  Type:  ET_EXEC
+Sections:
+  - Name:    .debug_foo
+    Type:    SHT_PROGBITS
+    Content: '01020304'


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87346.290644.patch
Type: text/x-patch
Size: 1751 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200909/81cd2f4d/attachment.bin>


More information about the llvm-commits mailing list