2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBAddress.cpp -------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBAddress.h"
|
2019-03-06 08:06:00 +08:00
|
|
|
#include "SBReproducerPrivate.h"
|
2019-03-06 08:05:55 +08:00
|
|
|
#include "Utils.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/API/SBProcess.h"
|
2011-09-24 08:52:29 +08:00
|
|
|
#include "lldb/API/SBSection.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Address.h"
|
2011-03-31 09:08:07 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2015-03-04 03:23:09 +08:00
|
|
|
#include "lldb/Symbol/LineEntry.h"
|
2010-12-21 04:49:23 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
2010-10-26 11:11:13 +08:00
|
|
|
using namespace lldb_private;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
SBAddress::SBAddress() : m_opaque_up(new Address()) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBAddress);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBAddress::SBAddress(const Address *lldb_object_ptr)
|
2019-02-13 14:25:41 +08:00
|
|
|
: m_opaque_up(new Address()) {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (lldb_object_ptr)
|
2019-03-06 08:05:55 +08:00
|
|
|
m_opaque_up = llvm::make_unique<Address>(*lldb_object_ptr);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
SBAddress::SBAddress(const SBAddress &rhs) : m_opaque_up(new Address()) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBAddress, (const lldb::SBAddress &), rhs);
|
|
|
|
|
2019-03-06 08:05:55 +08:00
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBAddress::SBAddress(lldb::SBSection section, lldb::addr_t offset)
|
2019-03-06 08:06:00 +08:00
|
|
|
: m_opaque_up(new Address(section.GetSP(), offset)) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBAddress, (lldb::SBSection, lldb::addr_t), section,
|
|
|
|
offset);
|
|
|
|
}
|
2012-02-04 10:58:17 +08:00
|
|
|
|
2011-07-23 00:46:35 +08:00
|
|
|
// Create an address by resolving a load address using the supplied target
|
2016-09-07 04:57:50 +08:00
|
|
|
SBAddress::SBAddress(lldb::addr_t load_addr, lldb::SBTarget &target)
|
2019-02-13 14:25:41 +08:00
|
|
|
: m_opaque_up(new Address()) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBAddress, (lldb::addr_t, lldb::SBTarget &),
|
|
|
|
load_addr, target);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SetLoadAddress(load_addr, target);
|
2011-07-23 00:46:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBAddress::~SBAddress() {}
|
2011-07-23 00:46:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const SBAddress &SBAddress::operator=(const SBAddress &rhs) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(const lldb::SBAddress &,
|
|
|
|
SBAddress, operator=,(const lldb::SBAddress &), rhs);
|
|
|
|
|
2019-03-06 08:05:55 +08:00
|
|
|
if (this != &rhs)
|
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2016-09-07 04:57:50 +08:00
|
|
|
return *this;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2017-05-04 19:34:42 +08:00
|
|
|
bool lldb::operator==(const SBAddress &lhs, const SBAddress &rhs) {
|
|
|
|
if (lhs.IsValid() && rhs.IsValid())
|
|
|
|
return lhs.ref() == rhs.ref();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBAddress::IsValid() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBAddress, IsValid);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up != NULL && m_opaque_up->IsValid();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
void SBAddress::Clear() {
|
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBAddress, Clear);
|
|
|
|
|
|
|
|
m_opaque_up.reset(new Address());
|
|
|
|
}
|
2010-09-11 02:31:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBAddress::SetAddress(lldb::SBSection section, lldb::addr_t offset) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBAddress, SetAddress,
|
|
|
|
(lldb::SBSection, lldb::addr_t), section, offset);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Address &addr = ref();
|
|
|
|
addr.SetSection(section.GetSP());
|
|
|
|
addr.SetOffset(offset);
|
2012-02-04 10:58:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBAddress::SetAddress(const Address *lldb_object_ptr) {
|
|
|
|
if (lldb_object_ptr)
|
|
|
|
ref() = *lldb_object_ptr;
|
|
|
|
else
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up.reset(new Address());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::addr_t SBAddress::GetFileAddress() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::addr_t, SBAddress, GetFileAddress);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid())
|
|
|
|
return m_opaque_up->GetFileAddress();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::addr_t SBAddress::GetLoadAddress(const SBTarget &target) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(lldb::addr_t, SBAddress, GetLoadAddress,
|
|
|
|
(const lldb::SBTarget &), target);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::addr_t addr = LLDB_INVALID_ADDRESS;
|
|
|
|
TargetSP target_sp(target.GetSP());
|
|
|
|
if (target_sp) {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid()) {
|
2016-09-07 04:57:50 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
|
2019-02-13 14:25:41 +08:00
|
|
|
addr = m_opaque_up->GetLoadAddress(target_sp.get());
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-12-21 04:49:23 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBAddress::SetLoadAddress(lldb::addr_t load_addr, lldb::SBTarget &target) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBAddress, SetLoadAddress,
|
|
|
|
(lldb::addr_t, lldb::SBTarget &), load_addr, target);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// Create the address object if we don't already have one
|
|
|
|
ref();
|
|
|
|
if (target.IsValid())
|
|
|
|
*this = target.ResolveLoadAddress(load_addr);
|
|
|
|
else
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Check if we weren't were able to resolve a section offset address. If we
|
|
|
|
// weren't it is ok, the load address might be a location on the stack or
|
|
|
|
// heap, so we should just have an address with no section and a valid offset
|
2019-02-13 14:25:41 +08:00
|
|
|
if (!m_opaque_up->IsValid())
|
|
|
|
m_opaque_up->SetOffset(load_addr);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SBAddress::OffsetAddress(addr_t offset) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(bool, SBAddress, OffsetAddress, (lldb::addr_t), offset);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid()) {
|
|
|
|
addr_t addr_offset = m_opaque_up->GetOffset();
|
2016-09-07 04:57:50 +08:00
|
|
|
if (addr_offset != LLDB_INVALID_ADDRESS) {
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->SetOffset(addr_offset + offset);
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::SBSection SBAddress::GetSection() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSection, SBAddress, GetSection);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::SBSection sb_section;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid())
|
|
|
|
sb_section.SetSP(m_opaque_up->GetSection());
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_section);
|
2011-09-24 08:52:29 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::addr_t SBAddress::GetOffset() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBAddress, GetOffset);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid())
|
|
|
|
return m_opaque_up->GetOffset();
|
2016-09-07 04:57:50 +08:00
|
|
|
return 0;
|
2012-01-29 14:07:39 +08:00
|
|
|
}
|
2011-09-24 08:52:29 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
Address *SBAddress::operator->() { return m_opaque_up.get(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
const Address *SBAddress::operator->() const { return m_opaque_up.get(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Address &SBAddress::ref() {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up == NULL)
|
|
|
|
m_opaque_up.reset(new Address());
|
|
|
|
return *m_opaque_up;
|
2010-09-11 02:31:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const Address &SBAddress::ref() const {
|
2018-05-01 00:49:04 +08:00
|
|
|
// This object should already have checked with "IsValid()" prior to calling
|
|
|
|
// this function. In case you didn't we will assert and die to let you know.
|
2019-02-13 14:25:41 +08:00
|
|
|
assert(m_opaque_up.get());
|
|
|
|
return *m_opaque_up;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
Address *SBAddress::get() { return m_opaque_up.get(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBAddress::GetDescription(SBStream &description) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(bool, SBAddress, GetDescription, (lldb::SBStream &),
|
|
|
|
description);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// Call "ref()" on the stream to make sure it creates a backing stream in
|
|
|
|
// case there isn't one already...
|
|
|
|
Stream &strm = description.ref();
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid()) {
|
|
|
|
m_opaque_up->Dump(&strm, NULL, Address::DumpStyleResolvedDescription,
|
2016-09-07 04:57:50 +08:00
|
|
|
Address::DumpStyleModuleWithFileAddress, 4);
|
|
|
|
StreamString sstrm;
|
2019-02-13 14:25:41 +08:00
|
|
|
// m_opaque_up->Dump (&sstrm, NULL,
|
2016-09-07 04:57:50 +08:00
|
|
|
// Address::DumpStyleResolvedDescription, Address::DumpStyleInvalid,
|
|
|
|
// 4);
|
|
|
|
// if (sstrm.GetData())
|
|
|
|
// strm.Printf (" (%s)", sstrm.GetData());
|
|
|
|
} else
|
|
|
|
strm.PutCString("No value");
|
2010-09-20 13:20:02 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
2010-09-20 13:20:02 +08:00
|
|
|
}
|
2011-03-31 09:08:07 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBModule SBAddress::GetModule() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBModule, SBAddress, GetModule);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBModule sb_module;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid())
|
|
|
|
sb_module.SetSP(m_opaque_up->GetModule());
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_module);
|
2011-03-31 09:08:07 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbolContext SBAddress::GetSymbolContext(uint32_t resolve_scope) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(lldb::SBSymbolContext, SBAddress, GetSymbolContext,
|
|
|
|
(uint32_t), resolve_scope);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbolContext sb_sc;
|
2018-10-26 04:45:19 +08:00
|
|
|
SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid())
|
|
|
|
m_opaque_up->CalculateSymbolContext(&sb_sc.ref(), scope);
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_sc);
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBCompileUnit SBAddress::GetCompileUnit() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBCompileUnit, SBAddress, GetCompileUnit);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBCompileUnit sb_comp_unit;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid())
|
|
|
|
sb_comp_unit.reset(m_opaque_up->CalculateSymbolContextCompileUnit());
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_comp_unit);
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFunction SBAddress::GetFunction() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFunction, SBAddress, GetFunction);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFunction sb_function;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid())
|
|
|
|
sb_function.reset(m_opaque_up->CalculateSymbolContextFunction());
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_function);
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBBlock SBAddress::GetBlock() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBlock, SBAddress, GetBlock);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBBlock sb_block;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid())
|
|
|
|
sb_block.SetPtr(m_opaque_up->CalculateSymbolContextBlock());
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_block);
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbol SBAddress::GetSymbol() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSymbol, SBAddress, GetSymbol);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBSymbol sb_symbol;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid())
|
|
|
|
sb_symbol.reset(m_opaque_up->CalculateSymbolContextSymbol());
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_symbol);
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBLineEntry SBAddress::GetLineEntry() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBLineEntry, SBAddress, GetLineEntry);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBLineEntry sb_line_entry;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->IsValid()) {
|
2016-09-07 04:57:50 +08:00
|
|
|
LineEntry line_entry;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->CalculateSymbolContextLineEntry(line_entry))
|
2016-09-07 04:57:50 +08:00
|
|
|
sb_line_entry.SetLineEntry(line_entry);
|
|
|
|
}
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_line_entry);
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|