blob: a8c33bc701d3ad82e42512a36d803ab8b6a77e9b [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
34Process*
35ProcessLinux::CreateInstance(Target& target, Listener &listener)
36{
37 return new ProcessLinux(target, listener);
38}
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
Johnny Chenb8f74aa2011-10-10 23:11:50 +000097uint32_t
98ProcessLinux::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));
108 if (!thread_sp)
Johnny Chen7e996472012-01-05 19:17:38 +0000109 thread_sp.reset(new POSIXThread(*this, GetID()));
Johnny Chen3bf3a9d2011-10-18 18:09:30 +0000110
Johnny Chen7e996472012-01-05 19:17:38 +0000111 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
Johnny Chen3bf3a9d2011-10-18 18:09:30 +0000112 log->Printf ("ProcessLinux::%s() updated pid = %i", __FUNCTION__, GetID());
113 new_thread_list.AddThread(thread_sp);
114
115 return new_thread_list.GetSize(false);
Johnny Chenb8f74aa2011-10-10 23:11:50 +0000116}
117
Stephen Wilsond1fbbb42011-03-23 02:14:42 +0000118
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000119//------------------------------------------------------------------------------
120// ProcessInterface protocol.
121
122const char *
123ProcessLinux::GetPluginName()
124{
125 return "process.linux";
126}
127
128const char *
129ProcessLinux::GetShortPluginName()
130{
131 return "process.linux";
132}
133
134uint32_t
135ProcessLinux::GetPluginVersion()
136{
137 return 1;
138}
139
140void
141ProcessLinux::GetPluginCommandHelp(const char *command, Stream *strm)
142{
143}
144
145Error
146ProcessLinux::ExecutePluginCommand(Args &command, Stream *strm)
147{
148 return Error(1, eErrorTypeGeneric);
149}
150
151Log *
152ProcessLinux::EnablePluginLogging(Stream *strm, Args &command)
153{
154 return NULL;
155}