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).

llvm-svn: 115738
This commit is contained in:
Greg Clayton
2010-10-06 03:53:16 +00:00
parent 964f521e85
commit 5d5028b54e
5 changed files with 179 additions and 55 deletions

View File

@@ -105,17 +105,6 @@ SBTarget::GetDebugger () const
return debugger;
}
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
(
@@ -126,23 +115,39 @@ SBTarget::LaunchProcess
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 @@ SBTarget::Disassemble (lldb::addr_t start_addr, lldb::addr_t end_addr, const cha
// 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 @@ SBTarget::Disassemble (lldb::addr_t start_addr, lldb::addr_t end_addr, const cha
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 @@ SBTarget::Disassemble (const char *function_name, const char *module_name)
// 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);