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