blob: c53a2eb2e3355b999af373cab6c032616c8e4eb6 [file] [log] [blame]
Stephen Wilsone6f9f662010-07-24 02:19:04 +00001//===-- ProcessLinux.cpp ----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// C Includes
Stephen Wilson26977162011-03-23 02:14:42 +000011#include <errno.h>
12
Stephen Wilsone6f9f662010-07-24 02:19:04 +000013// C++ Includes
14// Other libraries and framework includes
15#include "lldb/Core/PluginManager.h"
Peter Collingbourne70969ef2011-06-03 20:40:44 +000016#include "lldb/Core/State.h"
Stephen Wilsone6f9f662010-07-24 02:19:04 +000017#include "lldb/Host/Host.h"
18#include "lldb/Symbol/ObjectFile.h"
Stephen Wilson2103e252011-01-16 19:45:39 +000019#include "lldb/Target/DynamicLoader.h"
Stephen Wilsone6f9f662010-07-24 02:19:04 +000020#include "lldb/Target/Target.h"
21
22#include "ProcessLinux.h"
Johnny Chen30213ff2012-01-05 19:17:38 +000023#include "ProcessPOSIXLog.h"
Peter Collingbourne70969ef2011-06-03 20:40:44 +000024#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
Stephen Wilsone6f9f662010-07-24 02:19:04 +000025#include "ProcessMonitor.h"
Johnny Chen30213ff2012-01-05 19:17:38 +000026#include "POSIXThread.h"
Stephen Wilsone6f9f662010-07-24 02:19:04 +000027
28using namespace lldb;
29using namespace lldb_private;
30
31//------------------------------------------------------------------------------
32// Static functions.
33
Greg Clayton0c90ef42012-02-21 18:40:07 +000034ProcessSP
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +000035ProcessLinux::CreateInstance(Target &target, Listener &listener, const FileSpec *core_file)
Stephen Wilsone6f9f662010-07-24 02:19:04 +000036{
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +000037 return ProcessSP(new ProcessLinux(target, listener, (FileSpec *)core_file));
Stephen Wilsone6f9f662010-07-24 02:19:04 +000038}
39
40void
41ProcessLinux::Initialize()
42{
43 static bool g_initialized = false;
44
45 if (!g_initialized)
46 {
Johnny Chen6dcbeae2011-10-11 21:21:57 +000047 g_initialized = true;
Stephen Wilsone6f9f662010-07-24 02:19:04 +000048 PluginManager::RegisterPlugin(GetPluginNameStatic(),
49 GetPluginDescriptionStatic(),
50 CreateInstance);
Johnny Chen6dcbeae2011-10-11 21:21:57 +000051
52 Log::Callbacks log_callbacks = {
Johnny Chen30213ff2012-01-05 19:17:38 +000053 ProcessPOSIXLog::DisableLog,
54 ProcessPOSIXLog::EnableLog,
55 ProcessPOSIXLog::ListLogCategories
Johnny Chen6dcbeae2011-10-11 21:21:57 +000056 };
57
58 Log::RegisterLogChannel (ProcessLinux::GetPluginNameStatic(), log_callbacks);
Johnny Chen30213ff2012-01-05 19:17:38 +000059 ProcessPOSIXLog::RegisterPluginName(GetPluginNameStatic());
Stephen Wilsone6f9f662010-07-24 02:19:04 +000060 }
61}
62
Stephen Wilsone6f9f662010-07-24 02:19:04 +000063//------------------------------------------------------------------------------
64// Constructors and destructors.
65
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +000066ProcessLinux::ProcessLinux(Target& target, Listener &listener, FileSpec *core_file)
67 : ProcessPOSIX(target, listener), m_stopping_threads(false), m_core_file(core_file)
Stephen Wilsone6f9f662010-07-24 02:19:04 +000068{
Greg Clayton386ff182011-11-05 01:09:16 +000069#if 0
Stephen Wilsone6f9f662010-07-24 02:19:04 +000070 // FIXME: Putting this code in the ctor and saving the byte order in a
71 // member variable is a hack to avoid const qual issues in GetByteOrder.
72 ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile();
73 m_byte_order = obj_file->GetByteOrder();
Greg Clayton386ff182011-11-05 01:09:16 +000074#else
75 // XXX: Will work only for local processes.
76 m_byte_order = lldb::endian::InlHostByteOrder();
77#endif
Stephen Wilsone6f9f662010-07-24 02:19:04 +000078}
79
Stephen Wilson2103e252011-01-16 19:45:39 +000080void
Johnny Chen30213ff2012-01-05 19:17:38 +000081ProcessLinux::Terminate()
Stephen Wilson2103e252011-01-16 19:45:39 +000082{
Stephen Wilson2103e252011-01-16 19:45:39 +000083}
Greg Clayton57abc5d2013-05-10 21:47:16 +000084lldb_private::ConstString
Johnny Chen30213ff2012-01-05 19:17:38 +000085ProcessLinux::GetPluginNameStatic()
Stephen Wilsone6f9f662010-07-24 02:19:04 +000086{
Greg Clayton57abc5d2013-05-10 21:47:16 +000087 static ConstString g_name("linux");
88 return g_name;
Stephen Wilsone6f9f662010-07-24 02:19:04 +000089}
90
Johnny Chen30213ff2012-01-05 19:17:38 +000091const char *
92ProcessLinux::GetPluginDescriptionStatic()
Stephen Wilsonc4391cb2011-01-15 00:10:37 +000093{
Johnny Chen30213ff2012-01-05 19:17:38 +000094 return "Process plugin for Linux";
Stephen Wilsonc4391cb2011-01-15 00:10:37 +000095}
96
Stephen Wilsone6f9f662010-07-24 02:19:04 +000097
Greg Claytonc3c0b0e2012-04-12 19:04:34 +000098bool
Johnny Chen48d042b2011-10-10 23:11:50 +000099ProcessLinux::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list)
100{
Matt Kopec650648f2013-01-08 16:30:18 +0000101 new_thread_list = old_thread_list;
Greg Claytonc3c0b0e2012-04-12 19:04:34 +0000102 return new_thread_list.GetSize(false) > 0;
Johnny Chen48d042b2011-10-10 23:11:50 +0000103}
104
Stephen Wilson26977162011-03-23 02:14:42 +0000105
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000106//------------------------------------------------------------------------------
107// ProcessInterface protocol.
108
Greg Clayton57abc5d2013-05-10 21:47:16 +0000109lldb_private::ConstString
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000110ProcessLinux::GetPluginName()
111{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000112 return GetPluginNameStatic();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000113}
114
115uint32_t
116ProcessLinux::GetPluginVersion()
117{
118 return 1;
119}
120
121void
122ProcessLinux::GetPluginCommandHelp(const char *command, Stream *strm)
123{
124}
125
126Error
127ProcessLinux::ExecutePluginCommand(Args &command, Stream *strm)
128{
129 return Error(1, eErrorTypeGeneric);
130}
131
132Log *
133ProcessLinux::EnablePluginLogging(Stream *strm, Args &command)
134{
135 return NULL;
136}
Andrew Kaylor93132f52013-05-28 23:04:25 +0000137
138// ProcessPOSIX override
139void
140ProcessLinux::StopAllThreads(lldb::tid_t stop_tid)
141{
142 // If a breakpoint occurs while we're stopping threads, we'll get back
143 // here, but we don't want to do it again. Only the MonitorChildProcess
144 // thread calls this function, so we don't need to protect this flag.
145 if (m_stopping_threads)
146 return;
147 m_stopping_threads = true;
148
149 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
150 if (log)
151 log->Printf ("ProcessLinux::%s() stopping all threads", __FUNCTION__);
152
153 // Walk the thread list and stop the other threads. The thread that caused
154 // the stop should already be marked as stopped before we get here.
155 Mutex::Locker thread_list_lock(m_thread_list.GetMutex());
156
157 uint32_t thread_count = m_thread_list.GetSize(false);
158 for (uint32_t i = 0; i < thread_count; ++i)
159 {
160 POSIXThread *thread = static_cast<POSIXThread*>(
161 m_thread_list.GetThreadAtIndex(i, false).get());
162 assert(thread);
163 lldb::tid_t tid = thread->GetID();
164 if (!StateIsStoppedState(thread->GetState(), false))
165 m_monitor->StopThread(tid);
166 }
167
168 m_stopping_threads = false;
169
170 if (log)
171 log->Printf ("ProcessLinux::%s() finished", __FUNCTION__);
172}
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000173
174bool
175ProcessLinux::CanDebug(Target &target, bool plugin_specified_by_name)
176{
177 if (plugin_specified_by_name)
178 return true;
179
180 /* If core file is specified then let elf-core plugin handle it */
181 if (m_core_file)
182 return false;
183
184 return ProcessPOSIX::CanDebug(target, plugin_specified_by_name);
185}
186