[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- Address.cpp -------------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
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/Core/Address.h"
|
2021-04-30 11:35:59 +08:00
|
|
|
#include "lldb/Core/Declaration.h"
|
2017-03-04 04:57:05 +08:00
|
|
|
#include "lldb/Core/DumpDataExtractor.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Core/ModuleList.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Section.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Symbol/Block.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Symbol/LineEntry.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Symbol/Symbol.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
2013-07-02 03:45:50 +08:00
|
|
|
#include "lldb/Symbol/SymbolVendor.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Symbol/Symtab.h"
|
|
|
|
#include "lldb/Symbol/Type.h"
|
2011-07-11 13:12:02 +08:00
|
|
|
#include "lldb/Symbol/Variable.h"
|
|
|
|
#include "lldb/Symbol/VariableList.h"
|
2010-09-15 07:36:40 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Target/ExecutionContextScope.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2013-12-06 09:12:00 +08:00
|
|
|
#include "lldb/Target/SectionLoadList.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/ConstString.h"
|
|
|
|
#include "lldb/Utility/DataExtractor.h"
|
|
|
|
#include "lldb/Utility/Endian.h"
|
|
|
|
#include "lldb/Utility/FileSpec.h"
|
|
|
|
#include "lldb/Utility/Status.h"
|
|
|
|
#include "lldb/Utility/Stream.h"
|
|
|
|
#include "lldb/Utility/StreamString.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <cstring>
|
2017-04-07 05:28:29 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
class CompileUnit;
|
|
|
|
}
|
|
|
|
namespace lldb_private {
|
|
|
|
class Function;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
static size_t ReadBytes(ExecutionContextScope *exe_scope,
|
|
|
|
const Address &address, void *dst, size_t dst_len) {
|
2016-03-02 09:09:03 +08:00
|
|
|
if (exe_scope == nullptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
TargetSP target_sp(exe_scope->CalculateTarget());
|
2012-02-18 13:35:26 +08:00
|
|
|
if (target_sp) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2021-04-17 07:10:16 +08:00
|
|
|
bool force_live_memory = true;
|
|
|
|
return target_sp->ReadMemory(address, dst, dst_len, error,
|
|
|
|
force_live_memory);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
static bool GetByteOrderAndAddressSize(ExecutionContextScope *exe_scope,
|
|
|
|
const Address &address,
|
|
|
|
ByteOrder &byte_order,
|
|
|
|
uint32_t &addr_size) {
|
|
|
|
byte_order = eByteOrderInvalid;
|
|
|
|
addr_size = 0;
|
2016-03-02 09:09:03 +08:00
|
|
|
if (exe_scope == nullptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
TargetSP target_sp(exe_scope->CalculateTarget());
|
|
|
|
if (target_sp) {
|
|
|
|
byte_order = target_sp->GetArchitecture().GetByteOrder();
|
|
|
|
addr_size = target_sp->GetArchitecture().GetAddressByteSize();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (byte_order == eByteOrderInvalid || addr_size == 0) {
|
|
|
|
ModuleSP module_sp(address.GetModule());
|
2016-01-30 04:21:33 +08:00
|
|
|
if (module_sp) {
|
2010-06-09 00:52:24 +08:00
|
|
|
byte_order = module_sp->GetArchitecture().GetByteOrder();
|
|
|
|
addr_size = module_sp->GetArchitecture().GetAddressByteSize();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return byte_order != eByteOrderInvalid && addr_size != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t ReadUIntMax64(ExecutionContextScope *exe_scope,
|
|
|
|
const Address &address, uint32_t byte_size,
|
|
|
|
bool &success) {
|
|
|
|
uint64_t uval64 = 0;
|
2016-03-02 09:09:03 +08:00
|
|
|
if (exe_scope == nullptr || byte_size > sizeof(uint64_t)) {
|
2010-06-09 00:52:24 +08:00
|
|
|
success = false;
|
|
|
|
return 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
uint64_t buf = 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
success = ReadBytes(exe_scope, address, &buf, byte_size) == byte_size;
|
|
|
|
if (success) {
|
2010-10-04 09:05:56 +08:00
|
|
|
ByteOrder byte_order = eByteOrderInvalid;
|
2010-09-15 07:36:40 +08:00
|
|
|
uint32_t addr_size = 0;
|
2011-09-22 12:58:26 +08:00
|
|
|
if (GetByteOrderAndAddressSize(exe_scope, address, byte_order, addr_size)) {
|
|
|
|
DataExtractor data(&buf, sizeof(buf), byte_order, addr_size);
|
2013-01-26 02:06:21 +08:00
|
|
|
lldb::offset_t offset = 0;
|
2011-09-22 12:58:26 +08:00
|
|
|
uval64 = data.GetU64(&offset);
|
|
|
|
} else
|
|
|
|
success = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return uval64;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-09-22 12:58:26 +08:00
|
|
|
static bool ReadAddress(ExecutionContextScope *exe_scope,
|
2010-09-15 07:36:40 +08:00
|
|
|
const Address &address, uint32_t pointer_size,
|
2012-02-24 09:59:29 +08:00
|
|
|
Address &deref_so_addr) {
|
|
|
|
if (exe_scope == nullptr)
|
2010-09-15 07:36:40 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
addr_t deref_addr = ReadUIntMax64(exe_scope, address, pointer_size, success);
|
|
|
|
if (success) {
|
|
|
|
ExecutionContext exe_ctx;
|
|
|
|
exe_scope->CalculateExecutionContext(exe_ctx);
|
|
|
|
// If we have any sections that are loaded, try and resolve using the
|
|
|
|
// section load list
|
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
2011-09-22 12:58:26 +08:00
|
|
|
if (target && !target->GetSectionLoadList().IsEmpty()) {
|
2010-09-15 07:36:40 +08:00
|
|
|
if (target->GetSectionLoadList().ResolveLoadAddress(deref_addr,
|
2012-02-24 09:59:29 +08:00
|
|
|
deref_so_addr))
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// If we were not running, yet able to read an integer, we must have a
|
|
|
|
// module
|
2010-06-09 00:52:24 +08:00
|
|
|
ModuleSP module_sp(address.GetModule());
|
|
|
|
|
|
|
|
assert(module_sp);
|
|
|
|
if (module_sp->ResolveFileAddress(deref_addr, deref_so_addr))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We couldn't make "deref_addr" into a section offset value, but we were
|
2018-05-01 00:49:04 +08:00
|
|
|
// able to read the address, so we return a section offset address with no
|
|
|
|
// section and "deref_addr" as the offset (address).
|
2010-06-09 00:52:24 +08:00
|
|
|
deref_so_addr.SetRawAddress(deref_addr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
static bool DumpUInt(ExecutionContextScope *exe_scope, const Address &address,
|
|
|
|
uint32_t byte_size, Stream *strm) {
|
|
|
|
if (exe_scope == nullptr || byte_size == 0)
|
2019-05-24 08:44:33 +08:00
|
|
|
return false;
|
2012-02-24 09:59:29 +08:00
|
|
|
std::vector<uint8_t> buf(byte_size, 0);
|
|
|
|
|
|
|
|
if (ReadBytes(exe_scope, address, &buf[0], buf.size()) == buf.size()) {
|
|
|
|
ByteOrder byte_order = eByteOrderInvalid;
|
|
|
|
uint32_t addr_size = 0;
|
|
|
|
if (GetByteOrderAndAddressSize(exe_scope, address, byte_order, addr_size)) {
|
|
|
|
DataExtractor data(&buf.front(), buf.size(), byte_order, addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpDataExtractor(data, strm,
|
|
|
|
0, // Start offset in "data"
|
|
|
|
eFormatHex, // Print as characters
|
|
|
|
buf.size(), // Size of item
|
|
|
|
1, // Items count
|
|
|
|
UINT32_MAX, // num per line
|
|
|
|
LLDB_INVALID_ADDRESS, // base address
|
|
|
|
0, // bitfield bit size
|
|
|
|
0); // bitfield bit offset
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-30 04:56:30 +08:00
|
|
|
static size_t ReadCStringFromMemory(ExecutionContextScope *exe_scope,
|
2010-06-09 00:52:24 +08:00
|
|
|
const Address &address, Stream *strm) {
|
2012-01-30 04:56:30 +08:00
|
|
|
if (exe_scope == nullptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
const size_t k_buf_len = 256;
|
|
|
|
char buf[k_buf_len + 1];
|
|
|
|
buf[k_buf_len] = '\0'; // NULL terminate
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-01-30 04:56:30 +08:00
|
|
|
// Byte order and address size don't matter for C string dumping..
|
2015-11-07 12:40:13 +08:00
|
|
|
DataExtractor data(buf, sizeof(buf), endian::InlHostByteOrder(), 4);
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t total_len = 0;
|
|
|
|
size_t bytes_read;
|
|
|
|
Address curr_address(address);
|
|
|
|
strm->PutChar('"');
|
|
|
|
while ((bytes_read = ReadBytes(exe_scope, curr_address, buf, k_buf_len)) >
|
2016-09-07 04:57:50 +08:00
|
|
|
0) {
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t len = strlen(buf);
|
|
|
|
if (len == 0)
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (len > bytes_read)
|
|
|
|
len = bytes_read;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpDataExtractor(data, strm,
|
|
|
|
0, // Start offset in "data"
|
|
|
|
eFormatChar, // Print as characters
|
|
|
|
1, // Size of item (1 byte for a char!)
|
|
|
|
len, // How many bytes to print?
|
|
|
|
UINT32_MAX, // num per line
|
|
|
|
LLDB_INVALID_ADDRESS, // base address
|
|
|
|
0, // bitfield bit size
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-03-04 04:57:05 +08:00
|
|
|
0); // bitfield bit offset
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
total_len += bytes_read;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (len < k_buf_len)
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
curr_address.SetOffset(curr_address.GetOffset() + bytes_read);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
strm->PutChar('"');
|
2012-02-18 13:35:26 +08:00
|
|
|
return total_len;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-09-07 17:58:09 +08:00
|
|
|
Address::Address(lldb::addr_t abs_addr) : m_section_wp(), m_offset(abs_addr) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
Address::Address(addr_t address, const SectionList *section_list)
|
2010-06-09 00:52:24 +08:00
|
|
|
: m_section_wp(), m_offset(LLDB_INVALID_ADDRESS) {
|
2012-02-24 09:59:29 +08:00
|
|
|
ResolveAddressUsingFileSections(address, section_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const Address &Address::operator=(const Address &rhs) {
|
|
|
|
if (this != &rhs) {
|
2012-01-30 04:56:30 +08:00
|
|
|
m_section_wp = rhs.m_section_wp;
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
m_offset = rhs.m_offset;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return *this;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
bool Address::ResolveAddressUsingFileSections(addr_t file_addr,
|
|
|
|
const SectionList *section_list) {
|
|
|
|
if (section_list) {
|
|
|
|
SectionSP section_sp(
|
|
|
|
section_list->FindSectionContainingFileAddress(file_addr));
|
|
|
|
m_section_wp = section_sp;
|
|
|
|
if (section_sp) {
|
|
|
|
assert(section_sp->ContainsFileAddress(file_addr));
|
2012-01-30 04:56:30 +08:00
|
|
|
m_offset = file_addr - section_sp->GetFileAddress();
|
2012-02-24 09:59:29 +08:00
|
|
|
return true; // Successfully transformed addr into a section offset
|
|
|
|
// address
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2012-02-24 09:59:29 +08:00
|
|
|
m_offset = file_addr;
|
|
|
|
return false; // Failed to resolve this address to a section offset value
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-08-03 00:53:42 +08:00
|
|
|
/// if "addr_range_ptr" is not NULL, then fill in with the address range of the function.
|
|
|
|
bool Address::ResolveFunctionScope(SymbolContext &sym_ctx,
|
|
|
|
AddressRange *addr_range_ptr) {
|
|
|
|
constexpr SymbolContextItem resolve_scope =
|
|
|
|
eSymbolContextFunction | eSymbolContextSymbol;
|
|
|
|
|
|
|
|
if (!(CalculateSymbolContext(&sym_ctx, resolve_scope) & resolve_scope)) {
|
|
|
|
if (addr_range_ptr)
|
|
|
|
addr_range_ptr->Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!addr_range_ptr)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return sym_ctx.GetAddressRange(resolve_scope, 0, false, *addr_range_ptr);
|
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP Address::GetModule() const {
|
2012-01-30 04:56:30 +08:00
|
|
|
lldb::ModuleSP module_sp;
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp(GetSection());
|
|
|
|
if (section_sp)
|
|
|
|
module_sp = section_sp->GetModule();
|
2012-01-30 04:56:30 +08:00
|
|
|
return module_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
addr_t Address::GetFileAddress() const {
|
|
|
|
SectionSP section_sp(GetSection());
|
|
|
|
if (section_sp) {
|
|
|
|
addr_t sect_file_addr = section_sp->GetFileAddress();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (sect_file_addr == LLDB_INVALID_ADDRESS) {
|
|
|
|
// Section isn't resolved, we can't return a valid file address
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2018-05-01 00:49:04 +08:00
|
|
|
// We have a valid file range, so we can return the file based address by
|
|
|
|
// adding the file base address to our offset
|
2010-06-09 00:52:24 +08:00
|
|
|
return sect_file_addr + m_offset;
|
2018-09-11 07:09:09 +08:00
|
|
|
} else if (SectionWasDeletedPrivate()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Used to have a valid section but it got deleted so the offset doesn't
|
|
|
|
// mean anything without the section
|
2010-06-09 00:52:24 +08:00
|
|
|
return LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
// No section, we just return the offset since it is the value in this case
|
|
|
|
return m_offset;
|
2012-01-30 04:56:30 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
addr_t Address::GetLoadAddress(Target *target) const {
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp(GetSection());
|
|
|
|
if (section_sp) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (target) {
|
2012-02-24 09:59:29 +08:00
|
|
|
addr_t sect_load_addr = section_sp->GetLoadBaseAddress(target);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (sect_load_addr != LLDB_INVALID_ADDRESS) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// We have a valid file range, so we can return the file based address
|
|
|
|
// by adding the file base address to our offset
|
2010-06-09 00:52:24 +08:00
|
|
|
return sect_load_addr + m_offset;
|
|
|
|
}
|
2013-11-06 10:29:13 +08:00
|
|
|
}
|
2018-09-11 07:09:09 +08:00
|
|
|
} else if (SectionWasDeletedPrivate()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Used to have a valid section but it got deleted so the offset doesn't
|
|
|
|
// mean anything without the section
|
2010-06-09 00:52:24 +08:00
|
|
|
return LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2010-06-09 00:52:24 +08:00
|
|
|
// We don't have a section so the offset is the load address
|
|
|
|
return m_offset;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2018-05-01 00:49:04 +08:00
|
|
|
// The section isn't resolved or an invalid target was passed in so we can't
|
|
|
|
// return a valid load address.
|
2013-11-06 10:29:13 +08:00
|
|
|
return LLDB_INVALID_ADDRESS;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
addr_t Address::GetCallableLoadAddress(Target *target, bool is_indirect) const {
|
2013-11-06 10:29:13 +08:00
|
|
|
addr_t code_addr = LLDB_INVALID_ADDRESS;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-01-11 07:46:59 +08:00
|
|
|
if (is_indirect && target) {
|
2013-02-28 04:13:38 +08:00
|
|
|
ProcessSP processSP = target->GetProcessSP();
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-03-02 09:09:03 +08:00
|
|
|
if (processSP) {
|
2014-01-11 07:46:59 +08:00
|
|
|
code_addr = processSP->ResolveIndirectFunction(this, error);
|
|
|
|
if (!error.Success())
|
|
|
|
code_addr = LLDB_INVALID_ADDRESS;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2014-01-11 07:46:59 +08:00
|
|
|
code_addr = GetLoadAddress(target);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-01-11 07:46:59 +08:00
|
|
|
if (code_addr == LLDB_INVALID_ADDRESS)
|
2011-05-19 06:01:49 +08:00
|
|
|
return code_addr;
|
|
|
|
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
if (target)
|
|
|
|
return target->GetCallableLoadAddress(code_addr, GetAddressClass());
|
2011-05-22 12:32:55 +08:00
|
|
|
return code_addr;
|
|
|
|
}
|
|
|
|
|
2015-09-07 17:58:09 +08:00
|
|
|
bool Address::SetCallableLoadAddress(lldb::addr_t load_addr, Target *target) {
|
2011-05-20 02:17:41 +08:00
|
|
|
if (SetLoadAddress(load_addr, target)) {
|
|
|
|
if (target)
|
2015-09-07 17:58:09 +08:00
|
|
|
m_offset = target->GetCallableLoadAddress(m_offset, GetAddressClass());
|
2011-05-22 12:32:55 +08:00
|
|
|
return true;
|
2015-09-07 17:58:09 +08:00
|
|
|
}
|
2011-05-20 02:17:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-07 17:58:09 +08:00
|
|
|
addr_t Address::GetOpcodeLoadAddress(Target *target,
|
|
|
|
AddressClass addr_class) const {
|
2011-05-22 12:32:55 +08:00
|
|
|
addr_t code_addr = GetLoadAddress(target);
|
|
|
|
if (code_addr != LLDB_INVALID_ADDRESS) {
|
2018-06-26 21:06:54 +08:00
|
|
|
if (addr_class == AddressClass::eInvalid)
|
2015-09-07 17:58:09 +08:00
|
|
|
addr_class = GetAddressClass();
|
|
|
|
code_addr = target->GetOpcodeLoadAddress(code_addr, addr_class);
|
|
|
|
}
|
2011-05-22 12:32:55 +08:00
|
|
|
return code_addr;
|
|
|
|
}
|
|
|
|
|
2010-07-01 07:03:03 +08:00
|
|
|
bool Address::SetOpcodeLoadAddress(lldb::addr_t load_addr, Target *target,
|
2017-06-08 21:26:35 +08:00
|
|
|
AddressClass addr_class,
|
|
|
|
bool allow_section_end) {
|
|
|
|
if (SetLoadAddress(load_addr, target, allow_section_end)) {
|
2012-02-18 13:35:26 +08:00
|
|
|
if (target) {
|
2018-06-26 21:06:54 +08:00
|
|
|
if (addr_class == AddressClass::eInvalid)
|
2011-02-16 05:59:32 +08:00
|
|
|
addr_class = GetAddressClass();
|
|
|
|
m_offset = target->GetOpcodeLoadAddress(m_offset, addr_class);
|
2010-07-01 07:03:03 +08:00
|
|
|
}
|
2011-05-22 12:32:55 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-05-22 12:32:55 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-07-01 07:03:03 +08:00
|
|
|
bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
|
|
|
|
DumpStyle fallback_style, uint32_t addr_size) const {
|
2016-03-02 09:09:03 +08:00
|
|
|
// If the section was nullptr, only load address is going to work unless we
|
2018-05-01 00:49:04 +08:00
|
|
|
// are trying to deref a pointer
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp(GetSection());
|
2012-07-12 06:18:24 +08:00
|
|
|
if (!section_sp && style != DumpStyleResolvedPointerDescription)
|
2010-06-09 00:52:24 +08:00
|
|
|
style = DumpStyleLoadAddress;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-18 13:35:26 +08:00
|
|
|
ExecutionContext exe_ctx(exe_scope);
|
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
2018-05-01 00:49:04 +08:00
|
|
|
// If addr_byte_size is UINT32_MAX, then determine the correct address byte
|
|
|
|
// size for the process or default to the size of addr_t
|
2010-07-01 07:03:03 +08:00
|
|
|
if (addr_size == UINT32_MAX) {
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
if (target)
|
2012-02-18 13:35:26 +08:00
|
|
|
addr_size = target->GetArchitecture().GetAddressByteSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2010-07-01 07:03:03 +08:00
|
|
|
addr_size = sizeof(addr_t);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-10 09:30:46 +08:00
|
|
|
Address so_addr;
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (style) {
|
|
|
|
case DumpStyleInvalid:
|
2015-09-22 14:36:56 +08:00
|
|
|
return false;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case DumpStyleSectionNameOffset:
|
|
|
|
if (section_sp) {
|
2020-05-13 17:13:19 +08:00
|
|
|
section_sp->DumpName(s->AsRawOstream());
|
2010-07-01 07:03:03 +08:00
|
|
|
s->Printf(" + %" PRIu64, m_offset);
|
|
|
|
} else {
|
2019-12-05 21:41:09 +08:00
|
|
|
DumpAddress(s->AsRawOstream(), m_offset, addr_size);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-07-01 07:03:03 +08:00
|
|
|
case DumpStyleSectionPointerOffset:
|
|
|
|
s->Printf("(Section *)%p + ", static_cast<void *>(section_sp.get()));
|
2019-12-05 21:41:09 +08:00
|
|
|
DumpAddress(s->AsRawOstream(), m_offset, addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-07-01 09:26:43 +08:00
|
|
|
case DumpStyleModuleWithFileAddress:
|
2010-06-09 00:52:24 +08:00
|
|
|
if (section_sp) {
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp = section_sp->GetModule();
|
2016-01-30 04:21:33 +08:00
|
|
|
if (module_sp)
|
|
|
|
s->Printf("%s[", module_sp->GetFileSpec().GetFilename().AsCString(
|
2012-02-24 09:59:29 +08:00
|
|
|
"<Unknown>"));
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2016-01-30 04:21:33 +08:00
|
|
|
s->Printf("%s[", "<Unknown>");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-16 12:14:33 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2010-06-09 00:52:24 +08:00
|
|
|
case DumpStyleFileAddress: {
|
|
|
|
addr_t file_addr = GetFileAddress();
|
|
|
|
if (file_addr == LLDB_INVALID_ADDRESS) {
|
2012-02-24 09:59:29 +08:00
|
|
|
if (fallback_style != DumpStyleInvalid)
|
2010-07-01 07:03:03 +08:00
|
|
|
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
2010-07-10 04:39:50 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2019-12-05 21:41:09 +08:00
|
|
|
DumpAddress(s->AsRawOstream(), file_addr, addr_size);
|
2012-02-24 09:59:29 +08:00
|
|
|
if (style == DumpStyleModuleWithFileAddress && section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
s->PutChar(']');
|
2016-09-07 04:57:50 +08:00
|
|
|
} break;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case DumpStyleLoadAddress: {
|
2010-09-15 07:36:40 +08:00
|
|
|
addr_t load_addr = GetLoadAddress(target);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MIPS:
|
2015-09-22 14:36:56 +08:00
|
|
|
* Display address in compressed form for MIPS16 or microMIPS
|
2018-06-26 21:06:54 +08:00
|
|
|
* if the address belongs to AddressClass::eCodeAlternateISA.
|
2016-09-07 04:57:50 +08:00
|
|
|
*/
|
2011-02-16 05:59:32 +08:00
|
|
|
if (target) {
|
|
|
|
const llvm::Triple::ArchType llvm_arch =
|
|
|
|
target->GetArchitecture().GetMachine();
|
2012-02-24 09:59:29 +08:00
|
|
|
if (llvm_arch == llvm::Triple::mips ||
|
|
|
|
llvm_arch == llvm::Triple::mipsel ||
|
|
|
|
llvm_arch == llvm::Triple::mips64 ||
|
2013-07-02 03:45:50 +08:00
|
|
|
llvm_arch == llvm::Triple::mips64el)
|
2010-10-08 08:21:05 +08:00
|
|
|
load_addr = GetCallableLoadAddress(target);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (load_addr == LLDB_INVALID_ADDRESS) {
|
|
|
|
if (fallback_style != DumpStyleInvalid)
|
2010-10-08 08:21:05 +08:00
|
|
|
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
2010-07-10 04:39:50 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2019-12-05 21:41:09 +08:00
|
|
|
DumpAddress(s->AsRawOstream(), load_addr, addr_size);
|
2010-10-08 08:21:05 +08:00
|
|
|
} break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-08 08:21:05 +08:00
|
|
|
case DumpStyleResolvedDescription:
|
|
|
|
case DumpStyleResolvedDescriptionNoModule:
|
|
|
|
case DumpStyleResolvedDescriptionNoFunctionArguments:
|
2015-02-14 07:24:21 +08:00
|
|
|
case DumpStyleNoFunctionName:
|
2010-10-08 08:21:05 +08:00
|
|
|
if (IsSectionOffset()) {
|
|
|
|
uint32_t pointer_size = 4;
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp(GetModule());
|
2015-09-22 14:36:56 +08:00
|
|
|
if (target)
|
2012-02-18 13:35:26 +08:00
|
|
|
pointer_size = target->GetArchitecture().GetAddressByteSize();
|
2016-01-30 04:21:33 +08:00
|
|
|
else if (module_sp)
|
2010-10-08 08:21:05 +08:00
|
|
|
pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-08 08:21:05 +08:00
|
|
|
bool showed_info = false;
|
|
|
|
if (section_sp) {
|
|
|
|
SectionType sect_type = section_sp->GetType();
|
|
|
|
switch (sect_type) {
|
|
|
|
case eSectionTypeData:
|
2016-01-30 04:21:33 +08:00
|
|
|
if (module_sp) {
|
2019-08-05 17:21:47 +08:00
|
|
|
if (Symtab *symtab = module_sp->GetSymtab()) {
|
|
|
|
const addr_t file_Addr = GetFileAddress();
|
|
|
|
Symbol *symbol =
|
|
|
|
symtab->FindSymbolContainingFileAddress(file_Addr);
|
|
|
|
if (symbol) {
|
|
|
|
const char *symbol_name = symbol->GetName().AsCString();
|
|
|
|
if (symbol_name) {
|
|
|
|
s->PutCString(symbol_name);
|
|
|
|
addr_t delta =
|
|
|
|
file_Addr - symbol->GetAddressRef().GetFileAddress();
|
|
|
|
if (delta)
|
|
|
|
s->Printf(" + %" PRIu64, delta);
|
|
|
|
showed_info = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eSectionTypeDataCString:
|
|
|
|
// Read the C string from memory and display it
|
2010-10-08 08:21:05 +08:00
|
|
|
showed_info = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
ReadCStringFromMemory(exe_scope, *this, s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSectionTypeDataCStringPointers:
|
2016-03-02 09:09:03 +08:00
|
|
|
if (ReadAddress(exe_scope, *this, pointer_size, so_addr)) {
|
2010-06-09 00:52:24 +08:00
|
|
|
#if VERBOSE_OUTPUT
|
2016-03-02 09:09:03 +08:00
|
|
|
s->PutCString("(char *)");
|
|
|
|
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
|
|
|
|
DumpStyleFileAddress);
|
|
|
|
s->PutCString(": ");
|
2010-06-09 00:52:24 +08:00
|
|
|
#endif
|
2016-03-02 09:09:03 +08:00
|
|
|
showed_info = true;
|
|
|
|
ReadCStringFromMemory(exe_scope, so_addr, s);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eSectionTypeDataObjCMessageRefs:
|
2016-03-02 09:09:03 +08:00
|
|
|
if (ReadAddress(exe_scope, *this, pointer_size, so_addr)) {
|
|
|
|
if (target && so_addr.IsSectionOffset()) {
|
|
|
|
SymbolContext func_sc;
|
|
|
|
target->GetImages().ResolveSymbolContextForAddress(
|
|
|
|
so_addr, eSymbolContextEverything, func_sc);
|
|
|
|
if (func_sc.function != nullptr || func_sc.symbol != nullptr) {
|
|
|
|
showed_info = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
#if VERBOSE_OUTPUT
|
2016-03-02 09:09:03 +08:00
|
|
|
s->PutCString("(objc_msgref *) -> { (func*)");
|
|
|
|
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
|
|
|
|
DumpStyleFileAddress);
|
2010-06-09 00:52:24 +08:00
|
|
|
#else
|
2016-03-02 09:09:03 +08:00
|
|
|
s->PutCString("{ ");
|
2010-06-09 00:52:24 +08:00
|
|
|
#endif
|
2016-03-02 09:09:03 +08:00
|
|
|
Address cstr_addr(*this);
|
|
|
|
cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
|
|
|
|
func_sc.DumpStopContext(s, exe_scope, so_addr, true, true,
|
|
|
|
false, true, true);
|
|
|
|
if (ReadAddress(exe_scope, cstr_addr, pointer_size, so_addr)) {
|
2010-06-09 00:52:24 +08:00
|
|
|
#if VERBOSE_OUTPUT
|
2016-03-02 09:09:03 +08:00
|
|
|
s->PutCString("), (char *)");
|
|
|
|
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
|
|
|
|
DumpStyleFileAddress);
|
|
|
|
s->PutCString(" (");
|
2010-06-09 00:52:24 +08:00
|
|
|
#else
|
2016-03-02 09:09:03 +08:00
|
|
|
s->PutCString(", ");
|
2010-06-09 00:52:24 +08:00
|
|
|
#endif
|
2016-03-02 09:09:03 +08:00
|
|
|
ReadCStringFromMemory(exe_scope, so_addr, s);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
#if VERBOSE_OUTPUT
|
2016-03-02 09:09:03 +08:00
|
|
|
s->PutCString(") }");
|
2010-06-09 00:52:24 +08:00
|
|
|
#else
|
2016-03-02 09:09:03 +08:00
|
|
|
s->PutCString(" }");
|
2010-06-09 00:52:24 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eSectionTypeDataObjCCFStrings: {
|
|
|
|
Address cfstring_data_addr(*this);
|
|
|
|
cfstring_data_addr.SetOffset(cfstring_data_addr.GetOffset() +
|
|
|
|
(2 * pointer_size));
|
|
|
|
if (ReadAddress(exe_scope, cfstring_data_addr, pointer_size,
|
|
|
|
so_addr)) {
|
|
|
|
#if VERBOSE_OUTPUT
|
|
|
|
s->PutCString("(CFString *) ");
|
|
|
|
cfstring_data_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
|
|
|
|
DumpStyleFileAddress);
|
|
|
|
s->PutCString(" -> @");
|
|
|
|
#else
|
|
|
|
s->PutChar('@');
|
|
|
|
#endif
|
|
|
|
if (so_addr.Dump(s, exe_scope, DumpStyleResolvedDescription))
|
|
|
|
showed_info = true;
|
|
|
|
}
|
|
|
|
} break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eSectionTypeData4:
|
|
|
|
// Read the 4 byte data and display it
|
|
|
|
showed_info = true;
|
|
|
|
s->PutCString("(uint32_t) ");
|
|
|
|
DumpUInt(exe_scope, *this, 4, s);
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eSectionTypeData8:
|
|
|
|
// Read the 8 byte data and display it
|
|
|
|
showed_info = true;
|
|
|
|
s->PutCString("(uint64_t) ");
|
|
|
|
DumpUInt(exe_scope, *this, 8, s);
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eSectionTypeData16:
|
|
|
|
// Read the 16 byte data and display it
|
|
|
|
showed_info = true;
|
|
|
|
s->PutCString("(uint128_t) ");
|
|
|
|
DumpUInt(exe_scope, *this, 16, s);
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eSectionTypeDataPointers:
|
|
|
|
// Read the pointer data and display it
|
2016-03-02 09:09:03 +08:00
|
|
|
if (ReadAddress(exe_scope, *this, pointer_size, so_addr)) {
|
|
|
|
s->PutCString("(void *)");
|
|
|
|
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
|
|
|
|
DumpStyleFileAddress);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-02 09:09:03 +08:00
|
|
|
showed_info = true;
|
|
|
|
if (so_addr.IsSectionOffset()) {
|
|
|
|
SymbolContext pointer_sc;
|
|
|
|
if (target) {
|
|
|
|
target->GetImages().ResolveSymbolContextForAddress(
|
|
|
|
so_addr, eSymbolContextEverything, pointer_sc);
|
|
|
|
if (pointer_sc.function != nullptr ||
|
|
|
|
pointer_sc.symbol != nullptr) {
|
|
|
|
s->PutCString(": ");
|
|
|
|
pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false,
|
|
|
|
false, true, true);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-08 05:56:53 +08:00
|
|
|
default:
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-07-01 07:03:03 +08:00
|
|
|
if (!showed_info) {
|
2012-02-24 09:59:29 +08:00
|
|
|
if (module_sp) {
|
2010-09-10 09:30:46 +08:00
|
|
|
SymbolContext sc;
|
2015-01-15 10:59:20 +08:00
|
|
|
module_sp->ResolveSymbolContextForAddress(
|
|
|
|
*this, eSymbolContextEverything, sc);
|
2015-06-26 05:46:34 +08:00
|
|
|
if (sc.function || sc.symbol) {
|
2016-03-02 09:09:03 +08:00
|
|
|
bool show_stop_context = true;
|
2010-09-15 07:36:40 +08:00
|
|
|
const bool show_module = (style == DumpStyleResolvedDescription);
|
2011-07-11 13:12:02 +08:00
|
|
|
const bool show_fullpaths = false;
|
2016-02-25 20:23:37 +08:00
|
|
|
const bool show_inlined_frames = true;
|
|
|
|
const bool show_function_arguments =
|
2011-07-11 13:12:02 +08:00
|
|
|
(style != DumpStyleResolvedDescriptionNoFunctionArguments);
|
2013-01-26 02:06:21 +08:00
|
|
|
const bool show_function_name = (style != DumpStyleNoFunctionName);
|
2011-07-11 13:12:02 +08:00
|
|
|
if (sc.function == nullptr && sc.symbol != nullptr) {
|
|
|
|
// If we have just a symbol make sure it is in the right section
|
|
|
|
if (sc.symbol->ValueIsAddress()) {
|
2015-04-28 20:45:57 +08:00
|
|
|
if (sc.symbol->GetAddressRef().GetSection() != GetSection()) {
|
|
|
|
// don't show the module if the symbol is a trampoline symbol
|
2011-07-11 13:12:02 +08:00
|
|
|
show_stop_context = false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-07-01 07:03:03 +08:00
|
|
|
}
|
2011-07-11 13:12:02 +08:00
|
|
|
if (show_stop_context) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// We have a function or a symbol from the same sections as this
|
|
|
|
// address.
|
2011-07-11 13:12:02 +08:00
|
|
|
sc.DumpStopContext(s, exe_scope, *this, show_fullpaths,
|
2012-07-12 06:18:24 +08:00
|
|
|
show_module, show_inlined_frames,
|
|
|
|
show_function_arguments, show_function_name);
|
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// We found a symbol but it was in a different section so it
|
|
|
|
// isn't the symbol we should be showing, just show the section
|
|
|
|
// name + offset
|
2012-07-12 06:18:24 +08:00
|
|
|
Dump(s, exe_scope, DumpStyleSectionNameOffset);
|
|
|
|
}
|
2013-11-06 10:29:13 +08:00
|
|
|
}
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2011-12-11 05:05:26 +08:00
|
|
|
if (fallback_style != DumpStyleInvalid)
|
2012-02-24 09:59:29 +08:00
|
|
|
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-08-13 05:40:01 +08:00
|
|
|
case DumpStyleDetailedSymbolContext:
|
2011-12-11 05:05:26 +08:00
|
|
|
if (IsSectionOffset()) {
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp(GetModule());
|
|
|
|
if (module_sp) {
|
2011-08-13 05:40:01 +08:00
|
|
|
SymbolContext sc;
|
|
|
|
module_sp->ResolveSymbolContextForAddress(
|
|
|
|
*this, eSymbolContextEverything | eSymbolContextVariable, sc);
|
|
|
|
if (sc.symbol) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// If we have just a symbol make sure it is in the same section as
|
|
|
|
// our address. If it isn't, then we might have just found the last
|
|
|
|
// symbol that came before the address that we are looking up that
|
|
|
|
// has nothing to do with our address lookup.
|
2012-03-08 05:03:09 +08:00
|
|
|
if (sc.symbol->ValueIsAddress() &&
|
2011-08-13 05:40:01 +08:00
|
|
|
sc.symbol->GetAddressRef().GetSection() != GetSection())
|
|
|
|
sc.symbol = nullptr;
|
|
|
|
}
|
2012-02-24 09:59:29 +08:00
|
|
|
sc.GetDescription(s, eDescriptionLevelBrief, target);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
if (sc.block) {
|
2011-08-13 05:40:01 +08:00
|
|
|
bool can_create = true;
|
2012-02-24 09:59:29 +08:00
|
|
|
bool get_parent_variables = true;
|
|
|
|
bool stop_if_block_is_inlined_function = false;
|
|
|
|
VariableList variable_list;
|
2011-08-13 05:40:01 +08:00
|
|
|
sc.block->AppendVariables(can_create, get_parent_variables,
|
2011-07-11 13:12:02 +08:00
|
|
|
stop_if_block_is_inlined_function,
|
2016-02-25 20:23:37 +08:00
|
|
|
[](Variable *) { return true; },
|
2011-07-11 13:12:02 +08:00
|
|
|
&variable_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-11-25 22:03:46 +08:00
|
|
|
for (const VariableSP &var_sp : variable_list) {
|
|
|
|
if (var_sp && var_sp->LocationIsValidForAddress(*this)) {
|
2011-08-13 05:40:01 +08:00
|
|
|
s->Indent();
|
2016-03-02 09:09:03 +08:00
|
|
|
s->Printf(" Variable: id = {0x%8.8" PRIx64 "}, name = \"%s\"",
|
2019-11-25 22:03:46 +08:00
|
|
|
var_sp->GetID(), var_sp->GetName().GetCString());
|
|
|
|
Type *type = var_sp->GetType();
|
2012-02-24 09:59:29 +08:00
|
|
|
if (type)
|
|
|
|
s->Printf(", type = \"%s\"", type->GetName().GetCString());
|
|
|
|
else
|
2015-04-28 20:45:57 +08:00
|
|
|
s->PutCString(", type = <unknown>");
|
2012-02-24 09:59:29 +08:00
|
|
|
s->PutCString(", location = ");
|
2019-11-25 22:03:46 +08:00
|
|
|
var_sp->DumpLocationForAddress(s, *this);
|
2011-08-13 05:40:01 +08:00
|
|
|
s->PutCString(", decl = ");
|
2019-11-25 22:03:46 +08:00
|
|
|
var_sp->GetDeclaration().DumpStopContext(s, false);
|
2011-08-13 05:40:01 +08:00
|
|
|
s->EOL();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2016-03-02 09:09:03 +08:00
|
|
|
if (fallback_style != DumpStyleInvalid)
|
2010-07-01 07:03:03 +08:00
|
|
|
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
2016-03-02 09:09:03 +08:00
|
|
|
return false;
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-12-11 05:05:26 +08:00
|
|
|
case DumpStyleResolvedPointerDescription: {
|
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
2012-07-12 06:18:24 +08:00
|
|
|
if (process) {
|
2011-12-11 05:05:26 +08:00
|
|
|
addr_t load_addr = GetLoadAddress(target);
|
|
|
|
if (load_addr != LLDB_INVALID_ADDRESS) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status memory_error;
|
2012-02-24 09:59:29 +08:00
|
|
|
addr_t dereferenced_load_addr =
|
2011-08-13 05:40:01 +08:00
|
|
|
process->ReadPointerFromMemory(load_addr, memory_error);
|
|
|
|
if (dereferenced_load_addr != LLDB_INVALID_ADDRESS) {
|
|
|
|
Address dereferenced_addr;
|
|
|
|
if (dereferenced_addr.SetLoadAddress(dereferenced_load_addr,
|
2016-09-07 04:57:50 +08:00
|
|
|
target)) {
|
2011-08-13 05:40:01 +08:00
|
|
|
StreamString strm;
|
|
|
|
if (dereferenced_addr.Dump(&strm, exe_scope,
|
|
|
|
DumpStyleResolvedDescription,
|
2010-07-01 07:03:03 +08:00
|
|
|
DumpStyleInvalid, addr_size)) {
|
2019-12-05 21:41:09 +08:00
|
|
|
DumpAddress(s->AsRawOstream(), dereferenced_load_addr, addr_size,
|
|
|
|
" -> ", " ");
|
2016-11-17 05:15:24 +08:00
|
|
|
s->Write(strm.GetString().data(), strm.GetSize());
|
2011-08-13 05:40:01 +08:00
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
if (fallback_style != DumpStyleInvalid)
|
2011-08-13 05:40:01 +08:00
|
|
|
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
} break;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Address::SectionWasDeleted() const {
|
2018-09-11 07:09:09 +08:00
|
|
|
if (GetSection())
|
|
|
|
return false;
|
|
|
|
return SectionWasDeletedPrivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Address::SectionWasDeletedPrivate() const {
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb::SectionWP empty_section_wp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// If either call to "std::weak_ptr::owner_before(...) value returns true,
|
2018-05-01 00:49:04 +08:00
|
|
|
// this indicates that m_section_wp once contained (possibly still does) a
|
|
|
|
// reference to a valid shared pointer. This helps us know if we had a valid
|
|
|
|
// reference to a section which is now invalid because the module it was in
|
|
|
|
// was unloaded/deleted, or if the address doesn't have a valid reference to
|
|
|
|
// a section.
|
2013-11-06 10:29:13 +08:00
|
|
|
return empty_section_wp.owner_before(m_section_wp) ||
|
|
|
|
m_section_wp.owner_before(empty_section_wp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2018-10-26 04:45:19 +08:00
|
|
|
uint32_t
|
|
|
|
Address::CalculateSymbolContext(SymbolContext *sc,
|
|
|
|
SymbolContextItem resolve_scope) const {
|
2013-02-23 12:12:47 +08:00
|
|
|
sc->Clear(false);
|
2010-06-09 00:52:24 +08:00
|
|
|
// Absolute addresses don't have enough information to reconstruct even their
|
|
|
|
// target.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp(GetSection());
|
|
|
|
if (section_sp) {
|
|
|
|
ModuleSP module_sp(section_sp->GetModule());
|
|
|
|
if (module_sp) {
|
|
|
|
sc->module_sp = module_sp;
|
2011-08-13 05:40:01 +08:00
|
|
|
if (sc->module_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
return sc->module_sp->ResolveSymbolContextForAddress(
|
2011-08-13 05:40:01 +08:00
|
|
|
*this, resolve_scope, *sc);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2011-08-13 05:40:01 +08:00
|
|
|
return 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-12-11 05:05:26 +08:00
|
|
|
ModuleSP Address::CalculateSymbolContextModule() const {
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp(GetSection());
|
|
|
|
if (section_sp)
|
|
|
|
return section_sp->GetModule();
|
2011-08-13 05:40:01 +08:00
|
|
|
return ModuleSP();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
CompileUnit *Address::CalculateSymbolContextCompileUnit() const {
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp(GetSection());
|
|
|
|
if (section_sp) {
|
2011-08-13 05:40:01 +08:00
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
sc.module_sp = section_sp->GetModule();
|
|
|
|
if (sc.module_sp) {
|
|
|
|
sc.module_sp->ResolveSymbolContextForAddress(*this,
|
2011-08-13 05:40:01 +08:00
|
|
|
eSymbolContextCompUnit, sc);
|
|
|
|
return sc.comp_unit;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2016-03-02 09:09:03 +08:00
|
|
|
return nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
Function *Address::CalculateSymbolContextFunction() const {
|
|
|
|
SectionSP section_sp(GetSection());
|
|
|
|
if (section_sp) {
|
2011-08-13 05:40:01 +08:00
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
sc.module_sp = section_sp->GetModule();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (sc.module_sp) {
|
|
|
|
sc.module_sp->ResolveSymbolContextForAddress(*this,
|
2016-06-22 04:00:36 +08:00
|
|
|
eSymbolContextFunction, sc);
|
2010-06-09 00:52:24 +08:00
|
|
|
return sc.function;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2016-03-02 09:09:03 +08:00
|
|
|
return nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Block *Address::CalculateSymbolContextBlock() const {
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp(GetSection());
|
|
|
|
if (section_sp) {
|
2011-08-13 05:40:01 +08:00
|
|
|
SymbolContext sc;
|
2010-06-09 00:52:24 +08:00
|
|
|
sc.module_sp = section_sp->GetModule();
|
2011-08-13 05:40:01 +08:00
|
|
|
if (sc.module_sp) {
|
2016-06-22 04:00:36 +08:00
|
|
|
sc.module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextBlock,
|
2016-09-07 04:57:50 +08:00
|
|
|
sc);
|
2011-08-13 05:40:01 +08:00
|
|
|
return sc.block;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2016-03-02 09:09:03 +08:00
|
|
|
return nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-12-11 05:05:26 +08:00
|
|
|
Symbol *Address::CalculateSymbolContextSymbol() const {
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp(GetSection());
|
|
|
|
if (section_sp) {
|
2011-08-13 05:40:01 +08:00
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
sc.module_sp = section_sp->GetModule();
|
2011-08-13 05:40:01 +08:00
|
|
|
if (sc.module_sp) {
|
2016-06-22 04:00:36 +08:00
|
|
|
sc.module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextSymbol,
|
2016-09-07 04:57:50 +08:00
|
|
|
sc);
|
2011-08-13 05:40:01 +08:00
|
|
|
return sc.symbol;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2016-03-02 09:09:03 +08:00
|
|
|
return nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-12-11 05:05:26 +08:00
|
|
|
bool Address::CalculateSymbolContextLineEntry(LineEntry &line_entry) const {
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp(GetSection());
|
|
|
|
if (section_sp) {
|
2011-08-13 05:40:01 +08:00
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
sc.module_sp = section_sp->GetModule();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (sc.module_sp) {
|
2016-06-22 04:00:36 +08:00
|
|
|
sc.module_sp->ResolveSymbolContextForAddress(*this,
|
|
|
|
eSymbolContextLineEntry, sc);
|
2011-08-13 05:40:01 +08:00
|
|
|
if (sc.line_entry.IsValid()) {
|
|
|
|
line_entry = sc.line_entry;
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
line_entry.Clear();
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
int Address::CompareFileAddress(const Address &a, const Address &b) {
|
|
|
|
addr_t a_file_addr = a.GetFileAddress();
|
|
|
|
addr_t b_file_addr = b.GetFileAddress();
|
|
|
|
if (a_file_addr < b_file_addr)
|
|
|
|
return -1;
|
|
|
|
if (a_file_addr > b_file_addr)
|
|
|
|
return +1;
|
2011-08-13 05:40:01 +08:00
|
|
|
return 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
int Address::CompareLoadAddress(const Address &a, const Address &b,
|
|
|
|
Target *target) {
|
2016-03-02 09:09:03 +08:00
|
|
|
assert(target != nullptr);
|
2010-09-15 07:36:40 +08:00
|
|
|
addr_t a_load_addr = a.GetLoadAddress(target);
|
|
|
|
addr_t b_load_addr = b.GetLoadAddress(target);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (a_load_addr < b_load_addr)
|
|
|
|
return -1;
|
|
|
|
if (a_load_addr > b_load_addr)
|
|
|
|
return +1;
|
2011-08-13 05:40:01 +08:00
|
|
|
return 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
int Address::CompareModulePointerAndOffset(const Address &a, const Address &b) {
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP a_module_sp(a.GetModule());
|
|
|
|
ModuleSP b_module_sp(b.GetModule());
|
|
|
|
Module *a_module = a_module_sp.get();
|
|
|
|
Module *b_module = b_module_sp.get();
|
2011-01-08 08:05:12 +08:00
|
|
|
if (a_module < b_module)
|
2010-06-09 00:52:24 +08:00
|
|
|
return -1;
|
2011-01-08 08:05:12 +08:00
|
|
|
if (a_module > b_module)
|
2010-06-09 00:52:24 +08:00
|
|
|
return +1;
|
2018-05-01 00:49:04 +08:00
|
|
|
// Modules are the same, just compare the file address since they should be
|
|
|
|
// unique
|
2010-06-09 00:52:24 +08:00
|
|
|
addr_t a_file_addr = a.GetFileAddress();
|
|
|
|
addr_t b_file_addr = b.GetFileAddress();
|
|
|
|
if (a_file_addr < b_file_addr)
|
|
|
|
return -1;
|
|
|
|
if (a_file_addr > b_file_addr)
|
|
|
|
return +1;
|
|
|
|
return 0;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Address::MemorySize() const {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Noting special for the memory size of a single Address object, it is just
|
|
|
|
// the size of itself.
|
2010-06-09 00:52:24 +08:00
|
|
|
return sizeof(Address);
|
|
|
|
}
|
|
|
|
|
2011-01-08 08:05:12 +08:00
|
|
|
// NOTE: Be careful using this operator. It can correctly compare two
|
2018-05-01 00:49:04 +08:00
|
|
|
// addresses from the same Module correctly. It can't compare two addresses
|
|
|
|
// from different modules in any meaningful way, but it will compare the module
|
|
|
|
// pointers.
|
2011-01-08 08:05:12 +08:00
|
|
|
//
|
|
|
|
// To sum things up:
|
2018-05-01 00:49:04 +08:00
|
|
|
// - works great for addresses within the same module - it works for addresses
|
|
|
|
// across multiple modules, but don't expect the
|
2011-01-08 08:05:12 +08:00
|
|
|
// address results to make much sense
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2018-05-01 00:49:04 +08:00
|
|
|
// This basically lets Address objects be used in ordered collection classes.
|
2011-01-08 08:05:12 +08:00
|
|
|
|
|
|
|
bool lldb_private::operator<(const Address &lhs, const Address &rhs) {
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP lhs_module_sp(lhs.GetModule());
|
|
|
|
ModuleSP rhs_module_sp(rhs.GetModule());
|
|
|
|
Module *lhs_module = lhs_module_sp.get();
|
|
|
|
Module *rhs_module = rhs_module_sp.get();
|
2011-01-08 08:05:12 +08:00
|
|
|
if (lhs_module == rhs_module) {
|
|
|
|
// Addresses are in the same module, just compare the file addresses
|
|
|
|
return lhs.GetFileAddress() < rhs.GetFileAddress();
|
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// The addresses are from different modules, just use the module pointer
|
|
|
|
// value to get consistent ordering
|
2011-01-08 08:05:12 +08:00
|
|
|
return lhs_module < rhs_module;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-01-08 08:05:12 +08:00
|
|
|
bool lldb_private::operator>(const Address &lhs, const Address &rhs) {
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP lhs_module_sp(lhs.GetModule());
|
|
|
|
ModuleSP rhs_module_sp(rhs.GetModule());
|
|
|
|
Module *lhs_module = lhs_module_sp.get();
|
|
|
|
Module *rhs_module = rhs_module_sp.get();
|
2011-01-08 08:05:12 +08:00
|
|
|
if (lhs_module == rhs_module) {
|
|
|
|
// Addresses are in the same module, just compare the file addresses
|
|
|
|
return lhs.GetFileAddress() > rhs.GetFileAddress();
|
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// The addresses are from different modules, just use the module pointer
|
|
|
|
// value to get consistent ordering
|
2011-01-08 08:05:12 +08:00
|
|
|
return lhs_module > rhs_module;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// The operator == checks for exact equality only (same section, same offset)
|
|
|
|
bool lldb_private::operator==(const Address &a, const Address &rhs) {
|
2013-06-07 06:16:56 +08:00
|
|
|
return a.GetOffset() == rhs.GetOffset() && a.GetSection() == rhs.GetSection();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-03-02 09:09:03 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// The operator != checks for exact inequality only (differing section, or
|
|
|
|
// different offset)
|
|
|
|
bool lldb_private::operator!=(const Address &a, const Address &rhs) {
|
2013-06-07 06:16:56 +08:00
|
|
|
return a.GetOffset() != rhs.GetOffset() || a.GetSection() != rhs.GetSection();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-03-19 09:12:21 +08:00
|
|
|
AddressClass Address::GetAddressClass() const {
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp(GetModule());
|
|
|
|
if (module_sp) {
|
|
|
|
ObjectFile *obj_file = module_sp->GetObjectFile();
|
2011-03-19 09:12:21 +08:00
|
|
|
if (obj_file) {
|
2019-08-05 17:21:47 +08:00
|
|
|
// Give the symbol file a chance to add to the unified section list
|
|
|
|
// and to the symtab.
|
|
|
|
module_sp->GetSymtab();
|
2011-03-19 09:12:21 +08:00
|
|
|
return obj_file->GetAddressClass(GetFileAddress());
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2018-06-26 21:06:54 +08:00
|
|
|
return AddressClass::eUnknown;
|
2011-03-19 09:12:21 +08:00
|
|
|
}
|
2011-05-18 09:58:14 +08:00
|
|
|
|
2017-06-08 21:26:35 +08:00
|
|
|
bool Address::SetLoadAddress(lldb::addr_t load_addr, Target *target,
|
|
|
|
bool allow_section_end) {
|
|
|
|
if (target && target->GetSectionLoadList().ResolveLoadAddress(
|
|
|
|
load_addr, *this, allow_section_end))
|
2011-05-18 09:58:14 +08:00
|
|
|
return true;
|
2012-02-24 09:59:29 +08:00
|
|
|
m_section_wp.reset();
|
2011-05-18 09:58:14 +08:00
|
|
|
m_offset = load_addr;
|
|
|
|
return false;
|
|
|
|
}
|