41#include "llvm/ADT/StringRef.h"
42#include "llvm/Support/Compiler.h"
43#include "llvm/Support/Error.h"
44#include "llvm/TargetParser/Triple.h"
66 const Address &address,
void *dst,
size_t dst_len) {
67 if (exe_scope ==
nullptr)
73 bool force_live_memory =
true;
74 return target_sp->ReadMemory(address, dst, dst_len,
error,
83 uint32_t &addr_size) {
86 if (exe_scope ==
nullptr)
91 byte_order = target_sp->GetArchitecture().GetByteOrder();
92 addr_size = target_sp->GetArchitecture().GetAddressByteSize();
98 byte_order = module_sp->GetArchitecture().GetByteOrder();
99 addr_size = module_sp->GetArchitecture().GetAddressByteSize();
106 const Address &address, uint32_t byte_size,
109 if (exe_scope ==
nullptr || byte_size >
sizeof(uint64_t)) {
115 success =
ReadBytes(exe_scope, address, &buf, byte_size) == byte_size;
118 uint32_t addr_size = 0;
120 DataExtractor data(&buf,
sizeof(buf), byte_order, addr_size);
122 uval64 = data.
GetU64(&offset);
130 const Address &address, uint32_t pointer_size,
132 if (exe_scope ==
nullptr)
135 bool success =
false;
152 if (module_sp->ResolveFileAddress(deref_addr, deref_so_addr))
166 uint32_t byte_size,
Stream *strm) {
167 if (exe_scope ==
nullptr || byte_size == 0)
169 std::vector<uint8_t> buf(byte_size, 0);
171 if (
ReadBytes(exe_scope, address, &buf[0], buf.size()) == buf.size()) {
173 uint32_t addr_size = 0;
175 DataExtractor data(&buf.front(), buf.size(), byte_order, addr_size);
195 if (exe_scope ==
nullptr)
197 const size_t k_buf_len = 256;
198 char buf[k_buf_len + 1];
199 buf[k_buf_len] =
'\0';
203 size_t total_len = 0;
207 while ((bytes_read =
ReadBytes(exe_scope, curr_address, buf, k_buf_len)) >
209 size_t len = strlen(buf);
212 if (len > bytes_read)
226 total_len += bytes_read;
230 curr_address.
Slide(bytes_read);
258 assert(section_sp->ContainsFileAddress(file_addr));
259 m_offset = file_addr - section_sp->GetFileAddress();
269 constexpr SymbolContextItem resolve_scope =
270 eSymbolContextFunction | eSymbolContextSymbol;
279 module_sp = section_sp->GetModule();
286 addr_t sect_file_addr = section_sp->GetFileAddress();
307 addr_t sect_load_addr = section_sp->GetLoadBaseAddress(target);
331 if (is_indirect && target) {
335 code_addr = processSP->ResolveIndirectFunction(
this,
error);
336 if (!
error.Success())
373 bool allow_section_end) {
388 "Non-brief descriptions not implemented");
399 DumpStyle fallback_style, uint32_t addr_size,
401 std::optional<Stream::HighlightSettings> settings)
const {
416 addr_size =
sizeof(
addr_t);
434 s->
Printf(
"(Section *)%p + ",
static_cast<void *
>(section_sp.get()));
440 ModuleSP module_sp = section_sp->GetModule();
442 s->
Format(
"{0}[", module_sp->GetFileSpec().GetFilename().nonEmptyOr(
445 s->
Printf(
"%s[",
"<Unknown>");
469 const llvm::Triple::ArchType llvm_arch =
471 if (llvm_arch == llvm::Triple::mips ||
472 llvm_arch == llvm::Triple::mipsel ||
473 llvm_arch == llvm::Triple::mips64 ||
474 llvm_arch == llvm::Triple::mips64el)
491 uint32_t pointer_size = 4;
496 pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
497 bool showed_info =
false;
503 if (
Symtab *symtab = module_sp->GetSymtab()) {
506 symtab->FindSymbolContainingFileAddress(file_Addr);
509 if (!symbol_name.empty()) {
514 s->
Printf(
" + %" PRIu64, delta);
529 if (
ReadAddress(exe_scope, *
this, pointer_size, so_addr)) {
542 if (
ReadAddress(exe_scope, *
this, pointer_size, so_addr)) {
546 so_addr, eSymbolContextEverything, func_sc);
550 s->
PutCString(
"(objc_msgref *) -> { (func*)");
557 cstr_addr.
Slide(pointer_size);
560 if (
ReadAddress(exe_scope, cstr_addr, pointer_size, so_addr)) {
582 Address cfstring_data_addr(*
this);
583 cfstring_data_addr.
Slide(2 * pointer_size);
584 if (
ReadAddress(exe_scope, cfstring_data_addr, pointer_size,
622 if (
ReadAddress(exe_scope, *
this, pointer_size, so_addr)) {
632 so_addr, eSymbolContextEverything, pointer_sc);
633 if (pointer_sc.
function !=
nullptr ||
634 pointer_sc.
symbol !=
nullptr) {
637 false,
true,
true,
false,
653 module_sp->ResolveSymbolContextForAddress(
654 *
this, eSymbolContextEverything, sc);
656 bool show_stop_context =
true;
658 const bool show_fullpaths =
false;
659 const bool show_inlined_frames =
true;
660 const bool show_function_arguments =
668 show_stop_context =
false;
672 if (show_stop_context) {
676 show_module, show_inlined_frames,
677 show_function_arguments, show_function_name,
702 module_sp->ResolveSymbolContextForAddress(
703 *
this, eSymbolContextEverything | eSymbolContextVariable, sc);
716 bool can_create =
true;
717 bool get_parent_variables =
true;
718 bool stop_if_block_is_inlined_function =
false;
722 can_create, get_parent_variables,
723 stop_if_block_is_inlined_function,
730 for (
const VariableSP &var_sp : variable_list) {
732 s->
Printf(
" Variable: id = {0x%8.8" PRIx64
"}, name = \"%s\"",
733 var_sp->GetID(), var_sp->GetName().GetCString());
734 Type *type = var_sp->GetType();
740 if (var_sp->GetScopeRange().IsEmpty())
742 else if (all_ranges) {
743 for (
auto range : var_sp->GetScopeRange())
745 range.GetRangeEnd(), addr_size);
746 }
else if (
auto *range =
747 var_sp->GetScopeRange().FindEntryThatContains(
750 range->GetRangeEnd(), addr_size);
752 var_sp->DumpLocations(s, all_ranges ?
Address() : *
this);
754 var_sp->GetDeclaration().DumpStopContext(s,
false);
772 std::optional<addr_t> dereferenced_load_addr =
774 if (dereferenced_load_addr) {
779 if (dereferenced_addr.
Dump(&strm, exe_scope,
821 SymbolContextItem resolve_scope)
const {
828 ModuleSP module_sp(section_sp->GetModule());
832 return sc->
module_sp->ResolveSymbolContextForAddress(
833 *
this, resolve_scope, *sc);
842 return section_sp->GetModule();
852 sc.
module_sp->ResolveSymbolContextForAddress(*
this,
853 eSymbolContextCompUnit, sc);
866 sc.
module_sp->ResolveSymbolContextForAddress(*
this,
867 eSymbolContextFunction, sc);
880 sc.
module_sp->ResolveSymbolContextForAddress(*
this, eSymbolContextBlock,
894 sc.
module_sp->ResolveSymbolContextForAddress(*
this, eSymbolContextSymbol,
908 sc.
module_sp->ResolveSymbolContextForAddress(*
this,
909 eSymbolContextLineEntry, sc);
923 if (a_file_addr < b_file_addr)
925 if (a_file_addr > b_file_addr)
932 assert(target !=
nullptr);
935 if (a_load_addr < b_load_addr)
937 if (a_load_addr > b_load_addr)
945 Module *a_module = a_module_sp.get();
946 Module *b_module = b_module_sp.get();
947 if (a_module < b_module)
949 if (a_module > b_module)
955 if (a_file_addr < b_file_addr)
957 if (a_file_addr > b_file_addr)
977 Module *lhs_module = lhs_module_sp.get();
978 Module *rhs_module = rhs_module_sp.get();
979 if (lhs_module == rhs_module) {
985 return lhs_module < rhs_module;
992 Module *lhs_module = lhs_module_sp.get();
993 Module *rhs_module = rhs_module_sp.get();
994 if (lhs_module == rhs_module) {
1000 return lhs_module > rhs_module;
1018 ObjectFile *obj_file = module_sp->GetObjectFile();
1022 module_sp->GetSymtab();
1030 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 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)
Function * CalculateSymbolContextFunction() const
static int CompareModulePointerAndOffset(const Address &lhs, const Address &rhs)
bool SectionWasDeletedPrivate() const
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 Slide(int64_t offset)
bool ResolveFunctionScope(lldb_private::SymbolContext &sym_ctx)
Resolve this address to its containing function.
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
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.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
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.
llvm::StringRef 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.
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.
llvm::Expected< lldb::addr_t > ReadPointerFromMemory(lldb::addr_t vm_addr)
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.
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
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.
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.