JDevlieghere created this revision.
JDevlieghere added a reviewer: jasonmolenda.
Herald added a project: All.
JDevlieghere requested review of this revision.

Show the user the DBGError (if available) when dsymForUUID fails.

rdar://90949180


https://reviews.llvm.org/D123743

Files:
  lldb/include/lldb/Symbol/LocateSymbolFile.h
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Interpreter/CommandReturnObject.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
  lldb/source/Symbol/LocateSymbolFile.cpp
  lldb/source/Symbol/LocateSymbolFileMacOSX.cpp

Index: lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
===================================================================
--- lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
+++ lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
@@ -298,7 +298,8 @@
 }
 
 static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
-                                                ModuleSpec &module_spec) {
+                                                ModuleSpec &module_spec,
+                                                Status &error) {
   Log *log = GetLog(LLDBLog::Host);
   bool success = false;
   if (uuid_dict != NULL && CFGetTypeID(uuid_dict) == CFDictionaryGetTypeID()) {
@@ -306,6 +307,14 @@
     CFStringRef cf_str;
     CFDictionaryRef cf_dict;
 
+    cf_str = (CFStringRef)CFDictionaryGetValue((CFDictionaryRef)uuid_dict,
+                                               CFSTR("DBGError"));
+    if (cf_str && CFGetTypeID(cf_str) == CFStringGetTypeID()) {
+      if (CFCString::FileSystemRepresentation(cf_str, str)) {
+        error.SetErrorString(str);
+      }
+    }
+
     cf_str = (CFStringRef)CFDictionaryGetValue(
         (CFDictionaryRef)uuid_dict, CFSTR("DBGSymbolRichExecutable"));
     if (cf_str && CFGetTypeID(cf_str) == CFStringGetTypeID()) {
@@ -337,7 +346,6 @@
 
     std::string DBGBuildSourcePath;
     std::string DBGSourcePath;
-    std::string DBGError;
 
     // If DBGVersion 1 or DBGVersion missing, ignore DBGSourcePathRemapping.
     // If DBGVersion 2, strip last two components of path remappings from
@@ -458,7 +466,7 @@
 }
 
 bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
-                                          bool force_lookup) {
+                                          Status &error, bool force_lookup) {
   bool success = false;
   const UUID *uuid_ptr = module_spec.GetUUIDPtr();
   const FileSpec *file_spec_ptr = module_spec.GetFileSpecPtr();
@@ -578,7 +586,7 @@
             LLDB_LOGF(log, "Calling %s with file %s to find dSYM",
                       g_dsym_for_uuid_exe_path, file_path);
         }
-        Status error = Host::RunShellCommand(
+        error = Host::RunShellCommand(
             command.GetData(),
             FileSpec(),      // current working directory
             &exit_status,    // Exit status
@@ -602,8 +610,8 @@
               CFCString uuid_cfstr(uuid_str.c_str());
               CFDictionaryRef uuid_dict = (CFDictionaryRef)CFDictionaryGetValue(
                   plist.get(), uuid_cfstr.get());
-              success =
-                  GetModuleSpecInfoFromUUIDDictionary(uuid_dict, module_spec);
+              success = GetModuleSpecInfoFromUUIDDictionary(uuid_dict,
+                                                            module_spec, error);
             } else {
               const CFIndex num_values = ::CFDictionaryGetCount(plist.get());
               if (num_values > 0) {
@@ -612,14 +620,14 @@
                 ::CFDictionaryGetKeysAndValues(plist.get(), NULL,
                                                (const void **)&values[0]);
                 if (num_values == 1) {
-                  success = GetModuleSpecInfoFromUUIDDictionary(values[0],
-                                                                module_spec);
+                  success = GetModuleSpecInfoFromUUIDDictionary(
+                      values[0], module_spec, error);
                   return success;
                 } else {
                   for (CFIndex i = 0; i < num_values; ++i) {
                     ModuleSpec curr_module_spec;
-                    if (GetModuleSpecInfoFromUUIDDictionary(values[i],
-                                                            curr_module_spec)) {
+                    if (GetModuleSpecInfoFromUUIDDictionary(
+                            values[i], curr_module_spec, error)) {
                       if (module_spec.GetArchitecture().IsCompatibleMatch(
                               curr_module_spec.GetArchitecture())) {
                         module_spec = curr_module_spec;
Index: lldb/source/Symbol/LocateSymbolFile.cpp
===================================================================
--- lldb/source/Symbol/LocateSymbolFile.cpp
+++ lldb/source/Symbol/LocateSymbolFile.cpp
@@ -130,7 +130,8 @@
 
   if (FileSystem::Instance().Exists(dsym_yaa_fspec)) {
     ModuleSpec mutable_mod_spec = mod_spec;
-    if (Symbols::DownloadObjectAndSymbolFile(mutable_mod_spec, true) &&
+    Status error;
+    if (Symbols::DownloadObjectAndSymbolFile(mutable_mod_spec, error, true) &&
         FileSystem::Instance().Exists(mutable_mod_spec.GetSymbolFileSpec())) {
       dsym_fspec = mutable_mod_spec.GetSymbolFileSpec();
       return true;
@@ -390,7 +391,7 @@
 }
 
 bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
-                                          bool force_lookup) {
+                                          Status &error, bool force_lookup) {
   // Fill in the module_spec.GetFileSpec() for the object file and/or the
   // module_spec.GetSymbolFileSpec() for the debug symbols file.
   return false;
Index: lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
===================================================================
--- lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
+++ lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
@@ -198,8 +198,10 @@
 
     if (!module_sp.get()) {
       // Force a a dsymForUUID lookup, if that tool is available.
-      if (!module_spec.GetSymbolFileSpec())
-        Symbols::DownloadObjectAndSymbolFile(module_spec, true);
+      if (!module_spec.GetSymbolFileSpec()) {
+        Status error;
+        Symbols::DownloadObjectAndSymbolFile(module_spec, error, true);
+      }
 
       if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
         module_sp = std::make_shared<Module>(module_spec);
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -591,8 +591,10 @@
 
           if (!module_sp) {
             // Force a an external lookup, if that tool is available.
-            if (!module_spec.GetSymbolFileSpec())
-              Symbols::DownloadObjectAndSymbolFile(module_spec, true);
+            if (!module_spec.GetSymbolFileSpec()) {
+              Status error;
+              Symbols::DownloadObjectAndSymbolFile(module_spec, error, true);
+            }
 
             if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
               module_sp = std::make_shared<Module>(module_spec);
Index: lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
===================================================================
--- lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
+++ lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
@@ -290,8 +290,11 @@
                 }
               }
               if (!module_spec.GetSymbolFileSpec() ||
-                  !module_spec.GetSymbolFileSpec())
-                Symbols::DownloadObjectAndSymbolFile(module_spec, true);
+                  !module_spec.GetSymbolFileSpec()) {
+                Status symbl_error;
+                Symbols::DownloadObjectAndSymbolFile(module_spec, symbl_error,
+                                                     true);
+              }
 
               if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
                 ModuleSP module_sp(new Module(module_spec));
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6969,7 +6969,8 @@
       module_spec.GetFileSpec() = FileSpec(image.filename.c_str());
     }
     if (image.currently_executing) {
-      Symbols::DownloadObjectAndSymbolFile(module_spec, true);
+      Status error;
+      Symbols::DownloadObjectAndSymbolFile(module_spec, error, true);
       if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
         process.GetTarget().GetOrCreateModule(module_spec, false);
       }
Index: lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
===================================================================
--- lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -790,7 +790,8 @@
       // exists, instead of depending on the DebugSymbols preferences being
       // set.
       if (IsKernel()) {
-        if (Symbols::DownloadObjectAndSymbolFile(module_spec, true)) {
+        Status error;
+        if (Symbols::DownloadObjectAndSymbolFile(module_spec, error, true)) {
           if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
             m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
                                                    target.GetArchitecture());
Index: lldb/source/Interpreter/CommandReturnObject.cpp
===================================================================
--- lldb/source/Interpreter/CommandReturnObject.cpp
+++ lldb/source/Interpreter/CommandReturnObject.cpp
@@ -106,7 +106,8 @@
 
 void CommandReturnObject::SetError(const Status &error,
                                    const char *fallback_error_cstr) {
-  AppendError(error.AsCString(fallback_error_cstr));
+  if (error.Fail())
+    AppendError(error.AsCString(fallback_error_cstr));
 }
 
 void CommandReturnObject::SetError(llvm::Error error) {
Index: lldb/source/Commands/CommandObjectTarget.cpp
===================================================================
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -2464,7 +2464,8 @@
         if (m_symbol_file.GetOptionValue().OptionWasSet())
           module_spec.GetSymbolFileSpec() =
               m_symbol_file.GetOptionValue().GetCurrentValue();
-        if (Symbols::DownloadObjectAndSymbolFile(module_spec)) {
+        Status error;
+        if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
           ModuleSP module_sp(
               target->GetOrCreateModule(module_spec, true /* notify */));
           if (module_sp) {
@@ -2500,6 +2501,7 @@
           result.AppendErrorWithFormat(
               "Unable to locate the executable or symbol file with UUID %s",
               strm.GetData());
+          result.SetError(error);
           return false;
         }
       } else {
@@ -4165,10 +4167,13 @@
 
   bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
                                    CommandReturnObject &result, bool &flush) {
-    if (Symbols::DownloadObjectAndSymbolFile(module_spec)) {
+    Status error;
+    if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
       if (module_spec.GetSymbolFileSpec())
         return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
                                 result);
+    } else {
+      result.SetError(error);
     }
     return false;
   }
Index: lldb/include/lldb/Symbol/LocateSymbolFile.h
===================================================================
--- lldb/include/lldb/Symbol/LocateSymbolFile.h
+++ lldb/include/lldb/Symbol/LocateSymbolFile.h
@@ -13,6 +13,7 @@
 
 #include "lldb/Core/FileSpecList.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Status.h"
 
 namespace lldb_private {
 
@@ -50,6 +51,7 @@
   // enabled the external program before calling.
   //
   static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
+                                          Status &error,
                                           bool force_lookup = true);
 };
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to