[Lldb-commits] [lldb] r243200 - Add some initial logging for when lldb is searching for binaries,

Jason Molenda jmolenda at apple.com
Fri Jul 24 19:39:42 PDT 2015


Author: jmolenda
Date: Fri Jul 24 21:39:42 2015
New Revision: 243200

URL: http://llvm.org/viewvc/llvm-project?rev=243200&view=rev
Log:
Add some initial logging for when lldb is searching for binaries,
dSYMs, or reading binaries out of memory to the 'Host' log channel.
There's more to be done here, both for Mac and for other platforms,
but the initial set of new loggings are useful enough to check in
at this point.

Modified:
    lldb/trunk/source/Host/common/Symbols.cpp
    lldb/trunk/source/Host/macosx/Symbols.cpp
    lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/source/Host/common/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Symbols.cpp?rev=243200&r1=243199&r2=243200&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Symbols.cpp (original)
+++ lldb/trunk/source/Host/common/Symbols.cpp Fri Jul 24 21:39:42 2015
@@ -11,6 +11,7 @@
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/DataBuffer.h"
 #include "lldb/Core/DataExtractor.h"
+#include "lldb/Core/Log.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/StreamString.h"
@@ -79,6 +80,7 @@ FileAtPathContainsArchAndUUID (const Fil
 static bool
 LocateDSYMInVincinityOfExecutable (const ModuleSpec &module_spec, FileSpec &dsym_fspec)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
     const FileSpec *exec_fspec = module_spec.GetFileSpecPtr();
     if (exec_fspec)
     {
@@ -88,6 +90,17 @@ LocateDSYMInVincinityOfExecutable (const
             // Make sure the module isn't already just a dSYM file...
             if (strcasestr(path, ".dSYM/Contents/Resources/DWARF") == NULL)
             {
+                if (log)
+                {
+                    if (module_spec.GetUUIDPtr() && module_spec.GetUUIDPtr()->IsValid())
+                    {
+                        log->Printf ("Searching for dSYM bundle next to executable %s, UUID %s", path, module_spec.GetUUIDPtr()->GetAsString().c_str());
+                    }
+                    else
+                    {
+                        log->Printf ("Searching for dSYM bundle next to executable %s", path);
+                    }
+                }
                 size_t obj_file_path_length = strlen(path);
                 ::strncat(path, ".dSYM/Contents/Resources/DWARF/", sizeof(path) - strlen(path) - 1);
                 ::strncat(path, exec_fspec->GetFilename().AsCString(), sizeof(path) - strlen(path) - 1);
@@ -99,6 +112,10 @@ LocateDSYMInVincinityOfExecutable (const
                 if (dsym_fspec.Exists() &&
                     FileAtPathContainsArchAndUUID(dsym_fspec, module_spec.GetArchitecturePtr(), module_spec.GetUUIDPtr()))
                 {
+                    if (log)
+                    {
+                        log->Printf ("dSYM with matching UUID & arch found at %s", path);
+                    }
                     return true;
                 }
                 else
@@ -118,6 +135,10 @@ LocateDSYMInVincinityOfExecutable (const
                             if (dsym_fspec.Exists() &&
                                 FileAtPathContainsArchAndUUID(dsym_fspec, module_spec.GetArchitecturePtr(), module_spec.GetUUIDPtr()))
                             {
+                                if (log)
+                                {
+                                    log->Printf ("dSYM with matching UUID & arch found at %s", path);
+                                }
                                 return true;
                             }
                             else

Modified: lldb/trunk/source/Host/macosx/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Symbols.cpp?rev=243200&r1=243199&r2=243200&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Symbols.cpp (original)
+++ lldb/trunk/source/Host/macosx/Symbols.cpp Fri Jul 24 21:39:42 2015
@@ -22,6 +22,7 @@
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/DataBuffer.h"
 #include "lldb/Core/DataExtractor.h"
+#include "lldb/Core/Log.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/StreamString.h"
@@ -99,6 +100,7 @@ LocateMacOSXFilesUsingDebugSymbols
             {
                 CFCReleaser<CFURLRef> exec_url;
                 const FileSpec *exec_fspec = module_spec.GetFileSpecPtr();
+                Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
                 if (exec_fspec)
                 {
                     char exec_cf_path[PATH_MAX];
@@ -108,6 +110,23 @@ LocateMacOSXFilesUsingDebugSymbols
                                                                                   strlen(exec_cf_path),
                                                                                   FALSE));
                 }
+                if (log)
+                {
+                    std::string searching_for;
+                    if (out_exec_fspec && out_dsym_fspec)
+                    {
+                        searching_for = "executable binary and dSYM";
+                    }
+                    else if (out_exec_fspec)
+                    {
+                        searching_for = "executable binary";
+                    }
+                    else 
+                    {
+                        searching_for = "dSYM bundle";
+                    }
+                    log->Printf ("Calling DebugSymbols framework to locate dSYM bundle for UUID %s, searching for %s", uuid->GetAsString().c_str(), searching_for.c_str());
+                }
 
                 CFCReleaser<CFURLRef> dsym_url (::DBGCopyFullDSYMURLForUUID(module_uuid_ref.get(), exec_url.get()));
                 char path[PATH_MAX];
@@ -118,6 +137,10 @@ LocateMacOSXFilesUsingDebugSymbols
                     {
                         if (::CFURLGetFileSystemRepresentation (dsym_url.get(), true, (UInt8*)path, sizeof(path)-1))
                         {
+                            if (log)
+                            {
+                                log->Printf ("DebugSymbols framework returned dSYM path of %s for UUID %s -- looking for the dSYM", path, uuid->GetAsString().c_str());
+                            }
                             out_dsym_fspec->SetFile(path, path[0] == '~');
 
                             if (out_dsym_fspec->GetFileType () == FileSpec::eFileTypeDirectory)
@@ -136,6 +159,14 @@ LocateMacOSXFilesUsingDebugSymbols
                     if (out_exec_fspec)
                     {
                         bool success = false;
+                        if (log)
+                        {
+                            if (::CFURLGetFileSystemRepresentation (dsym_url.get(), true, (UInt8*)path, sizeof(path)-1))
+                            {
+                                log->Printf ("DebugSymbols framework returned dSYM path of %s for UUID %s -- looking for an exec file", path, uuid->GetAsString().c_str());
+                            }
+
+                        }
                         CFCReleaser<CFDictionaryRef> dict(::DBGCopyDSYMPropertyLists (dsym_url.get()));
                         CFDictionaryRef uuid_dict = NULL;
                         if (dict.get())
@@ -148,6 +179,10 @@ LocateMacOSXFilesUsingDebugSymbols
                             CFStringRef exec_cf_path = static_cast<CFStringRef>(::CFDictionaryGetValue (uuid_dict, CFSTR("DBGSymbolRichExecutable")));
                             if (exec_cf_path && ::CFStringGetFileSystemRepresentation (exec_cf_path, path, sizeof(path)))
                             {
+                                if (log)
+                                {
+                                    log->Printf ("plist bundle has exec path of %s for UUID %s", path, uuid->GetAsString().c_str());
+                                }
                                 ++items_found;
                                 out_exec_fspec->SetFile(path, path[0] == '~');
                                 if (out_exec_fspec->Exists())
@@ -164,6 +199,10 @@ LocateMacOSXFilesUsingDebugSymbols
                                 if (dsym_extension_pos)
                                 {
                                     *dsym_extension_pos = '\0';
+                                    if (log)
+                                    {
+                                        log->Printf ("Looking for executable binary next to dSYM bundle with name with name %s", path);
+                                    }
                                     FileSpec file_spec (path, true);
                                     ModuleSpecList module_specs;
                                     ModuleSpec matched_module_spec;
@@ -184,6 +223,10 @@ LocateMacOSXFilesUsingDebugSymbols
                                                         {
                                                             ++items_found;
                                                             *out_exec_fspec = bundle_exe_file_spec;
+                                                            if (log)
+                                                            {
+                                                                log->Printf ("Executable binary %s next to dSYM is compatible; using", path);
+                                                            }
                                                         }
                                                     }
                                                 }
@@ -205,6 +248,10 @@ LocateMacOSXFilesUsingDebugSymbols
                                             {
                                                 ++items_found;
                                                 *out_exec_fspec = file_spec;
+                                                if (log)
+                                                {
+                                                    log->Printf ("Executable binary %s next to dSYM is compatible; using", path);
+                                                }
                                             }
                                             break;
                                     }
@@ -279,6 +326,7 @@ Symbols::FindSymbolFileInBundle (const F
 static bool
 GetModuleSpecInfoFromUUIDDictionary (CFDictionaryRef uuid_dict, ModuleSpec &module_spec)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
     bool success = false;
     if (uuid_dict != NULL && CFGetTypeID (uuid_dict) == CFDictionaryGetTypeID ())
     {
@@ -289,7 +337,13 @@ GetModuleSpecInfoFromUUIDDictionary (CFD
         if (cf_str && CFGetTypeID (cf_str) == CFStringGetTypeID ())
         {
             if (CFCString::FileSystemRepresentation(cf_str, str))
+            {
                 module_spec.GetFileSpec().SetFile (str.c_str(), true);
+                if (log)
+                {
+                    log->Printf ("From dsymForUUID plist: Symbol rich executable is at '%s'", str.c_str());
+                }
+            }
         }
         
         cf_str = (CFStringRef)CFDictionaryGetValue ((CFDictionaryRef) uuid_dict, CFSTR("DBGDSYMPath"));
@@ -299,6 +353,10 @@ GetModuleSpecInfoFromUUIDDictionary (CFD
             {
                 module_spec.GetSymbolFileSpec().SetFile (str.c_str(), true);
                 success = true;
+                if (log)
+                {
+                    log->Printf ("From dsymForUUID plist: dSYM is at '%s'", str.c_str());
+                }
             }
         }
         
@@ -439,9 +497,17 @@ Symbols::DownloadObjectAndSymbolFile (Mo
             
             if (!command.GetString().empty())
             {
+                Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
                 int exit_status = -1;
                 int signo = -1;
                 std::string command_output;
+                if (log)
+                {
+                    if (!uuid_str.empty())
+                        log->Printf("Calling %s with UUID %s to find dSYM", g_dsym_for_uuid_exe_path, uuid_str.c_str());
+                    else if (file_path[0] != '\0')
+                        log->Printf("Calling %s with file %s to find dSYM", g_dsym_for_uuid_exe_path, file_path);
+                }
                 Error error = Host::RunShellCommand (command.GetData(),
                                                      NULL,              // current working directory
                                                      &exit_status,      // Exit status
@@ -497,6 +563,16 @@ Symbols::DownloadObjectAndSymbolFile (Mo
                         }
                     }
                 }
+                else
+                {
+                    if (log)
+                    {
+                        if (!uuid_str.empty())
+                            log->Printf("Called %s on %s, no matches", g_dsym_for_uuid_exe_path, uuid_str.c_str());
+                        else if (file_path[0] != '\0')
+                            log->Printf("Called %s on %s, no matches", g_dsym_for_uuid_exe_path, file_path);
+                    }
+                }
             }
         }
     }

Modified: lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp?rev=243200&r1=243199&r2=243200&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp Fri Jul 24 21:39:42 2015
@@ -668,6 +668,7 @@ DynamicLoaderDarwinKernel::KextImageInfo
 bool
 DynamicLoaderDarwinKernel::KextImageInfo::ReadMemoryModule (Process *process)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
     if (m_memory_module_sp.get() != NULL)
         return true;
     if (m_load_address == LLDB_INVALID_ADDRESS)
@@ -702,6 +703,10 @@ DynamicLoaderDarwinKernel::KextImageInfo
     {
         if (m_uuid != memory_module_sp->GetUUID())
         {
+            if (log)
+            {
+                log->Printf ("KextImageInfo::ReadMemoryModule the kernel said to find uuid %s at 0x%" PRIx64 " but instead we found uuid %s, throwing it away", m_uuid.GetAsString().c_str(), m_load_address, memory_module_sp->GetUUID().GetAsString().c_str());
+            }
             return false;
         }
     }
@@ -716,6 +721,11 @@ DynamicLoaderDarwinKernel::KextImageInfo
     m_kernel_image = is_kernel;
     if (is_kernel)
     {
+        if (log)
+        {
+            // This is unusual and probably not intended
+            log->Printf ("KextImageInfo::ReadMemoryModule read the kernel binary out of memory");
+        }
         if (memory_module_sp->GetArchitecture().IsValid())
         {
             process->GetTarget().SetArchitecture(memory_module_sp->GetArchitecture());

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp?rev=243200&r1=243199&r2=243200&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp Fri Jul 24 21:39:42 2015
@@ -16,6 +16,7 @@
 #include "lldb/Breakpoint/BreakpointLocation.h"
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/Error.h"
+#include "lldb/Core/Log.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/ModuleSpec.h"
@@ -302,6 +303,7 @@ PlatformRemoteiOS::GetContainedFilesInto
 bool
 PlatformRemoteiOS::UpdateSDKDirectoryInfosIfNeeded()
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
     if (m_sdk_directory_infos.empty())
     {
         // A --sysroot option was supplied - add it to our list of SDKs to check
@@ -310,9 +312,17 @@ PlatformRemoteiOS::UpdateSDKDirectoryInf
             FileSpec sdk_sysroot_fspec(m_sdk_sysroot.GetCString(), true);
             const SDKDirectoryInfo sdk_sysroot_directory_info(sdk_sysroot_fspec);
             m_sdk_directory_infos.push_back(sdk_sysroot_directory_info);
+            if (log)
+            {
+                log->Printf ("PlatformRemoteiOS::UpdateSDKDirectoryInfosIfNeeded added --sysroot SDK directory %s", m_sdk_sysroot.GetCString());
+            }
             return true;
         }
         const char *device_support_dir = GetDeviceSupportDirectory();
+        if (log)
+        {
+            log->Printf ("PlatformRemoteiOS::UpdateSDKDirectoryInfosIfNeeded Got DeviceSupport directory %s", device_support_dir);
+        }
         if (device_support_dir)
         {
             const bool find_directories = true;
@@ -337,6 +347,10 @@ PlatformRemoteiOS::UpdateSDKDirectoryInf
                 if (sdk_symbols_symlink_fspec.Exists())
                 {
                     m_sdk_directory_infos.push_back(sdk_directory_info);
+                    if (log)
+                    {
+                        log->Printf ("PlatformRemoteiOS::UpdateSDKDirectoryInfosIfNeeded added builtin SDK directory %s", sdk_symbols_symlink_fspec.GetPath().c_str());
+                    }
                 }
             }
 
@@ -344,6 +358,10 @@ PlatformRemoteiOS::UpdateSDKDirectoryInf
             FileSpec local_sdk_cache("~/Library/Developer/Xcode/iOS DeviceSupport", true);
             if (local_sdk_cache.Exists())
             {
+                if (log)
+                {
+                    log->Printf ("PlatformRemoteiOS::UpdateSDKDirectoryInfosIfNeeded searching %s for additional SDKs", local_sdk_cache.GetPath().c_str());
+                }
                 char path[PATH_MAX];
                 if (local_sdk_cache.GetPath(path, sizeof(path)))
                 {
@@ -358,6 +376,10 @@ PlatformRemoteiOS::UpdateSDKDirectoryInf
                     for (uint32_t i=num_installed; i<num_sdk_infos; ++i)
                     {
                         m_sdk_directory_infos[i].user_cached = true;
+                        if (log)
+                        {
+                            log->Printf ("PlatformRemoteiOS::UpdateSDKDirectoryInfosIfNeeded user SDK directory %s", m_sdk_directory_infos[i].directory.GetPath().c_str());
+                        }
                     }
                 }
             }
@@ -592,6 +614,7 @@ PlatformRemoteiOS::GetFileInSDKRoot (con
                                      bool symbols_dirs_only,
                                      lldb_private::FileSpec &local_file)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
     if (sdkroot_path && sdkroot_path[0] && platform_file_path && platform_file_path[0])
     {
         char resolved_path[PATH_MAX];
@@ -606,7 +629,13 @@ PlatformRemoteiOS::GetFileInSDKRoot (con
             
             local_file.SetFile(resolved_path, true);
             if (local_file.Exists())
+            {
+                if (log)
+                {
+                    log->Printf ("Found a copy of %s in the SDK dir %s", platform_file_path, sdkroot_path);
+                }
                 return true;
+            }
         }
             
         ::snprintf (resolved_path,
@@ -617,7 +646,13 @@ PlatformRemoteiOS::GetFileInSDKRoot (con
         
         local_file.SetFile(resolved_path, true);
         if (local_file.Exists())
+        {
+            if (log)
+            {
+                log->Printf ("Found a copy of %s in the SDK dir %s/Symbols.Internal", platform_file_path, sdkroot_path);
+            }
             return true;
+        }
         ::snprintf (resolved_path,
                     sizeof(resolved_path), 
                     "%s/Symbols%s", 
@@ -626,7 +661,13 @@ PlatformRemoteiOS::GetFileInSDKRoot (con
         
         local_file.SetFile(resolved_path, true);
         if (local_file.Exists())
+        {
+            if (log)
+            {
+                log->Printf ("Found a copy of %s in the SDK dir %s/Symbols", platform_file_path, sdkroot_path);
+            }
             return true;                
+        }
     }
     return false;
 }
@@ -637,6 +678,7 @@ PlatformRemoteiOS::GetSymbolFile (const
                                   const UUID *uuid_ptr,
                                   FileSpec &local_file)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
     Error error;
     char platform_file_path[PATH_MAX];
     if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path)))
@@ -654,7 +696,13 @@ PlatformRemoteiOS::GetSymbolFile (const
             
             local_file.SetFile(resolved_path, true);
             if (local_file.Exists())
+            {
+                if (log)
+                {
+                    log->Printf ("Found a copy of %s in the DeviceSupport dir %s", platform_file_path, os_version_dir);
+                }
                 return error;
+            }
 
             ::snprintf (resolved_path, 
                         sizeof(resolved_path), 
@@ -664,7 +712,13 @@ PlatformRemoteiOS::GetSymbolFile (const
 
             local_file.SetFile(resolved_path, true);
             if (local_file.Exists())
+            {
+                if (log)
+                {
+                    log->Printf ("Found a copy of %s in the DeviceSupport dir %s/Symbols.Internal", platform_file_path, os_version_dir);
+                }
                 return error;
+            }
             ::snprintf (resolved_path, 
                         sizeof(resolved_path), 
                         "%s/Symbols/%s", 
@@ -673,7 +727,13 @@ PlatformRemoteiOS::GetSymbolFile (const
 
             local_file.SetFile(resolved_path, true);
             if (local_file.Exists())
+            {
+                if (log)
+                {
+                    log->Printf ("Found a copy of %s in the DeviceSupport dir %s/Symbols", platform_file_path, os_version_dir);
+                }
                 return error;
+            }
 
         }
         local_file = platform_file;

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=243200&r1=243199&r2=243200&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Fri Jul 24 21:39:42 2015
@@ -3049,6 +3049,11 @@ Process::ReadModuleFromMemory (const Fil
                                lldb::addr_t header_addr,
                                size_t size_to_read)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+    if (log)
+    {
+        log->Printf ("Process::ReadModuleFromMemory reading %s binary from memory", file_spec.GetPath().c_str());
+    }
     ModuleSP module_sp (new Module (file_spec, ArchSpec()));
     if (module_sp)
     {





More information about the lldb-commits mailing list