blob: 4b0fd24864b4d939e01e0eda9fc4bcfee6a2625b [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
40Process*
41Process::FindPlugin (Target &target, const char *plugin_name, Listener &listener)
42{
43 ProcessCreateInstance create_callback = NULL;
44 if (plugin_name)
45 {
46 create_callback = PluginManager::GetProcessCreateCallbackForPluginName (plugin_name);
47 if (create_callback)
48 {
49 std::auto_ptr<Process> debugger_ap(create_callback(target, listener));
50 if (debugger_ap->CanDebug(target))
51 return debugger_ap.release();
52 }
53 }
54 else
55 {
Greg Claytonc982c762010-07-09 20:39:50 +000056 for (uint32_t idx = 0; (create_callback = PluginManager::GetProcessCreateCallbackAtIndex(idx)) != NULL; ++idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057 {
Greg Claytonc982c762010-07-09 20:39:50 +000058 std::auto_ptr<Process> debugger_ap(create_callback(target, listener));
59 if (debugger_ap->CanDebug(target))
60 return debugger_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061 }
62 }
63 return NULL;
64}
65
66
67//----------------------------------------------------------------------
68// Process constructor
69//----------------------------------------------------------------------
70Process::Process(Target &target, Listener &listener) :
71 UserID (LLDB_INVALID_PROCESS_ID),
Greg Claytoncfd1ace2010-10-31 03:01:06 +000072 Broadcaster ("lldb.process"),
Greg Claytondbe54502010-11-19 03:46:01 +000073 ProcessInstanceSettings (*GetSettingsController()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074 m_target (target),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075 m_public_state (eStateUnloaded),
76 m_private_state (eStateUnloaded),
77 m_private_state_broadcaster ("lldb.process.internal_state_broadcaster"),
78 m_private_state_control_broadcaster ("lldb.process.internal_state_control_broadcaster"),
79 m_private_state_listener ("lldb.process.internal_state_listener"),
80 m_private_state_control_wait(),
81 m_private_state_thread (LLDB_INVALID_HOST_THREAD),
82 m_stop_id (0),
83 m_thread_index_id (0),
84 m_exit_status (-1),
85 m_exit_string (),
86 m_thread_list (this),
87 m_notifications (),
Greg Clayton3af9ea52010-11-18 05:57:03 +000088 m_image_tokens (),
89 m_listener (listener),
90 m_breakpoint_site_list (),
Greg Clayton3af9ea52010-11-18 05:57:03 +000091 m_dynamic_checkers_ap (),
Caroline Ticeef5c6d02010-11-16 05:07:41 +000092 m_unix_signals (),
Greg Clayton3af9ea52010-11-18 05:57:03 +000093 m_target_triple (),
94 m_byte_order (eByteOrderHost),
95 m_addr_byte_size (0),
96 m_abi_sp (),
Caroline Ticeef5c6d02010-11-16 05:07:41 +000097 m_process_input_reader (),
Greg Claytond46c87a2010-12-04 02:39:47 +000098 m_stdio_communication ("lldb.process.stdio"),
Greg Clayton3af9ea52010-11-18 05:57:03 +000099 m_stdio_communication_mutex (Mutex::eMutexTypeRecursive),
Caroline Ticeef5c6d02010-11-16 05:07:41 +0000100 m_stdout_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101{
Caroline Tice1559a462010-09-27 00:30:10 +0000102 UpdateInstanceName();
103
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000104 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105 if (log)
106 log->Printf ("%p Process::Process()", this);
107
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000108 SetEventName (eBroadcastBitStateChanged, "state-changed");
109 SetEventName (eBroadcastBitInterrupt, "interrupt");
110 SetEventName (eBroadcastBitSTDOUT, "stdout-available");
111 SetEventName (eBroadcastBitSTDERR, "stderr-available");
112
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113 listener.StartListeningForEvents (this,
114 eBroadcastBitStateChanged |
115 eBroadcastBitInterrupt |
116 eBroadcastBitSTDOUT |
117 eBroadcastBitSTDERR);
118
119 m_private_state_listener.StartListeningForEvents(&m_private_state_broadcaster,
120 eBroadcastBitStateChanged);
121
122 m_private_state_listener.StartListeningForEvents(&m_private_state_control_broadcaster,
123 eBroadcastInternalStateControlStop |
124 eBroadcastInternalStateControlPause |
125 eBroadcastInternalStateControlResume);
126}
127
128//----------------------------------------------------------------------
129// Destructor
130//----------------------------------------------------------------------
131Process::~Process()
132{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000133 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134 if (log)
135 log->Printf ("%p Process::~Process()", this);
136 StopPrivateStateThread();
137}
138
139void
140Process::Finalize()
141{
142 // Do any cleanup needed prior to being destructed... Subclasses
143 // that override this method should call this superclass method as well.
144}
145
146void
147Process::RegisterNotificationCallbacks (const Notifications& callbacks)
148{
149 m_notifications.push_back(callbacks);
150 if (callbacks.initialize != NULL)
151 callbacks.initialize (callbacks.baton, this);
152}
153
154bool
155Process::UnregisterNotificationCallbacks(const Notifications& callbacks)
156{
157 std::vector<Notifications>::iterator pos, end = m_notifications.end();
158 for (pos = m_notifications.begin(); pos != end; ++pos)
159 {
160 if (pos->baton == callbacks.baton &&
161 pos->initialize == callbacks.initialize &&
162 pos->process_state_changed == callbacks.process_state_changed)
163 {
164 m_notifications.erase(pos);
165 return true;
166 }
167 }
168 return false;
169}
170
171void
172Process::SynchronouslyNotifyStateChanged (StateType state)
173{
174 std::vector<Notifications>::iterator notification_pos, notification_end = m_notifications.end();
175 for (notification_pos = m_notifications.begin(); notification_pos != notification_end; ++notification_pos)
176 {
177 if (notification_pos->process_state_changed)
178 notification_pos->process_state_changed (notification_pos->baton, this, state);
179 }
180}
181
182// FIXME: We need to do some work on events before the general Listener sees them.
183// For instance if we are continuing from a breakpoint, we need to ensure that we do
184// the little "insert real insn, step & stop" trick. But we can't do that when the
185// event is delivered by the broadcaster - since that is done on the thread that is
186// waiting for new events, so if we needed more than one event for our handling, we would
187// stall. So instead we do it when we fetch the event off of the queue.
188//
189
190StateType
191Process::GetNextEvent (EventSP &event_sp)
192{
193 StateType state = eStateInvalid;
194
195 if (m_listener.GetNextEventForBroadcaster (this, event_sp) && event_sp)
196 state = Process::ProcessEventData::GetStateFromEvent (event_sp.get());
197
198 return state;
199}
200
201
202StateType
203Process::WaitForProcessToStop (const TimeValue *timeout)
204{
205 StateType match_states[] = { eStateStopped, eStateCrashed, eStateDetached, eStateExited, eStateUnloaded };
206 return WaitForState (timeout, match_states, sizeof(match_states) / sizeof(StateType));
207}
208
209
210StateType
211Process::WaitForState
212(
213 const TimeValue *timeout,
214 const StateType *match_states, const uint32_t num_match_states
215)
216{
217 EventSP event_sp;
218 uint32_t i;
Greg Clayton05faeb72010-10-07 04:19:01 +0000219 StateType state = GetState();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220 while (state != eStateInvalid)
221 {
Greg Clayton05faeb72010-10-07 04:19:01 +0000222 // If we are exited or detached, we won't ever get back to any
223 // other valid state...
224 if (state == eStateDetached || state == eStateExited)
225 return state;
226
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227 state = WaitForStateChangedEvents (timeout, event_sp);
228
229 for (i=0; i<num_match_states; ++i)
230 {
231 if (match_states[i] == state)
232 return state;
233 }
234 }
235 return state;
236}
237
Jim Ingham30f9b212010-10-11 23:53:14 +0000238bool
239Process::HijackProcessEvents (Listener *listener)
240{
241 if (listener != NULL)
242 {
243 return HijackBroadcaster(listener, eBroadcastBitStateChanged);
244 }
245 else
246 return false;
247}
248
249void
250Process::RestoreProcessEvents ()
251{
252 RestoreBroadcaster();
253}
254
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000255StateType
256Process::WaitForStateChangedEvents (const TimeValue *timeout, EventSP &event_sp)
257{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000258 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259
260 if (log)
261 log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout);
262
263 StateType state = eStateInvalid;
Greg Clayton3fcbed62010-10-19 03:25:40 +0000264 if (m_listener.WaitForEventForBroadcasterWithType (timeout,
265 this,
266 eBroadcastBitStateChanged,
267 event_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268 state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
269
Caroline Tice20ad3c42010-10-29 21:48:37 +0000270 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271 if (log)
272 log->Printf ("Process::%s (timeout = %p, event_sp) => %s",
273 __FUNCTION__,
274 timeout,
275 StateAsCString(state));
276 return state;
277}
278
279Event *
280Process::PeekAtStateChangedEvents ()
281{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000282 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283
284 if (log)
285 log->Printf ("Process::%s...", __FUNCTION__);
286
287 Event *event_ptr;
Greg Clayton3fcbed62010-10-19 03:25:40 +0000288 event_ptr = m_listener.PeekAtNextEventForBroadcasterWithType (this,
289 eBroadcastBitStateChanged);
Caroline Tice20ad3c42010-10-29 21:48:37 +0000290 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000291 if (log)
292 {
293 if (event_ptr)
294 {
295 log->Printf ("Process::%s (event_ptr) => %s",
296 __FUNCTION__,
297 StateAsCString(ProcessEventData::GetStateFromEvent (event_ptr)));
298 }
299 else
300 {
301 log->Printf ("Process::%s no events found",
302 __FUNCTION__);
303 }
304 }
305 return event_ptr;
306}
307
308StateType
309Process::WaitForStateChangedEventsPrivate (const TimeValue *timeout, EventSP &event_sp)
310{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000311 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312
313 if (log)
314 log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout);
315
316 StateType state = eStateInvalid;
317 if (m_private_state_listener.WaitForEventForBroadcasterWithType(timeout,
318 &m_private_state_broadcaster,
319 eBroadcastBitStateChanged,
320 event_sp))
321 state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
322
323 // This is a bit of a hack, but when we wait here we could very well return
324 // to the command-line, and that could disable the log, which would render the
325 // log we got above invalid.
326 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
327 if (log)
328 log->Printf ("Process::%s (timeout = %p, event_sp) => %s", __FUNCTION__, timeout, StateAsCString(state));
329 return state;
330}
331
332bool
333Process::WaitForEventsPrivate (const TimeValue *timeout, EventSP &event_sp, bool control_only)
334{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000335 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336
337 if (log)
338 log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout);
339
340 if (control_only)
341 return m_private_state_listener.WaitForEventForBroadcaster(timeout, &m_private_state_control_broadcaster, event_sp);
342 else
343 return m_private_state_listener.WaitForEvent(timeout, event_sp);
344}
345
346bool
347Process::IsRunning () const
348{
349 return StateIsRunningState (m_public_state.GetValue());
350}
351
352int
353Process::GetExitStatus ()
354{
355 if (m_public_state.GetValue() == eStateExited)
356 return m_exit_status;
357 return -1;
358}
359
Greg Clayton85851dd2010-12-04 00:10:17 +0000360
361void
362Process::ProcessInstanceSettings::GetHostEnvironmentIfNeeded ()
363{
364 if (m_inherit_host_env && !m_got_host_env)
365 {
366 m_got_host_env = true;
367 StringList host_env;
368 const size_t host_env_count = Host::GetEnvironment (host_env);
369 for (size_t idx=0; idx<host_env_count; idx++)
370 {
371 const char *env_entry = host_env.GetStringAtIndex (idx);
372 if (env_entry)
373 {
Greg Claytone2956ee2010-12-15 20:52:40 +0000374 const char *equal_pos = ::strchr(env_entry, '=');
Greg Clayton85851dd2010-12-04 00:10:17 +0000375 if (equal_pos)
376 {
377 std::string key (env_entry, equal_pos - env_entry);
378 std::string value (equal_pos + 1);
379 if (m_env_vars.find (key) == m_env_vars.end())
380 m_env_vars[key] = value;
381 }
382 }
383 }
384 }
385}
386
387
388size_t
389Process::ProcessInstanceSettings::GetEnvironmentAsArgs (Args &env)
390{
391 GetHostEnvironmentIfNeeded ();
392
393 dictionary::const_iterator pos, end = m_env_vars.end();
394 for (pos = m_env_vars.begin(); pos != end; ++pos)
395 {
396 std::string env_var_equal_value (pos->first);
397 env_var_equal_value.append(1, '=');
398 env_var_equal_value.append (pos->second);
399 env.AppendArgument (env_var_equal_value.c_str());
400 }
401 return env.GetArgumentCount();
402}
403
404
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405const char *
406Process::GetExitDescription ()
407{
408 if (m_public_state.GetValue() == eStateExited && !m_exit_string.empty())
409 return m_exit_string.c_str();
410 return NULL;
411}
412
413void
414Process::SetExitStatus (int status, const char *cstr)
415{
Greg Clayton10177aa2010-12-08 05:08:21 +0000416 if (m_private_state.GetValue() != eStateExited)
417 {
418 m_exit_status = status;
419 if (cstr)
420 m_exit_string = cstr;
421 else
422 m_exit_string.clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423
Greg Clayton10177aa2010-12-08 05:08:21 +0000424 DidExit ();
425
426 SetPrivateState (eStateExited);
427 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428}
429
430// This static callback can be used to watch for local child processes on
431// the current host. The the child process exits, the process will be
432// found in the global target list (we want to be completely sure that the
433// lldb_private::Process doesn't go away before we can deliver the signal.
434bool
435Process::SetProcessExitStatus
436(
437 void *callback_baton,
438 lldb::pid_t pid,
439 int signo, // Zero for no signal
440 int exit_status // Exit value of process if signal is zero
441)
442{
443 if (signo == 0 || exit_status)
444 {
Greg Clayton66111032010-06-23 01:19:29 +0000445 TargetSP target_sp(Debugger::FindTargetWithProcessID (pid));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 if (target_sp)
447 {
448 ProcessSP process_sp (target_sp->GetProcessSP());
449 if (process_sp)
450 {
451 const char *signal_cstr = NULL;
452 if (signo)
453 signal_cstr = process_sp->GetUnixSignals().GetSignalAsCString (signo);
454
455 process_sp->SetExitStatus (exit_status, signal_cstr);
456 }
457 }
458 return true;
459 }
460 return false;
461}
462
463
464uint32_t
465Process::GetNextThreadIndexID ()
466{
467 return ++m_thread_index_id;
468}
469
470StateType
471Process::GetState()
472{
473 // If any other threads access this we will need a mutex for it
474 return m_public_state.GetValue ();
475}
476
477void
478Process::SetPublicState (StateType new_state)
479{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000480 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481 if (log)
482 log->Printf("Process::SetPublicState (%s)", StateAsCString(new_state));
483 m_public_state.SetValue (new_state);
484}
485
486StateType
487Process::GetPrivateState ()
488{
489 return m_private_state.GetValue();
490}
491
492void
493Process::SetPrivateState (StateType new_state)
494{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000495 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496 bool state_changed = false;
497
498 if (log)
499 log->Printf("Process::SetPrivateState (%s)", StateAsCString(new_state));
500
501 Mutex::Locker locker(m_private_state.GetMutex());
502
503 const StateType old_state = m_private_state.GetValueNoLock ();
504 state_changed = old_state != new_state;
505 if (state_changed)
506 {
507 m_private_state.SetValueNoLock (new_state);
508 if (StateIsStoppedState(new_state))
509 {
510 m_stop_id++;
511 if (log)
512 log->Printf("Process::SetPrivateState (%s) stop_id = %u", StateAsCString(new_state), m_stop_id);
513 }
514 // Use our target to get a shared pointer to ourselves...
515 m_private_state_broadcaster.BroadcastEvent (eBroadcastBitStateChanged, new ProcessEventData (GetTarget().GetProcessSP(), new_state));
516 }
517 else
518 {
519 if (log)
520 log->Printf("Process::SetPrivateState (%s) state didn't change. Ignoring...", StateAsCString(new_state), StateAsCString(old_state));
521 }
522}
523
524
525uint32_t
526Process::GetStopID() const
527{
528 return m_stop_id;
529}
530
531addr_t
532Process::GetImageInfoAddress()
533{
534 return LLDB_INVALID_ADDRESS;
535}
536
Greg Clayton8f343b02010-11-04 01:54:29 +0000537//----------------------------------------------------------------------
538// LoadImage
539//
540// This function provides a default implementation that works for most
541// unix variants. Any Process subclasses that need to do shared library
542// loading differently should override LoadImage and UnloadImage and
543// do what is needed.
544//----------------------------------------------------------------------
545uint32_t
546Process::LoadImage (const FileSpec &image_spec, Error &error)
547{
548 DynamicLoader *loader = GetDynamicLoader();
549 if (loader)
550 {
551 error = loader->CanLoadImage();
552 if (error.Fail())
553 return LLDB_INVALID_IMAGE_TOKEN;
554 }
555
556 if (error.Success())
557 {
558 ThreadSP thread_sp(GetThreadList ().GetSelectedThread());
559 if (thread_sp == NULL)
560 thread_sp = GetThreadList ().GetThreadAtIndex(0, true);
561
562 if (thread_sp)
563 {
564 StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (0));
565
566 if (frame_sp)
567 {
568 ExecutionContext exe_ctx;
569 frame_sp->CalculateExecutionContext (exe_ctx);
Jim Ingham399f1ca2010-11-05 19:25:48 +0000570 bool unwind_on_error = true;
Greg Clayton8f343b02010-11-04 01:54:29 +0000571 StreamString expr;
572 char path[PATH_MAX];
573 image_spec.GetPath(path, sizeof(path));
574 expr.Printf("dlopen (\"%s\", 2)", path);
575 const char *prefix = "extern \"C\" void* dlopen (const char *path, int mode);\n";
Jim Inghamf48169b2010-11-30 02:22:11 +0000576 lldb::ValueObjectSP result_valobj_sp;
577 ClangUserExpression::Evaluate (exe_ctx, unwind_on_error, expr.GetData(), prefix, result_valobj_sp);
Greg Clayton8f343b02010-11-04 01:54:29 +0000578 if (result_valobj_sp->GetError().Success())
579 {
580 Scalar scalar;
581 if (result_valobj_sp->ResolveValue (frame_sp.get(), scalar))
582 {
583 addr_t image_ptr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
584 if (image_ptr != 0 && image_ptr != LLDB_INVALID_ADDRESS)
585 {
586 uint32_t image_token = m_image_tokens.size();
587 m_image_tokens.push_back (image_ptr);
588 return image_token;
589 }
590 }
591 }
592 }
593 }
594 }
595 return LLDB_INVALID_IMAGE_TOKEN;
596}
597
598//----------------------------------------------------------------------
599// UnloadImage
600//
601// This function provides a default implementation that works for most
602// unix variants. Any Process subclasses that need to do shared library
603// loading differently should override LoadImage and UnloadImage and
604// do what is needed.
605//----------------------------------------------------------------------
606Error
607Process::UnloadImage (uint32_t image_token)
608{
609 Error error;
610 if (image_token < m_image_tokens.size())
611 {
612 const addr_t image_addr = m_image_tokens[image_token];
613 if (image_addr == LLDB_INVALID_ADDRESS)
614 {
615 error.SetErrorString("image already unloaded");
616 }
617 else
618 {
619 DynamicLoader *loader = GetDynamicLoader();
620 if (loader)
621 error = loader->CanLoadImage();
622
623 if (error.Success())
624 {
625 ThreadSP thread_sp(GetThreadList ().GetSelectedThread());
626 if (thread_sp == NULL)
627 thread_sp = GetThreadList ().GetThreadAtIndex(0, true);
628
629 if (thread_sp)
630 {
631 StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (0));
632
633 if (frame_sp)
634 {
635 ExecutionContext exe_ctx;
636 frame_sp->CalculateExecutionContext (exe_ctx);
Jim Ingham399f1ca2010-11-05 19:25:48 +0000637 bool unwind_on_error = true;
Greg Clayton8f343b02010-11-04 01:54:29 +0000638 StreamString expr;
639 expr.Printf("dlclose ((void *)0x%llx)", image_addr);
640 const char *prefix = "extern \"C\" int dlclose(void* handle);\n";
Jim Inghamf48169b2010-11-30 02:22:11 +0000641 lldb::ValueObjectSP result_valobj_sp;
642 ClangUserExpression::Evaluate (exe_ctx, unwind_on_error, expr.GetData(), prefix, result_valobj_sp);
Greg Clayton8f343b02010-11-04 01:54:29 +0000643 if (result_valobj_sp->GetError().Success())
644 {
645 Scalar scalar;
646 if (result_valobj_sp->ResolveValue (frame_sp.get(), scalar))
647 {
648 if (scalar.UInt(1))
649 {
650 error.SetErrorStringWithFormat("expression failed: \"%s\"", expr.GetData());
651 }
652 else
653 {
654 m_image_tokens[image_token] = LLDB_INVALID_ADDRESS;
655 }
656 }
657 }
658 else
659 {
660 error = result_valobj_sp->GetError();
661 }
662 }
663 }
664 }
665 }
666 }
667 else
668 {
669 error.SetErrorString("invalid image token");
670 }
671 return error;
672}
673
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000674DynamicLoader *
675Process::GetDynamicLoader()
676{
677 return NULL;
678}
679
680const ABI *
681Process::GetABI()
682{
683 ConstString& triple = m_target_triple;
684
685 if (triple.IsEmpty())
686 return NULL;
687
688 if (m_abi_sp.get() == NULL)
689 {
690 m_abi_sp.reset(ABI::FindPlugin(triple));
691 }
692
693 return m_abi_sp.get();
694}
695
Jim Ingham22777012010-09-23 02:01:19 +0000696LanguageRuntime *
697Process::GetLanguageRuntime(lldb::LanguageType language)
698{
699 LanguageRuntimeCollection::iterator pos;
700 pos = m_language_runtimes.find (language);
701 if (pos == m_language_runtimes.end())
702 {
703 lldb::LanguageRuntimeSP runtime(LanguageRuntime::FindPlugin(this, language));
704
705 m_language_runtimes[language]
706 = runtime;
707 return runtime.get();
708 }
709 else
710 return (*pos).second.get();
711}
712
713CPPLanguageRuntime *
714Process::GetCPPLanguageRuntime ()
715{
716 LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeC_plus_plus);
717 if (runtime != NULL && runtime->GetLanguageType() == eLanguageTypeC_plus_plus)
718 return static_cast<CPPLanguageRuntime *> (runtime);
719 return NULL;
720}
721
722ObjCLanguageRuntime *
723Process::GetObjCLanguageRuntime ()
724{
725 LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeObjC);
726 if (runtime != NULL && runtime->GetLanguageType() == eLanguageTypeObjC)
727 return static_cast<ObjCLanguageRuntime *> (runtime);
728 return NULL;
729}
730
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000731BreakpointSiteList &
732Process::GetBreakpointSiteList()
733{
734 return m_breakpoint_site_list;
735}
736
737const BreakpointSiteList &
738Process::GetBreakpointSiteList() const
739{
740 return m_breakpoint_site_list;
741}
742
743
744void
745Process::DisableAllBreakpointSites ()
746{
747 m_breakpoint_site_list.SetEnabledForAll (false);
748}
749
750Error
751Process::ClearBreakpointSiteByID (lldb::user_id_t break_id)
752{
753 Error error (DisableBreakpointSiteByID (break_id));
754
755 if (error.Success())
756 m_breakpoint_site_list.Remove(break_id);
757
758 return error;
759}
760
761Error
762Process::DisableBreakpointSiteByID (lldb::user_id_t break_id)
763{
764 Error error;
765 BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID (break_id);
766 if (bp_site_sp)
767 {
768 if (bp_site_sp->IsEnabled())
769 error = DisableBreakpoint (bp_site_sp.get());
770 }
771 else
772 {
773 error.SetErrorStringWithFormat("invalid breakpoint site ID: %i", break_id);
774 }
775
776 return error;
777}
778
779Error
780Process::EnableBreakpointSiteByID (lldb::user_id_t break_id)
781{
782 Error error;
783 BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID (break_id);
784 if (bp_site_sp)
785 {
786 if (!bp_site_sp->IsEnabled())
787 error = EnableBreakpoint (bp_site_sp.get());
788 }
789 else
790 {
791 error.SetErrorStringWithFormat("invalid breakpoint site ID: %i", break_id);
792 }
793 return error;
794}
795
Stephen Wilson50bd94f2010-07-17 00:56:13 +0000796lldb::break_id_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797Process::CreateBreakpointSite (BreakpointLocationSP &owner, bool use_hardware)
798{
Greg Claytonf5e56de2010-09-14 23:36:40 +0000799 const addr_t load_addr = owner->GetAddress().GetLoadAddress (&m_target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000800 if (load_addr != LLDB_INVALID_ADDRESS)
801 {
802 BreakpointSiteSP bp_site_sp;
803
804 // Look up this breakpoint site. If it exists, then add this new owner, otherwise
805 // create a new breakpoint site and add it.
806
807 bp_site_sp = m_breakpoint_site_list.FindByAddress (load_addr);
808
809 if (bp_site_sp)
810 {
811 bp_site_sp->AddOwner (owner);
812 owner->SetBreakpointSite (bp_site_sp);
813 return bp_site_sp->GetID();
814 }
815 else
816 {
817 bp_site_sp.reset (new BreakpointSite (&m_breakpoint_site_list, owner, load_addr, LLDB_INVALID_THREAD_ID, use_hardware));
818 if (bp_site_sp)
819 {
820 if (EnableBreakpoint (bp_site_sp.get()).Success())
821 {
822 owner->SetBreakpointSite (bp_site_sp);
823 return m_breakpoint_site_list.Add (bp_site_sp);
824 }
825 }
826 }
827 }
828 // We failed to enable the breakpoint
829 return LLDB_INVALID_BREAK_ID;
830
831}
832
833void
834Process::RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, lldb::user_id_t owner_loc_id, BreakpointSiteSP &bp_site_sp)
835{
836 uint32_t num_owners = bp_site_sp->RemoveOwner (owner_id, owner_loc_id);
837 if (num_owners == 0)
838 {
839 DisableBreakpoint(bp_site_sp.get());
840 m_breakpoint_site_list.RemoveByAddress(bp_site_sp->GetLoadAddress());
841 }
842}
843
844
845size_t
846Process::RemoveBreakpointOpcodesFromBuffer (addr_t bp_addr, size_t size, uint8_t *buf) const
847{
848 size_t bytes_removed = 0;
849 addr_t intersect_addr;
850 size_t intersect_size;
851 size_t opcode_offset;
852 size_t idx;
853 BreakpointSiteSP bp;
854
855 for (idx = 0; (bp = m_breakpoint_site_list.GetByIndex(idx)) != NULL; ++idx)
856 {
857 if (bp->GetType() == BreakpointSite::eSoftware)
858 {
859 if (bp->IntersectsRange(bp_addr, size, &intersect_addr, &intersect_size, &opcode_offset))
860 {
861 assert(bp_addr <= intersect_addr && intersect_addr < bp_addr + size);
862 assert(bp_addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= bp_addr + size);
863 assert(opcode_offset + intersect_size <= bp->GetByteSize());
864 size_t buf_offset = intersect_addr - bp_addr;
865 ::memcpy(buf + buf_offset, bp->GetSavedOpcodeBytes() + opcode_offset, intersect_size);
866 }
867 }
868 }
869 return bytes_removed;
870}
871
872
873Error
874Process::EnableSoftwareBreakpoint (BreakpointSite *bp_site)
875{
876 Error error;
877 assert (bp_site != NULL);
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000878 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879 const addr_t bp_addr = bp_site->GetLoadAddress();
880 if (log)
881 log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx", bp_site->GetID(), (uint64_t)bp_addr);
882 if (bp_site->IsEnabled())
883 {
884 if (log)
885 log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- already enabled", bp_site->GetID(), (uint64_t)bp_addr);
886 return error;
887 }
888
889 if (bp_addr == LLDB_INVALID_ADDRESS)
890 {
891 error.SetErrorString("BreakpointSite contains an invalid load address.");
892 return error;
893 }
894 // Ask the lldb::Process subclass to fill in the correct software breakpoint
895 // trap for the breakpoint site
896 const size_t bp_opcode_size = GetSoftwareBreakpointTrapOpcode(bp_site);
897
898 if (bp_opcode_size == 0)
899 {
900 error.SetErrorStringWithFormat ("Process::GetSoftwareBreakpointTrapOpcode() returned zero, unable to get breakpoint trap for address 0x%llx.\n", bp_addr);
901 }
902 else
903 {
904 const uint8_t * const bp_opcode_bytes = bp_site->GetTrapOpcodeBytes();
905
906 if (bp_opcode_bytes == NULL)
907 {
908 error.SetErrorString ("BreakpointSite doesn't contain a valid breakpoint trap opcode.");
909 return error;
910 }
911
912 // Save the original opcode by reading it
913 if (DoReadMemory(bp_addr, bp_site->GetSavedOpcodeBytes(), bp_opcode_size, error) == bp_opcode_size)
914 {
915 // Write a software breakpoint in place of the original opcode
916 if (DoWriteMemory(bp_addr, bp_opcode_bytes, bp_opcode_size, error) == bp_opcode_size)
917 {
918 uint8_t verify_bp_opcode_bytes[64];
919 if (DoReadMemory(bp_addr, verify_bp_opcode_bytes, bp_opcode_size, error) == bp_opcode_size)
920 {
921 if (::memcmp(bp_opcode_bytes, verify_bp_opcode_bytes, bp_opcode_size) == 0)
922 {
923 bp_site->SetEnabled(true);
924 bp_site->SetType (BreakpointSite::eSoftware);
925 if (log)
926 log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- SUCCESS",
927 bp_site->GetID(),
928 (uint64_t)bp_addr);
929 }
930 else
931 error.SetErrorString("Failed to verify the breakpoint trap in memory.");
932 }
933 else
934 error.SetErrorString("Unable to read memory to verify breakpoint trap.");
935 }
936 else
937 error.SetErrorString("Unable to write breakpoint trap to memory.");
938 }
939 else
940 error.SetErrorString("Unable to read memory at breakpoint address.");
941 }
942 if (log)
943 log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- FAILED: %s",
944 bp_site->GetID(),
945 (uint64_t)bp_addr,
946 error.AsCString());
947 return error;
948}
949
950Error
951Process::DisableSoftwareBreakpoint (BreakpointSite *bp_site)
952{
953 Error error;
954 assert (bp_site != NULL);
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000955 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956 addr_t bp_addr = bp_site->GetLoadAddress();
957 lldb::user_id_t breakID = bp_site->GetID();
958 if (log)
959 log->Printf ("ProcessMacOSX::DisableBreakpoint (breakID = %d) addr = 0x%llx", breakID, (uint64_t)bp_addr);
960
961 if (bp_site->IsHardware())
962 {
963 error.SetErrorString("Breakpoint site is a hardware breakpoint.");
964 }
965 else if (bp_site->IsEnabled())
966 {
967 const size_t break_op_size = bp_site->GetByteSize();
968 const uint8_t * const break_op = bp_site->GetTrapOpcodeBytes();
969 if (break_op_size > 0)
970 {
971 // Clear a software breakoint instruction
Greg Claytonc982c762010-07-09 20:39:50 +0000972 uint8_t curr_break_op[8];
Stephen Wilson4ab47682010-07-20 18:41:11 +0000973 assert (break_op_size <= sizeof(curr_break_op));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000974 bool break_op_found = false;
975
976 // Read the breakpoint opcode
977 if (DoReadMemory (bp_addr, curr_break_op, break_op_size, error) == break_op_size)
978 {
979 bool verify = false;
980 // Make sure we have the a breakpoint opcode exists at this address
981 if (::memcmp (curr_break_op, break_op, break_op_size) == 0)
982 {
983 break_op_found = true;
984 // We found a valid breakpoint opcode at this address, now restore
985 // the saved opcode.
986 if (DoWriteMemory (bp_addr, bp_site->GetSavedOpcodeBytes(), break_op_size, error) == break_op_size)
987 {
988 verify = true;
989 }
990 else
991 error.SetErrorString("Memory write failed when restoring original opcode.");
992 }
993 else
994 {
995 error.SetErrorString("Original breakpoint trap is no longer in memory.");
996 // Set verify to true and so we can check if the original opcode has already been restored
997 verify = true;
998 }
999
1000 if (verify)
1001 {
Greg Claytonc982c762010-07-09 20:39:50 +00001002 uint8_t verify_opcode[8];
Stephen Wilson4ab47682010-07-20 18:41:11 +00001003 assert (break_op_size < sizeof(verify_opcode));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001004 // Verify that our original opcode made it back to the inferior
1005 if (DoReadMemory (bp_addr, verify_opcode, break_op_size, error) == break_op_size)
1006 {
1007 // compare the memory we just read with the original opcode
1008 if (::memcmp (bp_site->GetSavedOpcodeBytes(), verify_opcode, break_op_size) == 0)
1009 {
1010 // SUCCESS
1011 bp_site->SetEnabled(false);
1012 if (log)
1013 log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- SUCCESS", bp_site->GetID(), (uint64_t)bp_addr);
1014 return error;
1015 }
1016 else
1017 {
1018 if (break_op_found)
1019 error.SetErrorString("Failed to restore original opcode.");
1020 }
1021 }
1022 else
1023 error.SetErrorString("Failed to read memory to verify that breakpoint trap was restored.");
1024 }
1025 }
1026 else
1027 error.SetErrorString("Unable to read memory that should contain the breakpoint trap.");
1028 }
1029 }
1030 else
1031 {
1032 if (log)
1033 log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- already disabled", bp_site->GetID(), (uint64_t)bp_addr);
1034 return error;
1035 }
1036
1037 if (log)
1038 log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- FAILED: %s",
1039 bp_site->GetID(),
1040 (uint64_t)bp_addr,
1041 error.AsCString());
1042 return error;
1043
1044}
1045
1046
1047size_t
1048Process::ReadMemory (addr_t addr, void *buf, size_t size, Error &error)
1049{
1050 if (buf == NULL || size == 0)
1051 return 0;
1052
1053 size_t bytes_read = 0;
1054 uint8_t *bytes = (uint8_t *)buf;
1055
1056 while (bytes_read < size)
1057 {
1058 const size_t curr_size = size - bytes_read;
1059 const size_t curr_bytes_read = DoReadMemory (addr + bytes_read,
1060 bytes + bytes_read,
1061 curr_size,
1062 error);
1063 bytes_read += curr_bytes_read;
1064 if (curr_bytes_read == curr_size || curr_bytes_read == 0)
1065 break;
1066 }
1067
1068 // Replace any software breakpoint opcodes that fall into this range back
1069 // into "buf" before we return
1070 if (bytes_read > 0)
1071 RemoveBreakpointOpcodesFromBuffer (addr, bytes_read, (uint8_t *)buf);
1072 return bytes_read;
1073}
1074
Greg Clayton58a4c462010-12-16 20:01:20 +00001075uint64_t
1076Process::ReadUnsignedInteger (lldb::addr_t vm_addr, size_t integer_byte_size, Error &error)
1077{
1078 if (integer_byte_size > sizeof(uint64_t))
1079 {
1080 error.SetErrorString ("unsupported integer size");
1081 }
1082 else
1083 {
1084 uint8_t tmp[sizeof(uint64_t)];
1085 DataExtractor data (tmp, integer_byte_size, GetByteOrder(), GetAddressByteSize());
1086 if (ReadMemory (vm_addr, tmp, integer_byte_size, error) == integer_byte_size)
1087 {
1088 uint32_t offset = 0;
1089 return data.GetMaxU64 (&offset, integer_byte_size);
1090 }
1091 }
1092 // Any plug-in that doesn't return success a memory read with the number
1093 // of bytes that were requested should be setting the error
1094 assert (error.Fail());
1095 return 0;
1096}
1097
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001098size_t
1099Process::WriteMemoryPrivate (addr_t addr, const void *buf, size_t size, Error &error)
1100{
1101 size_t bytes_written = 0;
1102 const uint8_t *bytes = (const uint8_t *)buf;
1103
1104 while (bytes_written < size)
1105 {
1106 const size_t curr_size = size - bytes_written;
1107 const size_t curr_bytes_written = DoWriteMemory (addr + bytes_written,
1108 bytes + bytes_written,
1109 curr_size,
1110 error);
1111 bytes_written += curr_bytes_written;
1112 if (curr_bytes_written == curr_size || curr_bytes_written == 0)
1113 break;
1114 }
1115 return bytes_written;
1116}
1117
1118size_t
1119Process::WriteMemory (addr_t addr, const void *buf, size_t size, Error &error)
1120{
1121 if (buf == NULL || size == 0)
1122 return 0;
1123 // We need to write any data that would go where any current software traps
1124 // (enabled software breakpoints) any software traps (breakpoints) that we
1125 // may have placed in our tasks memory.
1126
1127 BreakpointSiteList::collection::const_iterator iter = m_breakpoint_site_list.GetMap()->lower_bound (addr);
1128 BreakpointSiteList::collection::const_iterator end = m_breakpoint_site_list.GetMap()->end();
1129
1130 if (iter == end || iter->second->GetLoadAddress() > addr + size)
1131 return DoWriteMemory(addr, buf, size, error);
1132
1133 BreakpointSiteList::collection::const_iterator pos;
1134 size_t bytes_written = 0;
Greg Claytonc982c762010-07-09 20:39:50 +00001135 addr_t intersect_addr = 0;
1136 size_t intersect_size = 0;
1137 size_t opcode_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001138 const uint8_t *ubuf = (const uint8_t *)buf;
1139
1140 for (pos = iter; pos != end; ++pos)
1141 {
1142 BreakpointSiteSP bp;
1143 bp = pos->second;
1144
1145 assert(bp->IntersectsRange(addr, size, &intersect_addr, &intersect_size, &opcode_offset));
1146 assert(addr <= intersect_addr && intersect_addr < addr + size);
1147 assert(addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= addr + size);
1148 assert(opcode_offset + intersect_size <= bp->GetByteSize());
1149
1150 // Check for bytes before this breakpoint
1151 const addr_t curr_addr = addr + bytes_written;
1152 if (intersect_addr > curr_addr)
1153 {
1154 // There are some bytes before this breakpoint that we need to
1155 // just write to memory
1156 size_t curr_size = intersect_addr - curr_addr;
1157 size_t curr_bytes_written = WriteMemoryPrivate (curr_addr,
1158 ubuf + bytes_written,
1159 curr_size,
1160 error);
1161 bytes_written += curr_bytes_written;
1162 if (curr_bytes_written != curr_size)
1163 {
1164 // We weren't able to write all of the requested bytes, we
1165 // are done looping and will return the number of bytes that
1166 // we have written so far.
1167 break;
1168 }
1169 }
1170
1171 // Now write any bytes that would cover up any software breakpoints
1172 // directly into the breakpoint opcode buffer
1173 ::memcpy(bp->GetSavedOpcodeBytes() + opcode_offset, ubuf + bytes_written, intersect_size);
1174 bytes_written += intersect_size;
1175 }
1176
1177 // Write any remaining bytes after the last breakpoint if we have any left
1178 if (bytes_written < size)
1179 bytes_written += WriteMemoryPrivate (addr + bytes_written,
1180 ubuf + bytes_written,
1181 size - bytes_written,
1182 error);
1183
1184 return bytes_written;
1185}
1186
1187addr_t
1188Process::AllocateMemory(size_t size, uint32_t permissions, Error &error)
1189{
1190 // Fixme: we should track the blocks we've allocated, and clean them up...
1191 // We could even do our own allocator here if that ends up being more efficient.
1192 return DoAllocateMemory (size, permissions, error);
1193}
1194
1195Error
1196Process::DeallocateMemory (addr_t ptr)
1197{
1198 return DoDeallocateMemory (ptr);
1199}
1200
1201
1202Error
1203Process::EnableWatchpoint (WatchpointLocation *watchpoint)
1204{
1205 Error error;
1206 error.SetErrorString("watchpoints are not supported");
1207 return error;
1208}
1209
1210Error
1211Process::DisableWatchpoint (WatchpointLocation *watchpoint)
1212{
1213 Error error;
1214 error.SetErrorString("watchpoints are not supported");
1215 return error;
1216}
1217
1218StateType
1219Process::WaitForProcessStopPrivate (const TimeValue *timeout, EventSP &event_sp)
1220{
1221 StateType state;
1222 // Now wait for the process to launch and return control to us, and then
1223 // call DidLaunch:
1224 while (1)
1225 {
1226 // FIXME: Might want to put a timeout in here:
1227 state = WaitForStateChangedEventsPrivate (NULL, event_sp);
1228 if (state == eStateStopped || state == eStateCrashed || state == eStateExited)
1229 break;
1230 else
1231 HandlePrivateEvent (event_sp);
1232 }
1233 return state;
1234}
1235
1236Error
1237Process::Launch
1238(
1239 char const *argv[],
1240 char const *envp[],
Greg Claytonf681b942010-08-31 18:35:14 +00001241 uint32_t launch_flags,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242 const char *stdin_path,
1243 const char *stdout_path,
1244 const char *stderr_path
1245)
1246{
1247 Error error;
1248 m_target_triple.Clear();
1249 m_abi_sp.reset();
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001250 m_process_input_reader.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251
1252 Module *exe_module = m_target.GetExecutableModule().get();
1253 if (exe_module)
1254 {
1255 char exec_file_path[PATH_MAX];
1256 exe_module->GetFileSpec().GetPath(exec_file_path, sizeof(exec_file_path));
1257 if (exe_module->GetFileSpec().Exists())
1258 {
1259 error = WillLaunch (exe_module);
1260 if (error.Success())
1261 {
Greg Clayton05faeb72010-10-07 04:19:01 +00001262 SetPublicState (eStateLaunching);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001263 // The args coming in should not contain the application name, the
1264 // lldb_private::Process class will add this in case the executable
1265 // gets resolved to a different file than was given on the command
1266 // line (like when an applicaiton bundle is specified and will
1267 // resolve to the contained exectuable file, or the file given was
1268 // a symlink or other file system link that resolves to a different
1269 // file).
1270
1271 // Get the resolved exectuable path
1272
1273 // Make a new argument vector
1274 std::vector<const char *> exec_path_plus_argv;
1275 // Append the resolved executable path
1276 exec_path_plus_argv.push_back (exec_file_path);
1277
1278 // Push all args if there are any
1279 if (argv)
1280 {
1281 for (int i = 0; argv[i]; ++i)
1282 exec_path_plus_argv.push_back(argv[i]);
1283 }
1284
1285 // Push a NULL to terminate the args.
1286 exec_path_plus_argv.push_back(NULL);
1287
1288 // Now launch using these arguments.
Greg Clayton471b31c2010-07-20 22:52:08 +00001289 error = DoLaunch (exe_module,
1290 exec_path_plus_argv.empty() ? NULL : &exec_path_plus_argv.front(),
1291 envp,
Greg Claytonf681b942010-08-31 18:35:14 +00001292 launch_flags,
Greg Clayton471b31c2010-07-20 22:52:08 +00001293 stdin_path,
1294 stdout_path,
1295 stderr_path);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296
1297 if (error.Fail())
1298 {
1299 if (GetID() != LLDB_INVALID_PROCESS_ID)
1300 {
1301 SetID (LLDB_INVALID_PROCESS_ID);
1302 const char *error_string = error.AsCString();
1303 if (error_string == NULL)
1304 error_string = "launch failed";
1305 SetExitStatus (-1, error_string);
1306 }
1307 }
1308 else
1309 {
1310 EventSP event_sp;
1311 StateType state = WaitForProcessStopPrivate(NULL, event_sp);
1312
1313 if (state == eStateStopped || state == eStateCrashed)
1314 {
1315 DidLaunch ();
1316
1317 // This delays passing the stopped event to listeners till DidLaunch gets
1318 // a chance to complete...
1319 HandlePrivateEvent (event_sp);
1320 StartPrivateStateThread ();
1321 }
1322 else if (state == eStateExited)
1323 {
1324 // We exited while trying to launch somehow. Don't call DidLaunch as that's
1325 // not likely to work, and return an invalid pid.
1326 HandlePrivateEvent (event_sp);
1327 }
1328 }
1329 }
1330 }
1331 else
1332 {
1333 error.SetErrorStringWithFormat("File doesn't exist: '%s'.\n", exec_file_path);
1334 }
1335 }
1336 return error;
1337}
1338
1339Error
1340Process::CompleteAttach ()
1341{
1342 Error error;
Greg Clayton19388cf2010-10-18 01:45:30 +00001343
1344 if (GetID() == LLDB_INVALID_PROCESS_ID)
1345 {
1346 error.SetErrorString("no process");
1347 }
1348
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001349 EventSP event_sp;
1350 StateType state = WaitForProcessStopPrivate(NULL, event_sp);
1351 if (state == eStateStopped || state == eStateCrashed)
1352 {
1353 DidAttach ();
Jim Ingham5aee1622010-08-09 23:31:02 +00001354 // Figure out which one is the executable, and set that in our target:
1355 ModuleList &modules = GetTarget().GetImages();
1356
1357 size_t num_modules = modules.GetSize();
1358 for (int i = 0; i < num_modules; i++)
1359 {
1360 ModuleSP module_sp = modules.GetModuleAtIndex(i);
1361 if (module_sp->IsExecutable())
1362 {
1363 ModuleSP exec_module = GetTarget().GetExecutableModule();
1364 if (!exec_module || exec_module != module_sp)
1365 {
1366
1367 GetTarget().SetExecutableModule (module_sp, false);
1368 }
1369 break;
1370 }
1371 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001372
1373 // This delays passing the stopped event to listeners till DidLaunch gets
1374 // a chance to complete...
1375 HandlePrivateEvent(event_sp);
1376 StartPrivateStateThread();
1377 }
1378 else
1379 {
1380 // We exited while trying to launch somehow. Don't call DidLaunch as that's
1381 // not likely to work, and return an invalid pid.
1382 if (state == eStateExited)
1383 HandlePrivateEvent (event_sp);
1384 error.SetErrorStringWithFormat("invalid state after attach: %s",
1385 lldb_private::StateAsCString(state));
1386 }
1387 return error;
1388}
1389
1390Error
1391Process::Attach (lldb::pid_t attach_pid)
1392{
1393
1394 m_target_triple.Clear();
1395 m_abi_sp.reset();
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001396 m_process_input_reader.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001397
Jim Ingham5aee1622010-08-09 23:31:02 +00001398 // Find the process and its architecture. Make sure it matches the architecture
1399 // of the current Target, and if not adjust it.
1400
1401 ArchSpec attach_spec = GetArchSpecForExistingProcess (attach_pid);
1402 if (attach_spec != GetTarget().GetArchitecture())
1403 {
1404 // Set the architecture on the target.
1405 GetTarget().SetArchitecture(attach_spec);
1406 }
1407
Greg Claytonc982c762010-07-09 20:39:50 +00001408 Error error (WillAttachToProcessWithID(attach_pid));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001409 if (error.Success())
1410 {
Greg Clayton05faeb72010-10-07 04:19:01 +00001411 SetPublicState (eStateAttaching);
1412
Greg Claytonc982c762010-07-09 20:39:50 +00001413 error = DoAttachToProcessWithID (attach_pid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001414 if (error.Success())
1415 {
1416 error = CompleteAttach();
1417 }
1418 else
1419 {
1420 if (GetID() != LLDB_INVALID_PROCESS_ID)
1421 {
1422 SetID (LLDB_INVALID_PROCESS_ID);
1423 const char *error_string = error.AsCString();
1424 if (error_string == NULL)
1425 error_string = "attach failed";
1426
1427 SetExitStatus(-1, error_string);
1428 }
1429 }
1430 }
1431 return error;
1432}
1433
1434Error
1435Process::Attach (const char *process_name, bool wait_for_launch)
1436{
1437 m_target_triple.Clear();
1438 m_abi_sp.reset();
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001439 m_process_input_reader.reset();
Jim Ingham5aee1622010-08-09 23:31:02 +00001440
1441 // Find the process and its architecture. Make sure it matches the architecture
1442 // of the current Target, and if not adjust it.
1443
Jim Ingham2ecb7422010-08-17 21:54:19 +00001444 if (!wait_for_launch)
Jim Ingham5aee1622010-08-09 23:31:02 +00001445 {
Jim Ingham2ecb7422010-08-17 21:54:19 +00001446 ArchSpec attach_spec = GetArchSpecForExistingProcess (process_name);
Greg Clayton19388cf2010-10-18 01:45:30 +00001447 if (attach_spec.IsValid() && attach_spec != GetTarget().GetArchitecture())
Jim Ingham2ecb7422010-08-17 21:54:19 +00001448 {
1449 // Set the architecture on the target.
1450 GetTarget().SetArchitecture(attach_spec);
1451 }
Jim Ingham5aee1622010-08-09 23:31:02 +00001452 }
Jim Ingham2ecb7422010-08-17 21:54:19 +00001453
Greg Claytonc982c762010-07-09 20:39:50 +00001454 Error error (WillAttachToProcessWithName(process_name, wait_for_launch));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001455 if (error.Success())
1456 {
Greg Clayton05faeb72010-10-07 04:19:01 +00001457 SetPublicState (eStateAttaching);
Greg Claytonc982c762010-07-09 20:39:50 +00001458 error = DoAttachToProcessWithName (process_name, wait_for_launch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001459 if (error.Fail())
1460 {
1461 if (GetID() != LLDB_INVALID_PROCESS_ID)
1462 {
1463 SetID (LLDB_INVALID_PROCESS_ID);
1464 const char *error_string = error.AsCString();
1465 if (error_string == NULL)
1466 error_string = "attach failed";
1467
1468 SetExitStatus(-1, error_string);
1469 }
1470 }
1471 else
1472 {
1473 error = CompleteAttach();
1474 }
1475 }
1476 return error;
1477}
1478
1479Error
1480Process::Resume ()
1481{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001482 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001483 if (log)
1484 log->Printf("Process::Resume() m_stop_id = %u", m_stop_id);
1485
1486 Error error (WillResume());
1487 // Tell the process it is about to resume before the thread list
1488 if (error.Success())
1489 {
Johnny Chenc4221e42010-12-02 20:53:05 +00001490 // Now let the thread list know we are about to resume so it
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001491 // can let all of our threads know that they are about to be
1492 // resumed. Threads will each be called with
1493 // Thread::WillResume(StateType) where StateType contains the state
1494 // that they are supposed to have when the process is resumed
1495 // (suspended/running/stepping). Threads should also check
1496 // their resume signal in lldb::Thread::GetResumeSignal()
1497 // to see if they are suppoed to start back up with a signal.
1498 if (m_thread_list.WillResume())
1499 {
1500 error = DoResume();
1501 if (error.Success())
1502 {
1503 DidResume();
1504 m_thread_list.DidResume();
1505 }
1506 }
1507 else
1508 {
1509 error.SetErrorStringWithFormat("thread list returned flase after WillResume");
1510 }
1511 }
1512 return error;
1513}
1514
1515Error
1516Process::Halt ()
1517{
1518 Error error (WillHalt());
1519
1520 if (error.Success())
1521 {
Greg Clayton3af9ea52010-11-18 05:57:03 +00001522
1523 bool caused_stop = false;
1524 EventSP event_sp;
1525
1526 // Pause our private state thread so we can ensure no one else eats
1527 // the stop event out from under us.
1528 PausePrivateStateThread();
1529
1530 // Ask the process subclass to actually halt our process
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001531 error = DoHalt(caused_stop);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001532 if (error.Success())
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001533 {
Greg Clayton3af9ea52010-11-18 05:57:03 +00001534 // If "caused_stop" is true, then DoHalt stopped the process. If
1535 // "caused_stop" is false, the process was already stopped.
1536 // If the DoHalt caused the process to stop, then we want to catch
1537 // this event and set the interrupted bool to true before we pass
1538 // this along so clients know that the process was interrupted by
1539 // a halt command.
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001540 if (caused_stop)
1541 {
Greg Clayton3af9ea52010-11-18 05:57:03 +00001542 // Wait for 2 seconds for the process to stop.
1543 TimeValue timeout_time;
1544 timeout_time = TimeValue::Now();
1545 timeout_time.OffsetWithSeconds(2);
1546 StateType state = WaitForStateChangedEventsPrivate (&timeout_time, event_sp);
1547
1548 if (state == eStateInvalid)
1549 {
1550 // We timeout out and didn't get a stop event...
1551 error.SetErrorString ("Halt timed out.");
1552 }
1553 else
1554 {
Greg Clayton3af9ea52010-11-18 05:57:03 +00001555 if (StateIsStoppedState (state))
1556 {
1557 // We caused the process to interrupt itself, so mark this
1558 // as such in the stop event so clients can tell an interrupted
1559 // process from a natural stop
1560 ProcessEventData::SetInterruptedInEvent (event_sp.get(), true);
1561 }
1562 else
1563 {
1564 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
1565 if (log)
1566 log->Printf("Process::Halt() failed to stop, state is: %s", StateAsCString(state));
1567 error.SetErrorString ("Did not get stopped event after halt.");
1568 }
1569 }
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001570 }
Greg Clayton3af9ea52010-11-18 05:57:03 +00001571 DidHalt();
1572
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001573 }
Greg Clayton3af9ea52010-11-18 05:57:03 +00001574 // Resume our private state thread before we post the event (if any)
1575 ResumePrivateStateThread();
1576
1577 // Post any event we might have consumed. If all goes well, we will have
1578 // stopped the process, intercepted the event and set the interrupted
Jim Inghamf48169b2010-11-30 02:22:11 +00001579 // bool in the event. Post it to the private event queue and that will end up
1580 // correctly setting the state.
Greg Clayton3af9ea52010-11-18 05:57:03 +00001581 if (event_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +00001582 m_private_state_broadcaster.BroadcastEvent(event_sp);
Greg Clayton3af9ea52010-11-18 05:57:03 +00001583
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001584 }
1585 return error;
1586}
1587
1588Error
1589Process::Detach ()
1590{
1591 Error error (WillDetach());
1592
1593 if (error.Success())
1594 {
1595 DisableAllBreakpointSites();
1596 error = DoDetach();
1597 if (error.Success())
1598 {
1599 DidDetach();
1600 StopPrivateStateThread();
1601 }
1602 }
1603 return error;
1604}
1605
1606Error
1607Process::Destroy ()
1608{
1609 Error error (WillDestroy());
1610 if (error.Success())
1611 {
1612 DisableAllBreakpointSites();
1613 error = DoDestroy();
1614 if (error.Success())
1615 {
1616 DidDestroy();
1617 StopPrivateStateThread();
1618 }
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001619 m_stdio_communication.StopReadThread();
1620 m_stdio_communication.Disconnect();
1621 if (m_process_input_reader && m_process_input_reader->IsActive())
1622 m_target.GetDebugger().PopInputReader (m_process_input_reader);
1623 if (m_process_input_reader)
1624 m_process_input_reader.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001625 }
1626 return error;
1627}
1628
1629Error
1630Process::Signal (int signal)
1631{
1632 Error error (WillSignal());
1633 if (error.Success())
1634 {
1635 error = DoSignal(signal);
1636 if (error.Success())
1637 DidSignal();
1638 }
1639 return error;
1640}
1641
1642UnixSignals &
1643Process::GetUnixSignals ()
1644{
1645 return m_unix_signals;
1646}
1647
1648Target &
1649Process::GetTarget ()
1650{
1651 return m_target;
1652}
1653
1654const Target &
1655Process::GetTarget () const
1656{
1657 return m_target;
1658}
1659
1660uint32_t
1661Process::GetAddressByteSize()
1662{
Greg Clayton3af9ea52010-11-18 05:57:03 +00001663 if (m_addr_byte_size == 0)
1664 return m_target.GetArchitecture().GetAddressByteSize();
1665 return m_addr_byte_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001666}
1667
1668bool
1669Process::ShouldBroadcastEvent (Event *event_ptr)
1670{
1671 const StateType state = Process::ProcessEventData::GetStateFromEvent (event_ptr);
1672 bool return_value = true;
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001673 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001674
1675 switch (state)
1676 {
1677 case eStateAttaching:
1678 case eStateLaunching:
1679 case eStateDetached:
1680 case eStateExited:
1681 case eStateUnloaded:
1682 // These events indicate changes in the state of the debugging session, always report them.
1683 return_value = true;
1684 break;
1685 case eStateInvalid:
1686 // We stopped for no apparent reason, don't report it.
1687 return_value = false;
1688 break;
1689 case eStateRunning:
1690 case eStateStepping:
1691 // If we've started the target running, we handle the cases where we
1692 // are already running and where there is a transition from stopped to
1693 // running differently.
1694 // running -> running: Automatically suppress extra running events
1695 // stopped -> running: Report except when there is one or more no votes
1696 // and no yes votes.
1697 SynchronouslyNotifyStateChanged (state);
1698 switch (m_public_state.GetValue())
1699 {
1700 case eStateRunning:
1701 case eStateStepping:
1702 // We always suppress multiple runnings with no PUBLIC stop in between.
1703 return_value = false;
1704 break;
1705 default:
1706 // TODO: make this work correctly. For now always report
1707 // run if we aren't running so we don't miss any runnning
1708 // events. If I run the lldb/test/thread/a.out file and
1709 // break at main.cpp:58, run and hit the breakpoints on
1710 // multiple threads, then somehow during the stepping over
1711 // of all breakpoints no run gets reported.
1712 return_value = true;
1713
1714 // This is a transition from stop to run.
1715 switch (m_thread_list.ShouldReportRun (event_ptr))
1716 {
1717 case eVoteYes:
1718 case eVoteNoOpinion:
1719 return_value = true;
1720 break;
1721 case eVoteNo:
1722 return_value = false;
1723 break;
1724 }
1725 break;
1726 }
1727 break;
1728 case eStateStopped:
1729 case eStateCrashed:
1730 case eStateSuspended:
1731 {
1732 // We've stopped. First see if we're going to restart the target.
1733 // If we are going to stop, then we always broadcast the event.
1734 // 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 +00001735 // If no thread has an opinion, we don't report it.
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001736 if (ProcessEventData::GetInterruptedFromEvent (event_ptr))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001737 {
Greg Clayton3af9ea52010-11-18 05:57:03 +00001738 if (log)
1739 log->Printf ("Process::ShouldBroadcastEvent (%p) stopped due to an interrupt, state: %s", event_ptr, StateAsCString(state));
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001740 return true;
1741 }
1742 else
1743 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001744 RefreshStateAfterStop ();
1745
1746 if (m_thread_list.ShouldStop (event_ptr) == false)
1747 {
1748 switch (m_thread_list.ShouldReportStop (event_ptr))
1749 {
1750 case eVoteYes:
1751 Process::ProcessEventData::SetRestartedInEvent (event_ptr, true);
Johnny Chen3c230652010-10-14 00:54:32 +00001752 // Intentional fall-through here.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001753 case eVoteNoOpinion:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001754 case eVoteNo:
1755 return_value = false;
1756 break;
1757 }
1758
1759 if (log)
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001760 log->Printf ("Process::ShouldBroadcastEvent (%p) Restarting process from state: %s", event_ptr, StateAsCString(state));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001761 Resume ();
1762 }
1763 else
1764 {
1765 return_value = true;
1766 SynchronouslyNotifyStateChanged (state);
1767 }
1768 }
1769 }
1770 }
1771
1772 if (log)
1773 log->Printf ("Process::ShouldBroadcastEvent (%p) => %s", event_ptr, StateAsCString(state), return_value ? "YES" : "NO");
1774 return return_value;
1775}
1776
1777//------------------------------------------------------------------
1778// Thread Queries
1779//------------------------------------------------------------------
1780
1781ThreadList &
1782Process::GetThreadList ()
1783{
1784 return m_thread_list;
1785}
1786
1787const ThreadList &
1788Process::GetThreadList () const
1789{
1790 return m_thread_list;
1791}
1792
1793
1794bool
1795Process::StartPrivateStateThread ()
1796{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001797 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001798
1799 if (log)
1800 log->Printf ("Process::%s ( )", __FUNCTION__);
1801
1802 // Create a thread that watches our internal state and controls which
1803 // events make it to clients (into the DCProcess event queue).
1804 m_private_state_thread = Host::ThreadCreate ("<lldb.process.internal-state>", Process::PrivateStateThread, this, NULL);
1805 return m_private_state_thread != LLDB_INVALID_HOST_THREAD;
1806}
1807
1808void
1809Process::PausePrivateStateThread ()
1810{
1811 ControlPrivateStateThread (eBroadcastInternalStateControlPause);
1812}
1813
1814void
1815Process::ResumePrivateStateThread ()
1816{
1817 ControlPrivateStateThread (eBroadcastInternalStateControlResume);
1818}
1819
1820void
1821Process::StopPrivateStateThread ()
1822{
1823 ControlPrivateStateThread (eBroadcastInternalStateControlStop);
1824}
1825
1826void
1827Process::ControlPrivateStateThread (uint32_t signal)
1828{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001829 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001830
1831 assert (signal == eBroadcastInternalStateControlStop ||
1832 signal == eBroadcastInternalStateControlPause ||
1833 signal == eBroadcastInternalStateControlResume);
1834
1835 if (log)
1836 log->Printf ("Process::%s ( ) - signal: %d", __FUNCTION__, signal);
1837
1838 // Signal the private state thread
1839 if (m_private_state_thread != LLDB_INVALID_HOST_THREAD)
1840 {
1841 TimeValue timeout_time;
1842 bool timed_out;
1843
1844 m_private_state_control_broadcaster.BroadcastEvent (signal, NULL);
1845
1846 timeout_time = TimeValue::Now();
1847 timeout_time.OffsetWithSeconds(2);
1848 m_private_state_control_wait.WaitForValueEqualTo (true, &timeout_time, &timed_out);
1849 m_private_state_control_wait.SetValue (false, eBroadcastNever);
1850
1851 if (signal == eBroadcastInternalStateControlStop)
1852 {
1853 if (timed_out)
1854 Host::ThreadCancel (m_private_state_thread, NULL);
1855
1856 thread_result_t result = NULL;
1857 Host::ThreadJoin (m_private_state_thread, &result, NULL);
Greg Clayton49182ed2010-07-22 18:34:21 +00001858 m_private_state_thread = LLDB_INVALID_HOST_THREAD;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859 }
1860 }
1861}
1862
1863void
1864Process::HandlePrivateEvent (EventSP &event_sp)
1865{
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001866 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001867 const StateType internal_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
1868 // See if we should broadcast this state to external clients?
1869 const bool should_broadcast = ShouldBroadcastEvent (event_sp.get());
1870 if (log)
1871 log->Printf ("Process::%s (arg = %p, pid = %i) got event '%s' broadcast = %s", __FUNCTION__, this, GetID(), StateAsCString(internal_state), should_broadcast ? "yes" : "no");
1872
1873 if (should_broadcast)
1874 {
1875 if (log)
1876 {
1877 log->Printf ("\tChanging public state from: %s to %s", StateAsCString(GetState ()), StateAsCString (internal_state));
1878 }
Caroline Ticeef5c6d02010-11-16 05:07:41 +00001879 if (StateIsRunningState (internal_state))
1880 PushProcessInputReader ();
1881 else
1882 PopProcessInputReader ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001883 Process::ProcessEventData::SetUpdateStateOnRemoval(event_sp.get());
1884 BroadcastEvent (event_sp);
1885 }
1886 else
1887 {
1888 if (log)
1889 {
1890 log->Printf ("\tNot changing public state with event: %s", StateAsCString (internal_state));
1891 }
1892 }
1893}
1894
1895void *
1896Process::PrivateStateThread (void *arg)
1897{
1898 Process *proc = static_cast<Process*> (arg);
1899 void *result = proc->RunPrivateStateThread ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001900 return result;
1901}
1902
1903void *
1904Process::RunPrivateStateThread ()
1905{
1906 bool control_only = false;
1907 m_private_state_control_wait.SetValue (false, eBroadcastNever);
1908
Greg Clayton2d4edfb2010-11-06 01:53:30 +00001909 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001910 if (log)
1911 log->Printf ("Process::%s (arg = %p, pid = %i) thread starting...", __FUNCTION__, this, GetID());
1912
1913 bool exit_now = false;
1914 while (!exit_now)
1915 {
1916 EventSP event_sp;
1917 WaitForEventsPrivate (NULL, event_sp, control_only);
1918 if (event_sp->BroadcasterIs(&m_private_state_control_broadcaster))
1919 {
1920 switch (event_sp->GetType())
1921 {
1922 case eBroadcastInternalStateControlStop:
1923 exit_now = true;
1924 continue; // Go to next loop iteration so we exit without
1925 break; // doing any internal state managment below
1926
1927 case eBroadcastInternalStateControlPause:
1928 control_only = true;
1929 break;
1930
1931 case eBroadcastInternalStateControlResume:
1932 control_only = false;
1933 break;
1934 }
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001935
1936 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
1937 if (log)
1938 log->Printf ("Process::%s (arg = %p, pid = %i) got a control event: %d", __FUNCTION__, this, GetID(), event_sp->GetType());
1939
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940 m_private_state_control_wait.SetValue (true, eBroadcastAlways);
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001941 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001942 }
1943
1944
1945 const StateType internal_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
1946
1947 if (internal_state != eStateInvalid)
1948 {
1949 HandlePrivateEvent (event_sp);
1950 }
1951
Greg Clayton58d1c9a2010-10-18 04:14:23 +00001952 if (internal_state == eStateInvalid ||
1953 internal_state == eStateExited ||
1954 internal_state == eStateDetached )
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001955 {
1956 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
1957 if (log)
1958 log->Printf ("Process::%s (arg = %p, pid = %i) about to exit with internal state %s...", __FUNCTION__, this, GetID(), StateAsCString(internal_state));
1959
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001960 break;
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001961 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001962 }
1963
Caroline Tice20ad3c42010-10-29 21:48:37 +00001964 // Verify log is still enabled before attempting to write to it...
1965 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001966 if (log)
1967 log->Printf ("Process::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, this, GetID());
1968
Greg Claytonbe77e3b2010-08-19 21:50:06 +00001969 m_private_state_thread = LLDB_INVALID_HOST_THREAD;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001970 return NULL;
1971}
1972
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001973//------------------------------------------------------------------
1974// Process Event Data
1975//------------------------------------------------------------------
1976
1977Process::ProcessEventData::ProcessEventData () :
1978 EventData (),
1979 m_process_sp (),
1980 m_state (eStateInvalid),
Greg Claytonc982c762010-07-09 20:39:50 +00001981 m_restarted (false),
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001982 m_update_state (false),
1983 m_interrupted (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001984{
1985}
1986
1987Process::ProcessEventData::ProcessEventData (const ProcessSP &process_sp, StateType state) :
1988 EventData (),
1989 m_process_sp (process_sp),
1990 m_state (state),
Greg Claytonc982c762010-07-09 20:39:50 +00001991 m_restarted (false),
Jim Ingham0d8bcc72010-11-17 02:32:00 +00001992 m_update_state (false),
1993 m_interrupted (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001994{
1995}
1996
1997Process::ProcessEventData::~ProcessEventData()
1998{
1999}
2000
2001const ConstString &
2002Process::ProcessEventData::GetFlavorString ()
2003{
2004 static ConstString g_flavor ("Process::ProcessEventData");
2005 return g_flavor;
2006}
2007
2008const ConstString &
2009Process::ProcessEventData::GetFlavor () const
2010{
2011 return ProcessEventData::GetFlavorString ();
2012}
2013
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002014void
2015Process::ProcessEventData::DoOnRemoval (Event *event_ptr)
2016{
2017 // This function gets called twice for each event, once when the event gets pulled
2018 // off of the private process event queue, and once when it gets pulled off of
2019 // the public event queue. m_update_state is used to distinguish these
2020 // two cases; it is false when we're just pulling it off for private handling,
2021 // and we don't want to do the breakpoint command handling then.
2022
2023 if (!m_update_state)
2024 return;
2025
2026 m_process_sp->SetPublicState (m_state);
2027
2028 // If we're stopped and haven't restarted, then do the breakpoint commands here:
2029 if (m_state == eStateStopped && ! m_restarted)
2030 {
2031 int num_threads = m_process_sp->GetThreadList().GetSize();
2032 int idx;
Greg Claytonf4b47e12010-08-04 01:40:35 +00002033
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002034 for (idx = 0; idx < num_threads; ++idx)
2035 {
2036 lldb::ThreadSP thread_sp = m_process_sp->GetThreadList().GetThreadAtIndex(idx);
2037
Jim Inghamb15bfc72010-10-20 00:39:53 +00002038 StopInfoSP stop_info_sp = thread_sp->GetStopInfo ();
2039 if (stop_info_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002040 {
Jim Inghamb15bfc72010-10-20 00:39:53 +00002041 stop_info_sp->PerformAction(event_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002042 }
2043 }
Greg Claytonf4b47e12010-08-04 01:40:35 +00002044
Jim Ingham3ebcf7f2010-08-10 00:59:59 +00002045 // The stop action might restart the target. If it does, then we want to mark that in the
2046 // event so that whoever is receiving it will know to wait for the running event and reflect
2047 // that state appropriately.
2048
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002049 if (m_process_sp->GetPrivateState() == eStateRunning)
2050 SetRestarted(true);
2051 }
2052}
2053
2054void
2055Process::ProcessEventData::Dump (Stream *s) const
2056{
2057 if (m_process_sp)
2058 s->Printf(" process = %p (pid = %u), ", m_process_sp.get(), m_process_sp->GetID());
2059
2060 s->Printf("state = %s", StateAsCString(GetState()));;
2061}
2062
2063const Process::ProcessEventData *
2064Process::ProcessEventData::GetEventDataFromEvent (const Event *event_ptr)
2065{
2066 if (event_ptr)
2067 {
2068 const EventData *event_data = event_ptr->GetData();
2069 if (event_data && event_data->GetFlavor() == ProcessEventData::GetFlavorString())
2070 return static_cast <const ProcessEventData *> (event_ptr->GetData());
2071 }
2072 return NULL;
2073}
2074
2075ProcessSP
2076Process::ProcessEventData::GetProcessFromEvent (const Event *event_ptr)
2077{
2078 ProcessSP process_sp;
2079 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2080 if (data)
2081 process_sp = data->GetProcessSP();
2082 return process_sp;
2083}
2084
2085StateType
2086Process::ProcessEventData::GetStateFromEvent (const Event *event_ptr)
2087{
2088 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2089 if (data == NULL)
2090 return eStateInvalid;
2091 else
2092 return data->GetState();
2093}
2094
2095bool
2096Process::ProcessEventData::GetRestartedFromEvent (const Event *event_ptr)
2097{
2098 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2099 if (data == NULL)
2100 return false;
2101 else
2102 return data->GetRestarted();
2103}
2104
2105void
2106Process::ProcessEventData::SetRestartedInEvent (Event *event_ptr, bool new_value)
2107{
2108 ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr));
2109 if (data != NULL)
2110 data->SetRestarted(new_value);
2111}
2112
2113bool
Jim Ingham0d8bcc72010-11-17 02:32:00 +00002114Process::ProcessEventData::GetInterruptedFromEvent (const Event *event_ptr)
2115{
2116 const ProcessEventData *data = GetEventDataFromEvent (event_ptr);
2117 if (data == NULL)
2118 return false;
2119 else
2120 return data->GetInterrupted ();
2121}
2122
2123void
2124Process::ProcessEventData::SetInterruptedInEvent (Event *event_ptr, bool new_value)
2125{
2126 ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr));
2127 if (data != NULL)
2128 data->SetInterrupted(new_value);
2129}
2130
2131bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002132Process::ProcessEventData::SetUpdateStateOnRemoval (Event *event_ptr)
2133{
2134 ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr));
2135 if (data)
2136 {
2137 data->SetUpdateStateOnRemoval();
2138 return true;
2139 }
2140 return false;
2141}
2142
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002143Target *
2144Process::CalculateTarget ()
2145{
2146 return &m_target;
2147}
2148
2149Process *
2150Process::CalculateProcess ()
2151{
2152 return this;
2153}
2154
2155Thread *
2156Process::CalculateThread ()
2157{
2158 return NULL;
2159}
2160
2161StackFrame *
2162Process::CalculateStackFrame ()
2163{
2164 return NULL;
2165}
2166
2167void
Greg Clayton0603aa92010-10-04 01:05:56 +00002168Process::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002169{
2170 exe_ctx.target = &m_target;
2171 exe_ctx.process = this;
2172 exe_ctx.thread = NULL;
2173 exe_ctx.frame = NULL;
2174}
2175
2176lldb::ProcessSP
2177Process::GetSP ()
2178{
2179 return GetTarget().GetProcessSP();
2180}
2181
Jim Ingham5aee1622010-08-09 23:31:02 +00002182uint32_t
2183Process::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids)
2184{
2185 return 0;
2186}
2187
2188ArchSpec
2189Process::GetArchSpecForExistingProcess (lldb::pid_t pid)
2190{
2191 return Host::GetArchSpecForExistingProcess (pid);
2192}
2193
2194ArchSpec
2195Process::GetArchSpecForExistingProcess (const char *process_name)
2196{
2197 return Host::GetArchSpecForExistingProcess (process_name);
2198}
2199
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002200void
2201Process::AppendSTDOUT (const char * s, size_t len)
2202{
Greg Clayton3af9ea52010-11-18 05:57:03 +00002203 Mutex::Locker locker (m_stdio_communication_mutex);
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002204 m_stdout_data.append (s, len);
2205
Greg Claytona9ff3062010-12-05 19:16:56 +00002206 BroadcastEventIfUnique (eBroadcastBitSTDOUT, new ProcessEventData (GetTarget().GetProcessSP(), GetState()));
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002207}
2208
2209void
2210Process::STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len)
2211{
2212 Process *process = (Process *) baton;
2213 process->AppendSTDOUT (static_cast<const char *>(src), src_len);
2214}
2215
2216size_t
2217Process::ProcessInputReaderCallback (void *baton,
2218 InputReader &reader,
2219 lldb::InputReaderAction notification,
2220 const char *bytes,
2221 size_t bytes_len)
2222{
2223 Process *process = (Process *) baton;
2224
2225 switch (notification)
2226 {
2227 case eInputReaderActivate:
2228 break;
2229
2230 case eInputReaderDeactivate:
2231 break;
2232
2233 case eInputReaderReactivate:
2234 break;
2235
2236 case eInputReaderGotToken:
2237 {
2238 Error error;
2239 process->PutSTDIN (bytes, bytes_len, error);
2240 }
2241 break;
2242
Caroline Ticeefed6132010-11-19 20:47:54 +00002243 case eInputReaderInterrupt:
2244 process->Halt ();
2245 break;
2246
2247 case eInputReaderEndOfFile:
2248 process->AppendSTDOUT ("^D", 2);
2249 break;
2250
Caroline Ticeef5c6d02010-11-16 05:07:41 +00002251 case eInputReaderDone:
2252 break;
2253
2254 }
2255
2256 return bytes_len;
2257}
2258
2259void
2260Process::ResetProcessInputReader ()
2261{
2262 m_process_input_reader.reset();
2263}
2264
2265void
2266Process::SetUpProcessInputReader (int file_descriptor)
2267{
2268 // First set up the Read Thread for reading/handling process I/O
2269
2270 std::auto_ptr<ConnectionFileDescriptor> conn_ap (new ConnectionFileDescriptor (file_descriptor, true));
2271
2272 if (conn_ap.get())
2273 {
2274 m_stdio_communication.SetConnection (conn_ap.release());
2275 if (m_stdio_communication.IsConnected())
2276 {
2277 m_stdio_communication.SetReadThreadBytesReceivedCallback (STDIOReadThreadBytesReceived, this);
2278 m_stdio_communication.StartReadThread();
2279
2280 // Now read thread is set up, set up input reader.
2281
2282 if (!m_process_input_reader.get())
2283 {
2284 m_process_input_reader.reset (new InputReader(m_target.GetDebugger()));
2285 Error err (m_process_input_reader->Initialize (Process::ProcessInputReaderCallback,
2286 this,
2287 eInputReaderGranularityByte,
2288 NULL,
2289 NULL,
2290 false));
2291
2292 if (err.Fail())
2293 m_process_input_reader.reset();
2294 }
2295 }
2296 }
2297}
2298
2299void
2300Process::PushProcessInputReader ()
2301{
2302 if (m_process_input_reader && !m_process_input_reader->IsActive())
2303 m_target.GetDebugger().PushInputReader (m_process_input_reader);
2304}
2305
2306void
2307Process::PopProcessInputReader ()
2308{
2309 if (m_process_input_reader && m_process_input_reader->IsActive())
2310 m_target.GetDebugger().PopInputReader (m_process_input_reader);
2311}
2312
Greg Clayton99d0faf2010-11-18 23:32:35 +00002313
2314void
2315Process::Initialize ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002316{
Greg Clayton99d0faf2010-11-18 23:32:35 +00002317 UserSettingsControllerSP &usc = GetSettingsController();
2318 usc.reset (new SettingsController);
2319 UserSettingsController::InitializeSettingsController (usc,
2320 SettingsController::global_settings_table,
2321 SettingsController::instance_settings_table);
2322}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002323
Greg Clayton99d0faf2010-11-18 23:32:35 +00002324void
2325Process::Terminate ()
2326{
2327 UserSettingsControllerSP &usc = GetSettingsController();
2328 UserSettingsController::FinalizeSettingsController (usc);
2329 usc.reset();
2330}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002331
Greg Clayton99d0faf2010-11-18 23:32:35 +00002332UserSettingsControllerSP &
2333Process::GetSettingsController ()
2334{
2335 static UserSettingsControllerSP g_settings_controller;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002336 return g_settings_controller;
2337}
2338
Caroline Tice1559a462010-09-27 00:30:10 +00002339void
2340Process::UpdateInstanceName ()
2341{
2342 ModuleSP module_sp = GetTarget().GetExecutableModule();
2343 if (module_sp)
2344 {
2345 StreamString sstr;
2346 sstr.Printf ("%s", module_sp->GetFileSpec().GetFilename().AsCString());
2347
Greg Claytondbe54502010-11-19 03:46:01 +00002348 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
Caroline Tice1559a462010-09-27 00:30:10 +00002349 sstr.GetData());
2350 }
2351}
2352
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002353ExecutionResults
Jim Inghamf48169b2010-11-30 02:22:11 +00002354Process::RunThreadPlan (ExecutionContext &exe_ctx,
2355 lldb::ThreadPlanSP &thread_plan_sp,
2356 bool stop_others,
2357 bool try_all_threads,
2358 bool discard_on_error,
2359 uint32_t single_thread_timeout_usec,
2360 Stream &errors)
2361{
2362 ExecutionResults return_value = eExecutionSetupError;
2363
2364 // Save this value for restoration of the execution context after we run
2365 uint32_t tid = exe_ctx.thread->GetIndexID();
2366
2367 // N.B. Running the target may unset the currently selected thread and frame. We don't want to do that either,
2368 // so we should arrange to reset them as well.
2369
2370 lldb::ThreadSP selected_thread_sp = exe_ctx.process->GetThreadList().GetSelectedThread();
2371 lldb::StackFrameSP selected_frame_sp;
2372
2373 uint32_t selected_tid;
2374 if (selected_thread_sp != NULL)
2375 {
2376 selected_tid = selected_thread_sp->GetIndexID();
2377 selected_frame_sp = selected_thread_sp->GetSelectedFrame();
2378 }
2379 else
2380 {
2381 selected_tid = LLDB_INVALID_THREAD_ID;
2382 }
2383
2384 exe_ctx.thread->QueueThreadPlan(thread_plan_sp, true);
2385
2386 Listener listener("ClangFunction temporary listener");
2387 exe_ctx.process->HijackProcessEvents(&listener);
2388
2389 Error resume_error = exe_ctx.process->Resume ();
2390 if (!resume_error.Success())
2391 {
2392 errors.Printf("Error resuming inferior: \"%s\".\n", resume_error.AsCString());
2393 exe_ctx.process->RestoreProcessEvents();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002394 return lldb::eExecutionSetupError;
Jim Inghamf48169b2010-11-30 02:22:11 +00002395 }
2396
2397 // We need to call the function synchronously, so spin waiting for it to return.
2398 // If we get interrupted while executing, we're going to lose our context, and
2399 // won't be able to gather the result at this point.
2400 // We set the timeout AFTER the resume, since the resume takes some time and we
2401 // don't want to charge that to the timeout.
2402
2403 TimeValue* timeout_ptr = NULL;
2404 TimeValue real_timeout;
2405
2406 if (single_thread_timeout_usec != 0)
2407 {
2408 real_timeout = TimeValue::Now();
2409 real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec);
2410 timeout_ptr = &real_timeout;
2411 }
2412
2413 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
2414 while (1)
2415 {
2416 lldb::EventSP event_sp;
2417 lldb::StateType stop_state = lldb::eStateInvalid;
2418 // Now wait for the process to stop again:
2419 bool got_event = listener.WaitForEvent (timeout_ptr, event_sp);
2420
2421 if (!got_event)
2422 {
2423 // Right now this is the only way to tell we've timed out...
2424 // We should interrupt the process here...
2425 // Not really sure what to do if Halt fails here...
2426 if (log)
2427 if (try_all_threads)
2428 log->Printf ("Running function with timeout: %d timed out, trying with all threads enabled.",
2429 single_thread_timeout_usec);
2430 else
2431 log->Printf ("Running function with timeout: %d timed out, abandoning execution.",
2432 single_thread_timeout_usec);
2433
2434 if (exe_ctx.process->Halt().Success())
2435 {
2436 timeout_ptr = NULL;
2437 if (log)
2438 log->Printf ("Halt succeeded.");
2439
2440 // Between the time that we got the timeout and the time we halted, but target
2441 // might have actually completed the plan. If so, we're done. Note, I call WFE here with a short
2442 // timeout to
2443 got_event = listener.WaitForEvent(NULL, event_sp);
2444
2445 if (got_event)
2446 {
2447 stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
2448 if (log)
2449 {
2450 log->Printf ("Stopped with event: %s", StateAsCString(stop_state));
2451 if (stop_state == lldb::eStateStopped && Process::ProcessEventData::GetInterruptedFromEvent(event_sp.get()))
2452 log->Printf (" Event was the Halt interruption event.");
2453 }
2454
2455 if (exe_ctx.thread->IsThreadPlanDone (thread_plan_sp.get()))
2456 {
2457 if (log)
2458 log->Printf ("Even though we timed out, the call plan was done. Exiting wait loop.");
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002459 return_value = lldb::eExecutionCompleted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002460 break;
2461 }
2462
2463 if (try_all_threads
2464 && (stop_state == lldb::eStateStopped && Process::ProcessEventData::GetInterruptedFromEvent (event_sp.get())))
2465 {
2466
2467 thread_plan_sp->SetStopOthers (false);
2468 if (log)
2469 log->Printf ("About to resume.");
2470
2471 exe_ctx.process->Resume();
2472 continue;
2473 }
2474 else
2475 {
2476 exe_ctx.process->RestoreProcessEvents ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002477 return lldb::eExecutionInterrupted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002478 }
2479 }
2480 }
2481 }
2482
2483 stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
2484 if (log)
2485 log->Printf("Got event: %s.", StateAsCString(stop_state));
2486
2487 if (stop_state == lldb::eStateRunning || stop_state == lldb::eStateStepping)
2488 continue;
2489
2490 if (exe_ctx.thread->IsThreadPlanDone (thread_plan_sp.get()))
2491 {
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002492 return_value = lldb::eExecutionCompleted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002493 break;
2494 }
2495 else if (exe_ctx.thread->WasThreadPlanDiscarded (thread_plan_sp.get()))
2496 {
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002497 return_value = lldb::eExecutionDiscarded;
Jim Inghamf48169b2010-11-30 02:22:11 +00002498 break;
2499 }
2500 else
2501 {
2502 if (log)
2503 {
2504 StreamString s;
2505 event_sp->Dump (&s);
2506 StreamString ts;
2507
2508 const char *event_explanation;
2509
2510 do
2511 {
2512 const Process::ProcessEventData *event_data = Process::ProcessEventData::GetEventDataFromEvent (event_sp.get());
2513
2514 if (!event_data)
2515 {
2516 event_explanation = "<no event data>";
2517 break;
2518 }
2519
2520 Process *process = event_data->GetProcessSP().get();
2521
2522 if (!process)
2523 {
2524 event_explanation = "<no process>";
2525 break;
2526 }
2527
2528 ThreadList &thread_list = process->GetThreadList();
2529
2530 uint32_t num_threads = thread_list.GetSize();
2531 uint32_t thread_index;
2532
2533 ts.Printf("<%u threads> ", num_threads);
2534
2535 for (thread_index = 0;
2536 thread_index < num_threads;
2537 ++thread_index)
2538 {
2539 Thread *thread = thread_list.GetThreadAtIndex(thread_index).get();
2540
2541 if (!thread)
2542 {
2543 ts.Printf("<?> ");
2544 continue;
2545 }
2546
2547 ts.Printf("<");
2548 RegisterContext *register_context = thread->GetRegisterContext();
2549
2550 if (register_context)
2551 ts.Printf("[ip 0x%llx] ", register_context->GetPC());
2552 else
2553 ts.Printf("[ip unknown] ");
2554
2555 lldb::StopInfoSP stop_info_sp = thread->GetStopInfo();
2556 if (stop_info_sp)
2557 {
2558 const char *stop_desc = stop_info_sp->GetDescription();
2559 if (stop_desc)
2560 ts.PutCString (stop_desc);
2561 }
2562 ts.Printf(">");
2563 }
2564
2565 event_explanation = ts.GetData();
2566 } while (0);
2567
2568 if (log)
2569 log->Printf("Execution interrupted: %s %s", s.GetData(), event_explanation);
2570 }
2571
2572 if (discard_on_error && thread_plan_sp)
2573 {
2574 exe_ctx.thread->DiscardThreadPlansUpToPlan (thread_plan_sp);
2575 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002576 return_value = lldb::eExecutionInterrupted;
Jim Inghamf48169b2010-11-30 02:22:11 +00002577 break;
2578 }
2579 }
2580
2581 if (exe_ctx.process)
2582 exe_ctx.process->RestoreProcessEvents ();
2583
2584 // Thread we ran the function in may have gone away because we ran the target
2585 // Check that it's still there.
2586 exe_ctx.thread = exe_ctx.process->GetThreadList().FindThreadByIndexID(tid, true).get();
2587 if (exe_ctx.thread)
2588 exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex(0).get();
2589
2590 // Also restore the current process'es selected frame & thread, since this function calling may
2591 // be done behind the user's back.
2592
2593 if (selected_tid != LLDB_INVALID_THREAD_ID)
2594 {
2595 if (exe_ctx.process->GetThreadList().SetSelectedThreadByIndexID (selected_tid))
2596 {
2597 // We were able to restore the selected thread, now restore the frame:
2598 exe_ctx.process->GetThreadList().GetSelectedThread()->SetSelectedFrame(selected_frame_sp.get());
2599 }
2600 }
2601
2602 return return_value;
2603}
2604
2605const char *
2606Process::ExecutionResultAsCString (ExecutionResults result)
2607{
2608 const char *result_name;
2609
2610 switch (result)
2611 {
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002612 case lldb::eExecutionCompleted:
Jim Inghamf48169b2010-11-30 02:22:11 +00002613 result_name = "eExecutionCompleted";
2614 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002615 case lldb::eExecutionDiscarded:
Jim Inghamf48169b2010-11-30 02:22:11 +00002616 result_name = "eExecutionDiscarded";
2617 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002618 case lldb::eExecutionInterrupted:
Jim Inghamf48169b2010-11-30 02:22:11 +00002619 result_name = "eExecutionInterrupted";
2620 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002621 case lldb::eExecutionSetupError:
Jim Inghamf48169b2010-11-30 02:22:11 +00002622 result_name = "eExecutionSetupError";
2623 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002624 case lldb::eExecutionTimedOut:
Jim Inghamf48169b2010-11-30 02:22:11 +00002625 result_name = "eExecutionTimedOut";
2626 break;
2627 }
2628 return result_name;
2629}
2630
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002631//--------------------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002632// class Process::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002633//--------------------------------------------------------------
2634
Greg Clayton1b654882010-09-19 02:33:57 +00002635Process::SettingsController::SettingsController () :
Caroline Ticedaccaa92010-09-20 20:44:43 +00002636 UserSettingsController ("process", Target::GetSettingsController())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002637{
Greg Clayton85851dd2010-12-04 00:10:17 +00002638 m_default_settings.reset (new ProcessInstanceSettings (*this,
2639 false,
Caroline Tice91123da2010-09-08 17:48:55 +00002640 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002641}
2642
Greg Clayton1b654882010-09-19 02:33:57 +00002643Process::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002644{
2645}
2646
2647lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00002648Process::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002649{
Greg Claytondbe54502010-11-19 03:46:01 +00002650 ProcessInstanceSettings *new_settings = new ProcessInstanceSettings (*GetSettingsController(),
2651 false,
2652 instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002653 lldb::InstanceSettingsSP new_settings_sp (new_settings);
2654 return new_settings_sp;
2655}
2656
2657//--------------------------------------------------------------
2658// class ProcessInstanceSettings
2659//--------------------------------------------------------------
2660
Greg Clayton85851dd2010-12-04 00:10:17 +00002661ProcessInstanceSettings::ProcessInstanceSettings
2662(
2663 UserSettingsController &owner,
2664 bool live_instance,
2665 const char *name
2666) :
2667 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002668 m_run_args (),
2669 m_env_vars (),
2670 m_input_path (),
2671 m_output_path (),
2672 m_error_path (),
2673 m_plugin (),
Caroline Ticef8da8632010-12-03 18:46:09 +00002674 m_disable_aslr (true),
Greg Clayton85851dd2010-12-04 00:10:17 +00002675 m_disable_stdio (false),
2676 m_inherit_host_env (true),
2677 m_got_host_env (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002678{
Caroline Ticef20e8232010-09-09 18:26:37 +00002679 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2680 // until the vtables for ProcessInstanceSettings are properly set up, i.e. AFTER all the initializers.
2681 // 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 +00002682 // This is true for CreateInstanceName() too.
2683
2684 if (GetInstanceName () == InstanceSettings::InvalidName())
2685 {
2686 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
2687 m_owner.RegisterInstanceSettings (this);
2688 }
Caroline Ticef20e8232010-09-09 18:26:37 +00002689
2690 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002691 {
2692 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
2693 CopyInstanceSettings (pending_settings,false);
Caroline Ticef20e8232010-09-09 18:26:37 +00002694 //m_owner.RemovePendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002695 }
2696}
2697
2698ProcessInstanceSettings::ProcessInstanceSettings (const ProcessInstanceSettings &rhs) :
Greg Claytondbe54502010-11-19 03:46:01 +00002699 InstanceSettings (*Process::GetSettingsController(), CreateInstanceName().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002700 m_run_args (rhs.m_run_args),
2701 m_env_vars (rhs.m_env_vars),
2702 m_input_path (rhs.m_input_path),
2703 m_output_path (rhs.m_output_path),
2704 m_error_path (rhs.m_error_path),
2705 m_plugin (rhs.m_plugin),
Caroline Ticef8da8632010-12-03 18:46:09 +00002706 m_disable_aslr (rhs.m_disable_aslr),
2707 m_disable_stdio (rhs.m_disable_stdio)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002708{
2709 if (m_instance_name != InstanceSettings::GetDefaultName())
2710 {
2711 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
2712 CopyInstanceSettings (pending_settings,false);
2713 m_owner.RemovePendingSettings (m_instance_name);
2714 }
2715}
2716
2717ProcessInstanceSettings::~ProcessInstanceSettings ()
2718{
2719}
2720
2721ProcessInstanceSettings&
2722ProcessInstanceSettings::operator= (const ProcessInstanceSettings &rhs)
2723{
2724 if (this != &rhs)
2725 {
2726 m_run_args = rhs.m_run_args;
2727 m_env_vars = rhs.m_env_vars;
2728 m_input_path = rhs.m_input_path;
2729 m_output_path = rhs.m_output_path;
2730 m_error_path = rhs.m_error_path;
2731 m_plugin = rhs.m_plugin;
2732 m_disable_aslr = rhs.m_disable_aslr;
Caroline Ticef8da8632010-12-03 18:46:09 +00002733 m_disable_stdio = rhs.m_disable_stdio;
Greg Clayton85851dd2010-12-04 00:10:17 +00002734 m_inherit_host_env = rhs.m_inherit_host_env;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002735 }
2736
2737 return *this;
2738}
2739
2740
2741void
2742ProcessInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2743 const char *index_value,
2744 const char *value,
2745 const ConstString &instance_name,
2746 const SettingEntry &entry,
2747 lldb::VarSetOperationType op,
2748 Error &err,
2749 bool pending)
2750{
2751 if (var_name == RunArgsVarName())
2752 UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
2753 else if (var_name == EnvVarsVarName())
Greg Clayton85851dd2010-12-04 00:10:17 +00002754 {
2755 GetHostEnvironmentIfNeeded ();
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002756 UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
Greg Clayton85851dd2010-12-04 00:10:17 +00002757 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002758 else if (var_name == InputPathVarName())
2759 UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
2760 else if (var_name == OutputPathVarName())
2761 UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
2762 else if (var_name == ErrorPathVarName())
2763 UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
2764 else if (var_name == PluginVarName())
2765 UserSettingsController::UpdateEnumVariable (entry.enum_values, (int *) &m_plugin, value, err);
Greg Clayton85851dd2010-12-04 00:10:17 +00002766 else if (var_name == InheritHostEnvVarName())
2767 UserSettingsController::UpdateBooleanVariable (op, m_inherit_host_env, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002768 else if (var_name == DisableASLRVarName())
2769 UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, err);
Caroline Ticef8da8632010-12-03 18:46:09 +00002770 else if (var_name == DisableSTDIOVarName ())
2771 UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002772}
2773
2774void
2775ProcessInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
2776 bool pending)
2777{
2778 if (new_settings.get() == NULL)
2779 return;
2780
2781 ProcessInstanceSettings *new_process_settings = (ProcessInstanceSettings *) new_settings.get();
2782
2783 m_run_args = new_process_settings->m_run_args;
2784 m_env_vars = new_process_settings->m_env_vars;
2785 m_input_path = new_process_settings->m_input_path;
2786 m_output_path = new_process_settings->m_output_path;
2787 m_error_path = new_process_settings->m_error_path;
2788 m_plugin = new_process_settings->m_plugin;
2789 m_disable_aslr = new_process_settings->m_disable_aslr;
Caroline Ticef8da8632010-12-03 18:46:09 +00002790 m_disable_stdio = new_process_settings->m_disable_stdio;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002791}
2792
Caroline Tice12cecd72010-09-20 21:37:42 +00002793bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002794ProcessInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2795 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00002796 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00002797 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002798{
2799 if (var_name == RunArgsVarName())
2800 {
2801 if (m_run_args.GetArgumentCount() > 0)
Greg Claytona52c1552010-09-14 03:47:41 +00002802 {
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002803 for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
2804 value.AppendString (m_run_args.GetArgumentAtIndex (i));
Greg Claytona52c1552010-09-14 03:47:41 +00002805 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002806 }
2807 else if (var_name == EnvVarsVarName())
2808 {
Greg Clayton85851dd2010-12-04 00:10:17 +00002809 GetHostEnvironmentIfNeeded ();
2810
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002811 if (m_env_vars.size() > 0)
2812 {
2813 std::map<std::string, std::string>::iterator pos;
2814 for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
2815 {
2816 StreamString value_str;
2817 value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
2818 value.AppendString (value_str.GetData());
2819 }
2820 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002821 }
2822 else if (var_name == InputPathVarName())
2823 {
2824 value.AppendString (m_input_path.c_str());
2825 }
2826 else if (var_name == OutputPathVarName())
2827 {
2828 value.AppendString (m_output_path.c_str());
2829 }
2830 else if (var_name == ErrorPathVarName())
2831 {
2832 value.AppendString (m_error_path.c_str());
2833 }
2834 else if (var_name == PluginVarName())
2835 {
2836 value.AppendString (UserSettingsController::EnumToString (entry.enum_values, (int) m_plugin));
2837 }
Greg Clayton5c5f1a12010-12-04 00:12:24 +00002838 else if (var_name == InheritHostEnvVarName())
2839 {
2840 if (m_inherit_host_env)
2841 value.AppendString ("true");
2842 else
2843 value.AppendString ("false");
2844 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002845 else if (var_name == DisableASLRVarName())
2846 {
2847 if (m_disable_aslr)
2848 value.AppendString ("true");
2849 else
2850 value.AppendString ("false");
2851 }
Caroline Ticef8da8632010-12-03 18:46:09 +00002852 else if (var_name == DisableSTDIOVarName())
2853 {
2854 if (m_disable_stdio)
2855 value.AppendString ("true");
2856 else
2857 value.AppendString ("false");
2858 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002859 else
Caroline Tice12cecd72010-09-20 21:37:42 +00002860 {
2861 if (err)
2862 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2863 return false;
2864 }
2865 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002866}
2867
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002868const ConstString
2869ProcessInstanceSettings::CreateInstanceName ()
2870{
2871 static int instance_count = 1;
2872 StreamString sstr;
2873
2874 sstr.Printf ("process_%d", instance_count);
2875 ++instance_count;
2876
2877 const ConstString ret_val (sstr.GetData());
2878 return ret_val;
2879}
2880
2881const ConstString &
2882ProcessInstanceSettings::RunArgsVarName ()
2883{
2884 static ConstString run_args_var_name ("run-args");
2885
2886 return run_args_var_name;
2887}
2888
2889const ConstString &
2890ProcessInstanceSettings::EnvVarsVarName ()
2891{
2892 static ConstString env_vars_var_name ("env-vars");
2893
2894 return env_vars_var_name;
2895}
2896
2897const ConstString &
Greg Clayton85851dd2010-12-04 00:10:17 +00002898ProcessInstanceSettings::InheritHostEnvVarName ()
2899{
2900 static ConstString g_name ("inherit-env");
2901
2902 return g_name;
2903}
2904
2905const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002906ProcessInstanceSettings::InputPathVarName ()
2907{
2908 static ConstString input_path_var_name ("input-path");
2909
2910 return input_path_var_name;
2911}
2912
2913const ConstString &
2914ProcessInstanceSettings::OutputPathVarName ()
2915{
Caroline Tice49e27372010-09-07 18:35:40 +00002916 static ConstString output_path_var_name ("output-path");
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002917
2918 return output_path_var_name;
2919}
2920
2921const ConstString &
2922ProcessInstanceSettings::ErrorPathVarName ()
2923{
Caroline Tice49e27372010-09-07 18:35:40 +00002924 static ConstString error_path_var_name ("error-path");
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002925
2926 return error_path_var_name;
2927}
2928
2929const ConstString &
2930ProcessInstanceSettings::PluginVarName ()
2931{
2932 static ConstString plugin_var_name ("plugin");
2933
2934 return plugin_var_name;
2935}
2936
2937
2938const ConstString &
2939ProcessInstanceSettings::DisableASLRVarName ()
2940{
2941 static ConstString disable_aslr_var_name ("disable-aslr");
2942
2943 return disable_aslr_var_name;
2944}
2945
Caroline Ticef8da8632010-12-03 18:46:09 +00002946const ConstString &
2947ProcessInstanceSettings::DisableSTDIOVarName ()
2948{
2949 static ConstString disable_stdio_var_name ("disable-stdio");
2950
2951 return disable_stdio_var_name;
2952}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002953
2954//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002955// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002956//--------------------------------------------------
2957
2958SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002959Process::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002960{
2961 //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"},
2962 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
2963};
2964
2965
2966lldb::OptionEnumValueElement
Greg Clayton1b654882010-09-19 02:33:57 +00002967Process::SettingsController::g_plugins[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002968{
Caroline Tice5c9fdfa2010-09-09 18:01:59 +00002969 { eMacosx, "process.macosx", "Use the native MacOSX debugger plugin" },
2970 { eRemoteDebugger, "process.gdb-remote" , "Use the GDB Remote protocol based debugger plugin" },
2971 { 0, NULL, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002972};
2973
2974SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002975Process::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002976{
Greg Clayton85851dd2010-12-04 00:10:17 +00002977 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
2978 { "run-args", eSetVarTypeArray, NULL, NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." },
2979 { "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." },
2980 { "inherit-env", eSetVarTypeBoolean, "true", NULL, false, false, "Inherit the environment from the process that is running LLDB." },
2981 { "input-path", eSetVarTypeString, "/dev/stdin", NULL, false, false, "The file/path to be used by the executable program for reading its input." },
2982 { "output-path", eSetVarTypeString, "/dev/stdout", NULL, false, false, "The file/path to be used by the executable program for writing its output." },
2983 { "error-path", eSetVarTypeString, "/dev/stderr", NULL, false, false, "The file/path to be used by the executable program for writings its error messages." },
2984 { "plugin", eSetVarTypeEnum, NULL , g_plugins, false, false, "The plugin to be used to run the process." },
2985 { "disable-aslr", eSetVarTypeBoolean, "true", NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" },
2986 { "disable-stdio", eSetVarTypeBoolean, "false", NULL, false, false, "Disable stdin/stdout for process (e.g. for a GUI application)" },
2987 { NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002988};
2989
2990
Jim Ingham5aee1622010-08-09 23:31:02 +00002991