Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 1 | //===-- 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 Wilson | d1fbbb4 | 2011-03-23 02:14:42 +0000 | [diff] [blame] | 11 | #include <errno.h> |
| 12 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | #include "lldb/Core/PluginManager.h" |
Peter Collingbourne | ad11546 | 2011-06-03 20:40:44 +0000 | [diff] [blame] | 16 | #include "lldb/Core/State.h" |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 17 | #include "lldb/Host/Host.h" |
| 18 | #include "lldb/Symbol/ObjectFile.h" |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 19 | #include "lldb/Target/DynamicLoader.h" |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 20 | #include "lldb/Target/Target.h" |
| 21 | |
| 22 | #include "ProcessLinux.h" |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 23 | #include "ProcessPOSIXLog.h" |
Peter Collingbourne | ad11546 | 2011-06-03 20:40:44 +0000 | [diff] [blame] | 24 | #include "Plugins/Process/Utility/InferiorCallPOSIX.h" |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 25 | #include "ProcessMonitor.h" |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 26 | #include "POSIXThread.h" |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace lldb; |
| 29 | using namespace lldb_private; |
| 30 | |
| 31 | //------------------------------------------------------------------------------ |
| 32 | // Static functions. |
| 33 | |
| 34 | Process* |
| 35 | ProcessLinux::CreateInstance(Target& target, Listener &listener) |
| 36 | { |
| 37 | return new ProcessLinux(target, listener); |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | ProcessLinux::Initialize() |
| 42 | { |
| 43 | static bool g_initialized = false; |
| 44 | |
| 45 | if (!g_initialized) |
| 46 | { |
Johnny Chen | ac51e9f | 2011-10-11 21:21:57 +0000 | [diff] [blame] | 47 | g_initialized = true; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 48 | PluginManager::RegisterPlugin(GetPluginNameStatic(), |
| 49 | GetPluginDescriptionStatic(), |
| 50 | CreateInstance); |
Johnny Chen | ac51e9f | 2011-10-11 21:21:57 +0000 | [diff] [blame] | 51 | |
| 52 | Log::Callbacks log_callbacks = { |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 53 | ProcessPOSIXLog::DisableLog, |
| 54 | ProcessPOSIXLog::EnableLog, |
| 55 | ProcessPOSIXLog::ListLogCategories |
Johnny Chen | ac51e9f | 2011-10-11 21:21:57 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | Log::RegisterLogChannel (ProcessLinux::GetPluginNameStatic(), log_callbacks); |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 59 | ProcessPOSIXLog::RegisterPluginName(GetPluginNameStatic()); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 63 | //------------------------------------------------------------------------------ |
| 64 | // Constructors and destructors. |
| 65 | |
| 66 | ProcessLinux::ProcessLinux(Target& target, Listener &listener) |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 67 | : ProcessPOSIX(target, listener) |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 68 | { |
Greg Clayton | ce65d2f | 2011-11-05 01:09:16 +0000 | [diff] [blame] | 69 | #if 0 |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 70 | // 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 Clayton | ce65d2f | 2011-11-05 01:09:16 +0000 | [diff] [blame] | 74 | #else |
| 75 | // XXX: Will work only for local processes. |
| 76 | m_byte_order = lldb::endian::InlHostByteOrder(); |
| 77 | #endif |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 80 | void |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 81 | ProcessLinux::Terminate() |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 82 | { |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 83 | } |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 84 | const char * |
| 85 | ProcessLinux::GetPluginNameStatic() |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 86 | { |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 87 | return "linux"; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 90 | const char * |
| 91 | ProcessLinux::GetPluginDescriptionStatic() |
Stephen Wilson | 0131642 | 2011-01-15 00:10:37 +0000 | [diff] [blame] | 92 | { |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 93 | return "Process plugin for Linux"; |
Stephen Wilson | 0131642 | 2011-01-15 00:10:37 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 96 | |
Johnny Chen | b8f74aa | 2011-10-10 23:11:50 +0000 | [diff] [blame] | 97 | uint32_t |
| 98 | ProcessLinux::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list) |
| 99 | { |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 100 | LogSP log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD)); |
| 101 | if (log && log->GetMask().Test(POSIX_LOG_VERBOSE)) |
Johnny Chen | 3bf3a9d | 2011-10-18 18:09:30 +0000 | [diff] [blame] | 102 | log->Printf ("ProcessLinux::%s() (pid = %i)", __FUNCTION__, GetID()); |
Johnny Chen | ac51e9f | 2011-10-11 21:21:57 +0000 | [diff] [blame] | 103 | |
Johnny Chen | 3bf3a9d | 2011-10-18 18:09:30 +0000 | [diff] [blame] | 104 | // 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 Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 109 | thread_sp.reset(new POSIXThread(*this, GetID())); |
Johnny Chen | 3bf3a9d | 2011-10-18 18:09:30 +0000 | [diff] [blame] | 110 | |
Johnny Chen | 7e99647 | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 111 | if (log && log->GetMask().Test(POSIX_LOG_VERBOSE)) |
Johnny Chen | 3bf3a9d | 2011-10-18 18:09:30 +0000 | [diff] [blame] | 112 | 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 Chen | b8f74aa | 2011-10-10 23:11:50 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Stephen Wilson | d1fbbb4 | 2011-03-23 02:14:42 +0000 | [diff] [blame] | 118 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 119 | //------------------------------------------------------------------------------ |
| 120 | // ProcessInterface protocol. |
| 121 | |
| 122 | const char * |
| 123 | ProcessLinux::GetPluginName() |
| 124 | { |
| 125 | return "process.linux"; |
| 126 | } |
| 127 | |
| 128 | const char * |
| 129 | ProcessLinux::GetShortPluginName() |
| 130 | { |
| 131 | return "process.linux"; |
| 132 | } |
| 133 | |
| 134 | uint32_t |
| 135 | ProcessLinux::GetPluginVersion() |
| 136 | { |
| 137 | return 1; |
| 138 | } |
| 139 | |
| 140 | void |
| 141 | ProcessLinux::GetPluginCommandHelp(const char *command, Stream *strm) |
| 142 | { |
| 143 | } |
| 144 | |
| 145 | Error |
| 146 | ProcessLinux::ExecutePluginCommand(Args &command, Stream *strm) |
| 147 | { |
| 148 | return Error(1, eErrorTypeGeneric); |
| 149 | } |
| 150 | |
| 151 | Log * |
| 152 | ProcessLinux::EnablePluginLogging(Stream *strm, Args &command) |
| 153 | { |
| 154 | return NULL; |
| 155 | } |