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;
151 if (module_sp->ResolveFileAddress(deref_addr, deref_so_addr))
165 uint32_t byte_size,
Stream *strm) {
166 if (exe_scope ==
nullptr || byte_size == 0)
168 std::vector<uint8_t> buf(byte_size, 0);
170 if (
ReadBytes(exe_scope, address, &buf[0], buf.size()) == buf.size()) {
172 uint32_t addr_size = 0;
174 DataExtractor data(&buf.front(), buf.size(), byte_order, addr_size);
194 if (exe_scope ==
nullptr)
196 const size_t k_buf_len = 256;
197 char buf[k_buf_len + 1];
198 buf[k_buf_len] =
'\0';
202 size_t total_len = 0;
206 while ((bytes_read =
ReadBytes(exe_scope, curr_address, buf, k_buf_len)) >
208 size_t len = strlen(buf);
211 if (len > bytes_read)
225 total_len += bytes_read;
257 assert(section_sp->ContainsFileAddress(file_addr));
258 m_offset = file_addr - section_sp->GetFileAddress();
270 constexpr SymbolContextItem resolve_scope =
271 eSymbolContextFunction | eSymbolContextSymbol;
275 addr_range_ptr->
Clear();
282 return sym_ctx.
GetAddressRange(resolve_scope, 0,
false, *addr_range_ptr);
289 module_sp = section_sp->GetModule();
296 addr_t sect_file_addr = section_sp->GetFileAddress();
317 addr_t sect_load_addr = section_sp->GetLoadBaseAddress(target);
341 if (is_indirect && target) {
345 code_addr = processSP->ResolveIndirectFunction(
this,
error);
346 if (!
error.Success())
383 bool allow_section_end) {
398 "Non-brief descriptions not implemented");
409 DumpStyle fallback_style, uint32_t addr_size,
411 std::optional<Stream::HighlightSettings> settings)
const {
426 addr_size =
sizeof(
addr_t);
444 s->
Printf(
"(Section *)%p + ",
static_cast<void *
>(section_sp.get()));
450 ModuleSP module_sp = section_sp->GetModule();
452 s->
Printf(
"%s[", module_sp->GetFileSpec().GetFilename().AsCString(
455 s->
Printf(
"%s[",
"<Unknown>");
479 const llvm::Triple::ArchType llvm_arch =
481 if (llvm_arch == llvm::Triple::mips ||
482 llvm_arch == llvm::Triple::mipsel ||
483 llvm_arch == llvm::Triple::mips64 ||
484 llvm_arch == llvm::Triple::mips64el)
501 uint32_t pointer_size = 4;
506 pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
507 bool showed_info =
false;
513 if (
Symtab *symtab = module_sp->GetSymtab()) {
516 symtab->FindSymbolContainingFileAddress(file_Addr);
524 s->
Printf(
" + %" PRIu64, delta);
539 if (
ReadAddress(exe_scope, *
this, pointer_size, so_addr)) {
552 if (
ReadAddress(exe_scope, *
this, pointer_size, so_addr)) {
556 so_addr, eSymbolContextEverything, func_sc);
560 s->
PutCString(
"(objc_msgref *) -> { (func*)");
570 if (
ReadAddress(exe_scope, cstr_addr, pointer_size, so_addr)) {
592 Address cfstring_data_addr(*
this);
595 if (
ReadAddress(exe_scope, cfstring_data_addr, pointer_size,
633 if (
ReadAddress(exe_scope, *
this, pointer_size, so_addr)) {
643 so_addr, eSymbolContextEverything, pointer_sc);
644 if (pointer_sc.
function !=
nullptr ||
645 pointer_sc.
symbol !=
nullptr) {
648 false,
true,
true,
false,
664 module_sp->ResolveSymbolContextForAddress(
665 *
this, eSymbolContextEverything, sc);
667 bool show_stop_context =
true;
669 const bool show_fullpaths =
false;
670 const bool show_inlined_frames =
true;
671 const bool show_function_arguments =
679 show_stop_context =
false;
683 if (show_stop_context) {
687 show_module, show_inlined_frames,
688 show_function_arguments, show_function_name,
713 module_sp->ResolveSymbolContextForAddress(
714 *
this, eSymbolContextEverything | eSymbolContextVariable, sc);
727 bool can_create =
true;
728 bool get_parent_variables =
true;
729 bool stop_if_block_is_inlined_function =
false;
733 can_create, get_parent_variables,
734 stop_if_block_is_inlined_function,
741 for (
const VariableSP &var_sp : variable_list) {
743 s->
Printf(
" Variable: id = {0x%8.8" PRIx64
"}, name = \"%s\"",
744 var_sp->GetID(), var_sp->GetName().GetCString());
745 Type *type = var_sp->GetType();
751 if (var_sp->GetScopeRange().IsEmpty())
753 else if (all_ranges) {
754 for (
auto range : var_sp->GetScopeRange())
756 range.GetRangeEnd(), addr_size);
757 }
else if (
auto *range =
758 var_sp->GetScopeRange().FindEntryThatContains(
761 range->GetRangeEnd(), addr_size);
765 var_sp->GetDeclaration().DumpStopContext(s,
false);
784 addr_t dereferenced_load_addr =
791 if (dereferenced_addr.
Dump(&strm, exe_scope,
833 SymbolContextItem resolve_scope)
const {
840 ModuleSP module_sp(section_sp->GetModule());
844 return sc->
module_sp->ResolveSymbolContextForAddress(
845 *
this, resolve_scope, *sc);
854 return section_sp->GetModule();
864 sc.
module_sp->ResolveSymbolContextForAddress(*
this,
865 eSymbolContextCompUnit, sc);
878 sc.
module_sp->ResolveSymbolContextForAddress(*
this,
879 eSymbolContextFunction, sc);
892 sc.
module_sp->ResolveSymbolContextForAddress(*
this, eSymbolContextBlock,
906 sc.
module_sp->ResolveSymbolContextForAddress(*
this, eSymbolContextSymbol,
920 sc.
module_sp->ResolveSymbolContextForAddress(*
this,
921 eSymbolContextLineEntry, sc);
935 if (a_file_addr < b_file_addr)
937 if (a_file_addr > b_file_addr)
944 assert(target !=
nullptr);
947 if (a_load_addr < b_load_addr)
949 if (a_load_addr > b_load_addr)
957 Module *a_module = a_module_sp.get();
958 Module *b_module = b_module_sp.get();
959 if (a_module < b_module)
961 if (a_module > b_module)
967 if (a_file_addr < b_file_addr)
969 if (a_file_addr > b_file_addr)
995 Module *lhs_module = lhs_module_sp.get();
996 Module *rhs_module = rhs_module_sp.get();
997 if (lhs_module == rhs_module) {
1003 return lhs_module < rhs_module;
1010 Module *lhs_module = lhs_module_sp.get();
1011 Module *rhs_module = rhs_module_sp.get();
1012 if (lhs_module == rhs_module) {
1018 return lhs_module > rhs_module;
1036 ObjectFile *obj_file = module_sp->GetObjectFile();
1048 bool allow_section_end) {
1050 load_addr, *
this, 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
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) 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.
SectionLoadList & GetSectionLoadList()
const lldb::ProcessSP & GetProcessSP() const
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.