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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
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
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBCommandReturnObject::SBCommandReturnObject()
|
|
|
|
: m_opaque_ap(new CommandReturnObject()) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBCommandReturnObject::SBCommandReturnObject(const SBCommandReturnObject &rhs)
|
|
|
|
: m_opaque_ap() {
|
|
|
|
if (rhs.m_opaque_ap)
|
|
|
|
m_opaque_ap.reset(new CommandReturnObject(*rhs.m_opaque_ap));
|
2010-11-06 07:17:00 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBCommandReturnObject::SBCommandReturnObject(CommandReturnObject *ptr)
|
|
|
|
: m_opaque_ap(ptr) {}
|
2011-08-20 07:06:38 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
SBCommandReturnObject::~SBCommandReturnObject() = default;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
CommandReturnObject *SBCommandReturnObject::Release() {
|
|
|
|
return m_opaque_ap.release();
|
2011-08-20 07:06:38 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const SBCommandReturnObject &SBCommandReturnObject::
|
|
|
|
operator=(const SBCommandReturnObject &rhs) {
|
|
|
|
if (this != &rhs) {
|
|
|
|
if (rhs.m_opaque_ap)
|
|
|
|
m_opaque_ap.reset(new CommandReturnObject(*rhs.m_opaque_ap));
|
|
|
|
else
|
|
|
|
m_opaque_ap.reset();
|
|
|
|
}
|
|
|
|
return *this;
|
2010-11-06 07:17:00 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBCommandReturnObject::IsValid() const {
|
|
|
|
return m_opaque_ap.get() != nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBCommandReturnObject::GetOutput() {
|
|
|
|
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_opaque_ap) {
|
2016-11-17 05:15:24 +08:00
|
|
|
llvm::StringRef output = m_opaque_ap->GetOutputData();
|
|
|
|
ConstString result(output.empty() ? llvm::StringRef("") : output);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("SBCommandReturnObject(%p)::GetOutput () => \"%s\"",
|
2016-11-17 05:15:24 +08:00
|
|
|
static_cast<void *>(m_opaque_ap.get()), result.AsCString());
|
2010-10-27 07:49:36 +08:00
|
|
|
|
2016-11-17 05:15:24 +08:00
|
|
|
return result.AsCString();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("SBCommandReturnObject(%p)::GetOutput () => nullptr",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBCommandReturnObject::GetError() {
|
|
|
|
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_opaque_ap) {
|
2016-11-17 05:15:24 +08:00
|
|
|
llvm::StringRef output = m_opaque_ap->GetErrorData();
|
|
|
|
ConstString result(output.empty() ? llvm::StringRef("") : output);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("SBCommandReturnObject(%p)::GetError () => \"%s\"",
|
2016-11-17 05:15:24 +08:00
|
|
|
static_cast<void *>(m_opaque_ap.get()), result.AsCString());
|
2010-10-27 07:49:36 +08:00
|
|
|
|
2016-11-17 05:15:24 +08:00
|
|
|
return result.AsCString();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("SBCommandReturnObject(%p)::GetError () => nullptr",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t SBCommandReturnObject::GetOutputSize() {
|
2016-11-17 05:15:24 +08:00
|
|
|
return (m_opaque_ap ? m_opaque_ap->GetOutputData().size() : 0);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t SBCommandReturnObject::GetErrorSize() {
|
2016-11-17 05:15:24 +08:00
|
|
|
return (m_opaque_ap ? m_opaque_ap->GetErrorData().size() : 0);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t SBCommandReturnObject::PutOutput(FILE *fh) {
|
|
|
|
if (fh) {
|
|
|
|
size_t num_bytes = GetOutputSize();
|
|
|
|
if (num_bytes)
|
|
|
|
return ::fprintf(fh, "%s", GetOutput());
|
|
|
|
}
|
|
|
|
return 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t SBCommandReturnObject::PutError(FILE *fh) {
|
|
|
|
if (fh) {
|
|
|
|
size_t num_bytes = GetErrorSize();
|
|
|
|
if (num_bytes)
|
|
|
|
return ::fprintf(fh, "%s", GetError());
|
|
|
|
}
|
|
|
|
return 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBCommandReturnObject::Clear() {
|
|
|
|
if (m_opaque_ap)
|
|
|
|
m_opaque_ap->Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::ReturnStatus SBCommandReturnObject::GetStatus() {
|
|
|
|
return (m_opaque_ap ? m_opaque_ap->GetStatus() : lldb::eReturnStatusInvalid);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBCommandReturnObject::SetStatus(lldb::ReturnStatus status) {
|
|
|
|
if (m_opaque_ap)
|
|
|
|
m_opaque_ap->SetStatus(status);
|
2012-06-28 01:25:36 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBCommandReturnObject::Succeeded() {
|
|
|
|
return (m_opaque_ap ? m_opaque_ap->Succeeded() : false);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBCommandReturnObject::HasResult() {
|
|
|
|
return (m_opaque_ap ? m_opaque_ap->HasResult() : false);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBCommandReturnObject::AppendMessage(const char *message) {
|
|
|
|
if (m_opaque_ap)
|
|
|
|
m_opaque_ap->AppendMessage(message);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBCommandReturnObject::AppendWarning(const char *message) {
|
|
|
|
if (m_opaque_ap)
|
|
|
|
m_opaque_ap->AppendWarning(message);
|
2012-09-29 07:57:51 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
CommandReturnObject *SBCommandReturnObject::operator->() const {
|
|
|
|
return m_opaque_ap.get();
|
2010-06-23 09:19:29 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
CommandReturnObject *SBCommandReturnObject::get() const {
|
|
|
|
return m_opaque_ap.get();
|
2010-06-23 09:19:29 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
CommandReturnObject &SBCommandReturnObject::operator*() const {
|
|
|
|
assert(m_opaque_ap.get());
|
|
|
|
return *(m_opaque_ap.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
CommandReturnObject &SBCommandReturnObject::ref() const {
|
|
|
|
assert(m_opaque_ap.get());
|
|
|
|
return *(m_opaque_ap.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBCommandReturnObject::SetLLDBObjectPtr(CommandReturnObject *ptr) {
|
|
|
|
if (m_opaque_ap)
|
|
|
|
m_opaque_ap.reset(ptr);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBCommandReturnObject::GetDescription(SBStream &description) {
|
|
|
|
Stream &strm = description.ref();
|
2011-11-13 14:57:31 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_opaque_ap) {
|
|
|
|
description.Printf("Status: ");
|
|
|
|
lldb::ReturnStatus status = m_opaque_ap->GetStatus();
|
|
|
|
if (status == lldb::eReturnStatusStarted)
|
|
|
|
strm.PutCString("Started");
|
|
|
|
else if (status == lldb::eReturnStatusInvalid)
|
|
|
|
strm.PutCString("Invalid");
|
|
|
|
else if (m_opaque_ap->Succeeded())
|
|
|
|
strm.PutCString("Success");
|
|
|
|
else
|
|
|
|
strm.PutCString("Fail");
|
2010-09-20 13:20:02 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (GetOutputSize() > 0)
|
|
|
|
strm.Printf("\nOutput Message:\n%s", GetOutput());
|
2010-09-20 13:20:02 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (GetErrorSize() > 0)
|
|
|
|
strm.Printf("\nError Message:\n%s", GetError());
|
|
|
|
} else
|
|
|
|
strm.PutCString("No value");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBCommandReturnObject::SetImmediateOutputFile(FILE *fh) {
|
|
|
|
SetImmediateOutputFile(fh, false);
|
2012-10-17 04:57:12 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBCommandReturnObject::SetImmediateErrorFile(FILE *fh) {
|
|
|
|
SetImmediateErrorFile(fh, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBCommandReturnObject::SetImmediateOutputFile(FILE *fh,
|
|
|
|
bool transfer_ownership) {
|
|
|
|
if (m_opaque_ap)
|
|
|
|
m_opaque_ap->SetImmediateOutputFile(fh, transfer_ownership);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBCommandReturnObject::SetImmediateErrorFile(FILE *fh,
|
|
|
|
bool transfer_ownership) {
|
|
|
|
if (m_opaque_ap)
|
|
|
|
m_opaque_ap->SetImmediateErrorFile(fh, transfer_ownership);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBCommandReturnObject::PutCString(const char *string, int len) {
|
|
|
|
if (m_opaque_ap) {
|
|
|
|
if (len == 0 || string == nullptr || *string == 0) {
|
|
|
|
return;
|
|
|
|
} else if (len > 0) {
|
|
|
|
std::string buffer(string, len);
|
|
|
|
m_opaque_ap->AppendMessage(buffer.c_str());
|
|
|
|
} else
|
|
|
|
m_opaque_ap->AppendMessage(string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBCommandReturnObject::GetOutput(bool only_if_no_immediate) {
|
|
|
|
if (!m_opaque_ap)
|
2015-10-31 09:22:59 +08:00
|
|
|
return nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!only_if_no_immediate ||
|
|
|
|
m_opaque_ap->GetImmediateOutputStream().get() == nullptr)
|
|
|
|
return GetOutput();
|
|
|
|
return nullptr;
|
2012-10-17 04:57:12 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBCommandReturnObject::GetError(bool only_if_no_immediate) {
|
|
|
|
if (!m_opaque_ap)
|
|
|
|
return nullptr;
|
|
|
|
if (!only_if_no_immediate ||
|
|
|
|
m_opaque_ap->GetImmediateErrorStream().get() == nullptr)
|
|
|
|
return GetError();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SBCommandReturnObject::Printf(const char *format, ...) {
|
|
|
|
if (m_opaque_ap) {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
size_t result = m_opaque_ap->GetOutputStream().PrintfVarArg(format, args);
|
|
|
|
va_end(args);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBCommandReturnObject::SetError(lldb::SBError &error,
|
|
|
|
const char *fallback_error_cstr) {
|
|
|
|
if (m_opaque_ap) {
|
|
|
|
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 && error_cstr)
|
|
|
|
m_opaque_ap->SetError(error_cstr);
|
2013-07-10 04:14:26 +08:00
|
|
|
}
|