jasonmolenda created this revision.
jasonmolenda added a reviewer: bulbazord.
jasonmolenda added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

On Darwin systems, lldb will call into the DebugSymbols framework to find the 
debug info (and/or binary) for a given UUID.  The user may have set a 
DBGShellCommands preference in com.apple.DebugSymbols to find that binary by 
UUID.  lldb will also try a binary that is set in the env var 
LLDB_APPLE_DSYMFORUUID_EXECUTABLE (mostly used by the testsuite) and for 
certain "force a binary load" binaries (e.g. the Darwin kernel binary/symbols, 
without which kernel debugging is largely useless), we have a special case in 
source/Symbol/LocateSymbolFileMacOSX.cpp that knows about a binary called 
/usr/local/bin/dsymForUUID that may be installed.

These DBGShellCommands programs return a plist (xml) output giving lldb the 
location of the dSYM and/or binary.  They can also return an error message in 
that xml response.  Today lldb does not print that error, making it difficult 
for users to understand why a binary was not successfully loaded.

I also added some simple logging as lldb processes LC_NOTEs in a mach-o 
corefile binary that can be enabled, to understand what lldb is seeing as it 
loads one of these.

I have another patch that I'll be uploading soon where I fix the DBGError 
return from a test case TestMultipleBinaryCorefile.py, although the error 
message is sent to the Debugger's Stdout channel so I'm not capturing/testing 
it in the API test right now.  (the dsym-for-uuid.sh that this test case 
creates DOES emit a DBGError right now on an unknown uuid, but it doesn't 
format it correctly and lldb ignores it).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157160

Files:
  lldb/source/Core/DynamicLoader.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

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
@@ -5414,6 +5414,8 @@
 
 std::string ObjectFileMachO::GetIdentifierString() {
   std::string result;
+  Log *log(
+      GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
     std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
@@ -5449,6 +5451,9 @@
                 result = buf;
                 if (buf)
                   free(buf);
+                if (log)
+                  log->Printf("LC_NOTE 'kern ver str' found with text '%s'",
+                              result.c_str());
                 return result;
               }
             }
@@ -5472,6 +5477,8 @@
                                               buf) == ident_command.cmdsize) {
           buf[ident_command.cmdsize - 1] = '\0';
           result = buf;
+          if (log)
+            log->Printf("LC_IDENT found with text '%s'", result.c_str());
         }
         if (buf)
           free(buf);
@@ -5484,6 +5491,7 @@
 
 addr_t ObjectFileMachO::GetAddressMask() {
   addr_t mask = 0;
+  Log *log(GetLog(LLDBLog::Process));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
     std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
@@ -5511,6 +5519,10 @@
               if (num_addr_bits != 0) {
                 mask = ~((1ULL << num_addr_bits) - 1);
               }
+              if (log)
+                log->Printf("LC_NOTE 'addrable bits' found, value %d bits, "
+                            "mask 0x%" PRIx64,
+                            num_addr_bits, mask);
               break;
             }
           }
@@ -5526,6 +5538,8 @@
                                                 bool &value_is_offset,
                                                 UUID &uuid,
                                                 ObjectFile::BinaryType &type) {
+  Log *log(
+      GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
   value = LLDB_INVALID_ADDRESS;
   value_is_offset = false;
   uuid.Clear();
@@ -5605,20 +5619,32 @@
               uuid = UUID(raw_uuid, sizeof(uuid_t));
               // convert the "main bin spec" type into our
               // ObjectFile::BinaryType enum
+              const char *typestr = "unrecognized type";
               switch (binspec_type) {
               case 0:
                 type = eBinaryTypeUnknown;
+                typestr = "uknown";
                 break;
               case 1:
                 type = eBinaryTypeKernel;
+                typestr = "xnu kernel";
                 break;
               case 2:
                 type = eBinaryTypeUser;
+                typestr = "userland dyld";
                 break;
               case 3:
                 type = eBinaryTypeStandalone;
+                typestr = "standalone";
                 break;
               }
+              if (log)
+                log->Printf("LC_NOTE 'main bin spec' found, version %d type %d "
+                            "(%s), value 0x%" PRIx64
+                            " value-is-slide==%s uuid %s",
+                            version, type, typestr, value,
+                            value_is_offset ? "true" : "false",
+                            uuid.GetAsString().c_str());
               if (!m_data.GetU32(&offset, &log2_pagesize, 1))
                 return false;
               if (version > 1 && !m_data.GetU32(&offset, &platform, 1))
@@ -6811,6 +6837,8 @@
 ObjectFileMachO::MachOCorefileAllImageInfos
 ObjectFileMachO::GetCorefileAllImageInfos() {
   MachOCorefileAllImageInfos image_infos;
+  Log *log(
+      GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
 
   // Look for an "all image infos" LC_NOTE.
   lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
@@ -6840,6 +6868,10 @@
         //  offset += 4; // uint32_t entries_size;
         //  offset += 4; // uint32_t unused;
 
+        if (log)
+          log->Printf(
+              "LC_NOTE 'all image infos' found version %d with %d images",
+              version, imgcount);
         offset = entries_fileoff;
         for (uint32_t i = 0; i < imgcount; i++) {
           // Read the struct image_entry.
@@ -6871,6 +6903,14 @@
                                                     vmaddr};
             image_entry.segment_load_addresses.push_back(new_seg);
           }
+          if (log)
+            log->Printf("  image entry: %s %s 0x%" PRIx64 " %s",
+                        image_entry.filename.c_str(),
+                        image_entry.uuid.GetAsString().c_str(),
+                        image_entry.load_address,
+                        image_entry.currently_executing
+                            ? "currently executing"
+                            : "not currently executing");
           image_infos.all_image_infos.push_back(image_entry);
         }
       } else if (strcmp("load binary", data_owner) == 0) {
@@ -6890,6 +6930,14 @@
           image_entry.slide = slide;
           image_entry.currently_executing = true;
           image_infos.all_image_infos.push_back(image_entry);
+          if (log)
+            log->Printf("LC_NOTE 'load binary' found, filename %s uuid %s load "
+                        "address 0x%" PRIx64 " slide 0x%" PRIx64,
+                        filename.c_str(),
+                        image_entry.uuid.IsValid()
+                            ? image_entry.uuid.GetAsString().c_str()
+                            : "00000000-0000-0000-0000-000000000000",
+                        load_address, slide);
         }
       }
     }
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
@@ -767,9 +767,10 @@
       // to do anything useful. This will force a call to dsymForUUID if it
       // exists, instead of depending on the DebugSymbols preferences being
       // set.
+      Status kernel_search_error;
       if (IsKernel()) {
-        Status error;
-        if (Symbols::DownloadObjectAndSymbolFile(module_spec, error, true)) {
+        if (Symbols::DownloadObjectAndSymbolFile(module_spec,
+                                                 kernel_search_error, true)) {
           if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
             m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
                                                    target.GetArchitecture());
@@ -810,6 +811,11 @@
         Stream &s = target.GetDebugger().GetOutputStream();
         s.Printf("WARNING: Unable to locate kernel binary on the debugger "
                  "system.\n");
+        if (kernel_search_error.Fail() && kernel_search_error.AsCString("") &&
+            kernel_search_error.AsCString("")[0] != '\0') {
+          s.Printf("Tried DBGShellCommands cmd, got error: %s",
+                   kernel_search_error.AsCString());
+        }
       }
     }
 
Index: lldb/source/Core/DynamicLoader.cpp
===================================================================
--- lldb/source/Core/DynamicLoader.cpp
+++ lldb/source/Core/DynamicLoader.cpp
@@ -8,6 +8,7 @@
 
 #include "lldb/Target/DynamicLoader.h"
 
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/ModuleSpec.h"
@@ -235,6 +236,11 @@
                                            force_symbol_search);
       if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
         module_sp = std::make_shared<Module>(module_spec);
+      } else if (force_symbol_search && error.AsCString("") &&
+                 error.AsCString("")[0] != '\0') {
+        Stream &s = target.GetDebugger().GetOutputStream();
+        s.Printf("Tried DBGShellCommands cmd, got error: %s\n",
+                 error.AsCString());
       }
     }
 
@@ -266,8 +272,8 @@
         if (value != LLDB_INVALID_ADDRESS) {
           LLDB_LOGF(log,
                     "DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
-                    "binary UUID %s at %s 0x%" PRIx64,
-                    uuid.GetAsString().c_str(),
+                    "binary %s UUID %s at %s 0x%" PRIx64,
+                    name.str().c_str(), uuid.GetAsString().c_str(),
                     value_is_offset ? "offset" : "address", value);
           module_sp->SetLoadAddress(target, value, value_is_offset, changed);
         } else {
@@ -275,8 +281,8 @@
           // offset 0.
           LLDB_LOGF(log,
                     "DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
-                    "binary UUID %s at file address",
-                    uuid.GetAsString().c_str());
+                    "binary %s UUID %s at file address",
+                    name.str().c_str(), uuid.GetAsString().c_str());
           module_sp->SetLoadAddress(target, 0, true /* value_is_slide */,
                                     changed);
         }
@@ -284,8 +290,8 @@
         // In-memory image, load at its true address, offset 0.
         LLDB_LOGF(log,
                   "DynamicLoader::LoadBinaryWithUUIDAndAddress Loading binary "
-                  "UUID %s from memory at address 0x%" PRIx64,
-                  uuid.GetAsString().c_str(), value);
+                  "%s UUID %s from memory at address 0x%" PRIx64,
+                  name.str().c_str(), uuid.GetAsString().c_str(), value);
         module_sp->SetLoadAddress(target, 0, true /* value_is_slide */,
                                   changed);
       }
@@ -297,10 +303,26 @@
       target.ModulesDidLoad(added_module);
     }
   } else {
-    LLDB_LOGF(log, "Unable to find binary with UUID %s and load it at "
-                  "%s 0x%" PRIx64,
-                  uuid.GetAsString().c_str(),
-                  value_is_offset ? "offset" : "address", value);
+    if (force_symbol_search) {
+      Stream &s = target.GetDebugger().GetOutputStream();
+      s.Printf("Unable to find file");
+      if (!name.empty())
+        s.Printf(" %s", name.str().c_str());
+      if (uuid.IsValid())
+        s.Printf(" with UUID %s", uuid.GetAsString().c_str());
+      if (value != LLDB_INVALID_ADDRESS) {
+        if (value_is_offset)
+          s.Printf(" with slide 0x%" PRIx64, value);
+        else
+          s.Printf(" at address 0x%" PRIx64, value);
+      }
+      s.Printf("\n");
+    }
+    LLDB_LOGF(log,
+              "Unable to find binary %s with UUID %s and load it at "
+              "%s 0x%" PRIx64,
+              name.str().c_str(), uuid.GetAsString().c_str(),
+              value_is_offset ? "offset" : "address", value);
   }
 
   return module_sp;
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to