blob: 3327914d8bc15aacbb58d1a144fddf57a8bd8ddd [file] [log] [blame]
Stephen Wilsonf6f40332010-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 Wilsond1fbbb42011-03-23 02:14:42 +000011#include <errno.h>
12
Stephen Wilsonf6f40332010-07-24 02:19:04 +000013// C++ Includes
14// Other libraries and framework includes
15#include "lldb/Core/PluginManager.h"
Peter Collingbournead115462011-06-03 20:40:44 +000016#include "lldb/Core/State.h"
Stephen Wilsonf6f40332010-07-24 02:19:04 +000017#include "lldb/Host/Host.h"
18#include "lldb/Symbol/ObjectFile.h"
Stephen Wilson92241ef2011-01-16 19:45:39 +000019#include "lldb/Target/DynamicLoader.h"
Stephen Wilsonf6f40332010-07-24 02:19:04 +000020#include "lldb/Target/Target.h"
21
22#include "ProcessLinux.h"
Johnny Chen7e996472012-01-05 19:17:38 +000023#include "ProcessPOSIXLog.h"
Peter Collingbournead115462011-06-03 20:40:44 +000024#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
Stephen Wilsonf6f40332010-07-24 02:19:04 +000025#include "ProcessMonitor.h"
Johnny Chen7e996472012-01-05 19:17:38 +000026#include "POSIXThread.h"
Stephen Wilsonf6f40332010-07-24 02:19:04 +000027
28using namespace lldb;
29using namespace lldb_private;
30
31//------------------------------------------------------------------------------
32// Static functions.
33
Greg Claytone5eaa302012-02-21 18:40:07 +000034ProcessSP
35ProcessLinux::CreateInstance(Target &target, Listener &listener, const FileSpec *)
Stephen Wilsonf6f40332010-07-24 02:19:04 +000036{
Greg Claytone5eaa302012-02-21 18:40:07 +000037 return ProcessSP(new ProcessLinux(target, listener));
Stephen Wilsonf6f40332010-07-24 02:19:04 +000038}
39
40void
41ProcessLinux::Initialize()
42{
43 static bool g_initialized = false;
44
45 if (!g_initialized)
46 {
Johnny Chenac51e9f2011-10-11 21:21:57 +000047 g_initialized = true;
Stephen Wilsonf6f40332010-07-24 02:19:04 +000048 PluginManager::RegisterPlugin(GetPluginNameStatic(),
49 GetPluginDescriptionStatic(),
50 CreateInstance);
Johnny Chenac51e9f2011-10-11 21:21:57 +000051
52 Log::Callbacks log_callbacks = {
Johnny Chen7e996472012-01-05 19:17:38 +000053 ProcessPOSIXLog::DisableLog,
54 ProcessPOSIXLog::EnableLog,
55 ProcessPOSIXLog::ListLogCategories
Johnny Chenac51e9f2011-10-11 21:21:57 +000056 };
57
58 Log::RegisterLogChannel (ProcessLinux::GetPluginNameStatic(), log_callbacks);
Johnny Chen7e996472012-01-05 19:17:38 +000059 ProcessPOSIXLog::RegisterPluginName(GetPluginNameStatic());
Stephen Wilsonf6f40332010-07-24 02:19:04 +000060 }
61}
62
Stephen Wilsonf6f40332010-07-24 02:19:04 +000063//------------------------------------------------------------------------------
64// Constructors and destructors.
65
66ProcessLinux::ProcessLinux(Target& target, Listener &listener)
Johnny Chen7e996472012-01-05 19:17:38 +000067 : ProcessPOSIX(target, listener)
Stephen Wilsonf6f40332010-07-24 02:19:04 +000068{
Greg Claytonce65d2f2011-11-05 01:09:16 +000069#if 0
Stephen Wilsonf6f40332010-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 Claytonce65d2f2011-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 Wilsonf6f40332010-07-24 02:19:04 +000078}
79
Stephen Wilson92241ef2011-01-16 19:45:39 +000080void
Johnny Chen7e996472012-01-05 19:17:38 +000081ProcessLinux::Terminate()
Stephen Wilson92241ef2011-01-16 19:45:39 +000082{
Stephen Wilson92241ef2011-01-16 19:45:39 +000083}
Johnny Chen7e996472012-01-05 19:17:38 +000084const char *
85ProcessLinux::GetPluginNameStatic()
Stephen Wilsonf6f40332010-07-24 02:19:04 +000086{
Johnny Chen7e996472012-01-05 19:17:38 +000087 return "linux";
Stephen Wilsonf6f40332010-07-24 02:19:04 +000088}
89
Johnny Chen7e996472012-01-05 19:17:38 +000090const char *
91ProcessLinux::GetPluginDescriptionStatic()
Stephen Wilson01316422011-01-15 00:10:37 +000092{
Johnny Chen7e996472012-01-05 19:17:38 +000093 return "Process plugin for Linux";
Stephen Wilson01316422011-01-15 00:10:37 +000094}
95
Stephen Wilsonf6f40332010-07-24 02:19:04 +000096
Greg Claytonc8dd5702012-04-12 19:04:34 +000097bool
Johnny Chenb8f74aa2011-10-10 23:11:50 +000098ProcessLinux::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list)
99{
Johnny Chen7e996472012-01-05 19:17:38 +0000100 LogSP log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
101 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
Johnny Chen3bf3a9d2011-10-18 18:09:30 +0000102 log->Printf ("ProcessLinux::%s() (pid = %i)", __FUNCTION__, GetID());
Johnny Chenac51e9f2011-10-11 21:21:57 +0000103
Johnny Chen3bf3a9d2011-10-18 18:09:30 +0000104 // Update the process thread list with this new thread.
105 // FIXME: We should be using tid, not pid.
106 assert(m_monitor);
107 ThreadSP thread_sp (old_thread_list.FindThreadByID (GetID(), false));
Greg Claytone5eaa302012-02-21 18:40:07 +0000108 if (!thread_sp) {
109 ProcessSP me = this->shared_from_this();
110 thread_sp.reset(new POSIXThread(me, GetID()));
111 }
Johnny Chen3bf3a9d2011-10-18 18:09:30 +0000112
Johnny Chen7e996472012-01-05 19:17:38 +0000113 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
Johnny Chen3bf3a9d2011-10-18 18:09:30 +0000114 log->Printf ("ProcessLinux::%s() updated pid = %i", __FUNCTION__, GetID());
115 new_thread_list.AddThread(thread_sp);
116
Greg Claytonc8dd5702012-04-12 19:04:34 +0000117 return new_thread_list.GetSize(false) > 0;
Johnny Chenb8f74aa2011-10-10 23:11:50 +0000118}
119
Stephen Wilsond1fbbb42011-03-23 02:14:42 +0000120
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000121//------------------------------------------------------------------------------
122// ProcessInterface protocol.
123
124const char *
125ProcessLinux::GetPluginName()
126{
127 return "process.linux";
128}
129
130const char *
131ProcessLinux::GetShortPluginName()
132{
133 return "process.linux";
134}
135
136uint32_t
137ProcessLinux::GetPluginVersion()
138{
139 return 1;
140}
141
142void
143ProcessLinux::GetPluginCommandHelp(const char *command, Stream *strm)
144{
145}
146
147Error
148ProcessLinux::ExecutePluginCommand(Args &command, Stream *strm)
149{
150 return Error(1, eErrorTypeGeneric);
151}
152
153Log *
154ProcessLinux::EnablePluginLogging(Stream *strm, Args &command)
155{
156 return NULL;
157}