2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBProcess.cpp -------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-06-09 15:44:37 +08:00
|
|
|
#include "lldb/API/SBProcess.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
#include "lldb/lldb-defines.h"
|
|
|
|
#include "lldb/lldb-types.h"
|
|
|
|
|
2010-06-16 03:49:27 +08:00
|
|
|
#include "lldb/Interpreter/Args.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/DataBufferHeap.h"
|
|
|
|
#include "lldb/Core/DataExtractor.h"
|
2010-10-06 11:53:16 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/State.h"
|
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2010-06-23 09:19:29 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
#include "lldb/Target/Thread.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Project includes
|
|
|
|
|
2010-06-09 15:44:37 +08:00
|
|
|
#include "lldb/API/SBBroadcaster.h"
|
|
|
|
#include "lldb/API/SBDebugger.h"
|
|
|
|
#include "lldb/API/SBCommandReturnObject.h"
|
|
|
|
#include "lldb/API/SBEvent.h"
|
|
|
|
#include "lldb/API/SBThread.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-06-09 15:44:37 +08:00
|
|
|
#include "lldb/API/SBStringList.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SBProcess::SBProcess () :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// SBProcess constructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
SBProcess::SBProcess (const SBProcess& rhs) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp (rhs.m_opaque_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SBProcess::SBProcess (const lldb::ProcessSP &process_sp) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp (process_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
const SBProcess&
|
|
|
|
SBProcess::operator = (const SBProcess& rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
m_opaque_sp = rhs.m_opaque_sp;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
SBProcess::~SBProcess()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBProcess::SetProcess (const ProcessSP &process_sp)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp = process_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBProcess::Clear ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp.reset();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBProcess::IsValid() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_sp.get() != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBProcess::GetNumThreads ()
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
uint32_t num_threads = 0;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
const bool can_update = true;
|
2010-10-26 11:11:13 +08:00
|
|
|
num_threads = m_opaque_sp->GetThreadList().GetSize(can_update);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBProcess(%p)::GetNumThreads () => %d", m_opaque_sp.get(), num_threads);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return num_threads;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBThread
|
2010-08-27 05:32:51 +08:00
|
|
|
SBProcess::GetSelectedThread () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBThread sb_thread;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-08-27 05:32:51 +08:00
|
|
|
sb_thread.SetThread (m_opaque_sp->GetThreadList().GetSelectedThread());
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
2010-10-30 12:51:46 +08:00
|
|
|
log->Printf ("SBProcess(%p)::GetSelectedThread () => SBThread(%p)", m_opaque_sp.get(), sb_thread.get());
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBTarget
|
|
|
|
SBProcess::GetTarget() const
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBTarget sb_target;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_target = m_opaque_sp->GetTarget().GetSP();
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", m_opaque_sp.get(), sb_target.get());
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_target;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBProcess::PutSTDIN (const char *src, size_t src_len)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
size_t ret_val = 0;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Error error;
|
2010-10-26 11:11:13 +08:00
|
|
|
ret_val = m_opaque_sp->PutSTDIN (src, src_len, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-31 11:01:06 +08:00
|
|
|
log->Printf ("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%d) => %d",
|
2010-10-29 12:59:35 +08:00
|
|
|
m_opaque_sp.get(),
|
|
|
|
src,
|
|
|
|
(uint32_t) src_len,
|
|
|
|
ret_val);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return ret_val;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBProcess::GetSTDOUT (char *dst, size_t dst_len) const
|
|
|
|
{
|
2010-10-31 11:01:06 +08:00
|
|
|
size_t bytes_read = 0;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Error error;
|
2010-10-31 11:01:06 +08:00
|
|
|
bytes_read = m_opaque_sp->GetSTDOUT (dst, dst_len, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
2010-10-31 11:01:06 +08:00
|
|
|
log->Printf ("SBProcess(%p)::GetSTDOUT (dst=\"%.*s\", dst_len=%zu) => %zu",
|
|
|
|
m_opaque_sp.get(), (int) bytes_read, dst, dst_len, bytes_read);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-10-31 11:01:06 +08:00
|
|
|
return bytes_read;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBProcess::GetSTDERR (char *dst, size_t dst_len) const
|
|
|
|
{
|
2010-10-31 11:01:06 +08:00
|
|
|
size_t bytes_read = 0;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Error error;
|
2010-10-31 11:01:06 +08:00
|
|
|
bytes_read = m_opaque_sp->GetSTDERR (dst, dst_len, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
2010-10-31 11:01:06 +08:00
|
|
|
log->Printf ("SBProcess(%p)::GetSTDERR (dst=\"%.*s\", dst_len=%zu) => %zu",
|
|
|
|
m_opaque_sp.get(), (int) bytes_read, dst, dst_len, bytes_read);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-10-31 11:01:06 +08:00
|
|
|
return bytes_read;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-27 05:32:51 +08:00
|
|
|
SBProcess::ReportEventState (const SBEvent &event, FILE *out) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (out == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
const StateType event_state = SBProcess::GetStateFromEvent (event);
|
|
|
|
char message[1024];
|
|
|
|
int message_len = ::snprintf (message,
|
|
|
|
sizeof (message),
|
|
|
|
"Process %d %s\n",
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp->GetID(),
|
2010-06-09 00:52:24 +08:00
|
|
|
SBDebugger::StateAsCString (event_state));
|
|
|
|
|
|
|
|
if (message_len > 0)
|
|
|
|
::fwrite (message, 1, message_len, out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-27 05:32:51 +08:00
|
|
|
SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
const StateType event_state = SBProcess::GetStateFromEvent (event);
|
|
|
|
char message[1024];
|
|
|
|
::snprintf (message,
|
|
|
|
sizeof (message),
|
|
|
|
"Process %d %s\n",
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp->GetID(),
|
2010-06-09 00:52:24 +08:00
|
|
|
SBDebugger::StateAsCString (event_state));
|
|
|
|
|
|
|
|
result.AppendMessage (message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-08-27 05:32:51 +08:00
|
|
|
SBProcess::SetSelectedThread (const SBThread &thread)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
2010-08-27 05:32:51 +08:00
|
|
|
return m_opaque_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID());
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-08-27 05:32:51 +08:00
|
|
|
SBProcess::SetSelectedThreadByID (uint32_t tid)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
bool ret_val = false;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
2010-10-26 11:11:13 +08:00
|
|
|
ret_val = m_opaque_sp->GetThreadList().SetSelectedThreadByID (tid);
|
|
|
|
|
|
|
|
if (log)
|
2010-10-31 11:01:06 +08:00
|
|
|
log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4x) => %s",
|
2010-10-29 12:59:35 +08:00
|
|
|
m_opaque_sp.get(), tid, (ret_val ? "true" : "false"));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return ret_val;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBThread
|
|
|
|
SBProcess::GetThreadAtIndex (size_t index)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBThread thread;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
thread.SetThread (m_opaque_sp->GetThreadList().GetThreadAtIndex(index));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)",
|
2010-10-30 12:51:46 +08:00
|
|
|
m_opaque_sp.get(), (uint32_t) index, thread.get());
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
StateType
|
|
|
|
SBProcess::GetState ()
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
StateType ret_val = eStateInvalid;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
2010-10-26 11:11:13 +08:00
|
|
|
ret_val = m_opaque_sp->GetState();
|
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
2010-10-31 11:01:06 +08:00
|
|
|
log->Printf ("SBProcess(%p)::GetState () => %s",
|
2010-10-29 12:59:35 +08:00
|
|
|
m_opaque_sp.get(),
|
2010-10-27 07:49:36 +08:00
|
|
|
lldb_private::StateAsCString (ret_val));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return ret_val;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
SBProcess::GetExitStatus ()
|
|
|
|
{
|
2010-10-30 12:51:46 +08:00
|
|
|
int exit_status = 0;
|
|
|
|
if (m_opaque_sp)
|
|
|
|
exit_status = m_opaque_sp->GetExitStatus ();
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)",
|
|
|
|
m_opaque_sp.get(), exit_status, exit_status);
|
|
|
|
|
|
|
|
return exit_status;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBProcess::GetExitDescription ()
|
|
|
|
{
|
2010-10-30 12:51:46 +08:00
|
|
|
const char *exit_desc = NULL;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
2010-10-30 12:51:46 +08:00
|
|
|
exit_desc = m_opaque_sp->GetExitDescription ();
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("SBProcess(%p)::GetExitDescription () => %s",
|
|
|
|
m_opaque_sp.get(), exit_desc);
|
|
|
|
return exit_desc;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::pid_t
|
|
|
|
SBProcess::GetProcessID ()
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-10-26 11:11:13 +08:00
|
|
|
ret_val = m_opaque_sp->GetID();
|
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBProcess(%p)::GetProcessID () => %d", m_opaque_sp.get(), ret_val);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return ret_val;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBProcess::GetAddressByteSize () const
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
uint32_t size = 0;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-10-26 11:11:13 +08:00
|
|
|
size = m_opaque_sp->GetAddressByteSize();
|
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", m_opaque_sp.get(), size);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return size;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBError
|
|
|
|
SBProcess::Continue ()
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("SBProcess(%p)::Continue ()...", m_opaque_sp.get());
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBError sb_error;
|
|
|
|
if (IsValid())
|
2010-10-06 11:53:16 +08:00
|
|
|
{
|
|
|
|
Error error (m_opaque_sp->Resume());
|
|
|
|
if (error.Success())
|
|
|
|
{
|
|
|
|
if (m_opaque_sp->GetTarget().GetDebugger().GetAsyncExecution () == false)
|
2010-10-30 12:51:46 +08:00
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", m_opaque_sp.get());
|
2010-10-06 11:53:16 +08:00
|
|
|
m_opaque_sp->WaitForProcessToStop (NULL);
|
2010-10-30 12:51:46 +08:00
|
|
|
}
|
2010-10-06 11:53:16 +08:00
|
|
|
}
|
|
|
|
sb_error.SetError(error);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
sb_error.SetErrorString ("SBProcess is invalid");
|
|
|
|
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_error.GetDescription (sstr);
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBProcess(%p)::Continue () => SBError (%p): %s", m_opaque_sp.get(), sb_error.get(), sstr.GetData());
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SBError
|
|
|
|
SBProcess::Destroy ()
|
|
|
|
{
|
|
|
|
SBError sb_error;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_error.SetError(m_opaque_sp->Destroy());
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
sb_error.SetErrorString ("SBProcess is invalid");
|
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_error.GetDescription (sstr);
|
|
|
|
log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s", m_opaque_sp.get(), sb_error.get(), sstr.GetData());
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SBError
|
|
|
|
SBProcess::Stop ()
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBError sb_error;
|
|
|
|
if (IsValid())
|
2010-06-23 09:19:29 +08:00
|
|
|
sb_error.SetError (m_opaque_sp->Halt());
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
sb_error.SetErrorString ("SBProcess is invalid");
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_error.GetDescription (sstr);
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s",
|
|
|
|
m_opaque_sp.get(),
|
|
|
|
sb_error.get(),
|
2010-10-27 07:49:36 +08:00
|
|
|
sstr.GetData());
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError
|
|
|
|
SBProcess::Kill ()
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBError sb_error;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_error.SetError (m_opaque_sp->Destroy());
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
sb_error.SetErrorString ("SBProcess is invalid");
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_error.GetDescription (sstr);
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s",
|
|
|
|
m_opaque_sp.get(),
|
|
|
|
sb_error.get(),
|
2010-10-27 07:49:36 +08:00
|
|
|
sstr.GetData());
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SBError
|
2010-10-30 12:51:46 +08:00
|
|
|
SBProcess::AttachByName (const char *name, bool wait_for_launch) // DEPRECATED
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
SBError sb_error;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_error.SetError (m_opaque_sp->Attach (name, wait_for_launch));
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
sb_error.SetErrorString ("SBProcess is invalid");
|
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::pid_t
|
2010-10-30 12:51:46 +08:00
|
|
|
SBProcess::AttachByPID (lldb::pid_t attach_pid) // DEPRECATED
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Attach (attach_pid);
|
|
|
|
return GetProcessID();
|
|
|
|
}
|
|
|
|
|
2010-09-16 02:29:06 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBError
|
2010-10-30 12:51:46 +08:00
|
|
|
SBProcess::Attach (lldb::pid_t attach_pid) // DEPRECATED
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
SBError sb_error;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_error.SetError (m_opaque_sp->Attach (attach_pid));
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
sb_error.SetErrorString ("SBProcess is invalid");
|
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError
|
|
|
|
SBProcess::Detach ()
|
|
|
|
{
|
|
|
|
SBError sb_error;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_error.SetError (m_opaque_sp->Detach());
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
sb_error.SetErrorString ("SBProcess is invalid");
|
|
|
|
|
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError
|
2010-10-30 12:51:46 +08:00
|
|
|
SBProcess::Signal (int signo)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
SBError sb_error;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-10-30 12:51:46 +08:00
|
|
|
sb_error.SetError (m_opaque_sp->Signal (signo));
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
sb_error.SetErrorString ("SBProcess is invalid");
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_error.GetDescription (sstr);
|
|
|
|
log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s",
|
|
|
|
m_opaque_sp.get(),
|
|
|
|
signo,
|
|
|
|
sb_error.get(),
|
|
|
|
sstr.GetData());
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBThread
|
2010-10-30 12:51:46 +08:00
|
|
|
SBProcess::GetThreadByID (tid_t tid)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-30 12:51:46 +08:00
|
|
|
SBThread sb_thread;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-10-30 12:51:46 +08:00
|
|
|
sb_thread.SetThread (m_opaque_sp->GetThreadList().FindThreadByID ((tid_t) tid));
|
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4x) => SBThread (%p)",
|
|
|
|
m_opaque_sp.get(),
|
|
|
|
tid,
|
|
|
|
sb_thread.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb_thread;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StateType
|
|
|
|
SBProcess::GetStateFromEvent (const SBEvent &event)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get());
|
|
|
|
|
|
|
|
if (log)
|
2010-10-31 11:01:06 +08:00
|
|
|
log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => %s", event.get(),
|
2010-10-27 07:49:36 +08:00
|
|
|
lldb_private::StateAsCString (ret_val));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return ret_val;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBProcess::GetRestartedFromEvent (const SBEvent &event)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return Process::ProcessEventData::GetRestartedFromEvent (event.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBProcess
|
|
|
|
SBProcess::GetProcessFromEvent (const SBEvent &event)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get()));
|
2010-06-09 00:52:24 +08:00
|
|
|
return process;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SBBroadcaster
|
|
|
|
SBProcess::GetBroadcaster () const
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
SBBroadcaster broadcaster(m_opaque_sp.get(), false);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", m_opaque_sp.get(),
|
2010-10-27 07:49:36 +08:00
|
|
|
broadcaster.get());
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return broadcaster;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb_private::Process *
|
|
|
|
SBProcess::operator->() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_sp.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t bytes_read = 0;
|
|
|
|
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%llx, dst=%p, dst_len=%zu, SBError (%p))...",
|
|
|
|
m_opaque_sp.get(),
|
|
|
|
addr,
|
|
|
|
dst,
|
|
|
|
(uint32_t) dst_len,
|
|
|
|
sb_error.get());
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (IsValid())
|
|
|
|
{
|
|
|
|
Error error;
|
2010-06-23 09:19:29 +08:00
|
|
|
bytes_read = m_opaque_sp->ReadMemory (addr, dst, dst_len, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
sb_error.SetError (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sb_error.SetErrorString ("SBProcess is invalid");
|
|
|
|
}
|
|
|
|
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
2010-10-29 12:59:35 +08:00
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_error.GetDescription (sstr);
|
2010-10-30 12:51:46 +08:00
|
|
|
log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%llx, dst=%p, dst_len=%zu, SBError (%p): %s) => %d",
|
2010-10-29 12:59:35 +08:00
|
|
|
m_opaque_sp.get(),
|
|
|
|
addr,
|
|
|
|
dst,
|
|
|
|
(uint32_t) dst_len,
|
|
|
|
sb_error.get(),
|
|
|
|
sstr.GetData(),
|
|
|
|
(uint32_t) bytes_read);
|
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return bytes_read;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error)
|
|
|
|
{
|
|
|
|
size_t bytes_written = 0;
|
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%llx, src=%p, dst_len=%zu, SBError (%p))...",
|
|
|
|
m_opaque_sp.get(),
|
|
|
|
addr,
|
|
|
|
src,
|
|
|
|
(uint32_t) src_len,
|
|
|
|
sb_error.get());
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (IsValid())
|
|
|
|
{
|
|
|
|
Error error;
|
2010-06-23 09:19:29 +08:00
|
|
|
bytes_written = m_opaque_sp->WriteMemory (addr, src, src_len, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
sb_error.SetError (error);
|
|
|
|
}
|
|
|
|
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_error.GetDescription (sstr);
|
|
|
|
log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%llx, src=%p, dst_len=%zu, SBError (%p): %s) => %d",
|
|
|
|
m_opaque_sp.get(),
|
|
|
|
addr,
|
|
|
|
src,
|
|
|
|
(uint32_t) src_len,
|
|
|
|
sb_error.get(),
|
|
|
|
sstr.GetData(),
|
|
|
|
(uint32_t) bytes_written);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return bytes_written;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mimic shared pointer...
|
|
|
|
lldb_private::Process *
|
|
|
|
SBProcess::get() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_sp.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
bool
|
|
|
|
SBProcess::GetDescription (SBStream &description)
|
|
|
|
{
|
|
|
|
if (m_opaque_sp)
|
|
|
|
{
|
|
|
|
char path[PATH_MAX];
|
|
|
|
GetTarget().GetExecutable().GetPath (path, sizeof(path));
|
2010-10-06 11:09:58 +08:00
|
|
|
Module *exe_module = m_opaque_sp->GetTarget().GetExecutableModule ().get();
|
|
|
|
const char *exe_name = NULL;
|
|
|
|
if (exe_module)
|
|
|
|
exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
|
|
|
|
|
2010-10-07 12:19:01 +08:00
|
|
|
description.Printf ("SBProcess: pid = %d, state = %s, threads = %d%s%s",
|
2010-10-06 11:09:58 +08:00
|
|
|
m_opaque_sp->GetID(),
|
2010-10-26 11:11:13 +08:00
|
|
|
lldb_private::StateAsCString (GetState()),
|
2010-10-06 11:09:58 +08:00
|
|
|
GetNumThreads(),
|
2010-10-07 12:19:01 +08:00
|
|
|
exe_name ? ", executable = " : "",
|
2010-10-06 11:09:58 +08:00
|
|
|
exe_name ? exe_name : "");
|
2010-09-20 13:20:02 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
description.Printf ("No value");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-04 09:54:29 +08:00
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error)
|
|
|
|
{
|
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->LoadImage (*sb_image_spec, sb_error.ref());
|
|
|
|
return LLDB_INVALID_IMAGE_TOKEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::SBError
|
|
|
|
SBProcess::UnloadImage (uint32_t image_token)
|
|
|
|
{
|
|
|
|
lldb::SBError sb_error;
|
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_error.SetError (m_opaque_sp->UnloadImage (image_token));
|
|
|
|
else
|
|
|
|
sb_error.SetErrorString("invalid process");
|
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|