Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 1 | //===-- ProcessFreeBSD.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 |
| 11 | #include <errno.h> |
| 12 | |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | #include "lldb/Core/PluginManager.h" |
| 16 | #include "lldb/Core/State.h" |
| 17 | #include "lldb/Host/Host.h" |
| 18 | #include "lldb/Symbol/ObjectFile.h" |
| 19 | #include "lldb/Target/DynamicLoader.h" |
| 20 | #include "lldb/Target/Target.h" |
| 21 | |
| 22 | #include "ProcessFreeBSD.h" |
| 23 | #include "ProcessPOSIXLog.h" |
| 24 | #include "Plugins/Process/Utility/InferiorCallPOSIX.h" |
| 25 | #include "ProcessMonitor.h" |
| 26 | #include "POSIXThread.h" |
| 27 | |
| 28 | using namespace lldb; |
| 29 | using namespace lldb_private; |
| 30 | |
| 31 | //------------------------------------------------------------------------------ |
| 32 | // Static functions. |
| 33 | |
Greg Clayton | 29d1930 | 2012-02-27 18:40:48 +0000 | [diff] [blame] | 34 | lldb::ProcessSP |
| 35 | ProcessFreeBSD::CreateInstance(Target& target, |
| 36 | Listener &listener, |
| 37 | const FileSpec *crash_file_path) |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 38 | { |
Greg Clayton | 29d1930 | 2012-02-27 18:40:48 +0000 | [diff] [blame] | 39 | lldb::ProcessSP process_sp; |
| 40 | if (crash_file_path == NULL) |
| 41 | process_sp.reset(new ProcessFreeBSD (target, listener)); |
| 42 | return process_sp; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void |
| 46 | ProcessFreeBSD::Initialize() |
| 47 | { |
| 48 | static bool g_initialized = false; |
| 49 | |
| 50 | if (!g_initialized) |
| 51 | { |
| 52 | PluginManager::RegisterPlugin(GetPluginNameStatic(), |
| 53 | GetPluginDescriptionStatic(), |
| 54 | CreateInstance); |
| 55 | Log::Callbacks log_callbacks = { |
| 56 | ProcessPOSIXLog::DisableLog, |
| 57 | ProcessPOSIXLog::EnableLog, |
| 58 | ProcessPOSIXLog::ListLogCategories |
| 59 | }; |
| 60 | |
| 61 | Log::RegisterLogChannel (ProcessFreeBSD::GetPluginNameStatic(), log_callbacks); |
| 62 | ProcessPOSIXLog::RegisterPluginName(GetPluginNameStatic()); |
| 63 | g_initialized = true; |
| 64 | } |
| 65 | } |
| 66 | |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 67 | lldb_private::ConstString |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 68 | ProcessFreeBSD::GetPluginNameStatic() |
| 69 | { |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 70 | static ConstString g_name("freebsd"); |
| 71 | return g_name; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | const char * |
| 75 | ProcessFreeBSD::GetPluginDescriptionStatic() |
| 76 | { |
| 77 | return "Process plugin for FreeBSD"; |
| 78 | } |
| 79 | |
| 80 | //------------------------------------------------------------------------------ |
| 81 | // ProcessInterface protocol. |
| 82 | |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 83 | lldb_private::ConstString |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 84 | ProcessFreeBSD::GetPluginName() |
| 85 | { |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 86 | return GetPluginNameStatic(); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | uint32_t |
| 90 | ProcessFreeBSD::GetPluginVersion() |
| 91 | { |
| 92 | return 1; |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | ProcessFreeBSD::GetPluginCommandHelp(const char *command, Stream *strm) |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | Error |
| 101 | ProcessFreeBSD::ExecutePluginCommand(Args &command, Stream *strm) |
| 102 | { |
| 103 | return Error(1, eErrorTypeGeneric); |
| 104 | } |
| 105 | |
| 106 | Log * |
| 107 | ProcessFreeBSD::EnablePluginLogging(Stream *strm, Args &command) |
| 108 | { |
| 109 | return NULL; |
| 110 | } |
| 111 | |
| 112 | //------------------------------------------------------------------------------ |
| 113 | // Constructors and destructors. |
| 114 | |
| 115 | ProcessFreeBSD::ProcessFreeBSD(Target& target, Listener &listener) |
| 116 | : ProcessPOSIX(target, listener) |
| 117 | { |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void |
| 121 | ProcessFreeBSD::Terminate() |
| 122 | { |
| 123 | } |
| 124 | |
Greg Clayton | c3c0b0e | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 125 | bool |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 126 | ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list) |
| 127 | { |
Daniel Malea | 70e7e19 | 2013-08-29 15:54:34 +0000 | [diff] [blame] | 128 | Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD)); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 129 | if (log && log->GetMask().Test(POSIX_LOG_VERBOSE)) |
| 130 | log->Printf ("ProcessFreeBSD::%s() (pid = %i)", __FUNCTION__, GetID()); |
| 131 | |
| 132 | bool has_updated = false; |
| 133 | const tid_t tid = Host::GetCurrentThreadID(); |
| 134 | const lldb::pid_t pid = GetID(); |
| 135 | // Update the process thread list with this new thread. |
| 136 | // FIXME: We should be using tid, not pid. |
| 137 | assert(m_monitor); |
| 138 | ThreadSP thread_sp (old_thread_list.FindThreadByID (pid, false)); |
| 139 | if (!thread_sp) { |
| 140 | ProcessSP me = this->shared_from_this(); |
Ed Maste | 825d208 | 2013-08-29 20:41:39 +0000 | [diff] [blame^] | 141 | thread_sp.reset(new POSIXThread(*me, pid)); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 142 | has_updated = true; |
| 143 | } |
| 144 | |
| 145 | if (log && log->GetMask().Test(POSIX_LOG_VERBOSE)) |
| 146 | log->Printf ("ProcessFreeBSD::%s() updated tid = %i", __FUNCTION__, pid); |
| 147 | |
| 148 | new_thread_list.AddThread(thread_sp); |
| 149 | |
| 150 | return has_updated; // the list has been updated |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 151 | } |