Added the first of hopefully many python example scripts that show how to
use the python API that is exposed through SWIG to do some cool stuff.
Also fixed synchronous debugging so that all process control APIs exposed
through the python API will now wait for the process to stop if you set
the async mode to false (see disasm.py).
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@115738 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBProcess.cpp b/source/API/SBProcess.cpp
index 1a72f58..a288833 100644
--- a/source/API/SBProcess.cpp
+++ b/source/API/SBProcess.cpp
@@ -15,6 +15,7 @@
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/DataExtractor.h"
+#include "lldb/Core/Debugger.h"
#include "lldb/Core/State.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamFile.h"
@@ -287,7 +288,15 @@
{
SBError sb_error;
if (IsValid())
- sb_error.SetError(m_opaque_sp->Resume());
+ {
+ Error error (m_opaque_sp->Resume());
+ if (error.Success())
+ {
+ if (m_opaque_sp->GetTarget().GetDebugger().GetAsyncExecution () == false)
+ m_opaque_sp->WaitForProcessToStop (NULL);
+ }
+ sb_error.SetError(error);
+ }
else
sb_error.SetErrorString ("SBProcess is invalid");
diff --git a/source/API/SBTarget.cpp b/source/API/SBTarget.cpp
index 0ac463d..39b4e50 100644
--- a/source/API/SBTarget.cpp
+++ b/source/API/SBTarget.cpp
@@ -106,17 +106,6 @@
}
SBProcess
-SBTarget::CreateProcess ()
-{
- SBProcess sb_process;
-
- if (m_opaque_sp)
- sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
-
- return sb_process;
-}
-
-SBProcess
SBTarget::LaunchProcess
(
char const **argv,
@@ -126,23 +115,39 @@
bool stop_at_entry
)
{
- SBProcess process(GetProcess ());
- if (!process.IsValid())
- process = CreateProcess();
- if (process.IsValid())
+ SBProcess sb_process;
+ if (m_opaque_sp)
{
- Error error (process->Launch (argv, envp, launch_flags, tty, tty, tty));
- if (error.Success())
+ // When launching, we always want to create a new process
+ sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+
+ if (sb_process.IsValid())
{
- if (!stop_at_entry)
+ Error error (sb_process->Launch (argv, envp, launch_flags, tty, tty, tty));
+ if (error.Success())
{
- StateType state = process->WaitForProcessToStop (NULL);
+ // We we are stopping at the entry point, we can return now!
+ if (stop_at_entry)
+ return sb_process;
+
+ // Make sure we are stopped at the entry
+ StateType state = sb_process->WaitForProcessToStop (NULL);
if (state == eStateStopped)
- process->Resume();
+ {
+ // resume the process to skip the entry point
+ error = sb_process->Resume();
+ if (error.Success())
+ {
+ // If we are doing synchronous mode, then wait for the
+ // process to stop yet again!
+ if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
+ sb_process->WaitForProcessToStop (NULL);
+ }
+ }
}
}
}
- return process;
+ return sb_process;
}
SBFileSpec
@@ -401,9 +406,9 @@
// Make sure the process object is alive if we have one (it might be
// created but we might not be launched yet).
- Process *process = m_opaque_sp->GetProcessSP().get();
- if (process && !process->IsAlive())
- process = NULL;
+ Process *sb_process = m_opaque_sp->GetProcessSP().get();
+ if (sb_process && !sb_process->IsAlive())
+ sb_process = NULL;
// If we are given a module, then "start_addr" is a file address in
// that module.
@@ -430,8 +435,8 @@
ExecutionContext exe_ctx;
- if (process)
- process->CalculateExecutionContext(exe_ctx);
+ if (sb_process)
+ sb_process->CalculateExecutionContext(exe_ctx);
else
m_opaque_sp->CalculateExecutionContext(exe_ctx);
@@ -479,12 +484,12 @@
// Make sure the process object is alive if we have one (it might be
// created but we might not be launched yet).
- Process *process = m_opaque_sp->GetProcessSP().get();
- if (process && !process->IsAlive())
- process = NULL;
+ Process *sb_process = m_opaque_sp->GetProcessSP().get();
+ if (sb_process && !sb_process->IsAlive())
+ sb_process = NULL;
- if (process)
- process->CalculateExecutionContext(exe_ctx);
+ if (sb_process)
+ sb_process->CalculateExecutionContext(exe_ctx);
else
m_opaque_sp->CalculateExecutionContext(exe_ctx);
diff --git a/source/API/SBThread.cpp b/source/API/SBThread.cpp
index 7bf7dd2..0489dc5 100644
--- a/source/API/SBThread.cpp
+++ b/source/API/SBThread.cpp
@@ -233,25 +233,32 @@
{
SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
- eStepTypeOver,
- sc.line_entry.range,
- sc,
- stop_other_threads,
- false);
+ eStepTypeOver,
+ sc.line_entry.range,
+ sc,
+ stop_other_threads,
+ false);
}
else
{
m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true,
- abort_other_plans,
- stop_other_threads);
+ abort_other_plans,
+ stop_other_threads);
}
}
Process &process = m_opaque_sp->GetProcess();
// Why do we need to set the current thread by ID here???
process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
- process.Resume();
+ Error error (process.Resume());
+ if (error.Success())
+ {
+ // If we are doing synchronous mode, then wait for the
+ // process to stop yet again!
+ if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
+ process.WaitForProcessToStop (NULL);
+ }
}
}
@@ -269,24 +276,30 @@
bool avoid_code_without_debug_info = true;
SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
- eStepTypeInto,
- sc.line_entry.range,
- sc,
- stop_other_threads,
- avoid_code_without_debug_info);
+ eStepTypeInto,
+ sc.line_entry.range,
+ sc,
+ stop_other_threads,
+ avoid_code_without_debug_info);
}
else
{
m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false,
- abort_other_plans,
- stop_other_threads);
+ abort_other_plans,
+ stop_other_threads);
}
Process &process = m_opaque_sp->GetProcess();
// Why do we need to set the current thread by ID here???
process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
- process.Resume();
-
+ Error error (process.Resume());
+ if (error.Success())
+ {
+ // If we are doing synchronous mode, then wait for the
+ // process to stop yet again!
+ if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
+ process.WaitForProcessToStop (NULL);
+ }
}
}
@@ -302,7 +315,14 @@
Process &process = m_opaque_sp->GetProcess();
process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
- process.Resume();
+ Error error (process.Resume());
+ if (error.Success())
+ {
+ // If we are doing synchronous mode, then wait for the
+ // process to stop yet again!
+ if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
+ process.WaitForProcessToStop (NULL);
+ }
}
}
@@ -314,7 +334,14 @@
m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
Process &process = m_opaque_sp->GetProcess();
process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
- process.Resume();
+ Error error (process.Resume());
+ if (error.Success())
+ {
+ // If we are doing synchronous mode, then wait for the
+ // process to stop yet again!
+ if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
+ process.WaitForProcessToStop (NULL);
+ }
}
}
@@ -331,7 +358,14 @@
m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
Process &process = m_opaque_sp->GetProcess();
process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
- process.Resume();
+ Error error (process.Resume());
+ if (error.Success())
+ {
+ // If we are doing synchronous mode, then wait for the
+ // process to stop yet again!
+ if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
+ process.WaitForProcessToStop (NULL);
+ }
}
}