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
|
|
|
{
|
2010-10-27 07:49:36 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::SBProcess (rhs.sp=%p) => this.sp = %p", rhs.m_opaque_sp.get(), m_opaque_sp.get());
|
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-10-27 07:49:36 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::SBProcess (process_sp=%p) => this.sp = %p", process_sp.get(), m_opaque_sp.get());
|
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-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::GetNumThreads ()");
|
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-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetNumThreads (this.sp=%p) => %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-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::GetSelectedThread ()");
|
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)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_thread.GetDescription (sstr);
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetSelectedThread (this.sp=%p) => SBThread : this = %p, '%s'", m_opaque_sp.get(),
|
|
|
|
&sb_thread, sstr.GetData());
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBTarget
|
|
|
|
SBProcess::GetTarget() const
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::GetTarget ()");
|
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-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetTarget (this.sp=%p) => SBTarget (this.sp = %p)", m_opaque_sp.get(),
|
2010-10-26 11:11:13 +08:00
|
|
|
sb_target.get());
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_target;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBProcess::PutSTDIN (const char *src, size_t src_len)
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::PutSTDIN (%s, %d)", src, src_len);
|
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-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::PutSTDIN (this.sp=%p, src='%s', src_len=%d) => %d", 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-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::GetSTDOUT (char *dst, size_t dst_Len)");
|
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->GetSTDOUT (dst, dst_len, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetSTDOUT (this.sp=%p, dst='%s', dst_len=%d) => %d", m_opaque_sp.get(), dst,
|
|
|
|
(uint32_t) dst_len, (uint32_t) ret_val);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return ret_val;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBProcess::GetSTDERR (char *dst, size_t dst_len) const
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::GetSTDERR (char *dst, size_t dst_len)");
|
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->GetSTDERR (dst, dst_len, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetSTDERR (this.sp=%p, dst='%s', dst_len=%d) => %d", m_opaque_sp.get(), dst,
|
|
|
|
(uint32_t) dst_len, (uint32_t) ret_val);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return ret_val;
|
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-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::SetSelectedThreadByID (%d)", tid);
|
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-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::SetSelectedThreadByID (this.sp=%p, tid=%d) => '%s'", 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-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::GetThreadAtIndex (%d)");
|
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)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
thread.GetDescription (sstr);
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetThreadAtIndex (this.sp=%p, index=%d) => SBThread : this.sp = %p, '%s'",
|
|
|
|
m_opaque_sp.get(), (uint32_t) index, thread.GetLLDBObjectPtr(), sstr.GetData());
|
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
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("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();
|
|
|
|
|
|
|
|
if (log)
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetState (this.sp=%p) => '%s'", m_opaque_sp.get(),
|
|
|
|
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-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
|
|
|
return m_opaque_sp->GetExitStatus ();
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBProcess::GetExitDescription ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp != NULL)
|
|
|
|
return m_opaque_sp->GetExitDescription ();
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::pid_t
|
|
|
|
SBProcess::GetProcessID ()
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("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();
|
|
|
|
|
|
|
|
if (log)
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetProcessID (this.sp=%p) => %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
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::GetAddressByteSize()");
|
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();
|
|
|
|
|
|
|
|
if (log)
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetAddressByteSize (this.sp=%p) => %d", m_opaque_sp.get(), size);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return size;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBProcess::WaitUntilProcessHasStopped (SBCommandReturnObject &result)
|
|
|
|
{
|
|
|
|
bool state_changed = false;
|
|
|
|
|
|
|
|
if (IsValid())
|
|
|
|
{
|
|
|
|
EventSP event_sp;
|
2010-06-23 09:19:29 +08:00
|
|
|
StateType state = m_opaque_sp->WaitForStateChangedEvents (NULL, event_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
while (StateIsStoppedState (state))
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
state = m_opaque_sp->WaitForStateChangedEvents (NULL, event_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
SBEvent event (event_sp);
|
2010-08-27 05:32:51 +08:00
|
|
|
AppendEventStateReport (event, result);
|
2010-06-09 00:52:24 +08:00
|
|
|
state_changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return state_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError
|
|
|
|
SBProcess::Continue ()
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::Continue ()");
|
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)
|
|
|
|
m_opaque_sp->WaitForProcessToStop (NULL);
|
|
|
|
}
|
|
|
|
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-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::Continue (this.sp=%p) => SBError (this.ap = %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");
|
|
|
|
|
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SBError
|
|
|
|
SBProcess::Stop ()
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("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
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_error.GetDescription (sstr);
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::Stop (this.sp=%p) => SBError (this.ap = %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::Kill ()
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("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
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_error.GetDescription (sstr);
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::Kill (this.sp=%p) => SBError (this.ap = %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::AttachByName (const char *name, bool wait_for_launch)
|
|
|
|
{
|
|
|
|
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-09-16 02:29:06 +08:00
|
|
|
SBProcess::AttachByPID (lldb::pid_t attach_pid) // DEPRECATED: will be removed in a few builds in favor of SBError AttachByPID(pid_t)
|
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
|
|
|
|
SBProcess::Attach (lldb::pid_t attach_pid)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
SBProcess::Signal (int signal)
|
|
|
|
{
|
|
|
|
SBError sb_error;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_error.SetError (m_opaque_sp->Signal (signal));
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
sb_error.SetErrorString ("SBProcess is invalid");
|
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBThread
|
|
|
|
SBProcess::GetThreadByID (tid_t sb_thread_id)
|
|
|
|
{
|
|
|
|
SBThread thread;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
thread.SetThread (m_opaque_sp->GetThreadList().FindThreadByID ((tid_t) sb_thread_id));
|
2010-06-09 00:52:24 +08:00
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
StateType
|
|
|
|
SBProcess::GetStateFromEvent (const SBEvent &event)
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
//{
|
|
|
|
// SBStream sstr;
|
|
|
|
// event.GetDescription (sstr);
|
|
|
|
// log->Printf ("SBProcess::GetStateFromEvent (%s)", sstr.GetData());
|
|
|
|
//}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get());
|
|
|
|
|
|
|
|
if (log)
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => '%s'", event.get(),
|
|
|
|
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-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::GetBroadcaster ()");
|
|
|
|
|
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-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::GetBroadcaster (this.sp=%p) => SBBroadcaster (this.obj = %p)", m_opaque_sp.get(),
|
|
|
|
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-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBProcess::ReadMemory (%p, %p, %d, sb_error)", addr, dst, dst_len);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t bytes_read = 0;
|
|
|
|
|
|
|
|
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-27 07:49:36 +08:00
|
|
|
log->Printf ("SBProcess::ReadMemory (this.sp=%p, addr=%p, dst=%p, dst_len=%d, sb_error.ap=%p) => %d",
|
|
|
|
m_opaque_sp.get(), addr, dst, (uint32_t) dst_len, sb_error.get(), (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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|