2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBSymbolContext.cpp -------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBSymbolContext.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2011-09-26 15:11:27 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2010-10-31 11:01:06 +08:00
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/Symbol.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbolContext::SBSymbolContext() : m_opaque_ap() {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbolContext::SBSymbolContext(const SymbolContext *sc_ptr) : m_opaque_ap() {
|
|
|
|
if (sc_ptr)
|
|
|
|
m_opaque_ap.reset(new SymbolContext(*sc_ptr));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbolContext::SBSymbolContext(const SBSymbolContext &rhs) : m_opaque_ap() {
|
|
|
|
if (rhs.IsValid()) {
|
2018-12-21 05:02:55 +08:00
|
|
|
if (m_opaque_ap)
|
2016-09-07 04:57:50 +08:00
|
|
|
*m_opaque_ap = *rhs.m_opaque_ap;
|
|
|
|
else
|
|
|
|
ref() = *rhs.m_opaque_ap;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbolContext::~SBSymbolContext() {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const SBSymbolContext &SBSymbolContext::operator=(const SBSymbolContext &rhs) {
|
|
|
|
if (this != &rhs) {
|
|
|
|
if (rhs.IsValid())
|
2018-12-21 05:02:55 +08:00
|
|
|
m_opaque_ap.reset(new lldb_private::SymbolContext(*rhs.m_opaque_ap));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return *this;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBSymbolContext::SetSymbolContext(const SymbolContext *sc_ptr) {
|
|
|
|
if (sc_ptr) {
|
2018-12-21 05:02:55 +08:00
|
|
|
if (m_opaque_ap)
|
2016-09-07 04:57:50 +08:00
|
|
|
*m_opaque_ap = *sc_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2016-09-07 04:57:50 +08:00
|
|
|
m_opaque_ap.reset(new SymbolContext(*sc_ptr));
|
|
|
|
} else {
|
2018-12-21 05:02:55 +08:00
|
|
|
if (m_opaque_ap)
|
2016-09-07 04:57:50 +08:00
|
|
|
m_opaque_ap->Clear(true);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2018-12-21 05:02:55 +08:00
|
|
|
bool SBSymbolContext::IsValid() const { return m_opaque_ap != NULL; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBModule SBSymbolContext::GetModule() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBModule sb_module;
|
|
|
|
ModuleSP module_sp;
|
2018-12-21 05:02:55 +08:00
|
|
|
if (m_opaque_ap) {
|
2016-09-07 04:57:50 +08:00
|
|
|
module_sp = m_opaque_ap->module_sp;
|
|
|
|
sb_module.SetSP(module_sp);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log) {
|
|
|
|
SBStream sstr;
|
|
|
|
sb_module.GetDescription(sstr);
|
|
|
|
log->Printf("SBSymbolContext(%p)::GetModule () => SBModule(%p): %s",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()),
|
|
|
|
static_cast<void *>(module_sp.get()), sstr.GetData());
|
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return sb_module;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBCompileUnit SBSymbolContext::GetCompileUnit() {
|
2018-12-21 05:02:55 +08:00
|
|
|
return SBCompileUnit(m_opaque_ap ? m_opaque_ap->comp_unit : NULL);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFunction SBSymbolContext::GetFunction() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Function *function = NULL;
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2018-12-21 05:02:55 +08:00
|
|
|
if (m_opaque_ap)
|
2016-09-07 04:57:50 +08:00
|
|
|
function = m_opaque_ap->function;
|
2010-10-31 11:01:06 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFunction sb_function(function);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("SBSymbolContext(%p)::GetFunction () => SBFunction(%p)",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()),
|
|
|
|
static_cast<void *>(function));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return sb_function;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBBlock SBSymbolContext::GetBlock() {
|
2018-12-21 05:02:55 +08:00
|
|
|
return SBBlock(m_opaque_ap ? m_opaque_ap->block : NULL);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBLineEntry SBSymbolContext::GetLineEntry() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBLineEntry sb_line_entry;
|
2018-12-21 05:02:55 +08:00
|
|
|
if (m_opaque_ap)
|
2016-09-07 04:57:50 +08:00
|
|
|
sb_line_entry.SetLineEntry(m_opaque_ap->line_entry);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log) {
|
|
|
|
log->Printf("SBSymbolContext(%p)::GetLineEntry () => SBLineEntry(%p)",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()),
|
|
|
|
static_cast<void *>(sb_line_entry.get()));
|
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return sb_line_entry;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbol SBSymbolContext::GetSymbol() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Symbol *symbol = NULL;
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2018-12-21 05:02:55 +08:00
|
|
|
if (m_opaque_ap)
|
2016-09-07 04:57:50 +08:00
|
|
|
symbol = m_opaque_ap->symbol;
|
2010-10-31 11:01:06 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbol sb_symbol(symbol);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("SBSymbolContext(%p)::GetSymbol () => SBSymbol(%p)",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()),
|
|
|
|
static_cast<void *>(symbol));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return sb_symbol;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBSymbolContext::SetModule(lldb::SBModule module) {
|
|
|
|
ref().module_sp = module.GetSP();
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBSymbolContext::SetCompileUnit(lldb::SBCompileUnit compile_unit) {
|
|
|
|
ref().comp_unit = compile_unit.get();
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBSymbolContext::SetFunction(lldb::SBFunction function) {
|
|
|
|
ref().function = function.get();
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBSymbolContext::SetBlock(lldb::SBBlock block) {
|
|
|
|
ref().block = block.GetPtr();
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBSymbolContext::SetLineEntry(lldb::SBLineEntry line_entry) {
|
|
|
|
if (line_entry.IsValid())
|
|
|
|
ref().line_entry = line_entry.ref();
|
|
|
|
else
|
|
|
|
ref().line_entry.Clear();
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBSymbolContext::SetSymbol(lldb::SBSymbol symbol) {
|
|
|
|
ref().symbol = symbol.get();
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb_private::SymbolContext *SBSymbolContext::operator->() const {
|
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const lldb_private::SymbolContext &SBSymbolContext::operator*() const {
|
|
|
|
assert(m_opaque_ap.get());
|
2018-12-21 05:02:55 +08:00
|
|
|
return *m_opaque_ap;
|
2010-09-11 02:31:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb_private::SymbolContext &SBSymbolContext::operator*() {
|
2018-12-21 05:02:55 +08:00
|
|
|
if (m_opaque_ap == NULL)
|
2016-09-07 04:57:50 +08:00
|
|
|
m_opaque_ap.reset(new SymbolContext);
|
2018-12-21 05:02:55 +08:00
|
|
|
return *m_opaque_ap;
|
2010-09-11 02:31:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb_private::SymbolContext &SBSymbolContext::ref() {
|
2018-12-21 05:02:55 +08:00
|
|
|
if (m_opaque_ap == NULL)
|
2016-09-07 04:57:50 +08:00
|
|
|
m_opaque_ap.reset(new SymbolContext);
|
2018-12-21 05:02:55 +08:00
|
|
|
return *m_opaque_ap;
|
2010-09-23 07:01:29 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb_private::SymbolContext *SBSymbolContext::get() const {
|
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBSymbolContext::GetDescription(SBStream &description) {
|
|
|
|
Stream &strm = description.ref();
|
2011-11-13 14:57:31 +08:00
|
|
|
|
2018-12-21 05:02:55 +08:00
|
|
|
if (m_opaque_ap) {
|
2016-09-07 04:57:50 +08:00
|
|
|
m_opaque_ap->GetDescription(&strm, lldb::eDescriptionLevelFull, NULL);
|
|
|
|
} else
|
|
|
|
strm.PutCString("No value");
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
2010-09-20 13:20:02 +08:00
|
|
|
}
|
2011-09-26 15:11:27 +08:00
|
|
|
|
|
|
|
SBSymbolContext
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbolContext::GetParentOfInlinedScope(const SBAddress &curr_frame_pc,
|
|
|
|
SBAddress &parent_frame_addr) const {
|
|
|
|
SBSymbolContext sb_sc;
|
|
|
|
if (m_opaque_ap.get() && curr_frame_pc.IsValid()) {
|
|
|
|
if (m_opaque_ap->GetParentOfInlinedScope(curr_frame_pc.ref(), sb_sc.ref(),
|
|
|
|
parent_frame_addr.ref()))
|
|
|
|
return sb_sc;
|
|
|
|
}
|
|
|
|
return SBSymbolContext();
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|