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