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 | ac51e9f | 2011-10-11 21:21:57 +0000 | [diff] [blame^] | 23 | #include "ProcessLinuxLog.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" |
| 26 | #include "LinuxThread.h" |
| 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 = { |
| 53 | ProcessLinuxLog::DisableLog, |
| 54 | ProcessLinuxLog::EnableLog, |
| 55 | ProcessLinuxLog::ListLogCategories |
| 56 | }; |
| 57 | |
| 58 | Log::RegisterLogChannel (ProcessLinux::GetPluginNameStatic(), log_callbacks); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | ProcessLinux::Terminate() |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | const char * |
| 68 | ProcessLinux::GetPluginNameStatic() |
| 69 | { |
| 70 | return "plugin.process.linux"; |
| 71 | } |
| 72 | |
| 73 | const char * |
| 74 | ProcessLinux::GetPluginDescriptionStatic() |
| 75 | { |
| 76 | return "Process plugin for Linux"; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | //------------------------------------------------------------------------------ |
| 81 | // Constructors and destructors. |
| 82 | |
| 83 | ProcessLinux::ProcessLinux(Target& target, Listener &listener) |
| 84 | : Process(target, listener), |
| 85 | m_monitor(NULL), |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 86 | m_module(NULL), |
| 87 | m_in_limbo(false), |
| 88 | m_exit_now(false) |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 89 | { |
| 90 | // FIXME: Putting this code in the ctor and saving the byte order in a |
| 91 | // member variable is a hack to avoid const qual issues in GetByteOrder. |
| 92 | ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile(); |
| 93 | m_byte_order = obj_file->GetByteOrder(); |
| 94 | } |
| 95 | |
| 96 | ProcessLinux::~ProcessLinux() |
| 97 | { |
| 98 | delete m_monitor; |
| 99 | } |
| 100 | |
| 101 | //------------------------------------------------------------------------------ |
| 102 | // Process protocol. |
| 103 | |
| 104 | bool |
Peter Collingbourne | 4755698 | 2011-07-22 19:12:53 +0000 | [diff] [blame] | 105 | ProcessLinux::CanDebug(Target &target, bool plugin_specified_by_name) |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 106 | { |
| 107 | // For now we are just making sure the file exists for a given module |
| 108 | ModuleSP exe_module_sp(target.GetExecutableModule()); |
| 109 | if (exe_module_sp.get()) |
| 110 | return exe_module_sp->GetFileSpec().Exists(); |
| 111 | return false; |
| 112 | } |
| 113 | |
| 114 | Error |
| 115 | ProcessLinux::DoAttachToProcessWithID(lldb::pid_t pid) |
| 116 | { |
Johnny Chen | 9bab8d4 | 2011-06-14 19:19:50 +0000 | [diff] [blame] | 117 | Error error; |
| 118 | assert(m_monitor == NULL); |
| 119 | |
Johnny Chen | ac51e9f | 2011-10-11 21:21:57 +0000 | [diff] [blame^] | 120 | LogSP log (ProcessLinuxLog::GetLogIfAllCategoriesSet (LINUX_LOG_PROCESS)); |
| 121 | if (log && log->GetMask().Test(LINUX_LOG_VERBOSE)) |
| 122 | log->Printf ("ProcessLinux::%s (pid = %i)", __FUNCTION__, GetID()); |
| 123 | |
Johnny Chen | 9bab8d4 | 2011-06-14 19:19:50 +0000 | [diff] [blame] | 124 | m_monitor = new ProcessMonitor(this, pid, error); |
| 125 | |
| 126 | if (!error.Success()) |
| 127 | return error; |
| 128 | |
| 129 | SetID(pid); |
| 130 | return error; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | Error |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 134 | ProcessLinux::WillLaunch(Module* module) |
| 135 | { |
| 136 | Error error; |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 137 | return error; |
| 138 | } |
| 139 | |
| 140 | Error |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 141 | ProcessLinux::DoLaunch(Module *module, |
| 142 | char const *argv[], |
| 143 | char const *envp[], |
Stephen Wilson | 3a80431 | 2011-01-04 21:41:31 +0000 | [diff] [blame] | 144 | uint32_t launch_flags, |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 145 | const char *stdin_path, |
| 146 | const char *stdout_path, |
Greg Clayton | de915be | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 147 | const char *stderr_path, |
| 148 | const char *working_directory) |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 149 | { |
| 150 | Error error; |
| 151 | assert(m_monitor == NULL); |
| 152 | |
| 153 | SetPrivateState(eStateLaunching); |
| 154 | m_monitor = new ProcessMonitor(this, module, |
| 155 | argv, envp, |
| 156 | stdin_path, stdout_path, stderr_path, |
| 157 | error); |
| 158 | |
| 159 | m_module = module; |
| 160 | |
| 161 | if (!error.Success()) |
| 162 | return error; |
| 163 | |
Stephen Wilson | 1f004c6 | 2011-01-15 00:13:27 +0000 | [diff] [blame] | 164 | SetID(m_monitor->GetPID()); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 165 | return error; |
| 166 | } |
| 167 | |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 168 | void |
| 169 | ProcessLinux::DidLaunch() |
| 170 | { |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 173 | Error |
| 174 | ProcessLinux::DoResume() |
| 175 | { |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 176 | StateType state = GetPrivateState(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 177 | |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 178 | assert(state == eStateStopped || state == eStateCrashed); |
| 179 | |
| 180 | // We are about to resume a thread that will cause the process to exit so |
| 181 | // set our exit status now. Do not change our state if the inferior |
| 182 | // crashed. |
| 183 | if (state == eStateStopped) |
| 184 | { |
| 185 | if (m_in_limbo) |
| 186 | SetExitStatus(m_exit_status, NULL); |
| 187 | else |
| 188 | SetPrivateState(eStateRunning); |
| 189 | } |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 190 | |
| 191 | bool did_resume = false; |
| 192 | uint32_t thread_count = m_thread_list.GetSize(false); |
| 193 | for (uint32_t i = 0; i < thread_count; ++i) |
| 194 | { |
| 195 | LinuxThread *thread = static_cast<LinuxThread*>( |
| 196 | m_thread_list.GetThreadAtIndex(i, false).get()); |
| 197 | did_resume = thread->Resume() || did_resume; |
| 198 | } |
| 199 | assert(did_resume && "Process resume failed!"); |
| 200 | |
| 201 | return Error(); |
| 202 | } |
| 203 | |
Stephen Wilson | 0131642 | 2011-01-15 00:10:37 +0000 | [diff] [blame] | 204 | addr_t |
| 205 | ProcessLinux::GetImageInfoAddress() |
| 206 | { |
| 207 | Target *target = &GetTarget(); |
| 208 | ObjectFile *obj_file = target->GetExecutableModule()->GetObjectFile(); |
| 209 | Address addr = obj_file->GetImageInfoAddress(); |
| 210 | |
| 211 | if (addr.IsValid()) |
| 212 | return addr.GetLoadAddress(target); |
| 213 | else |
| 214 | return LLDB_INVALID_ADDRESS; |
| 215 | } |
| 216 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 217 | Error |
Stephen Wilson | 3a80431 | 2011-01-04 21:41:31 +0000 | [diff] [blame] | 218 | ProcessLinux::DoHalt(bool &caused_stop) |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 219 | { |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 220 | Error error; |
| 221 | |
| 222 | if (IsStopped()) |
| 223 | { |
| 224 | caused_stop = false; |
| 225 | } |
| 226 | else if (kill(GetID(), SIGSTOP)) |
| 227 | { |
| 228 | caused_stop = false; |
| 229 | error.SetErrorToErrno(); |
| 230 | } |
| 231 | else |
| 232 | { |
| 233 | caused_stop = true; |
| 234 | } |
| 235 | |
| 236 | return error; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | Error |
| 240 | ProcessLinux::DoDetach() |
| 241 | { |
| 242 | return Error(1, eErrorTypeGeneric); |
| 243 | } |
| 244 | |
| 245 | Error |
| 246 | ProcessLinux::DoSignal(int signal) |
| 247 | { |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 248 | Error error; |
| 249 | |
| 250 | if (kill(GetID(), signal)) |
| 251 | error.SetErrorToErrno(); |
| 252 | |
| 253 | return error; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | Error |
| 257 | ProcessLinux::DoDestroy() |
| 258 | { |
| 259 | Error error; |
| 260 | |
| 261 | if (!HasExited()) |
| 262 | { |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 263 | // Drive the exit event to completion (do not keep the inferior in |
| 264 | // limbo). |
| 265 | m_exit_now = true; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 266 | |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 267 | if (kill(m_monitor->GetPID(), SIGKILL) && error.Success()) |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 268 | { |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 269 | error.SetErrorToErrno(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 270 | return error; |
| 271 | } |
| 272 | |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 273 | SetPrivateState(eStateExited); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 276 | return error; |
| 277 | } |
| 278 | |
| 279 | void |
| 280 | ProcessLinux::SendMessage(const ProcessMessage &message) |
| 281 | { |
| 282 | Mutex::Locker lock(m_message_mutex); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 283 | |
| 284 | switch (message.GetKind()) |
| 285 | { |
| 286 | default: |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 287 | assert(false && "Unexpected process message!"); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 288 | break; |
| 289 | |
Stephen Wilson | 07fc7a9 | 2011-01-19 01:29:39 +0000 | [diff] [blame] | 290 | case ProcessMessage::eInvalidMessage: |
| 291 | return; |
| 292 | |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 293 | case ProcessMessage::eLimboMessage: |
| 294 | m_in_limbo = true; |
| 295 | m_exit_status = message.GetExitStatus(); |
| 296 | if (m_exit_now) |
| 297 | { |
| 298 | SetPrivateState(eStateExited); |
| 299 | m_monitor->Detach(); |
| 300 | } |
| 301 | else |
| 302 | SetPrivateState(eStateStopped); |
| 303 | break; |
| 304 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 305 | case ProcessMessage::eExitMessage: |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 306 | m_exit_status = message.GetExitStatus(); |
| 307 | SetExitStatus(m_exit_status, NULL); |
| 308 | break; |
| 309 | |
| 310 | case ProcessMessage::eTraceMessage: |
| 311 | case ProcessMessage::eBreakpointMessage: |
| 312 | SetPrivateState(eStateStopped); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 313 | break; |
| 314 | |
| 315 | case ProcessMessage::eSignalMessage: |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 316 | case ProcessMessage::eSignalDeliveredMessage: |
| 317 | SetPrivateState(eStateStopped); |
| 318 | break; |
| 319 | |
| 320 | case ProcessMessage::eCrashMessage: |
| 321 | SetPrivateState(eStateCrashed); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 322 | break; |
| 323 | } |
Stephen Wilson | 07fc7a9 | 2011-01-19 01:29:39 +0000 | [diff] [blame] | 324 | |
| 325 | m_message_queue.push(message); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | void |
| 329 | ProcessLinux::RefreshStateAfterStop() |
| 330 | { |
| 331 | Mutex::Locker lock(m_message_mutex); |
| 332 | if (m_message_queue.empty()) |
| 333 | return; |
| 334 | |
| 335 | ProcessMessage &message = m_message_queue.front(); |
| 336 | |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 337 | // Resolve the thread this message corresponds to and pass it along. |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 338 | lldb::tid_t tid = message.GetTID(); |
| 339 | LinuxThread *thread = static_cast<LinuxThread*>( |
| 340 | GetThreadList().FindThreadByID(tid, false).get()); |
| 341 | |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 342 | thread->Notify(message); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 343 | |
| 344 | m_message_queue.pop(); |
| 345 | } |
| 346 | |
| 347 | bool |
| 348 | ProcessLinux::IsAlive() |
| 349 | { |
| 350 | StateType state = GetPrivateState(); |
| 351 | return state != eStateExited && state != eStateInvalid; |
| 352 | } |
| 353 | |
| 354 | size_t |
| 355 | ProcessLinux::DoReadMemory(addr_t vm_addr, |
| 356 | void *buf, size_t size, Error &error) |
| 357 | { |
| 358 | return m_monitor->ReadMemory(vm_addr, buf, size, error); |
| 359 | } |
| 360 | |
| 361 | size_t |
| 362 | ProcessLinux::DoWriteMemory(addr_t vm_addr, const void *buf, size_t size, |
| 363 | Error &error) |
| 364 | { |
| 365 | return m_monitor->WriteMemory(vm_addr, buf, size, error); |
| 366 | } |
| 367 | |
| 368 | addr_t |
| 369 | ProcessLinux::DoAllocateMemory(size_t size, uint32_t permissions, |
| 370 | Error &error) |
| 371 | { |
Peter Collingbourne | ad11546 | 2011-06-03 20:40:44 +0000 | [diff] [blame] | 372 | addr_t allocated_addr = LLDB_INVALID_ADDRESS; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 373 | |
Peter Collingbourne | ad11546 | 2011-06-03 20:40:44 +0000 | [diff] [blame] | 374 | unsigned prot = 0; |
| 375 | if (permissions & lldb::ePermissionsReadable) |
| 376 | prot |= eMmapProtRead; |
| 377 | if (permissions & lldb::ePermissionsWritable) |
| 378 | prot |= eMmapProtWrite; |
| 379 | if (permissions & lldb::ePermissionsExecutable) |
| 380 | prot |= eMmapProtExec; |
| 381 | |
| 382 | if (InferiorCallMmap(this, allocated_addr, 0, size, prot, |
| 383 | eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) { |
| 384 | m_addr_to_mmap_size[allocated_addr] = size; |
| 385 | error.Clear(); |
| 386 | } else { |
| 387 | allocated_addr = LLDB_INVALID_ADDRESS; |
| 388 | error.SetErrorStringWithFormat("unable to allocate %zu bytes of memory with permissions %s", size, GetPermissionsAsCString (permissions)); |
| 389 | } |
| 390 | |
| 391 | return allocated_addr; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | Error |
Peter Collingbourne | ad11546 | 2011-06-03 20:40:44 +0000 | [diff] [blame] | 395 | ProcessLinux::DoDeallocateMemory(lldb::addr_t addr) |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 396 | { |
Peter Collingbourne | ad11546 | 2011-06-03 20:40:44 +0000 | [diff] [blame] | 397 | Error error; |
| 398 | MMapMap::iterator pos = m_addr_to_mmap_size.find(addr); |
| 399 | if (pos != m_addr_to_mmap_size.end() && |
| 400 | InferiorCallMunmap(this, addr, pos->second)) |
| 401 | m_addr_to_mmap_size.erase (pos); |
| 402 | else |
| 403 | error.SetErrorStringWithFormat("unable to deallocate memory at 0x%llx", addr); |
| 404 | |
| 405 | return error; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | size_t |
| 409 | ProcessLinux::GetSoftwareBreakpointTrapOpcode(BreakpointSite* bp_site) |
| 410 | { |
| 411 | static const uint8_t g_i386_opcode[] = { 0xCC }; |
| 412 | |
| 413 | ArchSpec arch = GetTarget().GetArchitecture(); |
| 414 | const uint8_t *opcode = NULL; |
| 415 | size_t opcode_size = 0; |
| 416 | |
Stephen Wilson | a1f0b72 | 2011-02-24 19:17:09 +0000 | [diff] [blame] | 417 | switch (arch.GetCore()) |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 418 | { |
| 419 | default: |
| 420 | assert(false && "CPU type not supported!"); |
| 421 | break; |
| 422 | |
Stephen Wilson | a1f0b72 | 2011-02-24 19:17:09 +0000 | [diff] [blame] | 423 | case ArchSpec::eCore_x86_32_i386: |
| 424 | case ArchSpec::eCore_x86_64_x86_64: |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 425 | opcode = g_i386_opcode; |
| 426 | opcode_size = sizeof(g_i386_opcode); |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | bp_site->SetTrapOpcode(opcode, opcode_size); |
| 431 | return opcode_size; |
| 432 | } |
| 433 | |
| 434 | Error |
| 435 | ProcessLinux::EnableBreakpoint(BreakpointSite *bp_site) |
| 436 | { |
| 437 | return EnableSoftwareBreakpoint(bp_site); |
| 438 | } |
| 439 | |
| 440 | Error |
| 441 | ProcessLinux::DisableBreakpoint(BreakpointSite *bp_site) |
| 442 | { |
| 443 | return DisableSoftwareBreakpoint(bp_site); |
| 444 | } |
| 445 | |
| 446 | uint32_t |
| 447 | ProcessLinux::UpdateThreadListIfNeeded() |
| 448 | { |
| 449 | // Do not allow recursive updates. |
| 450 | return m_thread_list.GetSize(false); |
| 451 | } |
| 452 | |
Johnny Chen | b8f74aa | 2011-10-10 23:11:50 +0000 | [diff] [blame] | 453 | uint32_t |
| 454 | ProcessLinux::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list) |
| 455 | { |
| 456 | // FIXME: Should this be implemented? |
Johnny Chen | ac51e9f | 2011-10-11 21:21:57 +0000 | [diff] [blame^] | 457 | LogSP log (ProcessLinuxLog::GetLogIfAllCategoriesSet (LINUX_LOG_THREAD)); |
| 458 | if (log && log->GetMask().Test(LINUX_LOG_VERBOSE)) |
| 459 | log->Printf ("ProcessLinux::%s (pid = %i)", __FUNCTION__, GetID()); |
| 460 | |
Johnny Chen | b8f74aa | 2011-10-10 23:11:50 +0000 | [diff] [blame] | 461 | return 0; |
| 462 | } |
| 463 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 464 | ByteOrder |
| 465 | ProcessLinux::GetByteOrder() const |
| 466 | { |
| 467 | // FIXME: We should be able to extract this value directly. See comment in |
| 468 | // ProcessLinux(). |
| 469 | return m_byte_order; |
| 470 | } |
| 471 | |
Stephen Wilson | d1fbbb4 | 2011-03-23 02:14:42 +0000 | [diff] [blame] | 472 | size_t |
| 473 | ProcessLinux::PutSTDIN(const char *buf, size_t len, Error &error) |
| 474 | { |
| 475 | ssize_t status; |
| 476 | if ((status = write(m_monitor->GetTerminalFD(), buf, len)) < 0) |
| 477 | { |
| 478 | error.SetErrorToErrno(); |
| 479 | return 0; |
| 480 | } |
| 481 | return status; |
| 482 | } |
| 483 | |
| 484 | size_t |
| 485 | ProcessLinux::GetSTDOUT(char *buf, size_t len, Error &error) |
| 486 | { |
| 487 | ssize_t bytes_read; |
| 488 | |
| 489 | // The terminal file descriptor is always in non-block mode. |
| 490 | if ((bytes_read = read(m_monitor->GetTerminalFD(), buf, len)) < 0) |
| 491 | { |
| 492 | if (errno != EAGAIN) |
| 493 | error.SetErrorToErrno(); |
| 494 | return 0; |
| 495 | } |
| 496 | return bytes_read; |
| 497 | } |
| 498 | |
| 499 | size_t |
| 500 | ProcessLinux::GetSTDERR(char *buf, size_t len, Error &error) |
| 501 | { |
| 502 | return GetSTDOUT(buf, len, error); |
| 503 | } |
| 504 | |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 505 | UnixSignals & |
| 506 | ProcessLinux::GetUnixSignals() |
| 507 | { |
| 508 | return m_linux_signals; |
| 509 | } |
Stephen Wilson | d1fbbb4 | 2011-03-23 02:14:42 +0000 | [diff] [blame] | 510 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 511 | //------------------------------------------------------------------------------ |
| 512 | // ProcessInterface protocol. |
| 513 | |
| 514 | const char * |
| 515 | ProcessLinux::GetPluginName() |
| 516 | { |
| 517 | return "process.linux"; |
| 518 | } |
| 519 | |
| 520 | const char * |
| 521 | ProcessLinux::GetShortPluginName() |
| 522 | { |
| 523 | return "process.linux"; |
| 524 | } |
| 525 | |
| 526 | uint32_t |
| 527 | ProcessLinux::GetPluginVersion() |
| 528 | { |
| 529 | return 1; |
| 530 | } |
| 531 | |
| 532 | void |
| 533 | ProcessLinux::GetPluginCommandHelp(const char *command, Stream *strm) |
| 534 | { |
| 535 | } |
| 536 | |
| 537 | Error |
| 538 | ProcessLinux::ExecutePluginCommand(Args &command, Stream *strm) |
| 539 | { |
| 540 | return Error(1, eErrorTypeGeneric); |
| 541 | } |
| 542 | |
| 543 | Log * |
| 544 | ProcessLinux::EnablePluginLogging(Stream *strm, Args &command) |
| 545 | { |
| 546 | return NULL; |
| 547 | } |
| 548 | |
| 549 | //------------------------------------------------------------------------------ |
| 550 | // Utility functions. |
| 551 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 552 | bool |
| 553 | ProcessLinux::HasExited() |
| 554 | { |
| 555 | switch (GetPrivateState()) |
| 556 | { |
| 557 | default: |
| 558 | break; |
| 559 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 560 | case eStateDetached: |
| 561 | case eStateExited: |
| 562 | return true; |
| 563 | } |
| 564 | |
| 565 | return false; |
| 566 | } |
Stephen Wilson | 67d9f7e | 2011-03-30 15:55:52 +0000 | [diff] [blame] | 567 | |
| 568 | bool |
| 569 | ProcessLinux::IsStopped() |
| 570 | { |
| 571 | switch (GetPrivateState()) |
| 572 | { |
| 573 | default: |
| 574 | break; |
| 575 | |
| 576 | case eStateStopped: |
| 577 | case eStateCrashed: |
| 578 | case eStateSuspended: |
| 579 | return true; |
| 580 | } |
| 581 | |
| 582 | return false; |
| 583 | } |