From fe7295dcf586a2b4913fec2fd74e03e7ea7c45ec Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Sat, 16 Aug 2014 00:32:58 +0000 Subject: [PATCH] In order for the debug script filename to be valid as a module name, LLDB does some textual replacements. However, if one were unaware of this, they might name their script using the 'untampered' file name and they would get no feedback about it. Add logic to LLDB to make sure we tell people about those changes if it turns out they might need to know. Fixes rdar://14310572 llvm-svn: 215798 --- lldb/include/lldb/Target/Platform.h | 3 +- lldb/source/Core/Module.cpp | 3 +- .../Platform/MacOSX/PlatformDarwin.cpp | 33 ++++++++++++++++++- .../Plugins/Platform/MacOSX/PlatformDarwin.h | 3 +- lldb/source/Target/Platform.cpp | 2 +- lldb/source/Target/Target.cpp | 6 ++-- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 887bf9a2ae63..d9122c38d6f9 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -331,7 +331,8 @@ namespace lldb_private { //---------------------------------------------------------------------- virtual FileSpecList LocateExecutableScriptingResources (Target *target, - Module &module); + Module &module, + Stream* feedback_stream); virtual Error GetSharedModule (const ModuleSpec &module_spec, diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index d337a8832b18..e06a458a17f8 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -1532,7 +1532,8 @@ Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* fee } FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target, - *this); + *this, + feedback_stream); const uint32_t num_specs = file_specs.GetSize(); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 77f6fd9f8965..71740c163560 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -56,7 +56,8 @@ PlatformDarwin::~PlatformDarwin() FileSpecList PlatformDarwin::LocateExecutableScriptingResources (Target *target, - Module &module) + Module &module, + Stream* feedback_stream) { FileSpecList file_list; if (target && target->GetDebugger().GetScriptLanguage() == eScriptLanguagePython) @@ -84,6 +85,7 @@ PlatformDarwin::LocateExecutableScriptingResources (Target *target, while (module_spec.GetFilename()) { std::string module_basename (module_spec.GetFilename().GetCString()); + std::string original_module_basename (module_basename); // FIXME: for Python, we cannot allow certain characters in module // filenames we import. Theoretically, different scripting languages may @@ -97,10 +99,39 @@ PlatformDarwin::LocateExecutableScriptingResources (Target *target, StreamString path_string; + StreamString original_path_string; // for OSX we are going to be in .dSYM/Contents/Resources/DWARF/ // let us go to .dSYM/Contents/Resources/Python/.py and see if the file exists path_string.Printf("%s/../Python/%s.py",symfile_spec.GetDirectory().GetCString(), module_basename.c_str()); + original_path_string.Printf("%s/../Python/%s.py",symfile_spec.GetDirectory().GetCString(), original_module_basename.c_str()); FileSpec script_fspec(path_string.GetData(), true); + FileSpec orig_script_fspec(original_path_string.GetData(), true); + + // if we did some replacements of reserved characters, and a file with the untampered name + // exists, then warn the user that the file as-is shall not be loaded + if (feedback_stream) + { + if (module_basename != original_module_basename + && orig_script_fspec.Exists()) + { + if (script_fspec.Exists()) + feedback_stream->Printf("warning: the symbol file '%s' contains a debug script. However, its name" + " '%s' contains reserved characters and as such cannot be loaded. LLDB will" + " load '%s' instead. Consider removing the file with the malformed name to" + " eliminate this warning.\n", + symfile_spec.GetPath().c_str(), + original_path_string.GetData(), + path_string.GetData()); + else + feedback_stream->Printf("warning: the symbol file '%s' contains a debug script. However, its name" + " contains reserved characters and as such cannot be loaded. If you intend" + " to have this script loaded, please rename '%s' to '%s' and retry.\n", + symfile_spec.GetPath().c_str(), + original_path_string.GetData(), + path_string.GetData()); + } + } + if (script_fspec.Exists()) { file_list.Append (script_fspec); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h index 21529a8e9611..535e38bf76ad 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -40,7 +40,8 @@ public: lldb_private::FileSpecList LocateExecutableScriptingResources (lldb_private::Target *target, - lldb_private::Module &module); + lldb_private::Module &module, + lldb_private::Stream* feedback_stream); virtual lldb_private::Error GetSharedModule (const lldb_private::ModuleSpec &module_spec, diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 82185847f3fc..f5dd66a3e597 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -92,7 +92,7 @@ Platform::GetFileWithUUID (const FileSpec &platform_file, } FileSpecList -Platform::LocateExecutableScriptingResources (Target *target, Module &module) +Platform::LocateExecutableScriptingResources (Target *target, Module &module, Stream* feedback_stream) { return FileSpecList(); } diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index e3fd790bdafe..d2d0b5098555 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1013,10 +1013,10 @@ LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target) target->GetDebugger().GetErrorFile()->Printf("unable to load scripting data for module %s - error reported was %s\n", module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(), error.AsCString()); - if (feedback_stream.GetSize()) - target->GetDebugger().GetErrorFile()->Printf("%s\n", - feedback_stream.GetData()); } + if (feedback_stream.GetSize()) + target->GetDebugger().GetErrorFile()->Printf("%s\n", + feedback_stream.GetData()); } void