diff options
| author | Oleksiy Vyalov <ovyalov@google.com> | 2015-03-10 01:15:28 +0000 |
|---|---|---|
| committer | Oleksiy Vyalov <ovyalov@google.com> | 2015-03-10 01:15:28 +0000 |
| commit | 63acdfdeb26616dfa1d9657fa666afc9b9440a2a (patch) | |
| tree | e16c9b93f68e2a5ddd835845a4801ec1dead78c5 /lldb/source/Plugins | |
| parent | 8fb05ac9987bb2fe210e3d0d02ef762793524c45 (diff) | |
| download | bcm5719-llvm-63acdfdeb26616dfa1d9657fa666afc9b9440a2a.tar.gz bcm5719-llvm-63acdfdeb26616dfa1d9657fa666afc9b9440a2a.zip | |
Add Utility/ModuleCache class and integrate it with PlatformGDBRemoteServer - in order to allow modules caching from remote targets.
http://reviews.llvm.org/D8037
llvm-svn: 231734
Diffstat (limited to 'lldb/source/Plugins')
14 files changed, 138 insertions, 18 deletions
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index 679c199a6ed..da10393b1b6 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -851,6 +851,7 @@ DynamicLoaderMacOSXDYLD::AddModulesUsingImageInfos (DYLDImageInfo::collection &i if (!commpage_image_module_sp) { module_spec.SetObjectOffset (objfile->GetFileOffset() + commpage_section->GetFileOffset()); + module_spec.SetObjectSize (objfile->GetByteSize()); commpage_image_module_sp = target.GetSharedModule (module_spec); if (!commpage_image_module_sp || commpage_image_module_sp->GetObjectFile() == NULL) { diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp index 87bf75321ed..8209d23c0ae 100644 --- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp +++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp @@ -595,7 +595,8 @@ ObjectContainerBSDArchive::GetModuleSpecifications (const lldb_private::FileSpec TimeValue object_mod_time; object_mod_time.OffsetWithSeconds(object->ar_date); spec.GetObjectName () = object->ar_name; - spec.SetObjectOffset(object_file_offset); + spec.SetObjectOffset (object_file_offset); + spec.SetObjectSize (file_size - object_file_offset); spec.GetObjectModificationTime () = object_mod_time; } } diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index a2d1c220528..0bfb1a46c3e 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -604,8 +604,7 @@ ObjectFileELF::GetModuleSpecifications (const lldb_private::FileSpec& file, { if (data_sp) { - ModuleSpec spec; - spec.GetFileSpec() = file; + ModuleSpec spec (file); const uint32_t sub_type = subTypeFromElfHeader(header); spec.GetArchitecture().SetArchitecture(eArchTypeELF, diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index b1553cca63a..824ce440430 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -995,7 +995,8 @@ ObjectFileMachO::GetModuleSpecifications (const lldb_private::FileSpec& file, ModuleSpec spec; spec.GetFileSpec() = file; spec.SetObjectOffset(file_offset); - + spec.SetObjectSize(length); + if (GetArchitecture (header, data, data_offset, spec.GetArchitecture())) { if (spec.GetArchitecture().IsValid()) diff --git a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp index a992b28143f..2fdebe127b8 100644 --- a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp +++ b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp @@ -165,6 +165,18 @@ PlatformFreeBSD::~PlatformFreeBSD() } //TODO:VK: inherit PlatformPOSIX + +bool +PlatformFreeBSD::GetModuleSpec (const FileSpec& module_file_spec, + const ArchSpec& arch, + ModuleSpec &module_spec) +{ + if (m_remote_platform_sp) + return m_remote_platform_sp->GetModuleSpec (module_file_spec, arch, module_spec); + + return Platform::GetModuleSpec (module_file_spec, arch, module_spec); +} + lldb_private::Error PlatformFreeBSD::RunShellCommand (const char *command, const char *working_dir, diff --git a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h index ce3f8cfad97..714b0d43e83 100644 --- a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h +++ b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h @@ -71,6 +71,11 @@ public: //------------------------------------------------------------ // lldb_private::Platform functions //------------------------------------------------------------ + virtual bool + GetModuleSpec (const lldb_private::FileSpec& module_file_spec, + const lldb_private::ArchSpec& arch, + lldb_private::ModuleSpec &module_spec); + virtual lldb_private::Error RunShellCommand (const char *command, const char *working_dir, diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp index 603b33d4a4e..257996a74b4 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -50,6 +50,17 @@ PlatformPOSIX::~PlatformPOSIX() { } +bool +PlatformPOSIX::GetModuleSpec (const FileSpec& module_file_spec, + const ArchSpec& arch, + ModuleSpec &module_spec) +{ + if (m_remote_platform_sp) + return m_remote_platform_sp->GetModuleSpec (module_file_spec, arch, module_spec); + + return Platform::GetModuleSpec (module_file_spec, arch, module_spec); +} + lldb_private::OptionGroupOptions* PlatformPOSIX::GetConnectionOptions (lldb_private::CommandInterpreter& interpreter) { diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h index 4fec694374f..1a8ddda8d18 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h @@ -31,6 +31,12 @@ public: //------------------------------------------------------------ // lldb_private::Platform functions //------------------------------------------------------------ + + virtual bool + GetModuleSpec (const lldb_private::FileSpec& module_file_spec, + const lldb_private::ArchSpec& arch, + lldb_private::ModuleSpec &module_spec); + virtual lldb_private::OptionGroupOptions *GetConnectionOptions( lldb_private::CommandInterpreter &interpreter) override; @@ -115,7 +121,7 @@ public: int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit std::string *command_output, // Pass NULL if you don't want the command output uint32_t timeout_sec) override;// Timeout in seconds to wait for shell program to finish - + virtual lldb_private::Error MakeDirectory (const char *path, uint32_t mode) override; diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp index 900b95e730f..9f59adb1713 100644 --- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp +++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -201,6 +201,17 @@ PlatformWindows::~PlatformWindows() { } +bool +PlatformWindows::GetModuleSpec (const FileSpec& module_file_spec, + const ArchSpec& arch, + ModuleSpec &module_spec) +{ + if (m_remote_platform_sp) + return m_remote_platform_sp->GetModuleSpec (module_file_spec, arch, module_spec); + + return Platform::GetModuleSpec (module_file_spec, arch, module_spec); +} + Error PlatformWindows::ResolveExecutable (const ModuleSpec &ms, lldb::ModuleSP &exe_module_sp, diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.h b/lldb/source/Plugins/Platform/Windows/PlatformWindows.h index a2511067276..7a785656399 100644 --- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.h +++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.h @@ -59,6 +59,11 @@ public: //------------------------------------------------------------ // lldb_private::Platform functions //------------------------------------------------------------ + virtual bool + GetModuleSpec (const lldb_private::FileSpec& module_file_spec, + const lldb_private::ArchSpec& arch, + lldb_private::ModuleSpec &module_spec); + virtual Error ResolveExecutable(const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp, diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index cfb3161f8ef..6ab48c82078 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -27,6 +27,8 @@ #include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" +#include "lldb/Host/HostInfo.h" +#include "lldb/Host/StringConvert.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" @@ -196,6 +198,73 @@ PlatformRemoteGDBServer::ResolveExecutable (const ModuleSpec &module_spec, return error; } +bool +PlatformRemoteGDBServer::GetModuleSpec (const FileSpec& module_file_spec, + const ArchSpec& arch, + ModuleSpec &module_spec) +{ + Log *log = GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PLATFORM); + + const auto module_path = module_file_spec.GetPath (); + + StringExtractorGDBRemote response; + if (!m_gdb_client.GetModuleInfo (module_path.c_str (), arch, response)) + { + if (log) + log->Printf ("PlatformRemoteGDBServer::%s - failed to get module info for %s:%s", + __FUNCTION__, module_path.c_str (), arch.GetTriple ().getTriple ().c_str ()); + return false; + } + + std::string name; + std::string value; + bool success; + StringExtractor extractor; + + module_spec.Clear (); + module_spec.GetFileSpec () = module_file_spec; + + while (response.GetNameColonValue (name, value)) + { + if (name == "uuid" || name == "md5") + { + extractor.GetStringRef ().swap (value); + extractor.SetFilePos (0); + extractor.GetHexByteString (value); + module_spec.GetUUID().SetFromCString (value.c_str(), value.size() / 2); + } + else if (name == "triple") + { + extractor.GetStringRef ().swap (value); + extractor.SetFilePos (0); + extractor.GetHexByteString (value); + module_spec.GetArchitecture().SetTriple (value.c_str ()); + } + else if (name == "file_offset") + { + const auto ival = StringConvert::ToUInt64 (value.c_str (), 0, 16, &success); + if (success) + module_spec.SetObjectOffset (ival); + } + else if (name == "file_size") + { + const auto ival = StringConvert::ToUInt64 (value.c_str (), 0, 16, &success); + if (success) + module_spec.SetObjectSize (ival); + } + } + + if (log) + { + StreamString stream; + module_spec.Dump (stream); + log->Printf ("PlatformRemoteGDBServer::%s - got module info for (%s:%s) : %s", + __FUNCTION__, module_path.c_str (), arch.GetTriple ().getTriple ().c_str (), stream.GetString ().c_str ()); + } + + return true; +} + Error PlatformRemoteGDBServer::GetFileWithUUID (const FileSpec &platform_file, const UUID *uuid_ptr, @@ -346,7 +415,6 @@ PlatformRemoteGDBServer::ConnectRemote (Args& args) { const char *url = args.GetArgumentAtIndex(0); m_gdb_client.SetConnection (new ConnectionFileDescriptor()); - // we're going to reuse the hostname when we connect to the debugserver std::string scheme; int port; @@ -380,7 +448,6 @@ PlatformRemoteGDBServer::ConnectRemote (Args& args) error.SetErrorString ("\"platform connect\" takes a single argument: <connect-url>"); } } - return error; } @@ -840,4 +907,4 @@ void PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames () { m_trap_handlers.push_back (ConstString ("_sigtramp")); -} +} diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h index 878a5186dc3..a920cf5ffac 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h @@ -68,6 +68,11 @@ public: lldb::ModuleSP &module_sp, const lldb_private::FileSpecList *module_search_paths_ptr); + virtual bool + GetModuleSpec (const lldb_private::FileSpec& module_file_spec, + const lldb_private::ArchSpec& arch, + lldb_private::ModuleSpec &module_spec); + virtual const char * GetDescription (); @@ -127,7 +132,6 @@ public: virtual bool SetRemoteWorkingDirectory(const lldb_private::ConstString &path); - // Remote subclasses should override this and return a valid instance // name if connected. diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 45939f4b8f6..e0ab7a34590 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -3720,5 +3720,6 @@ GDBRemoteCommunicationClient::GetModuleInfo (const char* module_path, const auto& tripple = arch_spec.GetTriple().getTriple(); packet.PutBytesAsRawHex8(tripple.c_str(), tripple.size()); - return SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success; + return SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success && + !response.IsErrorResponse (); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index e2b459196a7..389608e5ed9 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -19,7 +19,6 @@ // Other libraries and framework includes #include "llvm/ADT/Triple.h" #include "lldb/Core/Log.h" -#include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/StreamGDBRemote.h" #include "lldb/Core/StreamString.h" @@ -1149,19 +1148,16 @@ GDBRemoteCommunicationServerCommon::Handle_qModuleInfo (StringExtractorGDBRemote if (!module_specs.FindMatchingModuleSpec(module_spec, matched_module_spec)) return SendErrorResponse (4); - const ModuleSP module(new Module(matched_module_spec)); - - const auto obj_file(module->GetObjectFile()); - const auto file_offset = obj_file->GetFileOffset(); - const auto file_size = obj_file->GetByteSize(); + const auto file_offset = matched_module_spec.GetObjectOffset(); + const auto file_size = matched_module_spec.GetObjectSize(); + const auto uuid_str = matched_module_spec.GetUUID().GetAsString(""); StreamGDBRemote response; - const auto uuid_str = module->GetUUID().GetAsString(); if (uuid_str.empty()) { std::string md5_hash; - if (!FileSystem::CalculateMD5AsString(module_path_spec, file_offset, file_size, md5_hash)) + if (!FileSystem::CalculateMD5AsString(matched_module_spec.GetFileSpec(), file_offset, file_size, md5_hash)) return SendErrorResponse (5); response.PutCString ("md5:"); response.PutCStringAsRawHex8(md5_hash.c_str()); |

