blob: 46f3a4721ba1b6ad950962dd93d972a40e0953dc [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Process.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#include "lldb/Target/Process.h"
11
12#include "lldb/lldb-private-log.h"
13
14#include "lldb/Breakpoint/StoppointCallbackContext.h"
15#include "lldb/Breakpoint/BreakpointLocation.h"
16#include "lldb/Core/Event.h"
Caroline Ticeef5c6d02010-11-16 05:07:41 +000017#include "lldb/Core/ConnectionFileDescriptor.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Core/Debugger.h"
Caroline Ticeef5c6d02010-11-16 05:07:41 +000019#include "lldb/Core/InputReader.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/Log.h"
21#include "lldb/Core/PluginManager.h"
22#include "lldb/Core/State.h"
Caroline Tice3df9a8d2010-09-04 00:03:46 +000023#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Host/Host.h"
25#include "lldb/Target/ABI.h"
Greg Clayton8f343b02010-11-04 01:54:29 +000026#include "lldb/Target/DynamicLoader.h"
Jim Ingham22777012010-09-23 02:01:19 +000027#include "lldb/Target/LanguageRuntime.h"
28#include "lldb/Target/CPPLanguageRuntime.h"
29#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Target/RegisterContext.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000031#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Target/Target.h"
33#include "lldb/Target/TargetList.h"
34#include "lldb/Target/Thread.h"
35#include "lldb/Target/ThreadPlan.h"
36
37using namespace lldb;
38using namespace lldb_private;
39
Greg Clayton58be07b2011-01-07 06:08:19 +000040
41//----------------------------------------------------------------------
42// MemoryCache constructor
43//----------------------------------------------------------------------
44Process::MemoryCache::MemoryCache() :
45 m_cache_line_byte_size (512),
46 m_cache_mutex (Mutex::eMutexTypeRecursive),
47 m_cache ()
48{
49}
50
51//----------------------------------------------------------------------
52// Destructor
53//----------------------------------------------------------------------
54Process::MemoryCache::~MemoryCache()
55{
56}
57
58void
59Process::MemoryCache::Clear()
60{
61 Mutex::Locker locker (m_cache_mutex);
62 m_cache.clear();
63}
64
65void
66Process::MemoryCache::Flush (addr_t addr, size_t size)
67{
68 if (size == 0)
69 return;
70
71 const uint32_t cache_line_byte_size = m_cache_line_byte_size;
72 const addr_t end_addr = (addr + size - 1);
73 const addr_t flush_start_addr = addr - (addr % cache_line_byte_size);
74 const addr_t flush_end_addr = end_addr - (end_addr % cache_line_byte_size);
75
76 Mutex::Locker locker (m_cache_mutex);
77 if (m_cache.empty())
78 return;
79
80 assert ((flush_start_addr % cache_line_byte_size) == 0);
81
82 for (addr_t curr_addr = flush_start_addr; curr_addr <= flush_end_addr; curr_addr += cache_line_byte_size)
83 {
84 collection::iterator pos = m_cache.find (curr_addr);
85 if (pos != m_cache.end())
86 m_cache.erase(pos);
87 }
88}
89
90size_t
91Process::MemoryCache::Read
92(
93 Process *process,
94 addr_t addr,
95 void *dst,
96 size_t dst_len,
97 Error &error
98)
99{
100 size_t bytes_left = dst_len;
101 if (dst && bytes_left > 0)
102 {
103 const uint32_t cache_line_byte_size = m_cache_line_byte_size;
104 uint8_t *dst_buf = (uint8_t *)dst;
105 addr_t curr_addr = addr - (addr % cache_line_byte_size);
106 addr_t cache_offset = addr - curr_addr;
107 Mutex::Locker locker (m_cache_mutex);
108
109 while (bytes_left > 0)
110 {
111 collection::const_iterator pos = m_cache.find (curr_addr);
112 collection::const_iterator end = m_cache.end ();
113
114 if (pos != end)
115 {
116 size_t curr_read_size = cache_line_byte_size - cache_offset;
117 if (curr_read_size > bytes_left)
118 curr_read_size = bytes_left;
119
120 memcpy (dst_buf + dst_len - bytes_left, pos->second->GetBytes() + cache_offset, curr_read_size);
121
122 bytes_left -= curr_read_size;
123 curr_addr += curr_read_size + cache_offset;
124 cache_offset = 0;
125
126 if (bytes_left > 0)
127 {
128 // Get sequential cache page hits
129 for (++pos; (pos != end) && (bytes_left > 0); ++pos)
130 {
131 assert ((curr_addr % cache_line_byte_size) == 0);
132
133 if (pos->first != curr_addr)
134 break;
135
136 curr_read_size = pos->second->GetByteSize();
137 if (curr_read_size > bytes_left)
138 curr_read_size = bytes_left;
139
140 memcpy (dst_buf + dst_len - bytes_left, pos->second->GetBytes(), curr_read_size);
141
142 bytes_left -= curr_read_size;
143 curr_addr += curr_read_size;
144
145 // We have a cache page that succeeded to read some bytes
146 // but not an entire page. If this happens, we must cap
147 // off how much data we are able to read...
148 if (pos->second->GetByteSize() != cache_line_byte_size)
149 return dst_len - bytes_left;
150 }
151 }
152 }
153
154 // We need to read from the process
155
156 if (bytes_left > 0)
157 {
158 assert ((curr_addr % cache_line_byte_size) == 0);
159 std::auto_ptr<DataBufferHeap> data_buffer_heap_ap(new DataBufferHeap (cache_line_byte_size, 0));
160 size_t process_bytes_read = process->ReadMemoryFromInferior (curr_addr,
161 data_buffer_heap_ap->GetBytes(),
162 data_buffer_heap_ap->GetByteSize(),
163 error);
164 if (process_bytes_read == 0)
165 return dst_len - bytes_left;
166
167 if (process_bytes_read != cache_line_byte_size)
168 data_buffer_heap_ap->SetByteSize (process_bytes_read);
169 m_cache[curr_addr] = DataBufferSP (data_buffer_heap_ap.release());
170 // We have read data and put it into the cache, continue through the
171 // loop again to get the data out of the cache...
172 }
173 }
174 }
175
176 return dst_len - bytes_left;
177}
178
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179Process*
180Process::FindPlugin (Target &target, const char *plugin_name, Listener &listener)
181{
182 ProcessCreateInstance create_callback = NULL;
183 if (plugin_name)
184 {
185 create_callback = PluginManager::GetProcessCreateCallbackForPluginName (plugin_name);
186 if (create_callback)
187 {
188 std::auto_ptr<Process> debugger_ap(create_callback(target, listener));
189 if (debugger_ap->CanDebug(target))
190 return debugger_ap.release();
191 }
192 }
193 else
194 {
Greg Claytonc982c762010-07-09 20:39:50 +0000195 for (uint32_t idx = 0; (create_callback = PluginManager::GetProcessCreateCallbackAtIndex(idx)) != NULL; ++idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196 {
Greg Claytonc982c762010-07-09 20:39:50 +0000197 std::auto_ptr<Process> debugger_ap(create_callback(target, listener));
198 if (debugger_ap->CanDebug(target))
199 return debugger_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200 }
201 }
202 return NULL;
203}
204
205
206//----------------------------------------------------------------------
207// Process constructor
208//----------------------------------------------------------------------
209Process::Process(Target &target, Listener &listener) :
210 UserID (LLDB_INVALID_PROCESS_ID),
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000211 Broadcaster ("lldb.process"),
Greg Claytondbe54502010-11-19 03:46:01 +0000212 ProcessInstanceSettings (*GetSettingsController()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000213 m_target (target),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214 m_public_state (eStateUnloaded),
215 m_private_state (eStateUnloaded),
216 m_private_state_broadcaster ("lldb.process.internal_state_broadcaster"),
217 m_private_state_control_broadcaster ("lldb.process.internal_state_control_broadcaster"),
218 m_private_state_listener ("lldb.process.internal_state_listener"),
219 m_private_state_control_wait(),
220 m_private_state_thread (LLDB_INVALID_HOST_THREAD),
221 m_stop_id (0),
222 m_thread_index_id (0),
223 m_exit_status (-1),
224 m_exit_string (),
225 m_thread_list (this),
226 m_notifications (),
Greg Clayton3af9ea52010-11-18 05:57:03 +0000227 m_image_tokens (),
228 m_listener (listener),
229 m_breakpoint_site_list (),
Greg Clayton3af9ea52010-11-18 05:57:03 +0000230 m_dynamic_checkers_ap (),
Caroline Ticeef5c6d02010-11-16 05:07:41 +0000231 m_unix_signals (),
Greg Clayton3af9ea52010-11-18 05:57:03 +0000232 m_target_triple (),
233 m_byte_order (eByteOrderHost),
234 m_addr_byte_size (0),
235 m_abi_sp (),
Caroline Ticeef5c6d02010-11-16 05:07:41 +0000236 m_process_input_reader (),
Greg Clayton3e06bd92011-01-09 21:07:35 +0000237 m_stdio_communication ("process.stdio"),
Greg Clayton3af9ea52010-11-18 05:57:03 +0000238 m_stdio_communication_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton58be07b2011-01-07 06:08:19 +0000239 m_stdout_data (),
Jim Inghambb3a2832011-01-29 01:49:25 +0000240 m_memory_cache (),
Jim Ingham754ab982011-01-29 04:05:41 +0000241 m_next_event_action_ap(NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242{
Caroline Tice1559a462010-09-27 00:30:10 +0000243 UpdateInstanceName();
244
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000245 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246 if (log)
247 log->Printf ("%p Process::Process()", this);
248
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000249 SetEventName (eBroadcastBitStateChanged, "state-changed");
250 SetEventName (eBroadcastBitInterrupt, "interrupt");
251 SetEventName (eBroadcastBitSTDOUT, "stdout-available");
252 SetEventName (eBroadcastBitSTDERR, "stderr-available");
253
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254 listener.StartListeningForEvents (this,
255 eBroadcastBitStateChanged |
256 eBroadcastBitInterrupt |
257 eBroadcastBitSTDOUT |
258 eBroadcastBitSTDERR);
259
260 m_private_state_listener.StartListeningForEvents(&m_private_state_broadcaster,
261 eBroadcastBitStateChanged);
262
263 m_private_state_listener.StartListeningForEvents(&m_private_state_control_broadcaster,
264 eBroadcastInternalStateControlStop |
265 eBroadcastInternalStateControlPause |
266 eBroadcastInternalStateControlResume);
267}
268
269//----------------------------------------------------------------------
270// Destructor
271//----------------------------------------------------------------------
272Process::~Process()
273{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000274 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000275 if (log)
276 log->Printf ("%p Process::~Process()", this);
277 StopPrivateStateThread();
278}
279
280void
281Process::Finalize()
282{
283 // Do any cleanup needed prior to being destructed... Subclasses
284 // that override this method should call this superclass method as well.
285}
286
287void
288Process::RegisterNotificationCallbacks (const Notifications& callbacks)
289{
290 m_notifications.push_back(callbacks);
291 if (callbacks.initialize != NULL)
292 callbacks.initialize (callbacks.baton, this);
293}
294
295bool
296Process::UnregisterNotificationCallbacks(const Notifications& callbacks)
297{
298 std::vector<Notifications>::iterator pos, end = m_notifications.end();
299 for (pos = m_notifications.begin(); pos != end; ++pos)
300 {
301 if (pos->baton == callbacks.baton &&
302 pos->initialize == callbacks.initialize &&
303 pos->process_state_changed == callbacks.process_state_changed)
304 {
305 m_notifications.erase(pos);
306 return true;
307 }
308 }
309 return false;
310}
311
312void
313Process::SynchronouslyNotifyStateChanged (StateType state)
314{
315 std::vector<Notifications>::iterator notification_pos, notification_end = m_notifications.end();
316 for (notification_pos = m_notifications.begin(); notification_pos != notification_end; ++notification_pos)
317 {
318 if (notification_pos->process_state_changed)
319 notification_pos->process_state_changed (notification_pos->baton, this, state);
320 }
321}
322
323// FIXME: We need to do some work on events before the general Listener sees them.
324// For instance if we are continuing from a breakpoint, we need to ensure that we do
325// the little "insert real insn, step & stop" trick. But we can't do that when the
326// event is delivered by the broadcaster - since that is done on the thread that is
327// waiting for new events, so if we needed more than one event for our handling, we would
328// stall. So instead we do it when we fetch the event off of the queue.
329//
330
331StateType
332Process::GetNextEvent (EventSP &event_sp)
333{
334 StateType state = eStateInvalid;
335
336 if (m_listener.GetNextEventForBroadcaster (this, event_sp) && event_sp)
337 state = Process::ProcessEventData::GetStateFromEvent (event_sp.get());
338
339 return state;
340}
341
342
343StateType
344Process::WaitForProcessToStop (const TimeValue *timeout)
345{
346 StateType match_states[] = { eStateStopped, eStateCrashed, eStateDetached, eStateExited, eStateUnloaded };
347 return WaitForState (timeout, match_states, sizeof(match_states) / sizeof(StateType));
348}
349
350
351StateType
352Process::WaitForState
353(
354 const TimeValue *timeout,
355 const StateType *match_states, const uint32_t num_match_states
356)
357{
358 EventSP event_sp;
359 uint32_t i;
Greg Clayton05faeb72010-10-07 04:19:01 +0000360 StateType state = GetState();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361 while (state != eStateInvalid)
362 {
Greg Clayton05faeb72010-10-07 04:19:01 +0000363 // If we are exited or detached, we won't ever get back to any
364 // other valid state...
365 if (state == eStateDetached || state == eStateExited)
366 return state;
367
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368 state = WaitForStateChangedEvents (timeout, event_sp);
369
370 for (i=0; i<num_match_states; ++i)
371 {
372 if (match_states[i] == state)
373 return state;
374 }
375 }
376 return state;
377}
378
Jim Ingham30f9b212010-10-11 23:53:14 +0000379bool
380Process::HijackProcessEvents (Listener *listener)
381{
382 if (listener != NULL)
383 {
384 return HijackBroadcaster(listener, eBroadcastBitStateChanged);
385 }
386 else
387 return false;
388}
389
390void
391Process::RestoreProcessEvents ()
392{
393 RestoreBroadcaster();
394}
395
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396StateType
397Process::WaitForStateChangedEvents (const TimeValue *timeout, EventSP &event_sp)
398{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000399 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400
401 if (log)
402 log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout);
403
404 StateType state = eStateInvalid;
Greg Clayton3fcbed62010-10-19 03:25:40 +0000405 if (m_listener.WaitForEventForBroadcasterWithType (timeout,
406 this,
407 eBroadcastBitStateChanged,
408 event_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409 state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
410
411 if (log)
412 log->Printf ("Process::%s (timeout = %p, event_sp) => %s",
413 __FUNCTION__,
414 timeout,
415 StateAsCString(state));
416 return state;
417}
418
419Event *
420Process::PeekAtStateChangedEvents ()
421{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000422 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423
424 if (log)
425 log->Printf ("Process::%s...", __FUNCTION__);
426
427 Event *event_ptr;
Greg Clayton3fcbed62010-10-19 03:25:40 +0000428 event_ptr = m_listener.PeekAtNextEventForBroadcasterWithType (this,
429 eBroadcastBitStateChanged);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430 if (log)
431 {
432 if (event_ptr)
433 {
434 log->Printf ("Process::%s (event_ptr) => %s",
435 __FUNCTION__,
436 StateAsCString(ProcessEventData::GetStateFromEvent (event_ptr)));
437 }
438 else
439 {
440 log->Printf ("Process::%s no events found",
441 __FUNCTION__);
442 }
443 }
444 return event_ptr;
445}
446
447StateType
448Process::WaitForStateChangedEventsPrivate (const TimeValue *timeout, EventSP &event_sp)
449{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000450 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451
452 if (log)
453 log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout);
454
455 StateType state = eStateInvalid;
Greg Clayton6779606a2011-01-22 23:43:18 +0000456 if (m_private_state_listener.WaitForEventForBroadcasterWithType (timeout,
457 &m_private_state_broadcaster,
458 eBroadcastBitStateChanged,
459 event_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
461
462 // This is a bit of a hack, but when we wait here we could very well return
463 // to the command-line, and that could disable the log, which would render the
464 // log we got above invalid.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000465 if (log)
Greg Clayton6779606a2011-01-22 23:43:18 +0000466 {
467 if (state == eStateInvalid)
468 log->Printf ("Process::%s (timeout = %p, event_sp) => TIMEOUT", __FUNCTION__, timeout);
469 else
470 log->Printf ("Process::%s (timeout = %p, event_sp) => %s", __FUNCTION__, timeout, StateAsCString(state));
471 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 return state;
473}
474
475bool
476Process::WaitForEventsPrivate (const TimeValue *timeout, EventSP &event_sp, bool control_only)
477{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000478 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479
480 if (log)
481 log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout);
482
483 if (control_only)
484 return m_private_state_listener.WaitForEventForBroadcaster(timeout, &m_private_state_control_broadcaster, event_sp);
485 else
486 return m_private_state_listener.WaitForEvent(timeout, event_sp);
487}
488
489bool
490Process::IsRunning () const
491{
492 return StateIsRunningState (m_public_state.GetValue());
493}
494
495int
496Process::GetExitStatus ()
497{
498 if (m_public_state.GetValue() == eStateExited)
499 return m_exit_status;
500 return -1;
501}
502
Greg Clayton85851dd2010-12-04 00:10:17 +0000503
504void
505Process::ProcessInstanceSettings::GetHostEnvironmentIfNeeded ()
506{
507 if (m_inherit_host_env && !m_got_host_env)
508 {
509 m_got_host_env = true;
510 StringList host_env;
511 const size_t host_env_count = Host::GetEnvironment (host_env);
512 for (size_t idx=0; idx<host_env_count; idx++)
513 {
514 const char *env_entry = host_env.GetStringAtIndex (idx);
515 if (env_entry)
516 {
Greg Claytone2956ee2010-12-15 20:52:40 +0000517 const char *equal_pos = ::strchr(env_entry, '=');
Greg Clayton85851dd2010-12-04 00:10:17 +0000518 if (equal_pos)
519 {
520 std::string key (env_entry, equal_pos - env_entry);
521 std::string value (equal_pos + 1);
522 if (m_env_vars.find (key) == m_env_vars.end())
523 m_env_vars[key] = value;
524 }
525 }
526 }
527 }
528}
529
530
531size_t
532Process::ProcessInstanceSettings::GetEnvironmentAsArgs (Args &env)
533{
534 GetHostEnvironmentIfNeeded ();
535
536 dictionary::const_iterator pos, end = m_env_vars.end();
537 for (pos = m_env_vars.begin(); pos != end; ++pos)
538 {
539 std::string env_var_equal_value (pos->first);
540 env_var_equal_value.append(1, '=');
541 env_var_equal_value.append (pos->second);
542 env.AppendArgument (env_var_equal_value.c_str());
543 }
544 return env.GetArgumentCount();
545}
546
547
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548const char *
549Process::GetExitDescription ()
550{
551 if (m_public_state.GetValue() == eStateExited && !m_exit_string.empty())
552 return m_exit_string.c_str();
553 return NULL;
554}
555
Greg Clayton6779606a2011-01-22 23:43:18 +0000556bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557Process::SetExitStatus (int status, const char *cstr)
558{
Greg Clayton414f5d32011-01-25 02:58:48 +0000559 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS));
560 if (log)
561 log->Printf("Process::SetExitStatus (status=%i (0x%8.8x), description=%s%s%s)",
562 status, status,
563 cstr ? "\"" : "",
564 cstr ? cstr : "NULL",
565 cstr ? "\"" : "");
566
Greg Clayton6779606a2011-01-22 23:43:18 +0000567 // We were already in the exited state
568 if (m_private_state.GetValue() == eStateExited)
Greg Clayton414f5d32011-01-25 02:58:48 +0000569 {
Greg Clayton385d6032011-01-26 23:47:29 +0000570 if (log)
571 log->Printf("Process::SetExitStatus () ignoring exit status because state was already set to eStateExited");
Greg Clayton6779606a2011-01-22 23:43:18 +0000572 return false;
Greg Clayton414f5d32011-01-25 02:58:48 +0000573 }
Greg Clayton6779606a2011-01-22 23:43:18 +0000574
575 m_exit_status = status;
576 if (cstr)
577 m_exit_string = cstr;
578 else
579 m_exit_string.clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580
Greg Clayton6779606a2011-01-22 23:43:18 +0000581 DidExit ();
Greg Clayton10177aa2010-12-08 05:08:21 +0000582
Greg Clayton6779606a2011-01-22 23:43:18 +0000583 SetPrivateState (eStateExited);
584 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585}
586
587// This static callback can be used to watch for local child processes on
588// the current host. The the child process exits, the process will be
589// found in the global target list (we want to be completely sure that the
590// lldb_private::Process doesn't go away before we can deliver the signal.
591bool
592Process::SetProcessExitStatus
593(
594 void *callback_baton,
595 lldb::pid_t pid,
596 int signo, // Zero for no signal
597 int exit_status // Exit value of process if signal is zero
598)
599{
600 if (signo == 0 || exit_status)
601 {
Greg Clayton66111032010-06-23 01:19:29 +0000602 TargetSP target_sp(Debugger::FindTargetWithProcessID (pid));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603 if (target_sp)
604 {
605 ProcessSP process_sp (target_sp->GetProcessSP());
606 if (process_sp)
607 {
608 const char *signal_cstr = NULL;
609 if (signo)
610 signal_cstr = process_sp->GetUnixSignals().GetSignalAsCString (signo);
611
612 process_sp->SetExitStatus (exit_status, signal_cstr);
613 }
614 }
615 return true;
616 }
617 return false;
618}
619
620
621uint32_t
622Process::GetNextThreadIndexID ()
623{
624 return ++m_thread_index_id;
625}
626
627StateType
628Process::GetState()
629{
630 // If any other threads access this we will need a mutex for it
631 return m_public_state.GetValue ();
632}
633
634void
635Process::SetPublicState (StateType new_state)
636{
Greg Clayton414f5d32011-01-25 02:58:48 +0000637 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000638 if (log)
639 log->Printf("Process::SetPublicState (%s)", StateAsCString(new_state));
640 m_public_state.SetValue (new_state);
641}
642
643StateType
644Process::GetPrivateState ()
645{
646 return m_private_state.GetValue();
647}
648
649void
650Process::SetPrivateState (StateType new_state)
651{
Greg Clayton414f5d32011-01-25 02:58:48 +0000652 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653 bool state_changed = false;
654
655 if (log)
656 log->Printf("Process::SetPrivateState (%s)", StateAsCString(new_state));
657
658 Mutex::Locker locker(m_private_state.GetMutex());
659
660 const StateType old_state = m_private_state.GetValueNoLock ();
661 state_changed = old_state != new_state;
662 if (state_changed)
663 {
664 m_private_state.SetValueNoLock (new_state);
665 if (StateIsStoppedState(new_state))
666 {
667 m_stop_id++;
Greg Clayton58be07b2011-01-07 06:08:19 +0000668 m_memory_cache.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000669 if (log)
670 log->Printf("Process::SetPrivateState (%s) stop_id = %u", StateAsCString(new_state), m_stop_id);
671 }
672 // Use our target to get a shared pointer to ourselves...
673 m_private_state_broadcaster.BroadcastEvent (eBroadcastBitStateChanged, new ProcessEventData (GetTarget().GetProcessSP(), new_state));
674 }
675 else
676 {
677 if (log)
678 log->Printf("Process::SetPrivateState (%s) state didn't change. Ignoring...", StateAsCString(new_state), StateAsCString(old_state));
679 }
680}
681
682
683uint32_t
684Process::GetStopID() const
685{
686 return m_stop_id;
687}
688
689addr_t
690Process::GetImageInfoAddress()
691{
692 return LLDB_INVALID_ADDRESS;
693}
694
Greg Clayton8f343b02010-11-04 01:54:29 +0000695//----------------------------------------------------------------------
696// LoadImage
697//
698// This function provides a default implementation that works for most
699// unix variants. Any Process subclasses that need to do shared library
700// loading differently should override LoadImage and UnloadImage and
701// do what is needed.
702//----------------------------------------------------------------------
703uint32_t
704Process::LoadImage (const FileSpec &image_spec, Error &error)
705{
706 DynamicLoader *loader = GetDynamicLoader();
707 if (loader)
708 {
709 error = loader->CanLoadImage();
710 if (error.Fail())
711 return LLDB_INVALID_IMAGE_TOKEN;
712 }
713
714 if (error.Success())
715 {
716 ThreadSP thread_sp(GetThreadList ().GetSelectedThread());
717 if (thread_sp == NULL)
718 thread_sp = GetThreadList ().GetThreadAtIndex(0, true);
719
720 if (thread_sp)
721 {
722 StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (0));
723
724 if (frame_sp)
725 {
726 ExecutionContext exe_ctx;
727 frame_sp->CalculateExecutionContext (exe_ctx);
Jim Ingham399f1ca2010-11-05 19:25:48 +0000728 bool unwind_on_error = true;
Sean Callanan92adcac2011-01-13 08:53:35 +0000729 bool keep_in_memory = false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000730 StreamString expr;
731 char path[PATH_MAX];
732 image_spec.GetPath(path, sizeof(path));
733 expr.Printf("dlopen (\"%s\", 2)", path);
734 const char *prefix = "extern \"C\" void* dlopen (const char *path, int mode);\n";
Jim Inghamf48169b2010-11-30 02:22:11 +0000735 lldb::ValueObjectSP result_valobj_sp;
Sean Callanan92adcac2011-01-13 08:53:35 +0000736 ClangUserExpression::Evaluate (exe_ctx, keep_in_memory, unwind_on_error, expr.GetData(), prefix, result_valobj_sp);
Greg Clayton8f343b02010-11-04 01:54:29 +0000737 if (result_valobj_sp->GetError().Success())
738 {
739 Scalar scalar;
740 if (result_valobj_sp->ResolveValue (frame_sp.get(), scalar))
741 {
742 addr_t image_ptr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
743 if (image_ptr != 0 && image_ptr != LLDB_INVALID_ADDRESS)
744 {
745 uint32_t image_token = m_image_tokens.size();
746 m_image_tokens.push_back (image_ptr);
747 return image_token;
748 }
749 }
750 }
751 }
752 }
753 }
754 return LLDB_INVALID_IMAGE_TOKEN;
755}
756
757//----------------------------------------------------------------------
758// UnloadImage
759//
760// This function provides a default implementation that works for most
761// unix variants. Any Process subclasses that need to do shared library
762// loading differently should override LoadImage and UnloadImage and
763// do what is needed.
764//----------------------------------------------------------------------
765Error
766Process::UnloadImage (uint32_t image_token)
767{
768 Error error;
769 if (image_token < m_image_tokens.size())
770 {
771 const addr_t image_addr = m_image_tokens[image_token];
772 if (image_addr == LLDB_INVALID_ADDRESS)
773 {
774 error.SetErrorString("image already unloaded");
775 }
776 else
777 {
778 DynamicLoader *loader = GetDynamicLoader();
779 if (loader)
780 error = loader->CanLoadImage();
781
782 if (error.Success())
783 {
784 ThreadSP thread_sp(GetThreadList ().GetSelectedThread());
785 if (thread_sp == NULL)
786 thread_sp = GetThreadList ().GetThreadAtIndex(0, true);
787
788 if (thread_sp)
789 {
790 StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (0));
791
792 if (frame_sp)
793 {
794 ExecutionContext exe_ctx;
795 frame_sp->CalculateExecutionContext (exe_ctx);
Jim Ingham399f1ca2010-11-05 19:25:48 +0000796 bool unwind_on_error = true;
Sean Callanan92adcac2011-01-13 08:53:35 +0000797 bool keep_in_memory = false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000798 StreamString expr;
799 expr.Printf("dlclose ((void *)0x%llx)", image_addr);
800 const char *prefix = "extern \"C\" int dlclose(void* handle);\n";
Jim Inghamf48169b2010-11-30 02:22:11 +0000801 lldb::ValueObjectSP result_valobj_sp;
Sean Callanan92adcac2011-01-13 08:53:35 +0000802 ClangUserExpression::Evaluate (exe_ctx, unwind_on_error, keep_in_memory, expr.GetData(), prefix, result_valobj_sp);
Greg Clayton8f343b02010-11-04 01:54:29 +0000803 if (result_valobj_sp->GetError().Success())
804 {
805 Scalar scalar;
806 if (result_valobj_sp->ResolveValue (frame_sp.get(), scalar))
807 {
808 if (scalar.UInt(1))
809 {
810 error.SetErrorStringWithFormat("expression failed: \"%s\"", expr.GetData());
811 }
812 else
813 {
814 m_image_tokens[image_token] = LLDB_INVALID_ADDRESS;
815 }
816 }
817 }
818 else
819 {
820 error = result_valobj_sp->GetError();
821 }
822 }
823 }
824 }
825 }
826 }
827 else
828 {
829 error.SetErrorString("invalid image token");
830 }
831 return error;
832}
833
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000834DynamicLoader *
835Process::GetDynamicLoader()
836{
837 return NULL;
838}
839
840const ABI *
841Process::GetABI()
842{
843 ConstString& triple = m_target_triple;
844
845 if (triple.IsEmpty())
846 return NULL;
847
848 if (m_abi_sp.get() == NULL)
849 {
850 m_abi_sp.reset(ABI::FindPlugin(triple));
851 }
852
853 return m_abi_sp.get();
854}
855
Jim Ingham22777012010-09-23 02:01:19 +0000856LanguageRuntime *
857Process::GetLanguageRuntime(lldb::LanguageType language)
858{
859 LanguageRuntimeCollection::iterator pos;
860 pos = m_language_runtimes.find (language);
861 if (pos == m_language_runtimes.end())
862 {
863 lldb::LanguageRuntimeSP runtime(LanguageRuntime::FindPlugin(this, language));
864
865 m_language_runtimes[language]
866 = runtime;
867 return runtime.get();
868 }
869 else
870 return (*pos).second.get();
871}
872
873CPPLanguageRuntime *
874Process::GetCPPLanguageRuntime ()
875{
876 LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeC_plus_plus);
877 if (runtime != NULL && runtime->GetLanguageType() == eLanguageTypeC_plus_plus)
878 return static_cast<CPPLanguageRuntime *> (runtime);
879 return NULL;
880}
881
882ObjCLanguageRuntime *
883Process::GetObjCLanguageRuntime ()
884{
885 LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeObjC);
886 if (runtime != NULL && runtime->GetLanguageType() == eLanguageTypeObjC)
887 return static_cast<ObjCLanguageRuntime *> (runtime);
888 return NULL;
889}
890
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891BreakpointSiteList &
892Process::GetBreakpointSiteList()
893{
894 return m_breakpoint_site_list;
895}
896
897const BreakpointSiteList &
898Process::GetBreakpointSiteList() const
899{
900 return m_breakpoint_site_list;
901}
902
903
904void
905Process::DisableAllBreakpointSites ()
906{
907 m_breakpoint_site_list.SetEnabledForAll (false);
908}
909
910Error
911Process::ClearBreakpointSiteByID (lldb::user_id_t break_id)
912{
913 Error error (DisableBreakpointSiteByID (break_id));
914
915 if (error.Success())
916 m_breakpoint_site_list.Remove(break_id);
917
918 return error;
919}
920
921Error
922Process::DisableBreakpointSiteByID (lldb::user_id_t break_id)
923{
924 Error error;
925 BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID (break_id);
926 if (bp_site_sp)
927 {
928 if (bp_site_sp->IsEnabled())
929 error = DisableBreakpoint (bp_site_sp.get());
930 }
931 else
932 {
933 error.SetErrorStringWithFormat("invalid breakpoint site ID: %i", break_id);
934 }
935
936 return error;
937}
938
939Error
940Process::EnableBreakpointSiteByID (lldb::user_id_t break_id)
941{
942 Error error;
943 BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID (break_id);
944 if (bp_site_sp)
945 {
946 if (!bp_site_sp->IsEnabled())
947 error = EnableBreakpoint (bp_site_sp.get());
948 }
949 else
950 {
951 error.SetErrorStringWithFormat("invalid breakpoint site ID: %i", break_id);
952 }
953 return error;
954}
955
Stephen Wilson50bd94f2010-07-17 00:56:13 +0000956lldb::break_id_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000957Process::CreateBreakpointSite (BreakpointLocationSP &owner, bool use_hardware)
958{
Greg Claytonf5e56de2010-09-14 23:36:40 +0000959 const addr_t load_addr = owner->GetAddress().GetLoadAddress (&m_target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000960 if (load_addr != LLDB_INVALID_ADDRESS)
961 {
962 BreakpointSiteSP bp_site_sp;
963
964 // Look up this breakpoint site. If it exists, then add this new owner, otherwise
965 // create a new breakpoint site and add it.
966
967 bp_site_sp = m_breakpoint_site_list.FindByAddress (load_addr);
968
969 if (bp_site_sp)
970 {
971 bp_site_sp->AddOwner (owner);
972 owner->SetBreakpointSite (bp_site_sp);
973 return bp_site_sp->GetID();
974 }
975 else
976 {
977 bp_site_sp.reset (new BreakpointSite (&m_breakpoint_site_list, owner, load_addr, LLDB_INVALID_THREAD_ID, use_hardware));
978 if (bp_site_sp)
979 {
980 if (EnableBreakpoint (bp_site_sp.get()).Success())
981 {
982 owner->SetBreakpointSite (bp_site_sp);
983 return m_breakpoint_site_list.Add (bp_site_sp);
984 }
985 }
986 }
987 }
988 // We failed to enable the breakpoint
989 return LLDB_INVALID_BREAK_ID;
990
991}
992
993void
994Process::RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, lldb::user_id_t owner_loc_id, BreakpointSiteSP &bp_site_sp)
995{
996 uint32_t num_owners = bp_site_sp->RemoveOwner (owner_id, owner_loc_id);
997 if (num_owners == 0)
998 {
999 DisableBreakpoint(bp_site_sp.get());
1000 m_breakpoint_site_list.RemoveByAddress(bp_site_sp->GetLoadAddress());
1001 }
1002}
1003
1004
1005size_t
1006Process::RemoveBreakpointOpcodesFromBuffer (addr_t bp_addr, size_t size, uint8_t *buf) const
1007{
1008 size_t bytes_removed = 0;
1009 addr_t intersect_addr;
1010 size_t intersect_size;
1011 size_t opcode_offset;
1012 size_t idx;
1013 BreakpointSiteSP bp;
1014
1015 for (idx = 0; (bp = m_breakpoint_site_list.GetByIndex(idx)) != NULL; ++idx)
1016 {
1017 if (bp->GetType() == BreakpointSite::eSoftware)
1018 {
1019 if (bp->IntersectsRange(bp_addr, size, &intersect_addr, &intersect_size, &opcode_offset))
1020 {
1021 assert(bp_addr <= intersect_addr && intersect_addr < bp_addr + size);
1022 assert(bp_addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= bp_addr + size);
1023 assert(opcode_offset + intersect_size <= bp->GetByteSize());
1024 size_t buf_offset = intersect_addr - bp_addr;
1025 ::memcpy(buf + buf_offset, bp->GetSavedOpcodeBytes() + opcode_offset, intersect_size);
1026 }
1027 }
1028 }
1029 return bytes_removed;
1030}
1031
1032
1033Error
1034Process::EnableSoftwareBreakpoint (BreakpointSite *bp_site)
1035{
1036 Error error;
1037 assert (bp_site != NULL);
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001038 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001039 const addr_t bp_addr = bp_site->GetLoadAddress();
1040 if (log)
1041 log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx", bp_site->GetID(), (uint64_t)bp_addr);
1042 if (bp_site->IsEnabled())
1043 {
1044 if (log)
1045 log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- already enabled", bp_site->GetID(), (uint64_t)bp_addr);
1046 return error;
1047 }
1048
1049 if (bp_addr == LLDB_INVALID_ADDRESS)
1050 {
1051 error.SetErrorString("BreakpointSite contains an invalid load address.");
1052 return error;
1053 }
1054 // Ask the lldb::Process subclass to fill in the correct software breakpoint
1055 // trap for the breakpoint site
1056 const size_t bp_opcode_size = GetSoftwareBreakpointTrapOpcode(bp_site);
1057
1058 if (bp_opcode_size == 0)
1059 {
1060 error.SetErrorStringWithFormat ("Process::GetSoftwareBreakpointTrapOpcode() returned zero, unable to get breakpoint trap for address 0x%llx.\n", bp_addr);
1061 }
1062 else
1063 {
1064 const uint8_t * const bp_opcode_bytes = bp_site->GetTrapOpcodeBytes();
1065
1066 if (bp_opcode_bytes == NULL)
1067 {
1068 error.SetErrorString ("BreakpointSite doesn't contain a valid breakpoint trap opcode.");
1069 return error;
1070 }
1071
1072 // Save the original opcode by reading it
1073 if (DoReadMemory(bp_addr, bp_site->GetSavedOpcodeBytes(), bp_opcode_size, error) == bp_opcode_size)
1074 {
1075 // Write a software breakpoint in place of the original opcode
1076 if (DoWriteMemory(bp_addr, bp_opcode_bytes, bp_opcode_size, error) == bp_opcode_size)
1077 {
1078 uint8_t verify_bp_opcode_bytes[64];
1079 if (DoReadMemory(bp_addr, verify_bp_opcode_bytes, bp_opcode_size, error) == bp_opcode_size)
1080 {
1081 if (::memcmp(bp_opcode_bytes, verify_bp_opcode_bytes, bp_opcode_size) == 0)
1082 {
1083 bp_site->SetEnabled(true);
1084 bp_site->SetType (BreakpointSite::eSoftware);
1085 if (log)
1086 log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- SUCCESS",
1087 bp_site->GetID(),
1088 (uint64_t)bp_addr);
1089 }
1090 else
1091 error.SetErrorString("Failed to verify the breakpoint trap in memory.");
1092 }
1093 else
1094 error.SetErrorString("Unable to read memory to verify breakpoint trap.");
1095 }
1096 else
1097 error.SetErrorString("Unable to write breakpoint trap to memory.");
1098 }
1099 else
1100 error.SetErrorString("Unable to read memory at breakpoint address.");
1101 }
Stephen Wilson78a4feb2011-01-12 04:20:03 +00001102 if (log && error.Fail())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001103 log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- FAILED: %s",
1104 bp_site->GetID(),
1105 (uint64_t)bp_addr,
1106 error.AsCString());
1107 return error;
1108}
1109
1110Error
1111Process::DisableSoftwareBreakpoint (BreakpointSite *bp_site)
1112{
1113 Error error;
1114 assert (bp_site != NULL);
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001115 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001116 addr_t bp_addr = bp_site->GetLoadAddress();
1117 lldb::user_id_t breakID = bp_site->GetID();
1118 if (log)
Stephen Wilson5394e0d2011-01-14 21:07:07 +00001119 log->Printf ("Process::DisableBreakpoint (breakID = %d) addr = 0x%llx", breakID, (uint64_t)bp_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001120
1121 if (bp_site->IsHardware())
1122 {
1123 error.SetErrorString("Breakpoint site is a hardware breakpoint.");
1124 }
1125 else if (bp_site->IsEnabled())
1126 {
1127 const size_t break_op_size = bp_site->GetByteSize();
1128 const uint8_t * const break_op = bp_site->GetTrapOpcodeBytes();
1129 if (break_op_size > 0)
1130 {
1131 // Clear a software breakoint instruction
Greg Claytonc982c762010-07-09 20:39:50 +00001132 uint8_t curr_break_op[8];
Stephen Wilson4ab47682010-07-20 18:41:11 +00001133 assert (break_op_size <= sizeof(curr_break_op));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134 bool break_op_found = false;
1135
1136 // Read the breakpoint opcode
1137 if (DoReadMemory (bp_addr, curr_break_op, break_op_size, error) == break_op_size)
1138 {
1139 bool verify = false;
1140 // Make sure we have the a breakpoint opcode exists at this address
1141 if (::memcmp (curr_break_op, break_op, break_op_size) == 0)
1142 {
1143 break_op_found = true;
1144 // We found a valid breakpoint opcode at this address, now restore
1145 // the saved opcode.
1146 if (DoWriteMemory (bp_addr, bp_site->GetSavedOpcodeBytes(), break_op_size, error) == break_op_size)
1147 {
1148 verify = true;
1149 }
1150 else
1151 error.SetErrorString("Memory write failed when restoring original opcode.");
1152 }
1153 else
1154 {
1155 error.SetErrorString("Original breakpoint trap is no longer in memory.");
1156 // Set verify to true and so we can check if the original opcode has already been restored
1157 verify = true;
1158 }
1159
1160 if (verify)
1161 {
Greg Claytonc982c762010-07-09 20:39:50 +00001162 uint8_t verify_opcode[8];
Stephen Wilson4ab47682010-07-20 18:41:11 +00001163 assert (break_op_size < sizeof(verify_opcode));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164 // Verify that our original opcode made it back to the inferior
1165 if (DoReadMemory (bp_addr, verify_opcode, break_op_size, error) == break_op_size)
1166 {
1167 // compare the memory we just read with the original opcode
1168 if (::memcmp (bp_site->GetSavedOpcodeBytes(), verify_opcode, break_op_size) == 0)
1169 {
1170 // SUCCESS
1171 bp_site->SetEnabled(false);
1172 if (log)
1173 log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- SUCCESS", bp_site->GetID(), (uint64_t)bp_addr);
1174 return error;
1175 }
1176 else
1177 {
1178 if (break_op_found)
1179 error.SetErrorString("Failed to restore original opcode.");
1180 }
1181 }
1182 else
1183 error.SetErrorString("Failed to read memory to verify that breakpoint trap was restored.");
1184 }
1185 }
1186 else
1187 error.SetErrorString("Unable to read memory that should contain the breakpoint trap.");
1188 }
1189 }
1190 else
1191 {
1192 if (log)
1193 log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- already disabled", bp_site->GetID(), (uint64_t)bp_addr);
1194 return error;
1195 }
1196
1197 if (log)
1198 log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- FAILED: %s",
1199 bp_site->GetID(),
1200 (uint64_t)bp_addr,
1201 error.AsCString());
1202 return error;
1203
1204}
1205
Greg Clayton58be07b2011-01-07 06:08:19 +00001206// Comment out line below to disable memory caching
1207#define ENABLE_MEMORY_CACHING
1208// Uncomment to verify memory caching works after making changes to caching code
1209//#define VERIFY_MEMORY_READS
1210
1211#if defined (ENABLE_MEMORY_CACHING)
1212
1213#if defined (VERIFY_MEMORY_READS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214
1215size_t
1216Process::ReadMemory (addr_t addr, void *buf, size_t size, Error &error)
1217{
Greg Clayton58be07b2011-01-07 06:08:19 +00001218 // Memory caching is enabled, with debug verification
1219 if (buf && size)
1220 {
1221 // Uncomment the line below to make sure memory caching is working.
1222 // I ran this through the test suite and got no assertions, so I am
1223 // pretty confident this is working well. If any changes are made to
1224 // memory caching, uncomment the line below and test your changes!
1225
1226 // Verify all memory reads by using the cache first, then redundantly
1227 // reading the same memory from the inferior and comparing to make sure
1228 // everything is exactly the same.
1229 std::string verify_buf (size, '\0');
1230 assert (verify_buf.size() == size);
1231 const size_t cache_bytes_read = m_memory_cache.Read (this, addr, buf, size, error);
1232 Error verify_error;
1233 const size_t verify_bytes_read = ReadMemoryFromInferior (addr, const_cast<char *>(verify_buf.data()), verify_buf.size(), verify_error);
1234 assert (cache_bytes_read == verify_bytes_read);
1235 assert (memcmp(buf, verify_buf.data(), verify_buf.size()) == 0);
1236 assert (verify_error.Success() == error.Success());
1237 return cache_bytes_read;
1238 }
1239 return 0;
1240}
1241
1242#else // #if defined (VERIFY_MEMORY_READS)
1243
1244size_t
1245Process::ReadMemory (addr_t addr, void *buf, size_t size, Error &error)
1246{
1247 // Memory caching enabled, no verification
1248 return m_memory_cache.Read (this, addr, buf, size, error);
1249}
1250
1251#endif // #else for #if defined (VERIFY_MEMORY_READS)
1252
1253#else // #if defined (ENABLE_MEMORY_CACHING)
1254
1255size_t
1256Process::ReadMemory (addr_t addr, void *buf, size_t size, Error &error)
1257{
1258 // Memory caching is disabled
1259 return ReadMemoryFromInferior (addr, buf, size, error);
1260}
1261
1262#endif // #else for #if defined (ENABLE_MEMORY_CACHING)
1263
1264
1265size_t
1266Process::ReadMemoryFromInferior (addr_t addr, void *buf, size_t size, Error &error)
1267{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001268 if (buf == NULL || size == 0)
1269 return 0;
1270
1271 size_t bytes_read = 0;
1272 uint8_t *bytes = (uint8_t *)buf;
1273
1274 while (bytes_read < size)
1275 {
1276 const size_t curr_size = size - bytes_read;
1277 const size_t curr_bytes_read = DoReadMemory (addr + bytes_read,
1278 bytes + bytes_read,
1279 curr_size,
1280 error);
1281 bytes_read += curr_bytes_read;
1282 if (curr_bytes_read == curr_size || curr_bytes_read == 0)
1283 break;
1284 }
1285
1286 // Replace any software breakpoint opcodes that fall into this range back
1287 // into "buf" before we return
1288 if (bytes_read > 0)
1289 RemoveBreakpointOpcodesFromBuffer (addr, bytes_read, (uint8_t *)buf);
1290 return bytes_read;
1291}
1292
Greg Clayton58a4c462010-12-16 20:01:20 +00001293uint64_t
1294Process::ReadUnsignedInteger (lldb::addr_t vm_addr, size_t integer_byte_size, Error &error)
1295{
1296 if (integer_byte_size > sizeof(uint64_t))
1297 {
1298 error.SetErrorString ("unsupported integer size");
1299 }
1300 else
1301 {
1302 uint8_t tmp[sizeof(uint64_t)];
1303 DataExtractor data (tmp, integer_byte_size, GetByteOrder(), GetAddressByteSize());
1304 if (ReadMemory (vm_addr, tmp, integer_byte_size, error) == integer_byte_size)
1305 {
1306 uint32_t offset = 0;
1307 return data.GetMaxU64 (&offset, integer_byte_size);
1308 }
1309 }
1310 // Any plug-in that doesn't return success a memory read with the number
1311 // of bytes that were requested should be setting the error
1312 assert (error.Fail());
1313 return 0;
1314}
1315
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001316size_t
1317Process::WriteMemoryPrivate (addr_t addr, const void *buf, size_t size, Error &error)
1318{
1319 size_t bytes_written = 0;
1320 const uint8_t *bytes = (const uint8_t *)buf;
1321
1322 while (bytes_written < size)
1323 {
1324 const size_t curr_size = size - bytes_written;
1325 const size_t curr_bytes_written = DoWriteMemory (addr + bytes_written,
1326 bytes + bytes_written,
1327 curr_size,
1328 error);
1329 bytes_written += curr_bytes_written;
1330 if (curr_bytes_written == curr_size || curr_bytes_written == 0)
1331 break;
1332 }
1333 return bytes_written;
1334}
1335
1336size_t
1337Process::WriteMemory (addr_t addr, const void *buf, size_t size, Error &error)
1338{
Greg Clayton58be07b2011-01-07 06:08:19 +00001339#if defined (ENABLE_MEMORY_CACHING)
1340 m_memory_cache.Flush (addr, size);
1341#endif
1342
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001343 if (buf == NULL || size == 0)
1344 return 0;
1345 // We need to write any data that would go where any current software traps
1346 // (enabled software breakpoints) any software traps (breakpoints) that we
1347 // may have placed in our tasks memory.
1348
1349 BreakpointSiteList::collection::const_iterator iter = m_breakpoint_site_list.GetMap()->lower_bound (addr);
1350 BreakpointSiteList::collection::const_iterator end = m_breakpoint_site_list.GetMap()->end();
1351
1352 if (iter == end || iter->second->GetLoadAddress() > addr + size)
1353 return DoWriteMemory(addr, buf, size, error);
1354
1355 BreakpointSiteList::collection::const_iterator pos;
1356 size_t bytes_written = 0;
Greg Claytonc982c762010-07-09 20:39:50 +00001357 addr_t intersect_addr = 0;
1358 size_t intersect_size = 0;
1359 size_t opcode_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001360 const uint8_t *ubuf = (const uint8_t *)buf;
1361
1362 for (pos = iter; pos != end; ++pos)
1363 {
1364 BreakpointSiteSP bp;
1365 bp = pos->second;
1366
1367 assert(bp->IntersectsRange(addr, size, &intersect_addr, &intersect_size, &opcode_offset));
1368 assert(addr <= intersect_addr && intersect_addr < addr + size);
1369 assert(addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= addr + size);
1370 assert(opcode_offset + intersect_size <= bp->GetByteSize());
1371
1372 // Check for bytes before this breakpoint
1373 const addr_t curr_addr = addr + bytes_written;
1374 if (intersect_addr > curr_addr)
1375 {
1376 // There are some bytes before this breakpoint that we need to
1377 // just write to memory
1378 size_t curr_size = intersect_addr - curr_addr;
1379 size_t curr_bytes_written = WriteMemoryPrivate (curr_addr,
1380 ubuf + bytes_written,
1381 curr_size,
1382 error);
1383 bytes_written += curr_bytes_written;
1384 if (curr_bytes_written != curr_size)
1385 {
1386 // We weren't able to write all of the requested bytes, we
1387 // are done looping and will return the number of bytes that
1388 // we have written so far.
1389 break;
1390 }
1391 }
1392
1393 // Now write any bytes that would cover up any software breakpoints
1394 // directly into the breakpoint opcode buffer
1395 ::memcpy(bp->GetSavedOpcodeBytes() + opcode_offset, ubuf + bytes_written, intersect_size);
1396 bytes_written += intersect_size;
1397 }
1398
1399 // Write any remaining bytes after the last breakpoint if we have any left
1400 if (bytes_written < size)
1401 bytes_written += WriteMemoryPrivate (addr + bytes_written,
1402 ubuf + bytes_written,
1403 size - bytes_written,
1404 error);
1405
1406 return bytes_written;
1407}
1408
1409addr_t
1410Process::AllocateMemory(size_t size, uint32_t permissions, Error &error)
1411{
1412 // Fixme: we should track the blocks we've allocated, and clean them up...
1413 // We could even do our own allocator here if that ends up being more efficient.
Greg Claytonb2daec92011-01-23 19:58:49 +00001414 addr_t allocated_addr = DoAllocateMemory (size, permissions, error);
1415 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
1416 if (log)
Greg Clayton2ad66702011-01-24 06:30:45 +00001417 log->Printf("Process::AllocateMemory(size=%4zu, permissions=%c%c%c) => 0x%16.16llx (m_stop_id = %u)",
Greg Claytonb2daec92011-01-23 19:58:49 +00001418 size,
1419 permissions & ePermissionsReadable ? 'r' : '-',
1420 permissions & ePermissionsWritable ? 'w' : '-',
1421 permissions & ePermissionsExecutable ? 'x' : '-',
1422 (uint64_t)allocated_addr,
1423 m_stop_id);
1424 return allocated_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425}
1426
1427Error
1428Process::DeallocateMemory (addr_t ptr)
1429{
Greg Claytonb2daec92011-01-23 19:58:49 +00001430 Error error(DoDeallocateMemory (ptr));
1431
1432 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
1433 if (log)
1434 log->Printf("Process::DeallocateMemory(addr=0x%16.16llx) => err = %s (m_stop_id = %u)",
1435 ptr,
1436 error.AsCString("SUCCESS"),
1437 m_stop_id);
1438 return error;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439}
1440
1441
1442Error
1443Process::EnableWatchpoint (WatchpointLocation *watchpoint)
1444{
1445 Error error;
1446 error.SetErrorString("watchpoints are not supported");
1447 return error;
1448}
1449
1450Error
1451Process::DisableWatchpoint (WatchpointLocation *watchpoint)
1452{
1453 Error error;
1454 error.SetErrorString("watchpoints are not supported");
1455 return error;
1456}
1457
1458StateType
1459Process::WaitForProcessStopPrivate (const TimeValue *timeout, EventSP &event_sp)
1460{
1461 StateType state;
1462 // Now wait for the process to launch and return control to us, and then
1463 // call DidLaunch:
1464 while (1)
1465 {
Greg Clayton6779606a2011-01-22 23:43:18 +00001466 event_sp.reset();
1467 state = WaitForStateChangedEventsPrivate (timeout, event_sp);
1468
1469 if (StateIsStoppedState(state))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001470 break;
Greg Clayton6779606a2011-01-22 23:43:18 +00001471
1472 // If state is invalid, then we timed out
1473 if (state == eStateInvalid)
1474 break;
1475
1476 if (event_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001477 HandlePrivateEvent (event_sp);
1478 }
1479 return state;
1480}
1481
1482Error
1483Process::Launch
1484(
1485 char const *argv[],
1486 char const *envp[],
Greg Claytonf681b942010-08-31 18:35:14 +00001487 uint32_t launch_flags,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488 const char *stdin_path,
1489 const char *stdout_path,
Greg Claytonbd82a5d2011-01-23 05:56:20 +00001490 const char *stderr_path,
1491 const char *working_directory
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001492)
1493{
1494 Error error;
1495 m_target_triple.Clear();
1496 m_abi_sp.reset();
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001497 m_process_input_reader.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001498
1499 Module *exe_module = m_target.GetExecutableModule().get();
1500 if (exe_module)
1501 {
1502 char exec_file_path[PATH_MAX];
1503 exe_module->GetFileSpec().GetPath(exec_file_path, sizeof(exec_file_path));
1504 if (exe_module->GetFileSpec().Exists())
1505 {
1506 error = WillLaunch (exe_module);
1507 if (error.Success())
1508 {
Greg Clayton05faeb72010-10-07 04:19:01 +00001509 SetPublicState (eStateLaunching);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001510 // The args coming in should not contain the application name, the
1511 // lldb_private::Process class will add this in case the executable
1512 // gets resolved to a different file than was given on the command
1513 // line (like when an applicaiton bundle is specified and will
1514 // resolve to the contained exectuable file, or the file given was
1515 // a symlink or other file system link that resolves to a different
1516 // file).
1517
1518 // Get the resolved exectuable path
1519
1520 // Make a new argument vector
1521 std::vector<const char *> exec_path_plus_argv;
1522 // Append the resolved executable path
1523 exec_path_plus_argv.push_back (exec_file_path);
1524
1525 // Push all args if there are any
1526 if (argv)
1527 {
1528 for (int i = 0; argv[i]; ++i)
1529 exec_path_plus_argv.push_back(argv[i]);
1530 }
1531
1532 // Push a NULL to terminate the args.
1533 exec_path_plus_argv.push_back(NULL);
1534
1535 // Now launch using these arguments.
Greg Clayton471b31c2010-07-20 22:52:08 +00001536 error = DoLaunch (exe_module,
1537 exec_path_plus_argv.empty() ? NULL : &exec_path_plus_argv.front(),
1538 envp,
Greg Claytonf681b942010-08-31 18:35:14 +00001539 launch_flags,
Greg Clayton471b31c2010-07-20 22:52:08 +00001540 stdin_path,
1541 stdout_path,
Greg Claytonbd82a5d2011-01-23 05:56:20 +00001542 stderr_path,
1543 working_directory);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001544
1545 if (error.Fail())
1546 {
1547 if (GetID() != LLDB_INVALID_PROCESS_ID)
1548 {
1549 SetID (LLDB_INVALID_PROCESS_ID);
1550 const char *error_string = error.AsCString();
1551 if (error_string == NULL)
1552 error_string = "launch failed";
1553 SetExitStatus (-1, error_string);
1554 }
1555 }
1556 else
1557 {
1558 EventSP event_sp;
1559 StateType state = WaitForProcessStopPrivate(NULL, event_sp);
1560
1561 if (state == eStateStopped || state == eStateCrashed)
1562 {
1563 DidLaunch ();
1564
1565 // This delays passing the stopped event to listeners till DidLaunch gets
1566 // a chance to complete...
1567 HandlePrivateEvent (event_sp);
1568 StartPrivateStateThread ();
1569 }
1570 else if (state == eStateExited)
1571 {
1572 // We exited while trying to launch somehow. Don't call DidLaunch as that's
1573 // not likely to work, and return an invalid pid.
1574 HandlePrivateEvent (event_sp);
1575 }
1576 }
1577 }
1578 }
1579 else
1580 {
1581 error.SetErrorStringWithFormat("File doesn't exist: '%s'.\n", exec_file_path);
1582 }
1583 }
1584 return error;
1585}
1586
Jim Inghambb3a2832011-01-29 01:49:25 +00001587Process::NextEventAction::EventActionResult
1588Process::AttachCompletionHandler::PerformAction (lldb::EventSP &event_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001589{
Jim Inghambb3a2832011-01-29 01:49:25 +00001590 StateType state = ProcessEventData::GetStateFromEvent (event_sp.get());
1591 switch (state)
Greg Clayton19388cf2010-10-18 01:45:30 +00001592 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001593 case eStateStopped:
1594 case eStateCrashed:
1595 {
1596 m_process->DidAttach ();
Jim Ingham5aee1622010-08-09 23:31:02 +00001597 // Figure out which one is the executable, and set that in our target:
Jim Inghambb3a2832011-01-29 01:49:25 +00001598 ModuleList &modules = m_process->GetTarget().GetImages();
Jim Ingham5aee1622010-08-09 23:31:02 +00001599
1600 size_t num_modules = modules.GetSize();
1601 for (int i = 0; i < num_modules; i++)
1602 {
1603 ModuleSP module_sp = modules.GetModuleAtIndex(i);
1604 if (module_sp->IsExecutable())
1605 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001606 ModuleSP exec_module = m_process->GetTarget().GetExecutableModule();
Jim Ingham5aee1622010-08-09 23:31:02 +00001607 if (!exec_module || exec_module != module_sp)
1608 {
1609
Jim Inghambb3a2832011-01-29 01:49:25 +00001610 m_process->GetTarget().SetExecutableModule (module_sp, false);
Jim Ingham5aee1622010-08-09 23:31:02 +00001611 }
1612 break;
1613 }
1614 }
Jim Inghambb3a2832011-01-29 01:49:25 +00001615 return eEventActionSuccess;
1616 }
1617 break;
1618 default:
1619 case eStateExited:
1620 case eStateInvalid:
1621 m_exit_string.assign ("No valid Process");
1622 return eEventActionExit;
1623 break;
1624 }
1625}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001626
Jim Inghambb3a2832011-01-29 01:49:25 +00001627Process::NextEventAction::EventActionResult
1628Process::AttachCompletionHandler::HandleBeingInterrupted()
1629{
1630 return eEventActionSuccess;
1631}
1632
1633const char *
1634Process::AttachCompletionHandler::GetExitString ()
1635{
1636 return m_exit_string.c_str();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001637}
1638
1639Error
1640Process::Attach (lldb::pid_t attach_pid)
1641{
1642
1643 m_target_triple.Clear();
1644 m_abi_sp.reset();
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001645 m_process_input_reader.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001646
Jim Ingham5aee1622010-08-09 23:31:02 +00001647 // Find the process and its architecture. Make sure it matches the architecture
1648 // of the current Target, and if not adjust it.
1649
1650 ArchSpec attach_spec = GetArchSpecForExistingProcess (attach_pid);
1651 if (attach_spec != GetTarget().GetArchitecture())
1652 {
1653 // Set the architecture on the target.
1654 GetTarget().SetArchitecture(attach_spec);
1655 }
1656
Greg Claytonc982c762010-07-09 20:39:50 +00001657 Error error (WillAttachToProcessWithID(attach_pid));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001658 if (error.Success())
1659 {
Greg Clayton05faeb72010-10-07 04:19:01 +00001660 SetPublicState (eStateAttaching);
1661
Greg Claytonc982c762010-07-09 20:39:50 +00001662 error = DoAttachToProcessWithID (attach_pid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001663 if (error.Success())
1664 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001665 SetNextEventAction(new Process::AttachCompletionHandler(this));
1666 StartPrivateStateThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001667 }
1668 else
1669 {
1670 if (GetID() != LLDB_INVALID_PROCESS_ID)
1671 {
1672 SetID (LLDB_INVALID_PROCESS_ID);
1673 const char *error_string = error.AsCString();
1674 if (error_string == NULL)
1675 error_string = "attach failed";
1676
1677 SetExitStatus(-1, error_string);
1678 }
1679 }
1680 }
1681 return error;
1682}
1683
1684Error
1685Process::Attach (const char *process_name, bool wait_for_launch)
1686{
1687 m_target_triple.Clear();
1688 m_abi_sp.reset();
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001689 m_process_input_reader.reset();
Jim Ingham5aee1622010-08-09 23:31:02 +00001690
1691 // Find the process and its architecture. Make sure it matches the architecture
1692 // of the current Target, and if not adjust it.
1693
Jim Ingham2ecb7422010-08-17 21:54:19 +00001694 if (!wait_for_launch)
Jim Ingham5aee1622010-08-09 23:31:02 +00001695 {
Jim Ingham2ecb7422010-08-17 21:54:19 +00001696 ArchSpec attach_spec = GetArchSpecForExistingProcess (process_name);
Greg Clayton19388cf2010-10-18 01:45:30 +00001697 if (attach_spec.IsValid() && attach_spec != GetTarget().GetArchitecture())
Jim Ingham2ecb7422010-08-17 21:54:19 +00001698 {
1699 // Set the architecture on the target.
1700 GetTarget().SetArchitecture(attach_spec);
1701 }
Jim Ingham5aee1622010-08-09 23:31:02 +00001702 }
Jim Ingham2ecb7422010-08-17 21:54:19 +00001703
Greg Claytonc982c762010-07-09 20:39:50 +00001704 Error error (WillAttachToProcessWithName(process_name, wait_for_launch));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001705 if (error.Success())
1706 {
Greg Clayton05faeb72010-10-07 04:19:01 +00001707 SetPublicState (eStateAttaching);
Greg Claytonc982c762010-07-09 20:39:50 +00001708 error = DoAttachToProcessWithName (process_name, wait_for_launch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001709 if (error.Fail())
1710 {
1711 if (GetID() != LLDB_INVALID_PROCESS_ID)
1712 {
1713 SetID (LLDB_INVALID_PROCESS_ID);
1714 const char *error_string = error.AsCString();
1715 if (error_string == NULL)
1716 error_string = "attach failed";
1717
1718 SetExitStatus(-1, error_string);
1719 }
1720 }
1721 else
1722 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001723 SetNextEventAction(new Process::AttachCompletionHandler(this));
1724 StartPrivateStateThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001725 }
1726 }
1727 return error;
1728}
1729
1730Error
1731Process::Resume ()
1732{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001733 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001734 if (log)
Jim Ingham444586b2011-01-24 06:34:17 +00001735 log->Printf("Process::Resume() m_stop_id = %u, public state: %s private state: %s",
1736 m_stop_id,
1737 StateAsCString(m_public_state.GetValue()),
1738 StateAsCString(m_private_state.GetValue()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001739
1740 Error error (WillResume());
1741 // Tell the process it is about to resume before the thread list
1742 if (error.Success())
1743 {
Johnny Chenc4221e42010-12-02 20:53:05 +00001744 // Now let the thread list know we are about to resume so it
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001745 // can let all of our threads know that they are about to be
1746 // resumed. Threads will each be called with
1747 // Thread::WillResume(StateType) where StateType contains the state
1748 // that they are supposed to have when the process is resumed
1749 // (suspended/running/stepping). Threads should also check
1750 // their resume signal in lldb::Thread::GetResumeSignal()
1751 // to see if they are suppoed to start back up with a signal.
1752 if (m_thread_list.WillResume())
1753 {
1754 error = DoResume();
1755 if (error.Success())
1756 {
1757 DidResume();
1758 m_thread_list.DidResume();
Jim Ingham444586b2011-01-24 06:34:17 +00001759 if (log)
1760 log->Printf ("Process thinks the process has resumed.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001761 }
1762 }
1763 else
1764 {
Jim Ingham444586b2011-01-24 06:34:17 +00001765 error.SetErrorStringWithFormat("Process::WillResume() thread list returned false after WillResume");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001766 }
1767 }
Jim Ingham444586b2011-01-24 06:34:17 +00001768 else if (log)
1769 log->Printf ("Process::WillResume() got an error \"%s\".", error.AsCString("<unknown error>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001770 return error;
1771}
1772
1773Error
1774Process::Halt ()
1775{
Jim Inghambb3a2832011-01-29 01:49:25 +00001776 // Pause our private state thread so we can ensure no one else eats
1777 // the stop event out from under us.
1778 PausePrivateStateThread();
Greg Clayton3af9ea52010-11-18 05:57:03 +00001779
Jim Inghambb3a2832011-01-29 01:49:25 +00001780 EventSP event_sp;
1781 Error error;
1782
1783 if (m_public_state.GetValue() == eStateAttaching)
1784 {
1785 SetExitStatus(SIGKILL, "Cancelled async attach.");
1786 }
1787 else
1788 {
1789 error = WillHalt();
1790
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001791 if (error.Success())
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001792 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001793
1794 bool caused_stop = false;
1795
1796 // Ask the process subclass to actually halt our process
1797 error = DoHalt(caused_stop);
1798 if (error.Success())
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001799 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001800 // If "caused_stop" is true, then DoHalt stopped the process. If
1801 // "caused_stop" is false, the process was already stopped.
1802 // If the DoHalt caused the process to stop, then we want to catch
1803 // this event and set the interrupted bool to true before we pass
1804 // this along so clients know that the process was interrupted by
1805 // a halt command.
1806 if (caused_stop)
Greg Clayton3af9ea52010-11-18 05:57:03 +00001807 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001808 // Wait for 2 seconds for the process to stop.
1809 TimeValue timeout_time;
1810 timeout_time = TimeValue::Now();
1811 timeout_time.OffsetWithSeconds(1);
1812 StateType state = WaitForStateChangedEventsPrivate (&timeout_time, event_sp);
1813
1814 if (state == eStateInvalid)
Greg Clayton3af9ea52010-11-18 05:57:03 +00001815 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001816 // We timeout out and didn't get a stop event...
1817 error.SetErrorString ("Halt timed out.");
Greg Clayton3af9ea52010-11-18 05:57:03 +00001818 }
1819 else
1820 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001821 if (StateIsStoppedState (state))
1822 {
1823 // We caused the process to interrupt itself, so mark this
1824 // as such in the stop event so clients can tell an interrupted
1825 // process from a natural stop
1826 ProcessEventData::SetInterruptedInEvent (event_sp.get(), true);
1827 }
1828 else
1829 {
1830 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
1831 if (log)
1832 log->Printf("Process::Halt() failed to stop, state is: %s", StateAsCString(state));
1833 error.SetErrorString ("Did not get stopped event after halt.");
1834 }
Greg Clayton3af9ea52010-11-18 05:57:03 +00001835 }
1836 }
Jim Inghambb3a2832011-01-29 01:49:25 +00001837 DidHalt();
1838
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001839 }
1840 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001841 }
Jim Inghambb3a2832011-01-29 01:49:25 +00001842 // Resume our private state thread before we post the event (if any)
1843 ResumePrivateStateThread();
1844
1845 // Post any event we might have consumed. If all goes well, we will have
1846 // stopped the process, intercepted the event and set the interrupted
1847 // bool in the event. Post it to the private event queue and that will end up
1848 // correctly setting the state.
1849 if (event_sp)
1850 m_private_state_broadcaster.BroadcastEvent(event_sp);
1851
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001852 return error;
1853}
1854
1855Error
1856Process::Detach ()
1857{
1858 Error error (WillDetach());
1859
1860 if (error.Success())
1861 {
1862 DisableAllBreakpointSites();
1863 error = DoDetach();
1864 if (error.Success())
1865 {
1866 DidDetach();
1867 StopPrivateStateThread();
1868 }
1869 }
1870 return error;
1871}
1872
1873Error
1874Process::Destroy ()
1875{
1876 Error error (WillDestroy());
1877 if (error.Success())
1878 {
1879 DisableAllBreakpointSites();
1880 error = DoDestroy();
1881 if (error.Success())
1882 {
1883 DidDestroy();
1884 StopPrivateStateThread();
1885 }
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001886 m_stdio_communication.StopReadThread();
1887 m_stdio_communication.Disconnect();
1888 if (m_process_input_reader && m_process_input_reader->IsActive())
1889 m_target.GetDebugger().PopInputReader (m_process_input_reader);
1890 if (m_process_input_reader)
1891 m_process_input_reader.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001892 }
1893 return error;
1894}
1895
1896Error
1897Process::Signal (int signal)
1898{
1899 Error error (WillSignal());
1900 if (error.Success())
1901 {
1902 error = DoSignal(signal);
1903 if (error.Success())
1904 DidSignal();
1905 }
1906 return error;
1907}
1908
1909UnixSignals &
1910Process::GetUnixSignals ()
1911{
1912 return m_unix_signals;
1913}
1914
1915Target &
1916Process::GetTarget ()
1917{
1918 return m_target;
1919}
1920
1921const Target &
1922Process::GetTarget () const
1923{
1924 return m_target;
1925}
1926
1927uint32_t
1928Process::GetAddressByteSize()
1929{
Greg Clayton3af9ea52010-11-18 05:57:03 +00001930 if (m_addr_byte_size == 0)
1931 return m_target.GetArchitecture().GetAddressByteSize();
1932 return m_addr_byte_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001933}
1934
1935bool
1936Process::ShouldBroadcastEvent (Event *event_ptr)
1937{
1938 const StateType state = Process::ProcessEventData::GetStateFromEvent (event_ptr);
1939 bool return_value = true;
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001940 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001941
1942 switch (state)
1943 {
1944 case eStateAttaching:
1945 case eStateLaunching:
1946 case eStateDetached:
1947 case eStateExited:
1948 case eStateUnloaded:
1949 // These events indicate changes in the state of the debugging session, always report them.
1950 return_value = true;
1951 break;
1952 case eStateInvalid:
1953 // We stopped for no apparent reason, don't report it.
1954 return_value = false;
1955 break;
1956 case eStateRunning:
1957 case eStateStepping:
1958 // If we've started the target running, we handle the cases where we
1959 // are already running and where there is a transition from stopped to
1960 // running differently.
1961 // running -> running: Automatically suppress extra running events
1962 // stopped -> running: Report except when there is one or more no votes
1963 // and no yes votes.
1964 SynchronouslyNotifyStateChanged (state);
1965 switch (m_public_state.GetValue())
1966 {
1967 case eStateRunning:
1968 case eStateStepping:
1969 // We always suppress multiple runnings with no PUBLIC stop in between.
1970 return_value = false;
1971 break;
1972 default:
1973 // TODO: make this work correctly. For now always report
1974 // run if we aren't running so we don't miss any runnning
1975 // events. If I run the lldb/test/thread/a.out file and
1976 // break at main.cpp:58, run and hit the breakpoints on
1977 // multiple threads, then somehow during the stepping over
1978 // of all breakpoints no run gets reported.
1979 return_value = true;
1980
1981 // This is a transition from stop to run.
1982 switch (m_thread_list.ShouldReportRun (event_ptr))
1983 {
1984 case eVoteYes:
1985 case eVoteNoOpinion:
1986 return_value = true;
1987 break;
1988 case eVoteNo:
1989 return_value = false;
1990 break;
1991 }
1992 break;
1993 }
1994 break;
1995 case eStateStopped:
1996 case eStateCrashed:
1997 case eStateSuspended:
1998 {
1999 // We've stopped. First see if we're going to restart the target.
2000 // If we are going to stop, then we always broadcast the event.
2001 // If we aren't going to stop, let the thread plans decide if we're going to report this event.
Jim Inghamb01e7422010-06-19 04:45:32 +00002002 // If no thread has an opinion, we don't report it.
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002003 if (ProcessEventData::GetInterruptedFromEvent (event_ptr))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002004 {
Greg Clayton3af9ea52010-11-18 05:57:03 +00002005 if (log)
2006 log->Printf ("Process::ShouldBroadcastEvent (%p) stopped due to an interrupt, state: %s", event_ptr, StateAsCString(state));
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002007 return true;
2008 }
2009 else
2010 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002011 RefreshStateAfterStop ();
2012
2013 if (m_thread_list.ShouldStop (event_ptr) == false)
2014 {
2015 switch (m_thread_list.ShouldReportStop (event_ptr))
2016 {
2017 case eVoteYes:
2018 Process::ProcessEventData::SetRestartedInEvent (event_ptr, true);
Johnny Chen3c230652010-10-14 00:54:32 +00002019 // Intentional fall-through here.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002020 case eVoteNoOpinion:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002021 case eVoteNo:
2022 return_value = false;
2023 break;
2024 }
2025
2026 if (log)
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002027 log->Printf ("Process::ShouldBroadcastEvent (%p) Restarting process from state: %s", event_ptr, StateAsCString(state));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002028 Resume ();
2029 }
2030 else
2031 {
2032 return_value = true;
2033 SynchronouslyNotifyStateChanged (state);
2034 }
2035 }
2036 }
2037 }
2038
2039 if (log)
2040 log->Printf ("Process::ShouldBroadcastEvent (%p) => %s", event_ptr, StateAsCString(state), return_value ? "YES" : "NO");
2041 return return_value;
2042}
2043
2044//------------------------------------------------------------------
2045// Thread Queries
2046//------------------------------------------------------------------
2047
2048ThreadList &
2049Process::GetThreadList ()
2050{
2051 return m_thread_list;
2052}
2053
2054const ThreadList &
2055Process::GetThreadList () const
2056{
2057 return m_thread_list;
2058}
2059
2060
2061bool
2062Process::StartPrivateStateThread ()
2063{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00002064 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002065
2066 if (log)
2067 log->Printf ("Process::%s ( )", __FUNCTION__);
2068
2069 // Create a thread that watches our internal state and controls which
2070 // events make it to clients (into the DCProcess event queue).
Greg Clayton3e06bd92011-01-09 21:07:35 +00002071 char thread_name[1024];
2072 snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state(pid=%i)>", GetID());
2073 m_private_state_thread = Host::ThreadCreate (thread_name, Process::PrivateStateThread, this, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002074 return m_private_state_thread != LLDB_INVALID_HOST_THREAD;
2075}
2076
2077void
2078Process::PausePrivateStateThread ()
2079{
2080 ControlPrivateStateThread (eBroadcastInternalStateControlPause);
2081}
2082
2083void
2084Process::ResumePrivateStateThread ()
2085{
2086 ControlPrivateStateThread (eBroadcastInternalStateControlResume);
2087}
2088
2089void
2090Process::StopPrivateStateThread ()
2091{
2092 ControlPrivateStateThread (eBroadcastInternalStateControlStop);
2093}
2094
2095void
2096Process::ControlPrivateStateThread (uint32_t signal)
2097{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00002098 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002099
2100 assert (signal == eBroadcastInternalStateControlStop ||
2101 signal == eBroadcastInternalStateControlPause ||
2102 signal == eBroadcastInternalStateControlResume);
2103
2104 if (log)
Greg Clayton7ecb3a02011-01-22 17:43:17 +00002105 log->Printf ("Process::%s (signal = %d)", __FUNCTION__, signal);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002106
Greg Clayton7ecb3a02011-01-22 17:43:17 +00002107 // Signal the private state thread. First we should copy this is case the
2108 // thread starts exiting since the private state thread will NULL this out
2109 // when it exits
2110 const lldb::thread_t private_state_thread = m_private_state_thread;
2111 if (private_state_thread != LLDB_INVALID_HOST_THREAD)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002112 {
2113 TimeValue timeout_time;
2114 bool timed_out;
2115
2116 m_private_state_control_broadcaster.BroadcastEvent (signal, NULL);
2117
2118 timeout_time = TimeValue::Now();
2119 timeout_time.OffsetWithSeconds(2);
2120 m_private_state_control_wait.WaitForValueEqualTo (true, &timeout_time, &timed_out);
2121 m_private_state_control_wait.SetValue (false, eBroadcastNever);
2122
2123 if (signal == eBroadcastInternalStateControlStop)
2124 {
2125 if (timed_out)
Greg Clayton7ecb3a02011-01-22 17:43:17 +00002126 Host::ThreadCancel (private_state_thread, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002127
2128 thread_result_t result = NULL;
Greg Clayton7ecb3a02011-01-22 17:43:17 +00002129 Host::ThreadJoin (private_state_thread, &result, NULL);
Greg Clayton49182ed2010-07-22 18:34:21 +00002130 m_private_state_thread = LLDB_INVALID_HOST_THREAD;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002131 }
2132 }
2133}
2134
2135void
2136Process::HandlePrivateEvent (EventSP &event_sp)
2137{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00002138 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Jim Inghambb3a2832011-01-29 01:49:25 +00002139
Greg Clayton414f5d32011-01-25 02:58:48 +00002140 const StateType new_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
Jim Inghambb3a2832011-01-29 01:49:25 +00002141
2142 // First check to see if anybody wants a shot at this event:
Jim Ingham754ab982011-01-29 04:05:41 +00002143 if (m_next_event_action_ap.get() != NULL)
Jim Inghambb3a2832011-01-29 01:49:25 +00002144 {
Jim Ingham754ab982011-01-29 04:05:41 +00002145 NextEventAction::EventActionResult action_result = m_next_event_action_ap->PerformAction(event_sp);
Jim Inghambb3a2832011-01-29 01:49:25 +00002146 switch (action_result)
2147 {
2148 case NextEventAction::eEventActionSuccess:
2149 SetNextEventAction(NULL);
2150 break;
2151 case NextEventAction::eEventActionRetry:
2152 break;
2153 case NextEventAction::eEventActionExit:
Jim Ingham2a5fdd42011-01-29 01:57:31 +00002154 // Handle Exiting Here. If we already got an exited event,
2155 // we should just propagate it. Otherwise, swallow this event,
2156 // and set our state to exit so the next event will kill us.
2157 if (new_state != eStateExited)
2158 {
2159 // FIXME: should cons up an exited event, and discard this one.
Jim Ingham754ab982011-01-29 04:05:41 +00002160 SetExitStatus(0, m_next_event_action_ap->GetExitString());
Jim Ingham2a5fdd42011-01-29 01:57:31 +00002161 SetNextEventAction(NULL);
2162 return;
2163 }
2164 SetNextEventAction(NULL);
Jim Inghambb3a2832011-01-29 01:49:25 +00002165 break;
2166 }
2167 }
2168
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002169 // See if we should broadcast this state to external clients?
2170 const bool should_broadcast = ShouldBroadcastEvent (event_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002171
2172 if (should_broadcast)
2173 {
2174 if (log)
2175 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002176 log->Printf ("Process::%s (pid = %i) broadcasting new state %s (old state %s) to %s",
2177 __FUNCTION__,
2178 GetID(),
2179 StateAsCString(new_state),
2180 StateAsCString (GetState ()),
2181 IsHijackedForEvent(eBroadcastBitStateChanged) ? "hijacked" : "public");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002182 }
Greg Clayton414f5d32011-01-25 02:58:48 +00002183 if (StateIsRunningState (new_state))
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002184 PushProcessInputReader ();
2185 else
2186 PopProcessInputReader ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002187 Process::ProcessEventData::SetUpdateStateOnRemoval(event_sp.get());
2188 BroadcastEvent (event_sp);
2189 }
2190 else
2191 {
2192 if (log)
2193 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002194 log->Printf ("Process::%s (pid = %i) suppressing state %s (old state %s): should_broadcast == false",
2195 __FUNCTION__,
2196 GetID(),
2197 StateAsCString(new_state),
2198 StateAsCString (GetState ()),
2199 IsHijackedForEvent(eBroadcastBitStateChanged) ? "hijacked" : "public");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002200 }
2201 }
2202}
2203
2204void *
2205Process::PrivateStateThread (void *arg)
2206{
2207 Process *proc = static_cast<Process*> (arg);
2208 void *result = proc->RunPrivateStateThread ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002209 return result;
2210}
2211
2212void *
2213Process::RunPrivateStateThread ()
2214{
2215 bool control_only = false;
2216 m_private_state_control_wait.SetValue (false, eBroadcastNever);
2217
Greg Clayton2d4edfb2010-11-06 01:53:30 +00002218 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002219 if (log)
2220 log->Printf ("Process::%s (arg = %p, pid = %i) thread starting...", __FUNCTION__, this, GetID());
2221
2222 bool exit_now = false;
2223 while (!exit_now)
2224 {
2225 EventSP event_sp;
2226 WaitForEventsPrivate (NULL, event_sp, control_only);
2227 if (event_sp->BroadcasterIs(&m_private_state_control_broadcaster))
2228 {
2229 switch (event_sp->GetType())
2230 {
2231 case eBroadcastInternalStateControlStop:
2232 exit_now = true;
2233 continue; // Go to next loop iteration so we exit without
2234 break; // doing any internal state managment below
2235
2236 case eBroadcastInternalStateControlPause:
2237 control_only = true;
2238 break;
2239
2240 case eBroadcastInternalStateControlResume:
2241 control_only = false;
2242 break;
2243 }
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002244
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002245 if (log)
2246 log->Printf ("Process::%s (arg = %p, pid = %i) got a control event: %d", __FUNCTION__, this, GetID(), event_sp->GetType());
2247
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002248 m_private_state_control_wait.SetValue (true, eBroadcastAlways);
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002249 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002250 }
2251
2252
2253 const StateType internal_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
2254
2255 if (internal_state != eStateInvalid)
2256 {
2257 HandlePrivateEvent (event_sp);
2258 }
2259
Greg Clayton58d1c9a2010-10-18 04:14:23 +00002260 if (internal_state == eStateInvalid ||
2261 internal_state == eStateExited ||
2262 internal_state == eStateDetached )
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002263 {
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002264 if (log)
2265 log->Printf ("Process::%s (arg = %p, pid = %i) about to exit with internal state %s...", __FUNCTION__, this, GetID(), StateAsCString(internal_state));
2266
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002267 break;
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002268 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002269 }
2270
Caroline Tice20ad3c42010-10-29 21:48:37 +00002271 // Verify log is still enabled before attempting to write to it...
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002272 if (log)
2273 log->Printf ("Process::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, this, GetID());
2274
Greg Clayton6ed95942011-01-22 07:12:45 +00002275 m_private_state_control_wait.SetValue (true, eBroadcastAlways);
2276 m_private_state_thread = LLDB_INVALID_HOST_THREAD;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002277 return NULL;
2278}
2279
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002280//------------------------------------------------------------------
2281// Process Event Data
2282//------------------------------------------------------------------
2283
2284Process::ProcessEventData::ProcessEventData () :
2285 EventData (),
2286 m_process_sp (),
2287 m_state (eStateInvalid),
Greg Claytonc982c762010-07-09 20:39:50 +00002288 m_restarted (false),
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002289 m_update_state (false),
2290 m_interrupted (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002291{
2292}
2293
2294Process::ProcessEventData::ProcessEventData (const ProcessSP &process_sp, StateType state) :
2295 EventData (),
2296 m_process_sp (process_sp),
2297 m_state (state),
Greg Claytonc982c762010-07-09 20:39:50 +00002298 m_restarted (false),
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002299 m_update_state (false),
2300 m_interrupted (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002301{
2302}
2303
2304Process::ProcessEventData::~ProcessEventData()
2305{
2306}
2307
2308const ConstString &
2309Process::ProcessEventData::GetFlavorString ()
2310{
2311 static ConstString g_flavor ("Process::ProcessEventData");
2312 return g_flavor;
2313}
2314
2315const ConstString &
2316Process::ProcessEventData::GetFlavor () const
2317{
2318 return ProcessEventData::GetFlavorString ();
2319}
2320
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002321void
2322Process::ProcessEventData::DoOnRemoval (Event *event_ptr)
2323{
2324 // This function gets called twice for each event, once when the event gets pulled
2325 // off of the private process event queue, and once when it gets pulled off of
2326 // the public event queue. m_update_state is used to distinguish these
2327 // two cases; it is false when we're just pulling it off for private handling,
2328 // and we don't want to do the breakpoint command handling then.
2329
2330 if (!m_update_state)
2331 return;
2332
2333 m_process_sp->SetPublicState (m_state);
2334
2335 // If we're stopped and haven't restarted, then do the breakpoint commands here:
2336 if (m_state == eStateStopped && ! m_restarted)
2337 {
2338 int num_threads = m_process_sp->GetThreadList().GetSize();
2339 int idx;
Greg Claytonf4b47e12010-08-04 01:40:35 +00002340
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002341 for (idx = 0; idx < num_threads; ++idx)
2342 {
2343 lldb::ThreadSP thread_sp = m_process_sp->GetThreadList().GetThreadAtIndex(idx);
2344
Jim Inghamb15bfc72010-10-20 00:39:53 +00002345 StopInfoSP stop_info_sp = thread_sp->GetStopInfo ();
2346 if (stop_info_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002347 {
Jim Inghamb15bfc72010-10-20 00:39:53 +00002348 stop_info_sp->PerformAction(event_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002349 }
2350 }
Greg Claytonf4b47e12010-08-04 01:40:35 +00002351
Jim Ingham3ebcf7f2010-08-10 00:59:59 +00002352 // The stop action might restart the target. If it does, then we want to mark that in the
2353 // event so that whoever is receiving it will know to wait for the running event and reflect
2354 // that state appropriately.
2355
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002356 if (m_process_sp->GetPrivateState() == eStateRunning)
2357 SetRestarted(true);
2358 }
2359}
2360
2361void
2362Process::ProcessEventData::Dump (Stream *s) const
2363{
2364 if (m_process_sp)
2365 s->Printf(" process = %p (pid = %u), ", m_process_sp.get(), m_process_sp->GetID());
2366
2367 s->Printf("state = %s", StateAsCString(GetState()));;
2368}
2369
2370const Process::ProcessEventData *
2371Process::ProcessEventData::GetEventDataFromEvent (const Event *event_ptr)
2372{
2373 if (event_ptr)
2374 {
2375 const EventData *event_data = event_ptr->GetData();
2376 if (event_data && event_data->GetFlavor() == ProcessEventData::GetFlavorString())
2377 return static_cast <const ProcessEventData *> (event_ptr->GetData());
2378 }
2379 return NULL;
2380}
2381
2382ProcessSP
2383Process::ProcessEventData::GetProcessFromEvent (const Event *event_ptr)
2384{
2385 ProcessSP process_sp;
2386 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2387 if (data)
2388 process_sp = data->GetProcessSP();
2389 return process_sp;
2390}
2391
2392StateType
2393Process::ProcessEventData::GetStateFromEvent (const Event *event_ptr)
2394{
2395 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2396 if (data == NULL)
2397 return eStateInvalid;
2398 else
2399 return data->GetState();
2400}
2401
2402bool
2403Process::ProcessEventData::GetRestartedFromEvent (const Event *event_ptr)
2404{
2405 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2406 if (data == NULL)
2407 return false;
2408 else
2409 return data->GetRestarted();
2410}
2411
2412void
2413Process::ProcessEventData::SetRestartedInEvent (Event *event_ptr, bool new_value)
2414{
2415 ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr));
2416 if (data != NULL)
2417 data->SetRestarted(new_value);
2418}
2419
2420bool
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002421Process::ProcessEventData::GetInterruptedFromEvent (const Event *event_ptr)
2422{
2423 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2424 if (data == NULL)
2425 return false;
2426 else
2427 return data->GetInterrupted ();
2428}
2429
2430void
2431Process::ProcessEventData::SetInterruptedInEvent (Event *event_ptr, bool new_value)
2432{
2433 ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr));
2434 if (data != NULL)
2435 data->SetInterrupted(new_value);
2436}
2437
2438bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002439Process::ProcessEventData::SetUpdateStateOnRemoval (Event *event_ptr)
2440{
2441 ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr));
2442 if (data)
2443 {
2444 data->SetUpdateStateOnRemoval();
2445 return true;
2446 }
2447 return false;
2448}
2449
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002450Target *
2451Process::CalculateTarget ()
2452{
2453 return &m_target;
2454}
2455
2456Process *
2457Process::CalculateProcess ()
2458{
2459 return this;
2460}
2461
2462Thread *
2463Process::CalculateThread ()
2464{
2465 return NULL;
2466}
2467
2468StackFrame *
2469Process::CalculateStackFrame ()
2470{
2471 return NULL;
2472}
2473
2474void
Greg Clayton0603aa92010-10-04 01:05:56 +00002475Process::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002476{
2477 exe_ctx.target = &m_target;
2478 exe_ctx.process = this;
2479 exe_ctx.thread = NULL;
2480 exe_ctx.frame = NULL;
2481}
2482
2483lldb::ProcessSP
2484Process::GetSP ()
2485{
2486 return GetTarget().GetProcessSP();
2487}
2488
Jim Ingham5aee1622010-08-09 23:31:02 +00002489uint32_t
2490Process::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids)
2491{
2492 return 0;
2493}
2494
2495ArchSpec
2496Process::GetArchSpecForExistingProcess (lldb::pid_t pid)
2497{
2498 return Host::GetArchSpecForExistingProcess (pid);
2499}
2500
2501ArchSpec
2502Process::GetArchSpecForExistingProcess (const char *process_name)
2503{
2504 return Host::GetArchSpecForExistingProcess (process_name);
2505}
2506
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002507void
2508Process::AppendSTDOUT (const char * s, size_t len)
2509{
Greg Clayton3af9ea52010-11-18 05:57:03 +00002510 Mutex::Locker locker (m_stdio_communication_mutex);
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002511 m_stdout_data.append (s, len);
2512
Greg Claytona9ff3062010-12-05 19:16:56 +00002513 BroadcastEventIfUnique (eBroadcastBitSTDOUT, new ProcessEventData (GetTarget().GetProcessSP(), GetState()));
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002514}
2515
2516void
2517Process::STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len)
2518{
2519 Process *process = (Process *) baton;
2520 process->AppendSTDOUT (static_cast<const char *>(src), src_len);
2521}
2522
2523size_t
2524Process::ProcessInputReaderCallback (void *baton,
2525 InputReader &reader,
2526 lldb::InputReaderAction notification,
2527 const char *bytes,
2528 size_t bytes_len)
2529{
2530 Process *process = (Process *) baton;
2531
2532 switch (notification)
2533 {
2534 case eInputReaderActivate:
2535 break;
2536
2537 case eInputReaderDeactivate:
2538 break;
2539
2540 case eInputReaderReactivate:
2541 break;
2542
2543 case eInputReaderGotToken:
2544 {
2545 Error error;
2546 process->PutSTDIN (bytes, bytes_len, error);
2547 }
2548 break;
2549
Caroline Ticeefed6132010-11-19 20:47:54 +00002550 case eInputReaderInterrupt:
2551 process->Halt ();
2552 break;
2553
2554 case eInputReaderEndOfFile:
2555 process->AppendSTDOUT ("^D", 2);
2556 break;
2557
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002558 case eInputReaderDone:
2559 break;
2560
2561 }
2562
2563 return bytes_len;
2564}
2565
2566void
2567Process::ResetProcessInputReader ()
2568{
2569 m_process_input_reader.reset();
2570}
2571
2572void
2573Process::SetUpProcessInputReader (int file_descriptor)
2574{
2575 // First set up the Read Thread for reading/handling process I/O
2576
2577 std::auto_ptr<ConnectionFileDescriptor> conn_ap (new ConnectionFileDescriptor (file_descriptor, true));
2578
2579 if (conn_ap.get())
2580 {
2581 m_stdio_communication.SetConnection (conn_ap.release());
2582 if (m_stdio_communication.IsConnected())
2583 {
2584 m_stdio_communication.SetReadThreadBytesReceivedCallback (STDIOReadThreadBytesReceived, this);
2585 m_stdio_communication.StartReadThread();
2586
2587 // Now read thread is set up, set up input reader.
2588
2589 if (!m_process_input_reader.get())
2590 {
2591 m_process_input_reader.reset (new InputReader(m_target.GetDebugger()));
2592 Error err (m_process_input_reader->Initialize (Process::ProcessInputReaderCallback,
2593 this,
2594 eInputReaderGranularityByte,
2595 NULL,
2596 NULL,
2597 false));
2598
2599 if (err.Fail())
2600 m_process_input_reader.reset();
2601 }
2602 }
2603 }
2604}
2605
2606void
2607Process::PushProcessInputReader ()
2608{
2609 if (m_process_input_reader && !m_process_input_reader->IsActive())
2610 m_target.GetDebugger().PushInputReader (m_process_input_reader);
2611}
2612
2613void
2614Process::PopProcessInputReader ()
2615{
2616 if (m_process_input_reader && m_process_input_reader->IsActive())
2617 m_target.GetDebugger().PopInputReader (m_process_input_reader);
2618}
2619
Greg Clayton99d0faf2010-11-18 23:32:35 +00002620
2621void
2622Process::Initialize ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002623{
Greg Clayton99d0faf2010-11-18 23:32:35 +00002624 UserSettingsControllerSP &usc = GetSettingsController();
2625 usc.reset (new SettingsController);
2626 UserSettingsController::InitializeSettingsController (usc,
2627 SettingsController::global_settings_table,
2628 SettingsController::instance_settings_table);
2629}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002630
Greg Clayton99d0faf2010-11-18 23:32:35 +00002631void
2632Process::Terminate ()
2633{
2634 UserSettingsControllerSP &usc = GetSettingsController();
2635 UserSettingsController::FinalizeSettingsController (usc);
2636 usc.reset();
2637}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002638
Greg Clayton99d0faf2010-11-18 23:32:35 +00002639UserSettingsControllerSP &
2640Process::GetSettingsController ()
2641{
2642 static UserSettingsControllerSP g_settings_controller;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002643 return g_settings_controller;
2644}
2645
Caroline Tice1559a462010-09-27 00:30:10 +00002646void
2647Process::UpdateInstanceName ()
2648{
2649 ModuleSP module_sp = GetTarget().GetExecutableModule();
2650 if (module_sp)
2651 {
2652 StreamString sstr;
2653 sstr.Printf ("%s", module_sp->GetFileSpec().GetFilename().AsCString());
2654
Greg Claytondbe54502010-11-19 03:46:01 +00002655 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
Caroline Tice1559a462010-09-27 00:30:10 +00002656 sstr.GetData());
2657 }
2658}
2659
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002660ExecutionResults
Jim Inghamf48169b2010-11-30 02:22:11 +00002661Process::RunThreadPlan (ExecutionContext &exe_ctx,
2662 lldb::ThreadPlanSP &thread_plan_sp,
2663 bool stop_others,
2664 bool try_all_threads,
2665 bool discard_on_error,
2666 uint32_t single_thread_timeout_usec,
2667 Stream &errors)
2668{
2669 ExecutionResults return_value = eExecutionSetupError;
2670
Jim Ingham77787032011-01-20 02:03:18 +00002671 if (thread_plan_sp.get() == NULL)
2672 {
2673 errors.Printf("RunThreadPlan called with empty thread plan.");
2674 return lldb::eExecutionSetupError;
2675 }
2676
Jim Ingham444586b2011-01-24 06:34:17 +00002677 if (m_private_state.GetValue() != eStateStopped)
2678 {
2679 errors.Printf ("RunThreadPlan called while the private state was not stopped.");
2680 // REMOVE BEAR TRAP...
2681 // abort();
2682 }
2683
Jim Inghamf48169b2010-11-30 02:22:11 +00002684 // Save this value for restoration of the execution context after we run
2685 uint32_t tid = exe_ctx.thread->GetIndexID();
2686
2687 // N.B. Running the target may unset the currently selected thread and frame. We don't want to do that either,
2688 // so we should arrange to reset them as well.
2689
2690 lldb::ThreadSP selected_thread_sp = exe_ctx.process->GetThreadList().GetSelectedThread();
2691 lldb::StackFrameSP selected_frame_sp;
2692
2693 uint32_t selected_tid;
2694 if (selected_thread_sp != NULL)
2695 {
2696 selected_tid = selected_thread_sp->GetIndexID();
2697 selected_frame_sp = selected_thread_sp->GetSelectedFrame();
2698 }
2699 else
2700 {
2701 selected_tid = LLDB_INVALID_THREAD_ID;
2702 }
2703
2704 exe_ctx.thread->QueueThreadPlan(thread_plan_sp, true);
2705
Jim Ingham1e7a9ee2011-01-23 21:14:08 +00002706 Listener listener("lldb.process.listener.run-thread-plan");
Jim Inghamf48169b2010-11-30 02:22:11 +00002707 exe_ctx.process->HijackProcessEvents(&listener);
Jim Ingham444586b2011-01-24 06:34:17 +00002708
Jim Ingham1e7a9ee2011-01-23 21:14:08 +00002709 lldb::LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS));
Jim Ingham77787032011-01-20 02:03:18 +00002710 if (log)
2711 {
2712 StreamString s;
2713 thread_plan_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
Greg Clayton414f5d32011-01-25 02:58:48 +00002714 log->Printf ("Process::RunThreadPlan(): Resuming thread %u - 0x%4.4x to run thread plan \"%s\".", exe_ctx.thread->GetIndexID(), exe_ctx.thread->GetID(), s.GetData());
Jim Ingham77787032011-01-20 02:03:18 +00002715 }
2716
Jim Inghamf48169b2010-11-30 02:22:11 +00002717 Error resume_error = exe_ctx.process->Resume ();
2718 if (!resume_error.Success())
2719 {
2720 errors.Printf("Error resuming inferior: \"%s\".\n", resume_error.AsCString());
2721 exe_ctx.process->RestoreProcessEvents();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002722 return lldb::eExecutionSetupError;
Jim Inghamf48169b2010-11-30 02:22:11 +00002723 }
2724
2725 // We need to call the function synchronously, so spin waiting for it to return.
2726 // If we get interrupted while executing, we're going to lose our context, and
2727 // won't be able to gather the result at this point.
2728 // We set the timeout AFTER the resume, since the resume takes some time and we
2729 // don't want to charge that to the timeout.
2730
2731 TimeValue* timeout_ptr = NULL;
2732 TimeValue real_timeout;
2733
2734 if (single_thread_timeout_usec != 0)
2735 {
2736 real_timeout = TimeValue::Now();
2737 real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec);
2738 timeout_ptr = &real_timeout;
2739 }
2740
Jim Inghamf48169b2010-11-30 02:22:11 +00002741 while (1)
2742 {
2743 lldb::EventSP event_sp;
2744 lldb::StateType stop_state = lldb::eStateInvalid;
2745 // Now wait for the process to stop again:
2746 bool got_event = listener.WaitForEvent (timeout_ptr, event_sp);
2747
2748 if (!got_event)
2749 {
2750 // Right now this is the only way to tell we've timed out...
2751 // We should interrupt the process here...
2752 // Not really sure what to do if Halt fails here...
Stephen Wilson78a4feb2011-01-12 04:20:03 +00002753 if (log) {
Jim Inghamf48169b2010-11-30 02:22:11 +00002754 if (try_all_threads)
Greg Clayton414f5d32011-01-25 02:58:48 +00002755 log->Printf ("Process::RunThreadPlan(): Running function with timeout: %d timed out, trying with all threads enabled.",
Jim Inghamf48169b2010-11-30 02:22:11 +00002756 single_thread_timeout_usec);
2757 else
Greg Clayton414f5d32011-01-25 02:58:48 +00002758 log->Printf ("Process::RunThreadPlan(): Running function with timeout: %d timed out, abandoning execution.",
Jim Inghamf48169b2010-11-30 02:22:11 +00002759 single_thread_timeout_usec);
Stephen Wilson78a4feb2011-01-12 04:20:03 +00002760 }
Jim Inghamf48169b2010-11-30 02:22:11 +00002761
Jim Inghame22e88b2011-01-22 01:30:53 +00002762 Error halt_error = exe_ctx.process->Halt();
2763
2764 if (halt_error.Success())
Jim Inghamf48169b2010-11-30 02:22:11 +00002765 {
2766 timeout_ptr = NULL;
2767 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002768 log->Printf ("Process::RunThreadPlan(): Halt succeeded.");
Jim Inghamf48169b2010-11-30 02:22:11 +00002769
2770 // Between the time that we got the timeout and the time we halted, but target
2771 // might have actually completed the plan. If so, we're done. Note, I call WFE here with a short
2772 // timeout to
2773 got_event = listener.WaitForEvent(NULL, event_sp);
2774
2775 if (got_event)
2776 {
2777 stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
2778 if (log)
2779 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002780 log->Printf ("Process::RunThreadPlan(): Stopped with event: %s", StateAsCString(stop_state));
Jim Inghamf48169b2010-11-30 02:22:11 +00002781 if (stop_state == lldb::eStateStopped && Process::ProcessEventData::GetInterruptedFromEvent(event_sp.get()))
2782 log->Printf (" Event was the Halt interruption event.");
2783 }
2784
2785 if (exe_ctx.thread->IsThreadPlanDone (thread_plan_sp.get()))
2786 {
2787 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002788 log->Printf ("Process::RunThreadPlan(): Even though we timed out, the call plan was done. Exiting wait loop.");
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002789 return_value = lldb::eExecutionCompleted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002790 break;
2791 }
2792
2793 if (try_all_threads
2794 && (stop_state == lldb::eStateStopped && Process::ProcessEventData::GetInterruptedFromEvent (event_sp.get())))
2795 {
2796
2797 thread_plan_sp->SetStopOthers (false);
2798 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002799 log->Printf ("Process::RunThreadPlan(): About to resume.");
Jim Inghamf48169b2010-11-30 02:22:11 +00002800
2801 exe_ctx.process->Resume();
2802 continue;
2803 }
2804 else
2805 {
2806 exe_ctx.process->RestoreProcessEvents ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002807 return lldb::eExecutionInterrupted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002808 }
2809 }
2810 }
Jim Inghame22e88b2011-01-22 01:30:53 +00002811 else
2812 {
2813
2814 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002815 log->Printf ("Process::RunThreadPlan(): halt failed: error = \"%s\", I'm just going to wait a little longer and see if the world gets nicer to me.",
Jim Inghame22e88b2011-01-22 01:30:53 +00002816 halt_error.AsCString());
Jim Ingham444586b2011-01-24 06:34:17 +00002817// abort();
Jim Inghame22e88b2011-01-22 01:30:53 +00002818
Jim Ingham1e7a9ee2011-01-23 21:14:08 +00002819 if (single_thread_timeout_usec != 0)
2820 {
2821 real_timeout = TimeValue::Now();
2822 real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec);
2823 timeout_ptr = &real_timeout;
2824 }
2825 continue;
Jim Inghame22e88b2011-01-22 01:30:53 +00002826 }
2827
Jim Inghamf48169b2010-11-30 02:22:11 +00002828 }
2829
2830 stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
2831 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002832 log->Printf("Process::RunThreadPlan(): got event: %s.", StateAsCString(stop_state));
Jim Inghamf48169b2010-11-30 02:22:11 +00002833
2834 if (stop_state == lldb::eStateRunning || stop_state == lldb::eStateStepping)
2835 continue;
2836
2837 if (exe_ctx.thread->IsThreadPlanDone (thread_plan_sp.get()))
2838 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002839 if (log)
2840 log->Printf("Process::RunThreadPlan(): thread plan is done");
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002841 return_value = lldb::eExecutionCompleted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002842 break;
2843 }
2844 else if (exe_ctx.thread->WasThreadPlanDiscarded (thread_plan_sp.get()))
2845 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002846 if (log)
2847 log->Printf("Process::RunThreadPlan(): thread plan was discarded");
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002848 return_value = lldb::eExecutionDiscarded;
Jim Inghamf48169b2010-11-30 02:22:11 +00002849 break;
2850 }
2851 else
2852 {
2853 if (log)
2854 {
2855 StreamString s;
Jim Inghame22e88b2011-01-22 01:30:53 +00002856 if (event_sp)
2857 event_sp->Dump (&s);
2858 else
2859 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002860 log->Printf ("Process::RunThreadPlan(): Stop event that interrupted us is NULL.");
Jim Inghame22e88b2011-01-22 01:30:53 +00002861 }
2862
Jim Inghamf48169b2010-11-30 02:22:11 +00002863 StreamString ts;
2864
2865 const char *event_explanation;
2866
2867 do
2868 {
2869 const Process::ProcessEventData *event_data = Process::ProcessEventData::GetEventDataFromEvent (event_sp.get());
2870
2871 if (!event_data)
2872 {
2873 event_explanation = "<no event data>";
2874 break;
2875 }
2876
2877 Process *process = event_data->GetProcessSP().get();
2878
2879 if (!process)
2880 {
2881 event_explanation = "<no process>";
2882 break;
2883 }
2884
2885 ThreadList &thread_list = process->GetThreadList();
2886
2887 uint32_t num_threads = thread_list.GetSize();
2888 uint32_t thread_index;
2889
2890 ts.Printf("<%u threads> ", num_threads);
2891
2892 for (thread_index = 0;
2893 thread_index < num_threads;
2894 ++thread_index)
2895 {
2896 Thread *thread = thread_list.GetThreadAtIndex(thread_index).get();
2897
2898 if (!thread)
2899 {
2900 ts.Printf("<?> ");
2901 continue;
2902 }
2903
Jim Inghame22e88b2011-01-22 01:30:53 +00002904 ts.Printf("<0x%4.4x ", thread->GetID());
Greg Clayton5ccbd292011-01-06 22:15:06 +00002905 RegisterContext *register_context = thread->GetRegisterContext().get();
Jim Inghamf48169b2010-11-30 02:22:11 +00002906
2907 if (register_context)
2908 ts.Printf("[ip 0x%llx] ", register_context->GetPC());
2909 else
2910 ts.Printf("[ip unknown] ");
2911
2912 lldb::StopInfoSP stop_info_sp = thread->GetStopInfo();
2913 if (stop_info_sp)
2914 {
2915 const char *stop_desc = stop_info_sp->GetDescription();
2916 if (stop_desc)
2917 ts.PutCString (stop_desc);
2918 }
2919 ts.Printf(">");
2920 }
2921
2922 event_explanation = ts.GetData();
2923 } while (0);
2924
Jim Inghame22e88b2011-01-22 01:30:53 +00002925 // See if any of the threads that stopped think we ought to stop. Otherwise continue on.
2926 if (!GetThreadList().ShouldStop(event_sp.get()))
2927 {
2928 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002929 log->Printf("Process::RunThreadPlan(): execution interrupted, but nobody wanted to stop, so we continued: %s %s",
Jim Inghame22e88b2011-01-22 01:30:53 +00002930 s.GetData(), event_explanation);
2931 if (single_thread_timeout_usec != 0)
2932 {
2933 real_timeout = TimeValue::Now();
2934 real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec);
2935 timeout_ptr = &real_timeout;
2936 }
2937
2938 continue;
2939 }
2940 else
2941 {
2942 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002943 log->Printf("Process::RunThreadPlan(): execution interrupted: %s %s", s.GetData(), event_explanation);
Jim Inghame22e88b2011-01-22 01:30:53 +00002944 }
Jim Inghamf48169b2010-11-30 02:22:11 +00002945 }
2946
2947 if (discard_on_error && thread_plan_sp)
2948 {
2949 exe_ctx.thread->DiscardThreadPlansUpToPlan (thread_plan_sp);
2950 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002951 return_value = lldb::eExecutionInterrupted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002952 break;
2953 }
2954 }
2955
2956 if (exe_ctx.process)
2957 exe_ctx.process->RestoreProcessEvents ();
2958
2959 // Thread we ran the function in may have gone away because we ran the target
2960 // Check that it's still there.
2961 exe_ctx.thread = exe_ctx.process->GetThreadList().FindThreadByIndexID(tid, true).get();
2962 if (exe_ctx.thread)
2963 exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex(0).get();
2964
2965 // Also restore the current process'es selected frame & thread, since this function calling may
2966 // be done behind the user's back.
2967
2968 if (selected_tid != LLDB_INVALID_THREAD_ID)
2969 {
2970 if (exe_ctx.process->GetThreadList().SetSelectedThreadByIndexID (selected_tid))
2971 {
2972 // We were able to restore the selected thread, now restore the frame:
2973 exe_ctx.process->GetThreadList().GetSelectedThread()->SetSelectedFrame(selected_frame_sp.get());
2974 }
2975 }
2976
2977 return return_value;
2978}
2979
2980const char *
2981Process::ExecutionResultAsCString (ExecutionResults result)
2982{
2983 const char *result_name;
2984
2985 switch (result)
2986 {
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002987 case lldb::eExecutionCompleted:
Jim Inghamf48169b2010-11-30 02:22:11 +00002988 result_name = "eExecutionCompleted";
2989 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002990 case lldb::eExecutionDiscarded:
Jim Inghamf48169b2010-11-30 02:22:11 +00002991 result_name = "eExecutionDiscarded";
2992 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002993 case lldb::eExecutionInterrupted:
Jim Inghamf48169b2010-11-30 02:22:11 +00002994 result_name = "eExecutionInterrupted";
2995 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002996 case lldb::eExecutionSetupError:
Jim Inghamf48169b2010-11-30 02:22:11 +00002997 result_name = "eExecutionSetupError";
2998 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002999 case lldb::eExecutionTimedOut:
Jim Inghamf48169b2010-11-30 02:22:11 +00003000 result_name = "eExecutionTimedOut";
3001 break;
3002 }
3003 return result_name;
3004}
3005
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003006//--------------------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00003007// class Process::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003008//--------------------------------------------------------------
3009
Greg Clayton1b654882010-09-19 02:33:57 +00003010Process::SettingsController::SettingsController () :
Caroline Ticedaccaa92010-09-20 20:44:43 +00003011 UserSettingsController ("process", Target::GetSettingsController())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003012{
Greg Clayton85851dd2010-12-04 00:10:17 +00003013 m_default_settings.reset (new ProcessInstanceSettings (*this,
3014 false,
Caroline Tice91123da2010-09-08 17:48:55 +00003015 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003016}
3017
Greg Clayton1b654882010-09-19 02:33:57 +00003018Process::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003019{
3020}
3021
3022lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00003023Process::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003024{
Greg Claytondbe54502010-11-19 03:46:01 +00003025 ProcessInstanceSettings *new_settings = new ProcessInstanceSettings (*GetSettingsController(),
3026 false,
3027 instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003028 lldb::InstanceSettingsSP new_settings_sp (new_settings);
3029 return new_settings_sp;
3030}
3031
3032//--------------------------------------------------------------
3033// class ProcessInstanceSettings
3034//--------------------------------------------------------------
3035
Greg Clayton85851dd2010-12-04 00:10:17 +00003036ProcessInstanceSettings::ProcessInstanceSettings
3037(
3038 UserSettingsController &owner,
3039 bool live_instance,
3040 const char *name
3041) :
3042 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003043 m_run_args (),
3044 m_env_vars (),
3045 m_input_path (),
3046 m_output_path (),
3047 m_error_path (),
3048 m_plugin (),
Caroline Ticef8da8632010-12-03 18:46:09 +00003049 m_disable_aslr (true),
Greg Clayton85851dd2010-12-04 00:10:17 +00003050 m_disable_stdio (false),
3051 m_inherit_host_env (true),
3052 m_got_host_env (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003053{
Caroline Ticef20e8232010-09-09 18:26:37 +00003054 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
3055 // until the vtables for ProcessInstanceSettings are properly set up, i.e. AFTER all the initializers.
3056 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
Caroline Tice9e41c152010-09-16 19:05:55 +00003057 // This is true for CreateInstanceName() too.
3058
3059 if (GetInstanceName () == InstanceSettings::InvalidName())
3060 {
3061 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
3062 m_owner.RegisterInstanceSettings (this);
3063 }
Caroline Ticef20e8232010-09-09 18:26:37 +00003064
3065 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003066 {
3067 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
3068 CopyInstanceSettings (pending_settings,false);
Caroline Ticef20e8232010-09-09 18:26:37 +00003069 //m_owner.RemovePendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003070 }
3071}
3072
3073ProcessInstanceSettings::ProcessInstanceSettings (const ProcessInstanceSettings &rhs) :
Greg Claytondbe54502010-11-19 03:46:01 +00003074 InstanceSettings (*Process::GetSettingsController(), CreateInstanceName().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003075 m_run_args (rhs.m_run_args),
3076 m_env_vars (rhs.m_env_vars),
3077 m_input_path (rhs.m_input_path),
3078 m_output_path (rhs.m_output_path),
3079 m_error_path (rhs.m_error_path),
3080 m_plugin (rhs.m_plugin),
Caroline Ticef8da8632010-12-03 18:46:09 +00003081 m_disable_aslr (rhs.m_disable_aslr),
3082 m_disable_stdio (rhs.m_disable_stdio)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003083{
3084 if (m_instance_name != InstanceSettings::GetDefaultName())
3085 {
3086 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
3087 CopyInstanceSettings (pending_settings,false);
3088 m_owner.RemovePendingSettings (m_instance_name);
3089 }
3090}
3091
3092ProcessInstanceSettings::~ProcessInstanceSettings ()
3093{
3094}
3095
3096ProcessInstanceSettings&
3097ProcessInstanceSettings::operator= (const ProcessInstanceSettings &rhs)
3098{
3099 if (this != &rhs)
3100 {
3101 m_run_args = rhs.m_run_args;
3102 m_env_vars = rhs.m_env_vars;
3103 m_input_path = rhs.m_input_path;
3104 m_output_path = rhs.m_output_path;
3105 m_error_path = rhs.m_error_path;
3106 m_plugin = rhs.m_plugin;
3107 m_disable_aslr = rhs.m_disable_aslr;
Caroline Ticef8da8632010-12-03 18:46:09 +00003108 m_disable_stdio = rhs.m_disable_stdio;
Greg Clayton85851dd2010-12-04 00:10:17 +00003109 m_inherit_host_env = rhs.m_inherit_host_env;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003110 }
3111
3112 return *this;
3113}
3114
3115
3116void
3117ProcessInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
3118 const char *index_value,
3119 const char *value,
3120 const ConstString &instance_name,
3121 const SettingEntry &entry,
3122 lldb::VarSetOperationType op,
3123 Error &err,
3124 bool pending)
3125{
3126 if (var_name == RunArgsVarName())
3127 UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
3128 else if (var_name == EnvVarsVarName())
Greg Clayton85851dd2010-12-04 00:10:17 +00003129 {
3130 GetHostEnvironmentIfNeeded ();
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003131 UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
Greg Clayton85851dd2010-12-04 00:10:17 +00003132 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003133 else if (var_name == InputPathVarName())
3134 UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
3135 else if (var_name == OutputPathVarName())
3136 UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
3137 else if (var_name == ErrorPathVarName())
3138 UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
3139 else if (var_name == PluginVarName())
3140 UserSettingsController::UpdateEnumVariable (entry.enum_values, (int *) &m_plugin, value, err);
Greg Clayton85851dd2010-12-04 00:10:17 +00003141 else if (var_name == InheritHostEnvVarName())
3142 UserSettingsController::UpdateBooleanVariable (op, m_inherit_host_env, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003143 else if (var_name == DisableASLRVarName())
3144 UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, err);
Caroline Ticef8da8632010-12-03 18:46:09 +00003145 else if (var_name == DisableSTDIOVarName ())
3146 UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003147}
3148
3149void
3150ProcessInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
3151 bool pending)
3152{
3153 if (new_settings.get() == NULL)
3154 return;
3155
3156 ProcessInstanceSettings *new_process_settings = (ProcessInstanceSettings *) new_settings.get();
3157
3158 m_run_args = new_process_settings->m_run_args;
3159 m_env_vars = new_process_settings->m_env_vars;
3160 m_input_path = new_process_settings->m_input_path;
3161 m_output_path = new_process_settings->m_output_path;
3162 m_error_path = new_process_settings->m_error_path;
3163 m_plugin = new_process_settings->m_plugin;
3164 m_disable_aslr = new_process_settings->m_disable_aslr;
Caroline Ticef8da8632010-12-03 18:46:09 +00003165 m_disable_stdio = new_process_settings->m_disable_stdio;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003166}
3167
Caroline Tice12cecd72010-09-20 21:37:42 +00003168bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003169ProcessInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
3170 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00003171 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00003172 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003173{
3174 if (var_name == RunArgsVarName())
3175 {
3176 if (m_run_args.GetArgumentCount() > 0)
Greg Claytona52c1552010-09-14 03:47:41 +00003177 {
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003178 for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
3179 value.AppendString (m_run_args.GetArgumentAtIndex (i));
Greg Claytona52c1552010-09-14 03:47:41 +00003180 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003181 }
3182 else if (var_name == EnvVarsVarName())
3183 {
Greg Clayton85851dd2010-12-04 00:10:17 +00003184 GetHostEnvironmentIfNeeded ();
3185
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003186 if (m_env_vars.size() > 0)
3187 {
3188 std::map<std::string, std::string>::iterator pos;
3189 for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
3190 {
3191 StreamString value_str;
3192 value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
3193 value.AppendString (value_str.GetData());
3194 }
3195 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003196 }
3197 else if (var_name == InputPathVarName())
3198 {
3199 value.AppendString (m_input_path.c_str());
3200 }
3201 else if (var_name == OutputPathVarName())
3202 {
3203 value.AppendString (m_output_path.c_str());
3204 }
3205 else if (var_name == ErrorPathVarName())
3206 {
3207 value.AppendString (m_error_path.c_str());
3208 }
3209 else if (var_name == PluginVarName())
3210 {
3211 value.AppendString (UserSettingsController::EnumToString (entry.enum_values, (int) m_plugin));
3212 }
Greg Clayton5c5f1a12010-12-04 00:12:24 +00003213 else if (var_name == InheritHostEnvVarName())
3214 {
3215 if (m_inherit_host_env)
3216 value.AppendString ("true");
3217 else
3218 value.AppendString ("false");
3219 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003220 else if (var_name == DisableASLRVarName())
3221 {
3222 if (m_disable_aslr)
3223 value.AppendString ("true");
3224 else
3225 value.AppendString ("false");
3226 }
Caroline Ticef8da8632010-12-03 18:46:09 +00003227 else if (var_name == DisableSTDIOVarName())
3228 {
3229 if (m_disable_stdio)
3230 value.AppendString ("true");
3231 else
3232 value.AppendString ("false");
3233 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003234 else
Caroline Tice12cecd72010-09-20 21:37:42 +00003235 {
3236 if (err)
3237 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
3238 return false;
3239 }
3240 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003241}
3242
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003243const ConstString
3244ProcessInstanceSettings::CreateInstanceName ()
3245{
3246 static int instance_count = 1;
3247 StreamString sstr;
3248
3249 sstr.Printf ("process_%d", instance_count);
3250 ++instance_count;
3251
3252 const ConstString ret_val (sstr.GetData());
3253 return ret_val;
3254}
3255
3256const ConstString &
3257ProcessInstanceSettings::RunArgsVarName ()
3258{
3259 static ConstString run_args_var_name ("run-args");
3260
3261 return run_args_var_name;
3262}
3263
3264const ConstString &
3265ProcessInstanceSettings::EnvVarsVarName ()
3266{
3267 static ConstString env_vars_var_name ("env-vars");
3268
3269 return env_vars_var_name;
3270}
3271
3272const ConstString &
Greg Clayton85851dd2010-12-04 00:10:17 +00003273ProcessInstanceSettings::InheritHostEnvVarName ()
3274{
3275 static ConstString g_name ("inherit-env");
3276
3277 return g_name;
3278}
3279
3280const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003281ProcessInstanceSettings::InputPathVarName ()
3282{
3283 static ConstString input_path_var_name ("input-path");
3284
3285 return input_path_var_name;
3286}
3287
3288const ConstString &
3289ProcessInstanceSettings::OutputPathVarName ()
3290{
Caroline Tice49e27372010-09-07 18:35:40 +00003291 static ConstString output_path_var_name ("output-path");
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003292
3293 return output_path_var_name;
3294}
3295
3296const ConstString &
3297ProcessInstanceSettings::ErrorPathVarName ()
3298{
Caroline Tice49e27372010-09-07 18:35:40 +00003299 static ConstString error_path_var_name ("error-path");
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003300
3301 return error_path_var_name;
3302}
3303
3304const ConstString &
3305ProcessInstanceSettings::PluginVarName ()
3306{
3307 static ConstString plugin_var_name ("plugin");
3308
3309 return plugin_var_name;
3310}
3311
3312
3313const ConstString &
3314ProcessInstanceSettings::DisableASLRVarName ()
3315{
3316 static ConstString disable_aslr_var_name ("disable-aslr");
3317
3318 return disable_aslr_var_name;
3319}
3320
Caroline Ticef8da8632010-12-03 18:46:09 +00003321const ConstString &
3322ProcessInstanceSettings::DisableSTDIOVarName ()
3323{
3324 static ConstString disable_stdio_var_name ("disable-stdio");
3325
3326 return disable_stdio_var_name;
3327}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003328
3329//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00003330// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003331//--------------------------------------------------
3332
3333SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00003334Process::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003335{
3336 //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"},
3337 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
3338};
3339
3340
3341lldb::OptionEnumValueElement
Greg Clayton1b654882010-09-19 02:33:57 +00003342Process::SettingsController::g_plugins[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003343{
Caroline Tice5c9fdfa2010-09-09 18:01:59 +00003344 { eMacosx, "process.macosx", "Use the native MacOSX debugger plugin" },
3345 { eRemoteDebugger, "process.gdb-remote" , "Use the GDB Remote protocol based debugger plugin" },
3346 { 0, NULL, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003347};
3348
3349SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00003350Process::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003351{
Greg Clayton85851dd2010-12-04 00:10:17 +00003352 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
3353 { "run-args", eSetVarTypeArray, NULL, NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." },
3354 { "env-vars", eSetVarTypeDictionary, NULL, NULL, false, false, "A list of all the environment variables to be passed to the executable's environment, and their values." },
3355 { "inherit-env", eSetVarTypeBoolean, "true", NULL, false, false, "Inherit the environment from the process that is running LLDB." },
Greg Claytonbd82a5d2011-01-23 05:56:20 +00003356 { "input-path", eSetVarTypeString, NULL, NULL, false, false, "The file/path to be used by the executable program for reading its input." },
3357 { "output-path", eSetVarTypeString, NULL, NULL, false, false, "The file/path to be used by the executable program for writing its output." },
3358 { "error-path", eSetVarTypeString, NULL, NULL, false, false, "The file/path to be used by the executable program for writings its error messages." },
3359 { "plugin", eSetVarTypeEnum, NULL, g_plugins, false, false, "The plugin to be used to run the process." },
Greg Clayton85851dd2010-12-04 00:10:17 +00003360 { "disable-aslr", eSetVarTypeBoolean, "true", NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" },
3361 { "disable-stdio", eSetVarTypeBoolean, "false", NULL, false, false, "Disable stdin/stdout for process (e.g. for a GUI application)" },
3362 { NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003363};
3364
3365
Jim Ingham5aee1622010-08-09 23:31:02 +00003366