[llvm] 25ad7c9 - [dsymutil] Unify reporting of warnings and errors

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 4 21:57:50 PDT 2023


Author: Jonas Devlieghere
Date: 2023-04-04T21:57:41-07:00
New Revision: 25ad7c958a13c28a234af35abec2ecbd1429fd06

URL: https://github.com/llvm/llvm-project/commit/25ad7c958a13c28a234af35abec2ecbd1429fd06
DIFF: https://github.com/llvm/llvm-project/commit/25ad7c958a13c28a234af35abec2ecbd1429fd06.diff

LOG: [dsymutil] Unify reporting of warnings and errors

Make all error reporting in DwarfLinkerForBinary go through the
`reportWarning` and `reportError` wrappers.

Added: 
    

Modified: 
    llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
    llvm/tools/dsymutil/DwarfLinkerForBinary.h

Removed: 
    


################################################################################
diff  --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
index 4ece4767c329..0db7b6ecd1c5 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -105,25 +105,33 @@ static mc::RegisterMCTargetOptionsFlags MOF;
 
 namespace dsymutil {
 
-/// Report a warning to the user, optionally including information about a
-/// specific \p DIE related to the warning.
-void DwarfLinkerForBinary::reportWarning(const Twine &Warning,
-                                         StringRef Context,
-                                         const DWARFDie *DIE) const {
-
-  warn(Warning, Context);
-
-  if (!Options.Verbose || !DIE)
+static void dumpDIE(const DWARFDie *DIE, bool Verbose) {
+  if (!DIE || !Verbose)
     return;
 
   DIDumpOptions DumpOpts;
   DumpOpts.ChildRecurseDepth = 0;
-  DumpOpts.Verbose = Options.Verbose;
+  DumpOpts.Verbose = Verbose;
 
   WithColor::note() << "    in DIE:\n";
   DIE->dump(errs(), 6 /* Indent */, DumpOpts);
 }
 
+/// Report a warning to the user, optionally including information about a
+/// specific \p DIE related to the warning.
+void DwarfLinkerForBinary::reportWarning(Twine Warning, Twine Context,
+                                         const DWARFDie *DIE) const {
+
+  warn(Warning, Context);
+  dumpDIE(DIE, Options.Verbose);
+}
+
+void DwarfLinkerForBinary::reportError(Twine Error, Twine Context,
+                                       const DWARFDie *DIE) const {
+  error(Error, Context);
+  dumpDIE(DIE, Options.Verbose);
+}
+
 bool DwarfLinkerForBinary::createStreamer(const Triple &TheTriple,
                                           raw_fd_ostream &OutFile) {
   if (Options.NoOutput)
@@ -132,10 +140,10 @@ bool DwarfLinkerForBinary::createStreamer(const Triple &TheTriple,
   Streamer = std::make_unique<DwarfStreamer>(
       Options.FileType, OutFile, Options.Translator,
       [&](const Twine &Error, StringRef Context, const DWARFDie *) {
-        error(Error, Context);
+        reportError(Error, Context);
       },
       [&](const Twine &Warning, StringRef Context, const DWARFDie *) {
-        warn(Warning, Context);
+        reportWarning(Warning, Context);
       });
   return Streamer->init(TheTriple, "__DWARF");
 }
@@ -481,8 +489,8 @@ Error DwarfLinkerForBinary::copySwiftInterfaces(StringRef Architecture) const {
 
     // copy_file attempts an APFS clone first, so this should be cheap.
     if ((EC = sys::fs::copy_file(InterfaceFile, Path.str())))
-      warn(Twine("cannot copy parseable Swift interface ") + InterfaceFile +
-           ": " + toString(errorCodeToError(EC)));
+      reportWarning(Twine("cannot copy parseable Swift interface ") +
+                    InterfaceFile + ": " + toString(errorCodeToError(EC)));
     Path.resize(BaseLength);
   }
   return Error::success();
@@ -584,8 +592,8 @@ bool DwarfLinkerForBinary::link(const DebugMap &Map) {
         reportWarning(Warning, Context, DIE);
       });
   GeneralLinker.setErrorHandler(
-      [&](const Twine &Error, StringRef Context, const DWARFDie *) {
-        error(Error, Context);
+      [&](const Twine &Error, StringRef Context, const DWARFDie *DIE) {
+        reportError(Error, Context, DIE);
       });
   GeneralLinker.setInputVerificationHandler([&](const DWARFFile &File) {
     reportWarning("input verification failed", File.FileName);
@@ -677,12 +685,12 @@ bool DwarfLinkerForBinary::link(const DebugMap &Map) {
       StringRef File = Obj->getObjectFilename();
       auto ErrorOrMem = MemoryBuffer::getFile(File);
       if (!ErrorOrMem) {
-        warn("Could not open '" + File + "'");
+        reportWarning("Could not open '" + File + "'");
         continue;
       }
       sys::fs::file_status Stat;
       if (auto Err = sys::fs::status(File, Stat)) {
-        warn(Err.message());
+        reportWarning(Err.message());
         continue;
       }
       if (!Options.NoTimestamp) {

diff  --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.h b/llvm/tools/dsymutil/DwarfLinkerForBinary.h
index 742580f27248..4eb93ee92097 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.h
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.h
@@ -41,8 +41,10 @@ class DwarfLinkerForBinary {
   /// Link the contents of the DebugMap.
   bool link(const DebugMap &);
 
-  void reportWarning(const Twine &Warning, StringRef Context,
+  void reportWarning(Twine Warning, Twine Context = {},
                      const DWARFDie *DIE = nullptr) const;
+  void reportError(Twine Error, Twine Context = {},
+                   const DWARFDie *DIE = nullptr) const;
 
   /// Returns true if input verification is enabled and verification errors were
   /// found.


        


More information about the llvm-commits mailing list