LLDB mainline
CXXFunctionPointer.cpp
Go to the documentation of this file.
1//===-- CXXFunctionPointer.cpp---------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
12#include "lldb/Target/ABI.h"
14#include "lldb/Target/Target.h"
15#include "lldb/Utility/Stream.h"
17
18#include <string>
19
20using namespace lldb;
21using namespace lldb_private;
22using namespace lldb_private::formatters;
23
25 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
26 std::string destination;
27 StreamString sstr;
28 AddressType func_ptr_address_type = eAddressTypeInvalid;
29 addr_t func_ptr_address = valobj.GetPointerValue(&func_ptr_address_type);
30 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) {
31 switch (func_ptr_address_type) {
35 break;
36
37 case eAddressTypeLoad: {
39
40 Address so_addr;
41 Target *target = exe_ctx.GetTargetPtr();
42 if (target && !target->GetSectionLoadList().IsEmpty()) {
43 target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
44 so_addr);
45 if (so_addr.GetSection() == nullptr) {
46 // If we have an address that doesn't correspond to any symbol,
47 // it might have authentication bits. Strip them & see if it
48 // now points to a symbol -- if so, do the SymbolContext lookup
49 // based on the stripped address.
50 // If we find a symbol with the ptrauth bits stripped, print the
51 // raw value into the stream, and replace the Address with the
52 // one that points to a symbol for a fuller description.
53 if (Process *process = exe_ctx.GetProcessPtr()) {
54 if (ABISP abi_sp = process->GetABI()) {
55 addr_t fixed_addr = abi_sp->FixCodeAddress(func_ptr_address);
56 if (fixed_addr != func_ptr_address) {
57 Address test_address;
58 test_address.SetLoadAddress(fixed_addr, target);
59 if (test_address.GetSection() != nullptr) {
60 int addrsize = target->GetArchitecture().GetAddressByteSize();
61 sstr.Printf("actual=0x%*.*" PRIx64 " ", addrsize * 2,
62 addrsize * 2, fixed_addr);
63 so_addr = test_address;
64 }
65 }
66 }
67 }
68 }
69
70 if (so_addr.IsValid()) {
71 so_addr.Dump(&sstr, exe_ctx.GetBestExecutionContextScope(),
74 }
75 }
76 } break;
77 }
78 }
79 if (sstr.GetSize() > 0) {
81 stream.PutCString(sstr.GetData());
82 else
83 stream.Printf("(%s)", sstr.GetData());
84 return true;
85 } else
86 return false;
87}
A section + offset based address class.
Definition: Address.h:62
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition: Address.cpp:1047
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:439
@ DumpStyleSectionNameOffset
Display as the section name + offset.
Definition: Address.h:74
@ DumpStyleResolvedDescription
Display the details about what an address resolves to.
Definition: Address.h:104
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.
Definition: Address.cpp:408
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:355
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:691
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
A plug-in interface definition class for debugging a process.
Definition: Process.h:341
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
const char * GetData() const
Definition: StreamString.h:45
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1140
const ArchSpec & GetArchitecture() const
Definition: Target.h:1025
lldb::addr_t GetPointerValue(AddressType *address_type=nullptr)
virtual lldb::ValueType GetValueType() const =0
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:330
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
bool CXXFunctionPointerSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
A class that represents a running process on the host machine.
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
@ eAddressTypeHost
Address is an address in the process that is running this code.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ABI > ABISP
Definition: lldb-forward.h:314
uint64_t addr_t
Definition: lldb-types.h:80
@ eValueTypeVTableEntry
function pointer in virtual function table