2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBCommandReturnObject.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:37:52 +08:00
|
|
|
#include "lldb/API/SBCommandReturnObject.h"
|
2013-07-10 04:14:26 +08:00
|
|
|
#include "lldb/API/SBError.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
|
|
|
|
2013-07-10 04:14:26 +08:00
|
|
|
#include "lldb/Core/Error.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
2010-06-23 09:19:29 +08:00
|
|
|
using namespace lldb_private;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
SBCommandReturnObject::SBCommandReturnObject () :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap (new CommandReturnObject ())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
SBCommandReturnObject::SBCommandReturnObject (const SBCommandReturnObject &rhs):
|
|
|
|
m_opaque_ap ()
|
|
|
|
{
|
|
|
|
if (rhs.m_opaque_ap.get())
|
|
|
|
m_opaque_ap.reset (new CommandReturnObject (*rhs.m_opaque_ap));
|
|
|
|
}
|
|
|
|
|
2011-08-20 07:06:38 +08:00
|
|
|
SBCommandReturnObject::SBCommandReturnObject (CommandReturnObject *ptr) :
|
|
|
|
m_opaque_ap (ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandReturnObject *
|
|
|
|
SBCommandReturnObject::Release ()
|
|
|
|
{
|
|
|
|
return m_opaque_ap.release();
|
|
|
|
}
|
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
const SBCommandReturnObject &
|
|
|
|
SBCommandReturnObject::operator = (const SBCommandReturnObject &rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
if (rhs.m_opaque_ap.get())
|
|
|
|
m_opaque_ap.reset (new CommandReturnObject (*rhs.m_opaque_ap));
|
|
|
|
else
|
|
|
|
m_opaque_ap.reset();
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBCommandReturnObject::~SBCommandReturnObject ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
// m_opaque_ap will automatically delete any pointer it owns
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCommandReturnObject::IsValid() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get() != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBCommandReturnObject::GetOutput ()
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2010-10-26 11:11:13 +08:00
|
|
|
{
|
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBCommandReturnObject(%p)::GetOutput () => \"%s\"",
|
|
|
|
static_cast<void*>(m_opaque_ap.get()),
|
2011-02-19 10:53:09 +08:00
|
|
|
m_opaque_ap->GetOutputData());
|
2010-10-27 07:49:36 +08:00
|
|
|
|
2011-02-19 10:53:09 +08:00
|
|
|
return m_opaque_ap->GetOutputData();
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBCommandReturnObject(%p)::GetOutput () => NULL",
|
|
|
|
static_cast<void*>(m_opaque_ap.get()));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBCommandReturnObject::GetError ()
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2010-10-26 11:11:13 +08:00
|
|
|
{
|
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBCommandReturnObject(%p)::GetError () => \"%s\"",
|
|
|
|
static_cast<void*>(m_opaque_ap.get()),
|
2011-02-19 10:53:09 +08:00
|
|
|
m_opaque_ap->GetErrorData());
|
2010-10-27 07:49:36 +08:00
|
|
|
|
2011-02-19 10:53:09 +08:00
|
|
|
return m_opaque_ap->GetErrorData();
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBCommandReturnObject(%p)::GetError () => NULL",
|
|
|
|
static_cast<void*>(m_opaque_ap.get()));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBCommandReturnObject::GetOutputSize ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2011-02-19 10:53:09 +08:00
|
|
|
return strlen (m_opaque_ap->GetOutputData());
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBCommandReturnObject::GetErrorSize ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2011-02-19 10:53:09 +08:00
|
|
|
return strlen(m_opaque_ap->GetErrorData());
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBCommandReturnObject::PutOutput (FILE *fh)
|
|
|
|
{
|
|
|
|
if (fh)
|
|
|
|
{
|
|
|
|
size_t num_bytes = GetOutputSize ();
|
|
|
|
if (num_bytes)
|
|
|
|
return ::fprintf (fh, "%s", GetOutput());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBCommandReturnObject::PutError (FILE *fh)
|
|
|
|
{
|
|
|
|
if (fh)
|
|
|
|
{
|
|
|
|
size_t num_bytes = GetErrorSize ();
|
|
|
|
if (num_bytes)
|
|
|
|
return ::fprintf (fh, "%s", GetError());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBCommandReturnObject::Clear()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
m_opaque_ap->Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::ReturnStatus
|
|
|
|
SBCommandReturnObject::GetStatus()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
return m_opaque_ap->GetStatus();
|
2010-06-09 00:52:24 +08:00
|
|
|
return lldb::eReturnStatusInvalid;
|
|
|
|
}
|
|
|
|
|
2012-06-28 01:25:36 +08:00
|
|
|
void
|
|
|
|
SBCommandReturnObject::SetStatus(lldb::ReturnStatus status)
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get())
|
|
|
|
m_opaque_ap->SetStatus(status);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
SBCommandReturnObject::Succeeded ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
return m_opaque_ap->Succeeded();
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCommandReturnObject::HasResult ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
return m_opaque_ap->HasResult();
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBCommandReturnObject::AppendMessage (const char *message)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
m_opaque_ap->AppendMessage (message);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-09-29 07:57:51 +08:00
|
|
|
void
|
|
|
|
SBCommandReturnObject::AppendWarning (const char *message)
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get())
|
|
|
|
m_opaque_ap->AppendWarning (message);
|
|
|
|
}
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
CommandReturnObject *
|
|
|
|
SBCommandReturnObject::operator ->() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandReturnObject *
|
|
|
|
SBCommandReturnObject::get() const
|
|
|
|
{
|
|
|
|
return m_opaque_ap.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandReturnObject &
|
|
|
|
SBCommandReturnObject::operator *() const
|
|
|
|
{
|
|
|
|
assert(m_opaque_ap.get());
|
|
|
|
return *(m_opaque_ap.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
CommandReturnObject &
|
|
|
|
SBCommandReturnObject::ref() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
assert(m_opaque_ap.get());
|
|
|
|
return *(m_opaque_ap.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-06-23 09:19:29 +08:00
|
|
|
SBCommandReturnObject::SetLLDBObjectPtr (CommandReturnObject *ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
m_opaque_ap.reset (ptr);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
bool
|
|
|
|
SBCommandReturnObject::GetDescription (SBStream &description)
|
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
{
|
|
|
|
description.Printf ("Status: ");
|
|
|
|
lldb::ReturnStatus status = m_opaque_ap->GetStatus();
|
|
|
|
if (status == lldb::eReturnStatusStarted)
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString ("Started");
|
2010-09-20 13:20:02 +08:00
|
|
|
else if (status == lldb::eReturnStatusInvalid)
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString ("Invalid");
|
2010-09-20 13:20:02 +08:00
|
|
|
else if (m_opaque_ap->Succeeded())
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString ("Success");
|
2010-09-20 13:20:02 +08:00
|
|
|
else
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString ("Fail");
|
2010-09-20 13:20:02 +08:00
|
|
|
|
|
|
|
if (GetOutputSize() > 0)
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.Printf ("\nOutput Message:\n%s", GetOutput());
|
2010-09-20 13:20:02 +08:00
|
|
|
|
|
|
|
if (GetErrorSize() > 0)
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.Printf ("\nError Message:\n%s", GetError());
|
2010-09-20 13:20:02 +08:00
|
|
|
}
|
|
|
|
else
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString ("No value");
|
2010-09-20 13:20:02 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-02-19 10:53:09 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
SBCommandReturnObject::SetImmediateOutputFile (FILE *fh)
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get())
|
|
|
|
m_opaque_ap->SetImmediateOutputFile (fh);
|
|
|
|
}
|
2012-10-17 04:57:12 +08:00
|
|
|
|
2011-02-19 10:53:09 +08:00
|
|
|
void
|
|
|
|
SBCommandReturnObject::SetImmediateErrorFile (FILE *fh)
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get())
|
|
|
|
m_opaque_ap->SetImmediateErrorFile (fh);
|
|
|
|
}
|
2011-08-17 07:24:13 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
SBCommandReturnObject::PutCString(const char* string, int len)
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get())
|
|
|
|
{
|
2013-05-03 01:29:04 +08:00
|
|
|
if (len == 0 || string == NULL || *string == 0)
|
2012-12-15 10:40:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (len > 0)
|
|
|
|
{
|
|
|
|
std::string buffer(string, len);
|
|
|
|
m_opaque_ap->AppendMessage(buffer.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_opaque_ap->AppendMessage(string);
|
2011-08-17 07:24:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-17 04:57:12 +08:00
|
|
|
const char *
|
|
|
|
SBCommandReturnObject::GetOutput (bool only_if_no_immediate)
|
|
|
|
{
|
|
|
|
if (!m_opaque_ap.get())
|
|
|
|
return NULL;
|
|
|
|
if (only_if_no_immediate == false || m_opaque_ap->GetImmediateOutputStream().get() == NULL)
|
|
|
|
return GetOutput();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBCommandReturnObject::GetError (bool only_if_no_immediate)
|
|
|
|
{
|
|
|
|
if (!m_opaque_ap.get())
|
|
|
|
return NULL;
|
|
|
|
if (only_if_no_immediate == false || m_opaque_ap->GetImmediateErrorStream().get() == NULL)
|
|
|
|
return GetError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-17 07:24:13 +08:00
|
|
|
size_t
|
|
|
|
SBCommandReturnObject::Printf(const char* format, ...)
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get())
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
size_t result = m_opaque_ap->GetOutputStream().PrintfVarArg(format, args);
|
|
|
|
va_end (args);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-10 04:14:26 +08:00
|
|
|
void
|
|
|
|
SBCommandReturnObject::SetError (lldb::SBError &error, const char *fallback_error_cstr)
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get())
|
|
|
|
{
|
|
|
|
if (error.IsValid())
|
|
|
|
m_opaque_ap->SetError(error.ref(), fallback_error_cstr);
|
|
|
|
else if (fallback_error_cstr)
|
|
|
|
m_opaque_ap->SetError(Error(), fallback_error_cstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBCommandReturnObject::SetError (const char *error_cstr)
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get() && error_cstr)
|
|
|
|
m_opaque_ap->SetError(error_cstr);
|
|
|
|
}
|
|
|
|
|