diff options
author | Jim Ingham <jingham@apple.com> | 2010-08-09 23:31:02 +0000 |
---|---|---|
committer | Jim Ingham <jingham@apple.com> | 2010-08-09 23:31:02 +0000 |
commit | 5aee162f978eac7ffb6363d25b193e51edfbc0b1 (patch) | |
tree | affe5547d828a14a967f9b5deff564248940554b /lldb/source/Plugins | |
parent | 394a69ed528c403248c6354baeedaf0533b33afc (diff) | |
download | bcm5719-llvm-5aee162f978eac7ffb6363d25b193e51edfbc0b1.tar.gz bcm5719-llvm-5aee162f978eac7ffb6363d25b193e51edfbc0b1.zip |
Change Target & Process so they can really be initialized with an invalid architecture.
Arrange that this then gets properly set on attach, or when a "file" is set.
Add a completer for "process attach -n".
Caveats: there isn't currently a way to handle multiple processes with the same name. That
will have to wait on a way to pass annotations along with the completion strings.
llvm-svn: 110624
Diffstat (limited to 'lldb/source/Plugins')
10 files changed, 106 insertions, 39 deletions
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index fea069e5fc3..de6a51f7e40 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -1016,8 +1016,7 @@ DynamicLoaderMacOSXDYLD::SetNotificationBreakpoint () return m_break_id != LLDB_INVALID_BREAK_ID; } -//----------------------------------------------------------------------Target.h - +//---------------------------------------------------------------------- // Member function that gets called when the process state changes. //---------------------------------------------------------------------- void diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp index f9bf3eb8cb1..3a6860fe6de 100644 --- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp +++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp @@ -199,7 +199,18 @@ ObjectFile * ObjectContainerUniversalMachO::GetObjectFile (const FileSpec *file) { uint32_t arch_idx = 0; - const ArchSpec arch = m_module->GetArchitecture(); + ArchSpec arch; + // If the module hasn't specified an architecture yet, set it to the default + // architecture: + if (!m_module->GetArchitecture().IsValid()) + { + arch = lldb_private::GetDefaultArchitecture (); + if (!arch.IsValid()) + arch = LLDB_ARCH_DEFAULT; + } + else + arch = m_module->GetArchitecture(); + ArchSpec curr_arch; for (arch_idx = 0; arch_idx < m_header.nfat_arch; ++arch_idx) { diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index 032fb75c06d..1568639c811 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -145,6 +145,13 @@ ObjectFileELF::~ObjectFileELF() { } +bool +ObjectFileELF::IsExecutable() const +{ + // FIXME: How is this marked in ELF? + return false; +} + ByteOrder ObjectFileELF::GetByteOrder() const { diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h index 7c941a70e0e..dcee1ad5d09 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h @@ -86,6 +86,9 @@ public: virtual lldb::ByteOrder GetByteOrder() const; + virtual bool + IsExecutable () const; + virtual size_t GetAddressByteSize() const; diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index c0d7eecef23..9d05fac4d2e 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -161,7 +161,8 @@ ObjectFileMachO::ParseHeader () m_data.GetU32(&offset, &m_header.cputype, 6); ArchSpec mach_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype); - if (mach_arch == m_module->GetArchitecture()) + + if (SetModulesArchitecture (mach_arch)) { // Read in all only the load command data DataBufferSP data_sp(m_file.ReadFileContents(m_offset, m_header.sizeofcmds + MachHeaderSizeFromMagic(m_header.magic))); @@ -184,6 +185,11 @@ ObjectFileMachO::GetByteOrder () const return m_data.GetByteOrder (); } +bool +ObjectFileMachO::IsExecutable() const +{ + return m_header.filetype == HeaderFileTypeExecutable; +} size_t ObjectFileMachO::GetAddressByteSize () const diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h index d00ae0d73c0..d3000f45e87 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h @@ -66,6 +66,9 @@ public: virtual lldb::ByteOrder GetByteOrder () const; + + virtual bool + IsExecutable () const; virtual size_t GetAddressByteSize () const; diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp index 817c8380fcd..334c21e60ca 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp @@ -2208,5 +2208,10 @@ ProcessMacOSX::Initialize() } } +uint32_t +ProcessMacOSX::ListProcessesMatchingName (const char *name, lldb_private::StringList &matches, std::vector<lldb::pid_t> &pids) +{ + return Host::ListProcessesMatchingName (name, matches, pids); +} diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h index 6f1f3362679..20628622a8a 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h @@ -18,6 +18,7 @@ // Other libraries and framework includes #include "lldb/Core/ArchSpec.h" #include "lldb/Core/ThreadSafeValue.h" +#include "lldb/Core/StringList.h" #include "lldb/Target/Process.h" #include "lldb/Target/Thread.h" @@ -110,6 +111,9 @@ public: virtual void DidAttach (); + + virtual uint32_t + ListProcessesMatchingName (const char *name, lldb_private::StringList &matches, std::vector<lldb::pid_t> &pids); //------------------------------------------------------------------ // PluginInterface protocol diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 759f20dafb4..1c6b164ca61 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -93,7 +93,8 @@ ProcessGDBRemote::CanDebug(Target &target) ModuleSP exe_module_sp(target.GetExecutableModule()); if (exe_module_sp.get()) return exe_module_sp->GetFileSpec().Exists(); - return false; + // However, if there is no executable module, we return true since we might be preparing to attach. + return true; } //---------------------------------------------------------------------- @@ -106,7 +107,6 @@ ProcessGDBRemote::ProcessGDBRemote(Target& target, Listener &listener) : m_stdio_communication ("gdb-remote.stdio"), m_stdio_mutex (Mutex::eMutexTypeRecursive), m_stdout_data (), - m_arch_spec (), m_byte_order (eByteOrderHost), m_gdb_comm(), m_debugserver_pid (LLDB_INVALID_PROCESS_ID), @@ -124,7 +124,8 @@ ProcessGDBRemote::ProcessGDBRemote(Target& target, Listener &listener) : m_max_memory_size (512), m_libunwind_target_type (UNW_TARGET_UNSPECIFIED), m_libunwind_addr_space (NULL), - m_waiting_for_attach (false) + m_waiting_for_attach (false), + m_local_debugserver (true) { } @@ -563,11 +564,9 @@ ProcessGDBRemote::DidLaunchOrAttach () { m_dispatch_queue_offsets_addr = LLDB_INVALID_ADDRESS; - Module * exe_module = GetTarget().GetExecutableModule ().get(); + Module * exe_module = GetTarget().GetExecutableModule ().get(); assert(exe_module); - m_arch_spec = exe_module->GetArchitecture(); - ObjectFile *exe_objfile = exe_module->GetObjectFile(); assert(exe_objfile); @@ -580,8 +579,9 @@ ProcessGDBRemote::DidLaunchOrAttach () // See if the GDB server supports the qHostInfo information const char *vendor = m_gdb_comm.GetVendorString().AsCString(); const char *os_type = m_gdb_comm.GetOSString().AsCString(); + ArchSpec arch_spec = GetTarget().GetArchitecture(); - if (m_arch_spec.IsValid() && m_arch_spec == ArchSpec ("arm")) + if (arch_spec.IsValid() && arch_spec == ArchSpec ("arm")) { // For ARM we can't trust the arch of the process as it could // have an armv6 object file, but be running on armv7 kernel. @@ -589,7 +589,7 @@ ProcessGDBRemote::DidLaunchOrAttach () } if (!inferior_arch.IsValid()) - inferior_arch = m_arch_spec; + inferior_arch = arch_spec; if (vendor == NULL) vendor = Host::GetVendorString().AsCString("apple"); @@ -622,11 +622,11 @@ ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid) Error error; // Clear out and clean up from any current state Clear(); - // HACK: require arch be set correctly at the target level until we can - // figure out a good way to determine the arch of what we are attaching to - m_arch_spec = m_target.GetArchitecture(); - + ArchSpec arch_spec = GetTarget().GetArchitecture(); + //Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS); + + if (attach_pid != LLDB_INVALID_PROCESS_ID) { SetPrivateState (eStateAttaching); @@ -638,7 +638,7 @@ ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid) NULL, LLDB_INVALID_PROCESS_ID, NULL, false, - m_arch_spec); + arch_spec); if (error.Fail()) { @@ -724,7 +724,6 @@ ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait Clear(); // HACK: require arch be set correctly at the target level until we can // figure out a good way to determine the arch of what we are attaching to - m_arch_spec = m_target.GetArchitecture(); //Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS); if (process_name && process_name[0]) @@ -732,6 +731,7 @@ ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait SetPrivateState (eStateAttaching); char host_port[128]; + ArchSpec arch_spec = GetTarget().GetArchitecture(); snprintf (host_port, sizeof(host_port), "localhost:%u", get_random_port ()); error = StartDebugserverProcess (host_port, NULL, @@ -739,7 +739,7 @@ ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait NULL, LLDB_INVALID_PROCESS_ID, NULL, false, - m_arch_spec); + arch_spec); if (error.Fail()) { const char *error_string = error.AsCString(); @@ -840,9 +840,26 @@ ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait void ProcessGDBRemote::DidAttach () { - DidLaunchOrAttach (); + // If we haven't got an executable module yet, then we should make a dynamic loader, and + // see if it can find the executable module for us. If we do have an executable module, + // make sure it matches the process we've just attached to. + + ModuleSP exe_module_sp = GetTarget().GetExecutableModule(); + if (!m_dynamic_loader_ap.get()) + { + m_dynamic_loader_ap.reset(DynamicLoader::FindPlugin(this, "dynamic-loader.macosx-dyld")); + } + if (m_dynamic_loader_ap.get()) m_dynamic_loader_ap->DidAttach(); + + Module * new_exe_module = GetTarget().GetExecutableModule().get(); + if (new_exe_module == NULL) + { + + } + + DidLaunchOrAttach (); } Error @@ -876,7 +893,7 @@ ProcessGDBRemote::GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site) static const uint8_t g_ppc_breakpoint_opcode[] = { 0x7F, 0xC0, 0x00, 0x08 }; static const uint8_t g_i386_breakpoint_opcode[] = { 0xCC }; - ArchSpec::CPU arch_cpu = m_arch_spec.GetGenericCPUType(); + ArchSpec::CPU arch_cpu = GetTarget().GetArchitecture().GetGenericCPUType(); switch (arch_cpu) { case ArchSpec::eCPU_i386: @@ -1060,13 +1077,16 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) void ProcessGDBRemote::RefreshStateAfterStop () { + // FIXME - add a variable to tell that we're in the middle of attaching if we + // need to know that. // We must be attaching if we don't already have a valid architecture - if (!m_arch_spec.IsValid()) - { - Module *exe_module = GetTarget().GetExecutableModule().get(); - if (exe_module) - m_arch_spec = exe_module->GetArchitecture(); - } +// if (!GetTarget().GetArchitecture().IsValid()) +// { +// Module *exe_module = GetTarget().GetExecutableModule().get(); +// if (exe_module) +// m_arch_spec = exe_module->GetArchitecture(); +// } + // Let all threads recover from stopping and do any clean up based // on the previous thread state (if any). m_thread_list.RefreshStateAfterStop(); @@ -2251,3 +2271,19 @@ ProcessGDBRemote::GetDispatchQueueNameForThread return dispatch_queue_name.c_str(); } +uint32_t +ProcessGDBRemote::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids) +{ + // If we are planning to launch the debugserver remotely, then we need to fire up a debugserver + // process and ask it for the list of processes. But if we are local, we can let the Host do it. + if (m_local_debugserver) + { + return Host::ListProcessesMatchingName (name, matches, pids); + } + else + { + // FIXME: Implement talking to the remote debugserver. + return 0; + } + +} diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index 79872b4db4c..d1fb7bf9155 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -21,6 +21,7 @@ #include "lldb/Core/Error.h" #include "lldb/Core/InputReader.h" #include "lldb/Core/StreamString.h" +#include "lldb/Core/StringList.h" #include "lldb/Core/ThreadSafeValue.h" #include "lldb/Target/Process.h" #include "lldb/Target/Thread.h" @@ -67,6 +68,9 @@ public: virtual bool CanDebug (lldb_private::Target &target); + virtual uint32_t + ListProcessesMatchingName (const char *name, lldb_private::StringList &matches, std::vector<lldb::pid_t> &pids); + //------------------------------------------------------------------ // Creating a new process, or attaching to an existing one //------------------------------------------------------------------ @@ -262,17 +266,6 @@ protected: void AppendSTDOUT (const char* s, size_t len); - lldb_private::ArchSpec& - GetArchSpec() - { - return m_arch_spec; - } - const lldb_private::ArchSpec& - GetArchSpec() const - { - return m_arch_spec; - } - void Clear ( ); @@ -328,7 +321,6 @@ protected: lldb_private::Communication m_stdio_communication; lldb_private::Mutex m_stdio_mutex; // Multithreaded protection for stdio std::string m_stdout_data; - lldb_private::ArchSpec m_arch_spec; lldb::ByteOrder m_byte_order; GDBRemoteCommunication m_gdb_comm; lldb::pid_t m_debugserver_pid; @@ -349,6 +341,7 @@ protected: lldb_private::unw_targettype_t m_libunwind_target_type; lldb_private::unw_addr_space_t m_libunwind_addr_space; // libunwind address space object for this process. bool m_waiting_for_attach; + bool m_local_debugserver; // Is the debugserver process we are talking to local or on another machine. void ResetGDBRemoteState (); |