blob: e443ba6629289e731d4c9c2932dac9cde1f58e3d [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 (),
Greg Clayton513c26c2011-01-29 07:10:55 +0000241 m_next_event_action_ap()
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 {
Greg Clayton513c26c2011-01-29 07:10:55 +00001593 case eStateRunning:
1594 return eEventActionRetry;
1595
1596 case eStateStopped:
1597 case eStateCrashed:
Jim Ingham5aee1622010-08-09 23:31:02 +00001598 {
Greg Clayton513c26c2011-01-29 07:10:55 +00001599 // During attach, prior to sending the eStateStopped event,
1600 // lldb_private::Process subclasses must set the process must set
1601 // the new process ID.
1602 assert (m_process->GetID() != LLDB_INVALID_PROCESS_ID);
1603 m_process->DidAttach ();
1604 // Figure out which one is the executable, and set that in our target:
1605 ModuleList &modules = m_process->GetTarget().GetImages();
1606
1607 size_t num_modules = modules.GetSize();
1608 for (int i = 0; i < num_modules; i++)
Jim Ingham5aee1622010-08-09 23:31:02 +00001609 {
Greg Clayton513c26c2011-01-29 07:10:55 +00001610 ModuleSP module_sp = modules.GetModuleAtIndex(i);
1611 if (module_sp->IsExecutable())
Jim Ingham5aee1622010-08-09 23:31:02 +00001612 {
Greg Clayton513c26c2011-01-29 07:10:55 +00001613 ModuleSP exec_module = m_process->GetTarget().GetExecutableModule();
1614 if (!exec_module || exec_module != module_sp)
1615 {
1616
1617 m_process->GetTarget().SetExecutableModule (module_sp, false);
1618 }
1619 break;
Jim Ingham5aee1622010-08-09 23:31:02 +00001620 }
Jim Ingham5aee1622010-08-09 23:31:02 +00001621 }
Greg Clayton513c26c2011-01-29 07:10:55 +00001622 return eEventActionSuccess;
Jim Ingham5aee1622010-08-09 23:31:02 +00001623 }
Greg Clayton513c26c2011-01-29 07:10:55 +00001624
1625
1626 break;
1627 default:
1628 case eStateExited:
1629 case eStateInvalid:
1630 m_exit_string.assign ("No valid Process");
1631 return eEventActionExit;
1632 break;
Jim Inghambb3a2832011-01-29 01:49:25 +00001633 }
1634}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001635
Jim Inghambb3a2832011-01-29 01:49:25 +00001636Process::NextEventAction::EventActionResult
1637Process::AttachCompletionHandler::HandleBeingInterrupted()
1638{
1639 return eEventActionSuccess;
1640}
1641
1642const char *
1643Process::AttachCompletionHandler::GetExitString ()
1644{
1645 return m_exit_string.c_str();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001646}
1647
1648Error
1649Process::Attach (lldb::pid_t attach_pid)
1650{
1651
1652 m_target_triple.Clear();
1653 m_abi_sp.reset();
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001654 m_process_input_reader.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001655
Jim Ingham5aee1622010-08-09 23:31:02 +00001656 // Find the process and its architecture. Make sure it matches the architecture
1657 // of the current Target, and if not adjust it.
1658
1659 ArchSpec attach_spec = GetArchSpecForExistingProcess (attach_pid);
1660 if (attach_spec != GetTarget().GetArchitecture())
1661 {
1662 // Set the architecture on the target.
1663 GetTarget().SetArchitecture(attach_spec);
1664 }
1665
Greg Claytonc982c762010-07-09 20:39:50 +00001666 Error error (WillAttachToProcessWithID(attach_pid));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001667 if (error.Success())
1668 {
Greg Clayton05faeb72010-10-07 04:19:01 +00001669 SetPublicState (eStateAttaching);
1670
Greg Claytonc982c762010-07-09 20:39:50 +00001671 error = DoAttachToProcessWithID (attach_pid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001672 if (error.Success())
1673 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001674 SetNextEventAction(new Process::AttachCompletionHandler(this));
1675 StartPrivateStateThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001676 }
1677 else
1678 {
1679 if (GetID() != LLDB_INVALID_PROCESS_ID)
1680 {
1681 SetID (LLDB_INVALID_PROCESS_ID);
1682 const char *error_string = error.AsCString();
1683 if (error_string == NULL)
1684 error_string = "attach failed";
1685
1686 SetExitStatus(-1, error_string);
1687 }
1688 }
1689 }
1690 return error;
1691}
1692
1693Error
1694Process::Attach (const char *process_name, bool wait_for_launch)
1695{
1696 m_target_triple.Clear();
1697 m_abi_sp.reset();
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001698 m_process_input_reader.reset();
Jim Ingham5aee1622010-08-09 23:31:02 +00001699
1700 // Find the process and its architecture. Make sure it matches the architecture
1701 // of the current Target, and if not adjust it.
1702
Jim Ingham2ecb7422010-08-17 21:54:19 +00001703 if (!wait_for_launch)
Jim Ingham5aee1622010-08-09 23:31:02 +00001704 {
Jim Ingham2ecb7422010-08-17 21:54:19 +00001705 ArchSpec attach_spec = GetArchSpecForExistingProcess (process_name);
Greg Clayton19388cf2010-10-18 01:45:30 +00001706 if (attach_spec.IsValid() && attach_spec != GetTarget().GetArchitecture())
Jim Ingham2ecb7422010-08-17 21:54:19 +00001707 {
1708 // Set the architecture on the target.
1709 GetTarget().SetArchitecture(attach_spec);
1710 }
Jim Ingham5aee1622010-08-09 23:31:02 +00001711 }
Jim Ingham2ecb7422010-08-17 21:54:19 +00001712
Greg Claytonc982c762010-07-09 20:39:50 +00001713 Error error (WillAttachToProcessWithName(process_name, wait_for_launch));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001714 if (error.Success())
1715 {
Greg Clayton05faeb72010-10-07 04:19:01 +00001716 SetPublicState (eStateAttaching);
Greg Claytonc982c762010-07-09 20:39:50 +00001717 error = DoAttachToProcessWithName (process_name, wait_for_launch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001718 if (error.Fail())
1719 {
1720 if (GetID() != LLDB_INVALID_PROCESS_ID)
1721 {
1722 SetID (LLDB_INVALID_PROCESS_ID);
1723 const char *error_string = error.AsCString();
1724 if (error_string == NULL)
1725 error_string = "attach failed";
1726
1727 SetExitStatus(-1, error_string);
1728 }
1729 }
1730 else
1731 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001732 SetNextEventAction(new Process::AttachCompletionHandler(this));
1733 StartPrivateStateThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001734 }
1735 }
1736 return error;
1737}
1738
1739Error
1740Process::Resume ()
1741{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001742 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001743 if (log)
Jim Ingham444586b2011-01-24 06:34:17 +00001744 log->Printf("Process::Resume() m_stop_id = %u, public state: %s private state: %s",
1745 m_stop_id,
1746 StateAsCString(m_public_state.GetValue()),
1747 StateAsCString(m_private_state.GetValue()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001748
1749 Error error (WillResume());
1750 // Tell the process it is about to resume before the thread list
1751 if (error.Success())
1752 {
Johnny Chenc4221e42010-12-02 20:53:05 +00001753 // Now let the thread list know we are about to resume so it
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001754 // can let all of our threads know that they are about to be
1755 // resumed. Threads will each be called with
1756 // Thread::WillResume(StateType) where StateType contains the state
1757 // that they are supposed to have when the process is resumed
1758 // (suspended/running/stepping). Threads should also check
1759 // their resume signal in lldb::Thread::GetResumeSignal()
1760 // to see if they are suppoed to start back up with a signal.
1761 if (m_thread_list.WillResume())
1762 {
1763 error = DoResume();
1764 if (error.Success())
1765 {
1766 DidResume();
1767 m_thread_list.DidResume();
Jim Ingham444586b2011-01-24 06:34:17 +00001768 if (log)
1769 log->Printf ("Process thinks the process has resumed.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001770 }
1771 }
1772 else
1773 {
Jim Ingham444586b2011-01-24 06:34:17 +00001774 error.SetErrorStringWithFormat("Process::WillResume() thread list returned false after WillResume");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001775 }
1776 }
Jim Ingham444586b2011-01-24 06:34:17 +00001777 else if (log)
1778 log->Printf ("Process::WillResume() got an error \"%s\".", error.AsCString("<unknown error>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001779 return error;
1780}
1781
1782Error
1783Process::Halt ()
1784{
Jim Inghambb3a2832011-01-29 01:49:25 +00001785 // Pause our private state thread so we can ensure no one else eats
1786 // the stop event out from under us.
1787 PausePrivateStateThread();
Greg Clayton3af9ea52010-11-18 05:57:03 +00001788
Jim Inghambb3a2832011-01-29 01:49:25 +00001789 EventSP event_sp;
Greg Clayton513c26c2011-01-29 07:10:55 +00001790 Error error (WillHalt());
Jim Inghambb3a2832011-01-29 01:49:25 +00001791
Greg Clayton513c26c2011-01-29 07:10:55 +00001792 if (error.Success())
Jim Inghambb3a2832011-01-29 01:49:25 +00001793 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001794
Greg Clayton513c26c2011-01-29 07:10:55 +00001795 bool caused_stop = false;
1796
1797 // Ask the process subclass to actually halt our process
1798 error = DoHalt(caused_stop);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001799 if (error.Success())
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001800 {
Greg Clayton513c26c2011-01-29 07:10:55 +00001801 if (m_public_state.GetValue() == eStateAttaching)
1802 {
1803 SetExitStatus(SIGKILL, "Cancelled async attach.");
1804 Destroy ();
1805 }
1806 else
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001807 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001808 // If "caused_stop" is true, then DoHalt stopped the process. If
1809 // "caused_stop" is false, the process was already stopped.
1810 // If the DoHalt caused the process to stop, then we want to catch
1811 // this event and set the interrupted bool to true before we pass
1812 // this along so clients know that the process was interrupted by
1813 // a halt command.
1814 if (caused_stop)
Greg Clayton3af9ea52010-11-18 05:57:03 +00001815 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001816 // Wait for 2 seconds for the process to stop.
1817 TimeValue timeout_time;
1818 timeout_time = TimeValue::Now();
1819 timeout_time.OffsetWithSeconds(1);
1820 StateType state = WaitForStateChangedEventsPrivate (&timeout_time, event_sp);
1821
1822 if (state == eStateInvalid)
Greg Clayton3af9ea52010-11-18 05:57:03 +00001823 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001824 // We timeout out and didn't get a stop event...
1825 error.SetErrorString ("Halt timed out.");
Greg Clayton3af9ea52010-11-18 05:57:03 +00001826 }
1827 else
1828 {
Jim Inghambb3a2832011-01-29 01:49:25 +00001829 if (StateIsStoppedState (state))
1830 {
1831 // We caused the process to interrupt itself, so mark this
1832 // as such in the stop event so clients can tell an interrupted
1833 // process from a natural stop
1834 ProcessEventData::SetInterruptedInEvent (event_sp.get(), true);
1835 }
1836 else
1837 {
1838 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
1839 if (log)
1840 log->Printf("Process::Halt() failed to stop, state is: %s", StateAsCString(state));
1841 error.SetErrorString ("Did not get stopped event after halt.");
1842 }
Greg Clayton3af9ea52010-11-18 05:57:03 +00001843 }
1844 }
Jim Inghambb3a2832011-01-29 01:49:25 +00001845 DidHalt();
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001846 }
1847 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001848 }
Jim Inghambb3a2832011-01-29 01:49:25 +00001849 // Resume our private state thread before we post the event (if any)
1850 ResumePrivateStateThread();
1851
1852 // Post any event we might have consumed. If all goes well, we will have
1853 // stopped the process, intercepted the event and set the interrupted
1854 // bool in the event. Post it to the private event queue and that will end up
1855 // correctly setting the state.
1856 if (event_sp)
1857 m_private_state_broadcaster.BroadcastEvent(event_sp);
1858
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859 return error;
1860}
1861
1862Error
1863Process::Detach ()
1864{
1865 Error error (WillDetach());
1866
1867 if (error.Success())
1868 {
1869 DisableAllBreakpointSites();
1870 error = DoDetach();
1871 if (error.Success())
1872 {
1873 DidDetach();
1874 StopPrivateStateThread();
1875 }
1876 }
1877 return error;
1878}
1879
1880Error
1881Process::Destroy ()
1882{
1883 Error error (WillDestroy());
1884 if (error.Success())
1885 {
1886 DisableAllBreakpointSites();
1887 error = DoDestroy();
1888 if (error.Success())
1889 {
1890 DidDestroy();
1891 StopPrivateStateThread();
1892 }
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001893 m_stdio_communication.StopReadThread();
1894 m_stdio_communication.Disconnect();
1895 if (m_process_input_reader && m_process_input_reader->IsActive())
1896 m_target.GetDebugger().PopInputReader (m_process_input_reader);
1897 if (m_process_input_reader)
1898 m_process_input_reader.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001899 }
1900 return error;
1901}
1902
1903Error
1904Process::Signal (int signal)
1905{
1906 Error error (WillSignal());
1907 if (error.Success())
1908 {
1909 error = DoSignal(signal);
1910 if (error.Success())
1911 DidSignal();
1912 }
1913 return error;
1914}
1915
1916UnixSignals &
1917Process::GetUnixSignals ()
1918{
1919 return m_unix_signals;
1920}
1921
1922Target &
1923Process::GetTarget ()
1924{
1925 return m_target;
1926}
1927
1928const Target &
1929Process::GetTarget () const
1930{
1931 return m_target;
1932}
1933
1934uint32_t
1935Process::GetAddressByteSize()
1936{
Greg Clayton3af9ea52010-11-18 05:57:03 +00001937 if (m_addr_byte_size == 0)
1938 return m_target.GetArchitecture().GetAddressByteSize();
1939 return m_addr_byte_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940}
1941
1942bool
1943Process::ShouldBroadcastEvent (Event *event_ptr)
1944{
1945 const StateType state = Process::ProcessEventData::GetStateFromEvent (event_ptr);
1946 bool return_value = true;
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001947 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001948
1949 switch (state)
1950 {
1951 case eStateAttaching:
1952 case eStateLaunching:
1953 case eStateDetached:
1954 case eStateExited:
1955 case eStateUnloaded:
1956 // These events indicate changes in the state of the debugging session, always report them.
1957 return_value = true;
1958 break;
1959 case eStateInvalid:
1960 // We stopped for no apparent reason, don't report it.
1961 return_value = false;
1962 break;
1963 case eStateRunning:
1964 case eStateStepping:
1965 // If we've started the target running, we handle the cases where we
1966 // are already running and where there is a transition from stopped to
1967 // running differently.
1968 // running -> running: Automatically suppress extra running events
1969 // stopped -> running: Report except when there is one or more no votes
1970 // and no yes votes.
1971 SynchronouslyNotifyStateChanged (state);
1972 switch (m_public_state.GetValue())
1973 {
1974 case eStateRunning:
1975 case eStateStepping:
1976 // We always suppress multiple runnings with no PUBLIC stop in between.
1977 return_value = false;
1978 break;
1979 default:
1980 // TODO: make this work correctly. For now always report
1981 // run if we aren't running so we don't miss any runnning
1982 // events. If I run the lldb/test/thread/a.out file and
1983 // break at main.cpp:58, run and hit the breakpoints on
1984 // multiple threads, then somehow during the stepping over
1985 // of all breakpoints no run gets reported.
1986 return_value = true;
1987
1988 // This is a transition from stop to run.
1989 switch (m_thread_list.ShouldReportRun (event_ptr))
1990 {
1991 case eVoteYes:
1992 case eVoteNoOpinion:
1993 return_value = true;
1994 break;
1995 case eVoteNo:
1996 return_value = false;
1997 break;
1998 }
1999 break;
2000 }
2001 break;
2002 case eStateStopped:
2003 case eStateCrashed:
2004 case eStateSuspended:
2005 {
2006 // We've stopped. First see if we're going to restart the target.
2007 // If we are going to stop, then we always broadcast the event.
2008 // 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 +00002009 // If no thread has an opinion, we don't report it.
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002010 if (ProcessEventData::GetInterruptedFromEvent (event_ptr))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002011 {
Greg Clayton3af9ea52010-11-18 05:57:03 +00002012 if (log)
2013 log->Printf ("Process::ShouldBroadcastEvent (%p) stopped due to an interrupt, state: %s", event_ptr, StateAsCString(state));
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002014 return true;
2015 }
2016 else
2017 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002018 RefreshStateAfterStop ();
2019
2020 if (m_thread_list.ShouldStop (event_ptr) == false)
2021 {
2022 switch (m_thread_list.ShouldReportStop (event_ptr))
2023 {
2024 case eVoteYes:
2025 Process::ProcessEventData::SetRestartedInEvent (event_ptr, true);
Johnny Chen3c230652010-10-14 00:54:32 +00002026 // Intentional fall-through here.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002027 case eVoteNoOpinion:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002028 case eVoteNo:
2029 return_value = false;
2030 break;
2031 }
2032
2033 if (log)
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002034 log->Printf ("Process::ShouldBroadcastEvent (%p) Restarting process from state: %s", event_ptr, StateAsCString(state));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002035 Resume ();
2036 }
2037 else
2038 {
2039 return_value = true;
2040 SynchronouslyNotifyStateChanged (state);
2041 }
2042 }
2043 }
2044 }
2045
2046 if (log)
2047 log->Printf ("Process::ShouldBroadcastEvent (%p) => %s", event_ptr, StateAsCString(state), return_value ? "YES" : "NO");
2048 return return_value;
2049}
2050
2051//------------------------------------------------------------------
2052// Thread Queries
2053//------------------------------------------------------------------
2054
2055ThreadList &
2056Process::GetThreadList ()
2057{
2058 return m_thread_list;
2059}
2060
2061const ThreadList &
2062Process::GetThreadList () const
2063{
2064 return m_thread_list;
2065}
2066
2067
2068bool
2069Process::StartPrivateStateThread ()
2070{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00002071 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002072
2073 if (log)
2074 log->Printf ("Process::%s ( )", __FUNCTION__);
2075
2076 // Create a thread that watches our internal state and controls which
2077 // events make it to clients (into the DCProcess event queue).
Greg Clayton3e06bd92011-01-09 21:07:35 +00002078 char thread_name[1024];
2079 snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state(pid=%i)>", GetID());
2080 m_private_state_thread = Host::ThreadCreate (thread_name, Process::PrivateStateThread, this, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002081 return m_private_state_thread != LLDB_INVALID_HOST_THREAD;
2082}
2083
2084void
2085Process::PausePrivateStateThread ()
2086{
2087 ControlPrivateStateThread (eBroadcastInternalStateControlPause);
2088}
2089
2090void
2091Process::ResumePrivateStateThread ()
2092{
2093 ControlPrivateStateThread (eBroadcastInternalStateControlResume);
2094}
2095
2096void
2097Process::StopPrivateStateThread ()
2098{
2099 ControlPrivateStateThread (eBroadcastInternalStateControlStop);
2100}
2101
2102void
2103Process::ControlPrivateStateThread (uint32_t signal)
2104{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00002105 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002106
2107 assert (signal == eBroadcastInternalStateControlStop ||
2108 signal == eBroadcastInternalStateControlPause ||
2109 signal == eBroadcastInternalStateControlResume);
2110
2111 if (log)
Greg Clayton7ecb3a02011-01-22 17:43:17 +00002112 log->Printf ("Process::%s (signal = %d)", __FUNCTION__, signal);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002113
Greg Clayton7ecb3a02011-01-22 17:43:17 +00002114 // Signal the private state thread. First we should copy this is case the
2115 // thread starts exiting since the private state thread will NULL this out
2116 // when it exits
2117 const lldb::thread_t private_state_thread = m_private_state_thread;
2118 if (private_state_thread != LLDB_INVALID_HOST_THREAD)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002119 {
2120 TimeValue timeout_time;
2121 bool timed_out;
2122
2123 m_private_state_control_broadcaster.BroadcastEvent (signal, NULL);
2124
2125 timeout_time = TimeValue::Now();
2126 timeout_time.OffsetWithSeconds(2);
2127 m_private_state_control_wait.WaitForValueEqualTo (true, &timeout_time, &timed_out);
2128 m_private_state_control_wait.SetValue (false, eBroadcastNever);
2129
2130 if (signal == eBroadcastInternalStateControlStop)
2131 {
2132 if (timed_out)
Greg Clayton7ecb3a02011-01-22 17:43:17 +00002133 Host::ThreadCancel (private_state_thread, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002134
2135 thread_result_t result = NULL;
Greg Clayton7ecb3a02011-01-22 17:43:17 +00002136 Host::ThreadJoin (private_state_thread, &result, NULL);
Greg Clayton49182ed2010-07-22 18:34:21 +00002137 m_private_state_thread = LLDB_INVALID_HOST_THREAD;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002138 }
2139 }
2140}
2141
2142void
2143Process::HandlePrivateEvent (EventSP &event_sp)
2144{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00002145 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Jim Inghambb3a2832011-01-29 01:49:25 +00002146
Greg Clayton414f5d32011-01-25 02:58:48 +00002147 const StateType new_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
Jim Inghambb3a2832011-01-29 01:49:25 +00002148
2149 // First check to see if anybody wants a shot at this event:
Jim Ingham754ab982011-01-29 04:05:41 +00002150 if (m_next_event_action_ap.get() != NULL)
Jim Inghambb3a2832011-01-29 01:49:25 +00002151 {
Jim Ingham754ab982011-01-29 04:05:41 +00002152 NextEventAction::EventActionResult action_result = m_next_event_action_ap->PerformAction(event_sp);
Jim Inghambb3a2832011-01-29 01:49:25 +00002153 switch (action_result)
2154 {
2155 case NextEventAction::eEventActionSuccess:
2156 SetNextEventAction(NULL);
2157 break;
2158 case NextEventAction::eEventActionRetry:
2159 break;
2160 case NextEventAction::eEventActionExit:
Jim Ingham2a5fdd42011-01-29 01:57:31 +00002161 // Handle Exiting Here. If we already got an exited event,
2162 // we should just propagate it. Otherwise, swallow this event,
2163 // and set our state to exit so the next event will kill us.
2164 if (new_state != eStateExited)
2165 {
2166 // FIXME: should cons up an exited event, and discard this one.
Jim Ingham754ab982011-01-29 04:05:41 +00002167 SetExitStatus(0, m_next_event_action_ap->GetExitString());
Jim Ingham2a5fdd42011-01-29 01:57:31 +00002168 SetNextEventAction(NULL);
2169 return;
2170 }
2171 SetNextEventAction(NULL);
Jim Inghambb3a2832011-01-29 01:49:25 +00002172 break;
2173 }
2174 }
2175
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002176 // See if we should broadcast this state to external clients?
2177 const bool should_broadcast = ShouldBroadcastEvent (event_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002178
2179 if (should_broadcast)
2180 {
2181 if (log)
2182 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002183 log->Printf ("Process::%s (pid = %i) broadcasting new state %s (old state %s) to %s",
2184 __FUNCTION__,
2185 GetID(),
2186 StateAsCString(new_state),
2187 StateAsCString (GetState ()),
2188 IsHijackedForEvent(eBroadcastBitStateChanged) ? "hijacked" : "public");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002189 }
Greg Clayton414f5d32011-01-25 02:58:48 +00002190 if (StateIsRunningState (new_state))
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002191 PushProcessInputReader ();
2192 else
2193 PopProcessInputReader ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002194 Process::ProcessEventData::SetUpdateStateOnRemoval(event_sp.get());
2195 BroadcastEvent (event_sp);
2196 }
2197 else
2198 {
2199 if (log)
2200 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002201 log->Printf ("Process::%s (pid = %i) suppressing state %s (old state %s): should_broadcast == false",
2202 __FUNCTION__,
2203 GetID(),
2204 StateAsCString(new_state),
2205 StateAsCString (GetState ()),
2206 IsHijackedForEvent(eBroadcastBitStateChanged) ? "hijacked" : "public");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002207 }
2208 }
2209}
2210
2211void *
2212Process::PrivateStateThread (void *arg)
2213{
2214 Process *proc = static_cast<Process*> (arg);
2215 void *result = proc->RunPrivateStateThread ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002216 return result;
2217}
2218
2219void *
2220Process::RunPrivateStateThread ()
2221{
2222 bool control_only = false;
2223 m_private_state_control_wait.SetValue (false, eBroadcastNever);
2224
Greg Clayton2d4edfb2010-11-06 01:53:30 +00002225 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002226 if (log)
2227 log->Printf ("Process::%s (arg = %p, pid = %i) thread starting...", __FUNCTION__, this, GetID());
2228
2229 bool exit_now = false;
2230 while (!exit_now)
2231 {
2232 EventSP event_sp;
2233 WaitForEventsPrivate (NULL, event_sp, control_only);
2234 if (event_sp->BroadcasterIs(&m_private_state_control_broadcaster))
2235 {
2236 switch (event_sp->GetType())
2237 {
2238 case eBroadcastInternalStateControlStop:
2239 exit_now = true;
2240 continue; // Go to next loop iteration so we exit without
2241 break; // doing any internal state managment below
2242
2243 case eBroadcastInternalStateControlPause:
2244 control_only = true;
2245 break;
2246
2247 case eBroadcastInternalStateControlResume:
2248 control_only = false;
2249 break;
2250 }
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002251
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002252 if (log)
2253 log->Printf ("Process::%s (arg = %p, pid = %i) got a control event: %d", __FUNCTION__, this, GetID(), event_sp->GetType());
2254
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002255 m_private_state_control_wait.SetValue (true, eBroadcastAlways);
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002256 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002257 }
2258
2259
2260 const StateType internal_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
2261
2262 if (internal_state != eStateInvalid)
2263 {
2264 HandlePrivateEvent (event_sp);
2265 }
2266
Greg Clayton58d1c9a2010-10-18 04:14:23 +00002267 if (internal_state == eStateInvalid ||
2268 internal_state == eStateExited ||
2269 internal_state == eStateDetached )
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002270 {
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002271 if (log)
2272 log->Printf ("Process::%s (arg = %p, pid = %i) about to exit with internal state %s...", __FUNCTION__, this, GetID(), StateAsCString(internal_state));
2273
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002274 break;
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002275 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002276 }
2277
Caroline Tice20ad3c42010-10-29 21:48:37 +00002278 // Verify log is still enabled before attempting to write to it...
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002279 if (log)
2280 log->Printf ("Process::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, this, GetID());
2281
Greg Clayton6ed95942011-01-22 07:12:45 +00002282 m_private_state_control_wait.SetValue (true, eBroadcastAlways);
2283 m_private_state_thread = LLDB_INVALID_HOST_THREAD;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002284 return NULL;
2285}
2286
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002287//------------------------------------------------------------------
2288// Process Event Data
2289//------------------------------------------------------------------
2290
2291Process::ProcessEventData::ProcessEventData () :
2292 EventData (),
2293 m_process_sp (),
2294 m_state (eStateInvalid),
Greg Claytonc982c762010-07-09 20:39:50 +00002295 m_restarted (false),
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002296 m_update_state (false),
2297 m_interrupted (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002298{
2299}
2300
2301Process::ProcessEventData::ProcessEventData (const ProcessSP &process_sp, StateType state) :
2302 EventData (),
2303 m_process_sp (process_sp),
2304 m_state (state),
Greg Claytonc982c762010-07-09 20:39:50 +00002305 m_restarted (false),
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002306 m_update_state (false),
2307 m_interrupted (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002308{
2309}
2310
2311Process::ProcessEventData::~ProcessEventData()
2312{
2313}
2314
2315const ConstString &
2316Process::ProcessEventData::GetFlavorString ()
2317{
2318 static ConstString g_flavor ("Process::ProcessEventData");
2319 return g_flavor;
2320}
2321
2322const ConstString &
2323Process::ProcessEventData::GetFlavor () const
2324{
2325 return ProcessEventData::GetFlavorString ();
2326}
2327
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002328void
2329Process::ProcessEventData::DoOnRemoval (Event *event_ptr)
2330{
2331 // This function gets called twice for each event, once when the event gets pulled
2332 // off of the private process event queue, and once when it gets pulled off of
2333 // the public event queue. m_update_state is used to distinguish these
2334 // two cases; it is false when we're just pulling it off for private handling,
2335 // and we don't want to do the breakpoint command handling then.
2336
2337 if (!m_update_state)
2338 return;
2339
2340 m_process_sp->SetPublicState (m_state);
2341
2342 // If we're stopped and haven't restarted, then do the breakpoint commands here:
2343 if (m_state == eStateStopped && ! m_restarted)
2344 {
2345 int num_threads = m_process_sp->GetThreadList().GetSize();
2346 int idx;
Greg Claytonf4b47e12010-08-04 01:40:35 +00002347
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002348 for (idx = 0; idx < num_threads; ++idx)
2349 {
2350 lldb::ThreadSP thread_sp = m_process_sp->GetThreadList().GetThreadAtIndex(idx);
2351
Jim Inghamb15bfc72010-10-20 00:39:53 +00002352 StopInfoSP stop_info_sp = thread_sp->GetStopInfo ();
2353 if (stop_info_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002354 {
Jim Inghamb15bfc72010-10-20 00:39:53 +00002355 stop_info_sp->PerformAction(event_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002356 }
2357 }
Greg Claytonf4b47e12010-08-04 01:40:35 +00002358
Jim Ingham3ebcf7f2010-08-10 00:59:59 +00002359 // The stop action might restart the target. If it does, then we want to mark that in the
2360 // event so that whoever is receiving it will know to wait for the running event and reflect
2361 // that state appropriately.
2362
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002363 if (m_process_sp->GetPrivateState() == eStateRunning)
2364 SetRestarted(true);
2365 }
2366}
2367
2368void
2369Process::ProcessEventData::Dump (Stream *s) const
2370{
2371 if (m_process_sp)
2372 s->Printf(" process = %p (pid = %u), ", m_process_sp.get(), m_process_sp->GetID());
2373
2374 s->Printf("state = %s", StateAsCString(GetState()));;
2375}
2376
2377const Process::ProcessEventData *
2378Process::ProcessEventData::GetEventDataFromEvent (const Event *event_ptr)
2379{
2380 if (event_ptr)
2381 {
2382 const EventData *event_data = event_ptr->GetData();
2383 if (event_data && event_data->GetFlavor() == ProcessEventData::GetFlavorString())
2384 return static_cast <const ProcessEventData *> (event_ptr->GetData());
2385 }
2386 return NULL;
2387}
2388
2389ProcessSP
2390Process::ProcessEventData::GetProcessFromEvent (const Event *event_ptr)
2391{
2392 ProcessSP process_sp;
2393 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2394 if (data)
2395 process_sp = data->GetProcessSP();
2396 return process_sp;
2397}
2398
2399StateType
2400Process::ProcessEventData::GetStateFromEvent (const Event *event_ptr)
2401{
2402 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2403 if (data == NULL)
2404 return eStateInvalid;
2405 else
2406 return data->GetState();
2407}
2408
2409bool
2410Process::ProcessEventData::GetRestartedFromEvent (const Event *event_ptr)
2411{
2412 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2413 if (data == NULL)
2414 return false;
2415 else
2416 return data->GetRestarted();
2417}
2418
2419void
2420Process::ProcessEventData::SetRestartedInEvent (Event *event_ptr, bool new_value)
2421{
2422 ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr));
2423 if (data != NULL)
2424 data->SetRestarted(new_value);
2425}
2426
2427bool
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002428Process::ProcessEventData::GetInterruptedFromEvent (const Event *event_ptr)
2429{
2430 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2431 if (data == NULL)
2432 return false;
2433 else
2434 return data->GetInterrupted ();
2435}
2436
2437void
2438Process::ProcessEventData::SetInterruptedInEvent (Event *event_ptr, bool new_value)
2439{
2440 ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr));
2441 if (data != NULL)
2442 data->SetInterrupted(new_value);
2443}
2444
2445bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002446Process::ProcessEventData::SetUpdateStateOnRemoval (Event *event_ptr)
2447{
2448 ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr));
2449 if (data)
2450 {
2451 data->SetUpdateStateOnRemoval();
2452 return true;
2453 }
2454 return false;
2455}
2456
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002457Target *
2458Process::CalculateTarget ()
2459{
2460 return &m_target;
2461}
2462
2463Process *
2464Process::CalculateProcess ()
2465{
2466 return this;
2467}
2468
2469Thread *
2470Process::CalculateThread ()
2471{
2472 return NULL;
2473}
2474
2475StackFrame *
2476Process::CalculateStackFrame ()
2477{
2478 return NULL;
2479}
2480
2481void
Greg Clayton0603aa92010-10-04 01:05:56 +00002482Process::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002483{
2484 exe_ctx.target = &m_target;
2485 exe_ctx.process = this;
2486 exe_ctx.thread = NULL;
2487 exe_ctx.frame = NULL;
2488}
2489
2490lldb::ProcessSP
2491Process::GetSP ()
2492{
2493 return GetTarget().GetProcessSP();
2494}
2495
Jim Ingham5aee1622010-08-09 23:31:02 +00002496uint32_t
2497Process::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids)
2498{
2499 return 0;
2500}
2501
2502ArchSpec
2503Process::GetArchSpecForExistingProcess (lldb::pid_t pid)
2504{
2505 return Host::GetArchSpecForExistingProcess (pid);
2506}
2507
2508ArchSpec
2509Process::GetArchSpecForExistingProcess (const char *process_name)
2510{
2511 return Host::GetArchSpecForExistingProcess (process_name);
2512}
2513
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002514void
2515Process::AppendSTDOUT (const char * s, size_t len)
2516{
Greg Clayton3af9ea52010-11-18 05:57:03 +00002517 Mutex::Locker locker (m_stdio_communication_mutex);
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002518 m_stdout_data.append (s, len);
2519
Greg Claytona9ff3062010-12-05 19:16:56 +00002520 BroadcastEventIfUnique (eBroadcastBitSTDOUT, new ProcessEventData (GetTarget().GetProcessSP(), GetState()));
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002521}
2522
2523void
2524Process::STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len)
2525{
2526 Process *process = (Process *) baton;
2527 process->AppendSTDOUT (static_cast<const char *>(src), src_len);
2528}
2529
2530size_t
2531Process::ProcessInputReaderCallback (void *baton,
2532 InputReader &reader,
2533 lldb::InputReaderAction notification,
2534 const char *bytes,
2535 size_t bytes_len)
2536{
2537 Process *process = (Process *) baton;
2538
2539 switch (notification)
2540 {
2541 case eInputReaderActivate:
2542 break;
2543
2544 case eInputReaderDeactivate:
2545 break;
2546
2547 case eInputReaderReactivate:
2548 break;
2549
2550 case eInputReaderGotToken:
2551 {
2552 Error error;
2553 process->PutSTDIN (bytes, bytes_len, error);
2554 }
2555 break;
2556
Caroline Ticeefed6132010-11-19 20:47:54 +00002557 case eInputReaderInterrupt:
2558 process->Halt ();
2559 break;
2560
2561 case eInputReaderEndOfFile:
2562 process->AppendSTDOUT ("^D", 2);
2563 break;
2564
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002565 case eInputReaderDone:
2566 break;
2567
2568 }
2569
2570 return bytes_len;
2571}
2572
2573void
2574Process::ResetProcessInputReader ()
2575{
2576 m_process_input_reader.reset();
2577}
2578
2579void
2580Process::SetUpProcessInputReader (int file_descriptor)
2581{
2582 // First set up the Read Thread for reading/handling process I/O
2583
2584 std::auto_ptr<ConnectionFileDescriptor> conn_ap (new ConnectionFileDescriptor (file_descriptor, true));
2585
2586 if (conn_ap.get())
2587 {
2588 m_stdio_communication.SetConnection (conn_ap.release());
2589 if (m_stdio_communication.IsConnected())
2590 {
2591 m_stdio_communication.SetReadThreadBytesReceivedCallback (STDIOReadThreadBytesReceived, this);
2592 m_stdio_communication.StartReadThread();
2593
2594 // Now read thread is set up, set up input reader.
2595
2596 if (!m_process_input_reader.get())
2597 {
2598 m_process_input_reader.reset (new InputReader(m_target.GetDebugger()));
2599 Error err (m_process_input_reader->Initialize (Process::ProcessInputReaderCallback,
2600 this,
2601 eInputReaderGranularityByte,
2602 NULL,
2603 NULL,
2604 false));
2605
2606 if (err.Fail())
2607 m_process_input_reader.reset();
2608 }
2609 }
2610 }
2611}
2612
2613void
2614Process::PushProcessInputReader ()
2615{
2616 if (m_process_input_reader && !m_process_input_reader->IsActive())
2617 m_target.GetDebugger().PushInputReader (m_process_input_reader);
2618}
2619
2620void
2621Process::PopProcessInputReader ()
2622{
2623 if (m_process_input_reader && m_process_input_reader->IsActive())
2624 m_target.GetDebugger().PopInputReader (m_process_input_reader);
2625}
2626
Greg Clayton99d0faf2010-11-18 23:32:35 +00002627
2628void
2629Process::Initialize ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002630{
Greg Clayton99d0faf2010-11-18 23:32:35 +00002631 UserSettingsControllerSP &usc = GetSettingsController();
2632 usc.reset (new SettingsController);
2633 UserSettingsController::InitializeSettingsController (usc,
2634 SettingsController::global_settings_table,
2635 SettingsController::instance_settings_table);
2636}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002637
Greg Clayton99d0faf2010-11-18 23:32:35 +00002638void
2639Process::Terminate ()
2640{
2641 UserSettingsControllerSP &usc = GetSettingsController();
2642 UserSettingsController::FinalizeSettingsController (usc);
2643 usc.reset();
2644}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002645
Greg Clayton99d0faf2010-11-18 23:32:35 +00002646UserSettingsControllerSP &
2647Process::GetSettingsController ()
2648{
2649 static UserSettingsControllerSP g_settings_controller;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002650 return g_settings_controller;
2651}
2652
Caroline Tice1559a462010-09-27 00:30:10 +00002653void
2654Process::UpdateInstanceName ()
2655{
2656 ModuleSP module_sp = GetTarget().GetExecutableModule();
2657 if (module_sp)
2658 {
2659 StreamString sstr;
2660 sstr.Printf ("%s", module_sp->GetFileSpec().GetFilename().AsCString());
2661
Greg Claytondbe54502010-11-19 03:46:01 +00002662 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
Caroline Tice1559a462010-09-27 00:30:10 +00002663 sstr.GetData());
2664 }
2665}
2666
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002667ExecutionResults
Jim Inghamf48169b2010-11-30 02:22:11 +00002668Process::RunThreadPlan (ExecutionContext &exe_ctx,
2669 lldb::ThreadPlanSP &thread_plan_sp,
2670 bool stop_others,
2671 bool try_all_threads,
2672 bool discard_on_error,
2673 uint32_t single_thread_timeout_usec,
2674 Stream &errors)
2675{
2676 ExecutionResults return_value = eExecutionSetupError;
2677
Jim Ingham77787032011-01-20 02:03:18 +00002678 if (thread_plan_sp.get() == NULL)
2679 {
2680 errors.Printf("RunThreadPlan called with empty thread plan.");
2681 return lldb::eExecutionSetupError;
2682 }
2683
Jim Ingham444586b2011-01-24 06:34:17 +00002684 if (m_private_state.GetValue() != eStateStopped)
2685 {
2686 errors.Printf ("RunThreadPlan called while the private state was not stopped.");
2687 // REMOVE BEAR TRAP...
2688 // abort();
2689 }
2690
Jim Inghamf48169b2010-11-30 02:22:11 +00002691 // Save this value for restoration of the execution context after we run
2692 uint32_t tid = exe_ctx.thread->GetIndexID();
2693
2694 // N.B. Running the target may unset the currently selected thread and frame. We don't want to do that either,
2695 // so we should arrange to reset them as well.
2696
2697 lldb::ThreadSP selected_thread_sp = exe_ctx.process->GetThreadList().GetSelectedThread();
2698 lldb::StackFrameSP selected_frame_sp;
2699
2700 uint32_t selected_tid;
2701 if (selected_thread_sp != NULL)
2702 {
2703 selected_tid = selected_thread_sp->GetIndexID();
2704 selected_frame_sp = selected_thread_sp->GetSelectedFrame();
2705 }
2706 else
2707 {
2708 selected_tid = LLDB_INVALID_THREAD_ID;
2709 }
2710
2711 exe_ctx.thread->QueueThreadPlan(thread_plan_sp, true);
2712
Jim Ingham1e7a9ee2011-01-23 21:14:08 +00002713 Listener listener("lldb.process.listener.run-thread-plan");
Jim Inghamf48169b2010-11-30 02:22:11 +00002714 exe_ctx.process->HijackProcessEvents(&listener);
Jim Ingham444586b2011-01-24 06:34:17 +00002715
Jim Ingham1e7a9ee2011-01-23 21:14:08 +00002716 lldb::LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS));
Jim Ingham77787032011-01-20 02:03:18 +00002717 if (log)
2718 {
2719 StreamString s;
2720 thread_plan_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
Greg Clayton414f5d32011-01-25 02:58:48 +00002721 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 +00002722 }
2723
Jim Inghamf48169b2010-11-30 02:22:11 +00002724 Error resume_error = exe_ctx.process->Resume ();
2725 if (!resume_error.Success())
2726 {
2727 errors.Printf("Error resuming inferior: \"%s\".\n", resume_error.AsCString());
2728 exe_ctx.process->RestoreProcessEvents();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002729 return lldb::eExecutionSetupError;
Jim Inghamf48169b2010-11-30 02:22:11 +00002730 }
2731
2732 // We need to call the function synchronously, so spin waiting for it to return.
2733 // If we get interrupted while executing, we're going to lose our context, and
2734 // won't be able to gather the result at this point.
2735 // We set the timeout AFTER the resume, since the resume takes some time and we
2736 // don't want to charge that to the timeout.
2737
2738 TimeValue* timeout_ptr = NULL;
2739 TimeValue real_timeout;
2740
2741 if (single_thread_timeout_usec != 0)
2742 {
2743 real_timeout = TimeValue::Now();
2744 real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec);
2745 timeout_ptr = &real_timeout;
2746 }
2747
Jim Inghamf48169b2010-11-30 02:22:11 +00002748 while (1)
2749 {
2750 lldb::EventSP event_sp;
2751 lldb::StateType stop_state = lldb::eStateInvalid;
2752 // Now wait for the process to stop again:
2753 bool got_event = listener.WaitForEvent (timeout_ptr, event_sp);
2754
2755 if (!got_event)
2756 {
2757 // Right now this is the only way to tell we've timed out...
2758 // We should interrupt the process here...
2759 // Not really sure what to do if Halt fails here...
Stephen Wilson78a4feb2011-01-12 04:20:03 +00002760 if (log) {
Jim Inghamf48169b2010-11-30 02:22:11 +00002761 if (try_all_threads)
Greg Clayton414f5d32011-01-25 02:58:48 +00002762 log->Printf ("Process::RunThreadPlan(): Running function with timeout: %d timed out, trying with all threads enabled.",
Jim Inghamf48169b2010-11-30 02:22:11 +00002763 single_thread_timeout_usec);
2764 else
Greg Clayton414f5d32011-01-25 02:58:48 +00002765 log->Printf ("Process::RunThreadPlan(): Running function with timeout: %d timed out, abandoning execution.",
Jim Inghamf48169b2010-11-30 02:22:11 +00002766 single_thread_timeout_usec);
Stephen Wilson78a4feb2011-01-12 04:20:03 +00002767 }
Jim Inghamf48169b2010-11-30 02:22:11 +00002768
Jim Inghame22e88b2011-01-22 01:30:53 +00002769 Error halt_error = exe_ctx.process->Halt();
2770
2771 if (halt_error.Success())
Jim Inghamf48169b2010-11-30 02:22:11 +00002772 {
2773 timeout_ptr = NULL;
2774 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002775 log->Printf ("Process::RunThreadPlan(): Halt succeeded.");
Jim Inghamf48169b2010-11-30 02:22:11 +00002776
2777 // Between the time that we got the timeout and the time we halted, but target
2778 // might have actually completed the plan. If so, we're done. Note, I call WFE here with a short
2779 // timeout to
2780 got_event = listener.WaitForEvent(NULL, event_sp);
2781
2782 if (got_event)
2783 {
2784 stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
2785 if (log)
2786 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002787 log->Printf ("Process::RunThreadPlan(): Stopped with event: %s", StateAsCString(stop_state));
Jim Inghamf48169b2010-11-30 02:22:11 +00002788 if (stop_state == lldb::eStateStopped && Process::ProcessEventData::GetInterruptedFromEvent(event_sp.get()))
2789 log->Printf (" Event was the Halt interruption event.");
2790 }
2791
2792 if (exe_ctx.thread->IsThreadPlanDone (thread_plan_sp.get()))
2793 {
2794 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002795 log->Printf ("Process::RunThreadPlan(): Even though we timed out, the call plan was done. Exiting wait loop.");
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002796 return_value = lldb::eExecutionCompleted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002797 break;
2798 }
2799
2800 if (try_all_threads
2801 && (stop_state == lldb::eStateStopped && Process::ProcessEventData::GetInterruptedFromEvent (event_sp.get())))
2802 {
2803
2804 thread_plan_sp->SetStopOthers (false);
2805 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002806 log->Printf ("Process::RunThreadPlan(): About to resume.");
Jim Inghamf48169b2010-11-30 02:22:11 +00002807
2808 exe_ctx.process->Resume();
2809 continue;
2810 }
2811 else
2812 {
2813 exe_ctx.process->RestoreProcessEvents ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002814 return lldb::eExecutionInterrupted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002815 }
2816 }
2817 }
Jim Inghame22e88b2011-01-22 01:30:53 +00002818 else
2819 {
2820
2821 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002822 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 +00002823 halt_error.AsCString());
Jim Ingham444586b2011-01-24 06:34:17 +00002824// abort();
Jim Inghame22e88b2011-01-22 01:30:53 +00002825
Jim Ingham1e7a9ee2011-01-23 21:14:08 +00002826 if (single_thread_timeout_usec != 0)
2827 {
2828 real_timeout = TimeValue::Now();
2829 real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec);
2830 timeout_ptr = &real_timeout;
2831 }
2832 continue;
Jim Inghame22e88b2011-01-22 01:30:53 +00002833 }
2834
Jim Inghamf48169b2010-11-30 02:22:11 +00002835 }
2836
2837 stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
2838 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002839 log->Printf("Process::RunThreadPlan(): got event: %s.", StateAsCString(stop_state));
Jim Inghamf48169b2010-11-30 02:22:11 +00002840
2841 if (stop_state == lldb::eStateRunning || stop_state == lldb::eStateStepping)
2842 continue;
2843
2844 if (exe_ctx.thread->IsThreadPlanDone (thread_plan_sp.get()))
2845 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002846 if (log)
2847 log->Printf("Process::RunThreadPlan(): thread plan is done");
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002848 return_value = lldb::eExecutionCompleted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002849 break;
2850 }
2851 else if (exe_ctx.thread->WasThreadPlanDiscarded (thread_plan_sp.get()))
2852 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002853 if (log)
2854 log->Printf("Process::RunThreadPlan(): thread plan was discarded");
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002855 return_value = lldb::eExecutionDiscarded;
Jim Inghamf48169b2010-11-30 02:22:11 +00002856 break;
2857 }
2858 else
2859 {
2860 if (log)
2861 {
2862 StreamString s;
Jim Inghame22e88b2011-01-22 01:30:53 +00002863 if (event_sp)
2864 event_sp->Dump (&s);
2865 else
2866 {
Greg Clayton414f5d32011-01-25 02:58:48 +00002867 log->Printf ("Process::RunThreadPlan(): Stop event that interrupted us is NULL.");
Jim Inghame22e88b2011-01-22 01:30:53 +00002868 }
2869
Jim Inghamf48169b2010-11-30 02:22:11 +00002870 StreamString ts;
2871
2872 const char *event_explanation;
2873
2874 do
2875 {
2876 const Process::ProcessEventData *event_data = Process::ProcessEventData::GetEventDataFromEvent (event_sp.get());
2877
2878 if (!event_data)
2879 {
2880 event_explanation = "<no event data>";
2881 break;
2882 }
2883
2884 Process *process = event_data->GetProcessSP().get();
2885
2886 if (!process)
2887 {
2888 event_explanation = "<no process>";
2889 break;
2890 }
2891
2892 ThreadList &thread_list = process->GetThreadList();
2893
2894 uint32_t num_threads = thread_list.GetSize();
2895 uint32_t thread_index;
2896
2897 ts.Printf("<%u threads> ", num_threads);
2898
2899 for (thread_index = 0;
2900 thread_index < num_threads;
2901 ++thread_index)
2902 {
2903 Thread *thread = thread_list.GetThreadAtIndex(thread_index).get();
2904
2905 if (!thread)
2906 {
2907 ts.Printf("<?> ");
2908 continue;
2909 }
2910
Jim Inghame22e88b2011-01-22 01:30:53 +00002911 ts.Printf("<0x%4.4x ", thread->GetID());
Greg Clayton5ccbd292011-01-06 22:15:06 +00002912 RegisterContext *register_context = thread->GetRegisterContext().get();
Jim Inghamf48169b2010-11-30 02:22:11 +00002913
2914 if (register_context)
2915 ts.Printf("[ip 0x%llx] ", register_context->GetPC());
2916 else
2917 ts.Printf("[ip unknown] ");
2918
2919 lldb::StopInfoSP stop_info_sp = thread->GetStopInfo();
2920 if (stop_info_sp)
2921 {
2922 const char *stop_desc = stop_info_sp->GetDescription();
2923 if (stop_desc)
2924 ts.PutCString (stop_desc);
2925 }
2926 ts.Printf(">");
2927 }
2928
2929 event_explanation = ts.GetData();
2930 } while (0);
2931
Jim Inghame22e88b2011-01-22 01:30:53 +00002932 // See if any of the threads that stopped think we ought to stop. Otherwise continue on.
2933 if (!GetThreadList().ShouldStop(event_sp.get()))
2934 {
2935 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002936 log->Printf("Process::RunThreadPlan(): execution interrupted, but nobody wanted to stop, so we continued: %s %s",
Jim Inghame22e88b2011-01-22 01:30:53 +00002937 s.GetData(), event_explanation);
2938 if (single_thread_timeout_usec != 0)
2939 {
2940 real_timeout = TimeValue::Now();
2941 real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec);
2942 timeout_ptr = &real_timeout;
2943 }
2944
2945 continue;
2946 }
2947 else
2948 {
2949 if (log)
Greg Clayton414f5d32011-01-25 02:58:48 +00002950 log->Printf("Process::RunThreadPlan(): execution interrupted: %s %s", s.GetData(), event_explanation);
Jim Inghame22e88b2011-01-22 01:30:53 +00002951 }
Jim Inghamf48169b2010-11-30 02:22:11 +00002952 }
2953
2954 if (discard_on_error && thread_plan_sp)
2955 {
2956 exe_ctx.thread->DiscardThreadPlansUpToPlan (thread_plan_sp);
2957 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002958 return_value = lldb::eExecutionInterrupted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002959 break;
2960 }
2961 }
2962
2963 if (exe_ctx.process)
2964 exe_ctx.process->RestoreProcessEvents ();
2965
2966 // Thread we ran the function in may have gone away because we ran the target
2967 // Check that it's still there.
2968 exe_ctx.thread = exe_ctx.process->GetThreadList().FindThreadByIndexID(tid, true).get();
2969 if (exe_ctx.thread)
2970 exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex(0).get();
2971
2972 // Also restore the current process'es selected frame & thread, since this function calling may
2973 // be done behind the user's back.
2974
2975 if (selected_tid != LLDB_INVALID_THREAD_ID)
2976 {
2977 if (exe_ctx.process->GetThreadList().SetSelectedThreadByIndexID (selected_tid))
2978 {
2979 // We were able to restore the selected thread, now restore the frame:
2980 exe_ctx.process->GetThreadList().GetSelectedThread()->SetSelectedFrame(selected_frame_sp.get());
2981 }
2982 }
2983
2984 return return_value;
2985}
2986
2987const char *
2988Process::ExecutionResultAsCString (ExecutionResults result)
2989{
2990 const char *result_name;
2991
2992 switch (result)
2993 {
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002994 case lldb::eExecutionCompleted:
Jim Inghamf48169b2010-11-30 02:22:11 +00002995 result_name = "eExecutionCompleted";
2996 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002997 case lldb::eExecutionDiscarded:
Jim Inghamf48169b2010-11-30 02:22:11 +00002998 result_name = "eExecutionDiscarded";
2999 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003000 case lldb::eExecutionInterrupted:
Jim Inghamf48169b2010-11-30 02:22:11 +00003001 result_name = "eExecutionInterrupted";
3002 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003003 case lldb::eExecutionSetupError:
Jim Inghamf48169b2010-11-30 02:22:11 +00003004 result_name = "eExecutionSetupError";
3005 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003006 case lldb::eExecutionTimedOut:
Jim Inghamf48169b2010-11-30 02:22:11 +00003007 result_name = "eExecutionTimedOut";
3008 break;
3009 }
3010 return result_name;
3011}
3012
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003013//--------------------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00003014// class Process::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003015//--------------------------------------------------------------
3016
Greg Clayton1b654882010-09-19 02:33:57 +00003017Process::SettingsController::SettingsController () :
Caroline Ticedaccaa92010-09-20 20:44:43 +00003018 UserSettingsController ("process", Target::GetSettingsController())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003019{
Greg Clayton85851dd2010-12-04 00:10:17 +00003020 m_default_settings.reset (new ProcessInstanceSettings (*this,
3021 false,
Caroline Tice91123da2010-09-08 17:48:55 +00003022 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003023}
3024
Greg Clayton1b654882010-09-19 02:33:57 +00003025Process::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003026{
3027}
3028
3029lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00003030Process::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003031{
Greg Claytondbe54502010-11-19 03:46:01 +00003032 ProcessInstanceSettings *new_settings = new ProcessInstanceSettings (*GetSettingsController(),
3033 false,
3034 instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003035 lldb::InstanceSettingsSP new_settings_sp (new_settings);
3036 return new_settings_sp;
3037}
3038
3039//--------------------------------------------------------------
3040// class ProcessInstanceSettings
3041//--------------------------------------------------------------
3042
Greg Clayton85851dd2010-12-04 00:10:17 +00003043ProcessInstanceSettings::ProcessInstanceSettings
3044(
3045 UserSettingsController &owner,
3046 bool live_instance,
3047 const char *name
3048) :
3049 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003050 m_run_args (),
3051 m_env_vars (),
3052 m_input_path (),
3053 m_output_path (),
3054 m_error_path (),
3055 m_plugin (),
Caroline Ticef8da8632010-12-03 18:46:09 +00003056 m_disable_aslr (true),
Greg Clayton85851dd2010-12-04 00:10:17 +00003057 m_disable_stdio (false),
3058 m_inherit_host_env (true),
3059 m_got_host_env (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003060{
Caroline Ticef20e8232010-09-09 18:26:37 +00003061 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
3062 // until the vtables for ProcessInstanceSettings are properly set up, i.e. AFTER all the initializers.
3063 // 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 +00003064 // This is true for CreateInstanceName() too.
3065
3066 if (GetInstanceName () == InstanceSettings::InvalidName())
3067 {
3068 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
3069 m_owner.RegisterInstanceSettings (this);
3070 }
Caroline Ticef20e8232010-09-09 18:26:37 +00003071
3072 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003073 {
3074 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
3075 CopyInstanceSettings (pending_settings,false);
Caroline Ticef20e8232010-09-09 18:26:37 +00003076 //m_owner.RemovePendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003077 }
3078}
3079
3080ProcessInstanceSettings::ProcessInstanceSettings (const ProcessInstanceSettings &rhs) :
Greg Claytondbe54502010-11-19 03:46:01 +00003081 InstanceSettings (*Process::GetSettingsController(), CreateInstanceName().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003082 m_run_args (rhs.m_run_args),
3083 m_env_vars (rhs.m_env_vars),
3084 m_input_path (rhs.m_input_path),
3085 m_output_path (rhs.m_output_path),
3086 m_error_path (rhs.m_error_path),
3087 m_plugin (rhs.m_plugin),
Caroline Ticef8da8632010-12-03 18:46:09 +00003088 m_disable_aslr (rhs.m_disable_aslr),
3089 m_disable_stdio (rhs.m_disable_stdio)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003090{
3091 if (m_instance_name != InstanceSettings::GetDefaultName())
3092 {
3093 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
3094 CopyInstanceSettings (pending_settings,false);
3095 m_owner.RemovePendingSettings (m_instance_name);
3096 }
3097}
3098
3099ProcessInstanceSettings::~ProcessInstanceSettings ()
3100{
3101}
3102
3103ProcessInstanceSettings&
3104ProcessInstanceSettings::operator= (const ProcessInstanceSettings &rhs)
3105{
3106 if (this != &rhs)
3107 {
3108 m_run_args = rhs.m_run_args;
3109 m_env_vars = rhs.m_env_vars;
3110 m_input_path = rhs.m_input_path;
3111 m_output_path = rhs.m_output_path;
3112 m_error_path = rhs.m_error_path;
3113 m_plugin = rhs.m_plugin;
3114 m_disable_aslr = rhs.m_disable_aslr;
Caroline Ticef8da8632010-12-03 18:46:09 +00003115 m_disable_stdio = rhs.m_disable_stdio;
Greg Clayton85851dd2010-12-04 00:10:17 +00003116 m_inherit_host_env = rhs.m_inherit_host_env;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003117 }
3118
3119 return *this;
3120}
3121
3122
3123void
3124ProcessInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
3125 const char *index_value,
3126 const char *value,
3127 const ConstString &instance_name,
3128 const SettingEntry &entry,
3129 lldb::VarSetOperationType op,
3130 Error &err,
3131 bool pending)
3132{
3133 if (var_name == RunArgsVarName())
3134 UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
3135 else if (var_name == EnvVarsVarName())
Greg Clayton85851dd2010-12-04 00:10:17 +00003136 {
3137 GetHostEnvironmentIfNeeded ();
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003138 UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
Greg Clayton85851dd2010-12-04 00:10:17 +00003139 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003140 else if (var_name == InputPathVarName())
3141 UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
3142 else if (var_name == OutputPathVarName())
3143 UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
3144 else if (var_name == ErrorPathVarName())
3145 UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
3146 else if (var_name == PluginVarName())
3147 UserSettingsController::UpdateEnumVariable (entry.enum_values, (int *) &m_plugin, value, err);
Greg Clayton85851dd2010-12-04 00:10:17 +00003148 else if (var_name == InheritHostEnvVarName())
3149 UserSettingsController::UpdateBooleanVariable (op, m_inherit_host_env, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003150 else if (var_name == DisableASLRVarName())
3151 UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, err);
Caroline Ticef8da8632010-12-03 18:46:09 +00003152 else if (var_name == DisableSTDIOVarName ())
3153 UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003154}
3155
3156void
3157ProcessInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
3158 bool pending)
3159{
3160 if (new_settings.get() == NULL)
3161 return;
3162
3163 ProcessInstanceSettings *new_process_settings = (ProcessInstanceSettings *) new_settings.get();
3164
3165 m_run_args = new_process_settings->m_run_args;
3166 m_env_vars = new_process_settings->m_env_vars;
3167 m_input_path = new_process_settings->m_input_path;
3168 m_output_path = new_process_settings->m_output_path;
3169 m_error_path = new_process_settings->m_error_path;
3170 m_plugin = new_process_settings->m_plugin;
3171 m_disable_aslr = new_process_settings->m_disable_aslr;
Caroline Ticef8da8632010-12-03 18:46:09 +00003172 m_disable_stdio = new_process_settings->m_disable_stdio;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003173}
3174
Caroline Tice12cecd72010-09-20 21:37:42 +00003175bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003176ProcessInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
3177 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00003178 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00003179 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003180{
3181 if (var_name == RunArgsVarName())
3182 {
3183 if (m_run_args.GetArgumentCount() > 0)
Greg Claytona52c1552010-09-14 03:47:41 +00003184 {
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003185 for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
3186 value.AppendString (m_run_args.GetArgumentAtIndex (i));
Greg Claytona52c1552010-09-14 03:47:41 +00003187 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003188 }
3189 else if (var_name == EnvVarsVarName())
3190 {
Greg Clayton85851dd2010-12-04 00:10:17 +00003191 GetHostEnvironmentIfNeeded ();
3192
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003193 if (m_env_vars.size() > 0)
3194 {
3195 std::map<std::string, std::string>::iterator pos;
3196 for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
3197 {
3198 StreamString value_str;
3199 value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
3200 value.AppendString (value_str.GetData());
3201 }
3202 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003203 }
3204 else if (var_name == InputPathVarName())
3205 {
3206 value.AppendString (m_input_path.c_str());
3207 }
3208 else if (var_name == OutputPathVarName())
3209 {
3210 value.AppendString (m_output_path.c_str());
3211 }
3212 else if (var_name == ErrorPathVarName())
3213 {
3214 value.AppendString (m_error_path.c_str());
3215 }
3216 else if (var_name == PluginVarName())
3217 {
3218 value.AppendString (UserSettingsController::EnumToString (entry.enum_values, (int) m_plugin));
3219 }
Greg Clayton5c5f1a12010-12-04 00:12:24 +00003220 else if (var_name == InheritHostEnvVarName())
3221 {
3222 if (m_inherit_host_env)
3223 value.AppendString ("true");
3224 else
3225 value.AppendString ("false");
3226 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003227 else if (var_name == DisableASLRVarName())
3228 {
3229 if (m_disable_aslr)
3230 value.AppendString ("true");
3231 else
3232 value.AppendString ("false");
3233 }
Caroline Ticef8da8632010-12-03 18:46:09 +00003234 else if (var_name == DisableSTDIOVarName())
3235 {
3236 if (m_disable_stdio)
3237 value.AppendString ("true");
3238 else
3239 value.AppendString ("false");
3240 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003241 else
Caroline Tice12cecd72010-09-20 21:37:42 +00003242 {
3243 if (err)
3244 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
3245 return false;
3246 }
3247 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003248}
3249
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003250const ConstString
3251ProcessInstanceSettings::CreateInstanceName ()
3252{
3253 static int instance_count = 1;
3254 StreamString sstr;
3255
3256 sstr.Printf ("process_%d", instance_count);
3257 ++instance_count;
3258
3259 const ConstString ret_val (sstr.GetData());
3260 return ret_val;
3261}
3262
3263const ConstString &
3264ProcessInstanceSettings::RunArgsVarName ()
3265{
3266 static ConstString run_args_var_name ("run-args");
3267
3268 return run_args_var_name;
3269}
3270
3271const ConstString &
3272ProcessInstanceSettings::EnvVarsVarName ()
3273{
3274 static ConstString env_vars_var_name ("env-vars");
3275
3276 return env_vars_var_name;
3277}
3278
3279const ConstString &
Greg Clayton85851dd2010-12-04 00:10:17 +00003280ProcessInstanceSettings::InheritHostEnvVarName ()
3281{
3282 static ConstString g_name ("inherit-env");
3283
3284 return g_name;
3285}
3286
3287const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003288ProcessInstanceSettings::InputPathVarName ()
3289{
3290 static ConstString input_path_var_name ("input-path");
3291
3292 return input_path_var_name;
3293}
3294
3295const ConstString &
3296ProcessInstanceSettings::OutputPathVarName ()
3297{
Caroline Tice49e27372010-09-07 18:35:40 +00003298 static ConstString output_path_var_name ("output-path");
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003299
3300 return output_path_var_name;
3301}
3302
3303const ConstString &
3304ProcessInstanceSettings::ErrorPathVarName ()
3305{
Caroline Tice49e27372010-09-07 18:35:40 +00003306 static ConstString error_path_var_name ("error-path");
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003307
3308 return error_path_var_name;
3309}
3310
3311const ConstString &
3312ProcessInstanceSettings::PluginVarName ()
3313{
3314 static ConstString plugin_var_name ("plugin");
3315
3316 return plugin_var_name;
3317}
3318
3319
3320const ConstString &
3321ProcessInstanceSettings::DisableASLRVarName ()
3322{
3323 static ConstString disable_aslr_var_name ("disable-aslr");
3324
3325 return disable_aslr_var_name;
3326}
3327
Caroline Ticef8da8632010-12-03 18:46:09 +00003328const ConstString &
3329ProcessInstanceSettings::DisableSTDIOVarName ()
3330{
3331 static ConstString disable_stdio_var_name ("disable-stdio");
3332
3333 return disable_stdio_var_name;
3334}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003335
3336//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00003337// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003338//--------------------------------------------------
3339
3340SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00003341Process::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003342{
3343 //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"},
3344 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
3345};
3346
3347
3348lldb::OptionEnumValueElement
Greg Clayton1b654882010-09-19 02:33:57 +00003349Process::SettingsController::g_plugins[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003350{
Caroline Tice5c9fdfa2010-09-09 18:01:59 +00003351 { eMacosx, "process.macosx", "Use the native MacOSX debugger plugin" },
3352 { eRemoteDebugger, "process.gdb-remote" , "Use the GDB Remote protocol based debugger plugin" },
3353 { 0, NULL, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003354};
3355
3356SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00003357Process::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003358{
Greg Clayton85851dd2010-12-04 00:10:17 +00003359 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
3360 { "run-args", eSetVarTypeArray, NULL, NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." },
3361 { "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." },
3362 { "inherit-env", eSetVarTypeBoolean, "true", NULL, false, false, "Inherit the environment from the process that is running LLDB." },
Greg Claytonbd82a5d2011-01-23 05:56:20 +00003363 { "input-path", eSetVarTypeString, NULL, NULL, false, false, "The file/path to be used by the executable program for reading its input." },
3364 { "output-path", eSetVarTypeString, NULL, NULL, false, false, "The file/path to be used by the executable program for writing its output." },
3365 { "error-path", eSetVarTypeString, NULL, NULL, false, false, "The file/path to be used by the executable program for writings its error messages." },
3366 { "plugin", eSetVarTypeEnum, NULL, g_plugins, false, false, "The plugin to be used to run the process." },
Greg Clayton85851dd2010-12-04 00:10:17 +00003367 { "disable-aslr", eSetVarTypeBoolean, "true", NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" },
3368 { "disable-stdio", eSetVarTypeBoolean, "false", NULL, false, false, "Disable stdin/stdout for process (e.g. for a GUI application)" },
3369 { NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003370};
3371
3372
Jim Ingham5aee1622010-08-09 23:31:02 +00003373