41#include "llvm/ADT/StringRef.h"
42#include "llvm/Support/Compiler.h"
43#include "llvm/TargetParser/Triple.h"
64 const Address &address,
void *dst,
size_t dst_len) {
65 if (exe_scope ==
nullptr)
71 bool force_live_memory =
true;
72 return target_sp->ReadMemory(address, dst, dst_len,
error,
81 uint32_t &addr_size) {
84 if (exe_scope ==
nullptr)
89 byte_order = target_sp->GetArchitecture().GetByteOrder();
90 addr_size = target_sp->GetArchitecture().GetAddressByteSize();
96 byte_order = module_sp->GetArchitecture().GetByteOrder();
97 addr_size = module_sp->GetArchitecture().GetAddressByteSize();
104 const Address &address, uint32_t byte_size,
107 if (exe_scope ==
nullptr || byte_size >
sizeof(uint64_t)) {
113 success =
ReadBytes(exe_scope, address, &buf, byte_size) == byte_size;
116 uint32_t addr_size = 0;
118 DataExtractor data(&buf,
sizeof(buf), byte_order, addr_size);
120 uval64 = data.
GetU64(&offset);
128 const Address &address, uint32_t pointer_size,
130 if (exe_scope ==
nullptr)
133 bool success =
false;
150 if (module_sp->ResolveFileAddress(deref_addr, deref_so_addr))
164 uint32_t byte_size,
Stream *strm) {
165 if (exe_scope ==
nullptr || byte_size == 0)
167 std::vector<uint8_t> buf(byte_size, 0);
169 if (
ReadBytes(exe_scope, address, &buf[0], buf.size()) == buf.size()) {
171 uint32_t addr_size = 0;
173 DataExtractor data(&buf.front(), buf.size(), byte_order, addr_size);
193 if (exe_scope ==
nullptr)
195 const size_t k_buf_len = 256;
196 char buf[k_buf_len + 1];
197 buf[k_buf_len] =
'\0';
201 size_t total_len = 0;
205 while ((bytes_read =
ReadBytes(exe_scope, curr_address, buf, k_buf_len)) >
207 size_t len = strlen(buf);
210 if (len > bytes_read)
224 total_len += bytes_read;
256 assert(section_sp->ContainsFileAddress(file_addr));
257 m_offset = file_addr - section_sp->GetFileAddress();
269 constexpr SymbolContextItem resolve_scope =
270 eSymbolContextFunction | eSymbolContextSymbol;
274 addr_range_ptr->
Clear();
281 return sym_ctx.
GetAddressRange(resolve_scope, 0,
false, *addr_range_ptr);
288 module_sp = section_sp->GetModule();
295 addr_t sect_file_addr = section_sp->GetFileAddress();
316 addr_t sect_load_addr = section_sp->GetLoadBaseAddress(target);
340 if (is_indirect && target) {
344 code_addr = processSP->ResolveIndirectFunction(
this,
error);
345 if (!
error.Success())
382 bool allow_section_end) {
397 "Non-brief descriptions not implemented");
408 DumpStyle fallback_style, uint32_t addr_size,
410 std::optional<Stream::HighlightSettings> settings)
const {
425 addr_size =
sizeof(
addr_t);
443 s->
Printf(
"(Section *)%p + ",
static_cast<void *
>(section_sp.get()));
449 ModuleSP module_sp = section_sp->GetModule();
451 s->
Printf(
"%s[", module_sp->GetFileSpec().GetFilename().AsCString(
454 s->
Printf(
"%s[",
"<Unknown>");
478 const llvm::Triple::ArchType llvm_arch =
480 if (llvm_arch == llvm::Triple::mips ||
481 llvm_arch == llvm::Triple::mipsel ||
482 llvm_arch == llvm::Triple::mips64 ||
483 llvm_arch == llvm::Triple::mips64el)
500 uint32_t pointer_size = 4;
505 pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
506 bool showed_info =
false;
512 if (
Symtab *symtab = module_sp->GetSymtab()) {
515 symtab->FindSymbolContainingFileAddress(file_Addr);
523 s->
Printf(
" + %" PRIu64, delta);
538 if (
ReadAddress(exe_scope, *
this, pointer_size, so_addr)) {
551 if (
ReadAddress(exe_scope, *
this, pointer_size, so_addr)) {
555 so_addr, eSymbolContextEverything, func_sc);
559 s->
PutCString(
"(objc_msgref *) -> { (func*)");
569 if (
ReadAddress(exe_scope, cstr_addr, pointer_size, so_addr)) {
591 Address cfstring_data_addr(*
this);
594 if (
ReadAddress(exe_scope, cfstring_data_addr, pointer_size,
632 if (
ReadAddress(exe_scope, *
this, pointer_size, so_addr)) {
642 so_addr, eSymbolContextEverything, pointer_sc);
643 if (pointer_sc.
function !=
nullptr ||
644 pointer_sc.
symbol !=
nullptr) {
647 false,
true,
true,
false,
663 module_sp->ResolveSymbolContextForAddress(
664 *
this, eSymbolContextEverything, sc);
666 bool show_stop_context =
true;
668 const bool show_fullpaths =
false;
669 const bool show_inlined_frames =
true;
670 const bool show_function_arguments =
678 show_stop_context =
false;
682 if (show_stop_context) {
686 show_module, show_inlined_frames,
687 show_function_arguments, show_function_name,
712 module_sp->ResolveSymbolContextForAddress(
713 *
this, eSymbolContextEverything | eSymbolContextVariable, sc);
726 bool can_create =
true;
727 bool get_parent_variables =
true;
728 bool stop_if_block_is_inlined_function =
false;
732 can_create, get_parent_variables,
733 stop_if_block_is_inlined_function,
740 for (
const VariableSP &var_sp : variable_list) {
742 s->
Printf(
" Variable: id = {0x%8.8" PRIx64
"}, name = \"%s\"",
743 var_sp->GetID(), var_sp->GetName().GetCString());
744 Type *type = var_sp->GetType();
750 if (var_sp->GetScopeRange().IsEmpty())
752 else if (all_ranges) {
753 for (
auto range : var_sp->GetScopeRange())
755 range.GetRangeEnd(), addr_size);
756 }
else if (
auto *range =
757 var_sp->GetScopeRange().FindEntryThatContains(
760 range->GetRangeEnd(), addr_size);
764 var_sp->GetDeclaration().DumpStopContext(s,
false);
783 addr_t dereferenced_load_addr =
790 if (dereferenced_addr.
Dump(&strm, exe_scope,
832 SymbolContextItem resolve_scope)
const {
839 ModuleSP module_sp(section_sp->GetModule());
843 return sc->
module_sp->ResolveSymbolContextForAddress(
844 *
this, resolve_scope, *sc);
853 return section_sp->GetModule();
863 sc.
module_sp->ResolveSymbolContextForAddress(*
this,
864 eSymbolContextCompUnit, sc);
877 sc.
module_sp->ResolveSymbolContextForAddress(*
this,
878 eSymbolContextFunction, sc);
891 sc.
module_sp->ResolveSymbolContextForAddress(*
this, eSymbolContextBlock,
905 sc.
module_sp->ResolveSymbolContextForAddress(*
this, eSymbolContextSymbol,
919 sc.
module_sp->ResolveSymbolContextForAddress(*
this,
920 eSymbolContextLineEntry, sc);
934 if (a_file_addr < b_file_addr)
936 if (a_file_addr > b_file_addr)
943 assert(target !=
nullptr);
946 if (a_load_addr < b_load_addr)
948 if (a_load_addr > b_load_addr)
956 Module *a_module = a_module_sp.get();
957 Module *b_module = b_module_sp.get();
958 if (a_module < b_module)
960 if (a_module > b_module)
966 if (a_file_addr < b_file_addr)
968 if (a_file_addr > b_file_addr)
994 Module *lhs_module = lhs_module_sp.get();
995 Module *rhs_module = rhs_module_sp.get();
996 if (lhs_module == rhs_module) {
1002 return lhs_module < rhs_module;
1009 Module *lhs_module = lhs_module_sp.get();
1010 Module *rhs_module = rhs_module_sp.get();
1011 if (lhs_module == rhs_module) {
1017 return lhs_module > rhs_module;
1035 ObjectFile *obj_file = module_sp->GetObjectFile();
1047 bool allow_section_end) {
static bool DumpUInt(ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, Stream *strm)
static size_t ReadCStringFromMemory(ExecutionContextScope *exe_scope, const Address &address, Stream *strm)
static size_t ReadBytes(ExecutionContextScope *exe_scope, const Address &address, void *dst, size_t dst_len)
static bool ReadAddress(ExecutionContextScope *exe_scope, const Address &address, uint32_t pointer_size, Address &deref_so_addr)
static uint64_t ReadUIntMax64(ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, bool &success)
static bool GetByteOrderAndAddressSize(ExecutionContextScope *exe_scope, const Address &address, ByteOrder &byte_order, uint32_t &addr_size)
static llvm::raw_ostream & error(Stream &strm)
static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch)
A section + offset based address range class.
void Clear()
Clear the object's state.
A section + offset based address class.
static int CompareFileAddress(const Address &lhs, const Address &rhs)
Compare two Address objects.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
lldb::SectionWP m_section_wp
The section for the address, can be NULL.
bool ResolveAddressUsingFileSections(lldb::addr_t addr, const SectionList *sections)
Resolve a file virtual address using a section list.
lldb::addr_t GetCallableLoadAddress(Target *target, bool is_indirect=false) const
Get the load address as a callable code load address.
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
lldb::SectionSP GetSection() const
Get const accessor for the section.
bool SectionWasDeleted() const
static int CompareLoadAddress(const Address &lhs, const Address &rhs, Target *target)
uint32_t CalculateSymbolContext(SymbolContext *sc, lldb::SymbolContextItem resolve_scope=lldb::eSymbolContextEverything) const
Reconstruct a symbol context from an address.
const Address & operator=(const Address &rhs)
Assignment operator.
lldb::addr_t GetOpcodeLoadAddress(Target *target, AddressClass addr_class=AddressClass::eInvalid) const
Get the load address as an opcode load address.
lldb::addr_t m_offset
Offset into section if m_section_wp is valid...
bool SetOpcodeLoadAddress(lldb::addr_t load_addr, Target *target, AddressClass addr_class=AddressClass::eInvalid, bool allow_section_end=false)
bool ResolveFunctionScope(lldb_private::SymbolContext &sym_ctx, lldb_private::AddressRange *addr_range_ptr=nullptr)
Resolve this address to its containing function and optionally get that function's address range.
Function * CalculateSymbolContextFunction() const
static int CompareModulePointerAndOffset(const Address &lhs, const Address &rhs)
bool SectionWasDeletedPrivate() const
size_t MemorySize() const
Get the memory cost of this object.
void SetRawAddress(lldb::addr_t addr)
DumpStyle
Dump styles allow the Address::Dump(Stream *,DumpStyle) const function to display Address contents in...
@ DumpStyleFileAddress
Display as the file address (if any).
@ DumpStyleSectionNameOffset
Display as the section name + offset.
@ DumpStyleNoFunctionName
Elide the function name; display an offset into the current function.
@ DumpStyleResolvedDescriptionNoFunctionArguments
@ DumpStyleDetailedSymbolContext
Detailed symbol context information for an address for all symbol context members.
@ DumpStyleInvalid
Invalid dump style.
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
@ DumpStyleSectionPointerOffset
Display as the section pointer + offset (debug output).
@ DumpStyleResolvedDescription
Display the details about what an address resolves to.
@ DumpStyleLoadAddress
Display as the load address (if resolved).
@ DumpStyleResolvedDescriptionNoModule
@ DumpStyleResolvedPointerDescription
Dereference a pointer at the current address and then lookup the dereferenced address using DumpStyle...
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX, bool all_ranges=false, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Dump a description of this object to a Stream.
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
lldb::addr_t GetFileAddress() const
Get the file address.
lldb::addr_t GetOffset() const
Get the section relative offset value.
bool GetDescription(Stream &s, Target &target, lldb::DescriptionLevel level) const
Write a description of this object to a Stream.
bool IsSectionOffset() const
Check if an address is section offset.
bool CalculateSymbolContextLineEntry(LineEntry &line_entry) const
CompileUnit * CalculateSymbolContextCompileUnit() const
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
Address()=default
Default constructor.
Block * CalculateSymbolContextBlock() const
bool SetCallableLoadAddress(lldb::addr_t load_addr, Target *target)
AddressClass GetAddressClass() const
Symbol * CalculateSymbolContextSymbol() const
lldb::ModuleSP CalculateSymbolContextModule() const
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
A class that describes a single lexical block.
uint32_t AppendVariables(bool can_create, bool get_parent_variables, bool stop_if_block_is_inlined_function, const std::function< bool(Variable *)> &filter, VariableList *variable_list)
Appends the variables from this block, and optionally from all parent blocks, to variable_list.
A class that describes a compilation unit.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual void CalculateExecutionContext(ExecutionContext &exe_ctx)=0
Reconstruct the object's execution context into sc.
virtual lldb::TargetSP CalculateTarget()=0
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
const ConstString & GetFilename() const
Filename string const get accessor.
A class that describes a function.
uint32_t ResolveSymbolContextForAddress(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) const
Resolve the symbol context for the given address. (const Address&,uint32_t,SymbolContext&)
A class that describes an executable image and its associated object and symbol files.
A plug-in interface definition class for object file parsers.
Symtab * GetSymtab()
Gets the symbol table for the currently selected architecture (and object for archives).
virtual AddressClass GetAddressClass(lldb::addr_t file_addr)
Get the address type given a file address in an object file.
A plug-in interface definition class for debugging a process.
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
lldb::SectionSP FindSectionContainingFileAddress(lldb::addr_t addr, uint32_t depth=UINT32_MAX) const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
void PutCStringColorHighlighted(llvm::StringRef text, std::optional< HighlightSettings > settings=std::nullopt)
Output a C string to the stream with color highlighting.
size_t EOL()
Output and End of Line character to the stream.
Defines a symbol context baton that can be handed other debug core functions.
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Function * function
The Function for a given query.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, const Address &so_addr, bool show_fullpaths, bool show_module, bool show_inlined_frames, bool show_function_arguments, bool show_function_name, bool show_function_display_name=false, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Dump the stop context in this object to a Stream.
void Clear(bool clear_target)
Clear the object's state.
bool GetAddressRange(uint32_t scope, uint32_t range_idx, bool use_inline_block_range, AddressRange &range) const
Get the address range contained within a symbol context.
Symbol * symbol
The Symbol for a given query.
LineEntry line_entry
The LineEntry for a given query.
bool ValueIsAddress() const
Address & GetAddressRef()
ConstString GetName() const
lldb::addr_t GetCallableLoadAddress(lldb::addr_t load_addr, AddressClass addr_class=AddressClass::eInvalid) const
Get load_addr as a callable code load address for this target.
lldb::addr_t GetOpcodeLoadAddress(lldb::addr_t load_addr, AddressClass addr_class=AddressClass::eInvalid) const
Get load_addr as an opcode for this target.
const lldb::ProcessSP & GetProcessSP() const
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
bool LocationIsValidForAddress(const Address &address)
#define LLDB_INVALID_ADDRESS
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
void DumpAddressRange(llvm::raw_ostream &s, uint64_t lo_addr, uint64_t hi_addr, uint32_t addr_size, const char *prefix=nullptr, const char *suffix=nullptr)
Output an address range to this stream.
bool operator!=(const Address &lhs, const Address &rhs)
bool operator>(const Address &lhs, const Address &rhs)
void DumpAddress(llvm::raw_ostream &s, uint64_t addr, uint32_t addr_size, const char *prefix=nullptr, const char *suffix=nullptr)
Output an address value to this stream.
lldb::offset_t DumpDataExtractor(const DataExtractor &DE, Stream *s, lldb::offset_t offset, lldb::Format item_format, size_t item_byte_size, size_t item_count, size_t num_per_line, uint64_t base_addr, uint32_t item_bit_size, uint32_t item_bit_offset, ExecutionContextScope *exe_scope=nullptr, bool show_memory_tags=false)
Dumps item_count objects into the stream s.
bool operator==(const Address &lhs, const Address &rhs)
bool operator<(const Address &lhs, const Address &rhs)
std::shared_ptr< lldb_private::ABI > ABISP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::shared_ptr< lldb_private::Process > ProcessSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::Target > TargetSP
@ eSectionTypeDataObjCCFStrings
Objective-C const CFString/NSString objects.
@ eSectionTypeDataObjCMessageRefs
Pointer to function pointer + selector.
@ eSectionTypeDataCStringPointers
Pointers to C string data.
@ eSectionTypeDataPointers
@ eSectionTypeDataCString
Inlined C string data.
std::shared_ptr< lldb_private::Module > ModuleSP
std::weak_ptr< lldb_private::Section > SectionWP
A line table entry class.
uint16_t column
The column number of the source line, or zero if there is no column information.
void Clear()
Clear the object's state.
bool IsValid() const
Check if a line entry object is valid.
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
const FileSpec & GetFile() const
Helper to access the file.