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 
11 #include "lldb/Core/ValueObject.h"
12 #include "lldb/Target/ABI.h"
14 #include "lldb/Target/Target.h"
15 #include "lldb/Utility/Stream.h"
16 
17 #include <string>
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 using namespace lldb_private::formatters;
22 
24  ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
25  std::string destination;
26  StreamString sstr;
27  AddressType func_ptr_address_type = eAddressTypeInvalid;
28  addr_t func_ptr_address = valobj.GetPointerValue(&func_ptr_address_type);
29  if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) {
30  switch (func_ptr_address_type) {
32  case eAddressTypeFile:
33  case eAddressTypeHost:
34  break;
35 
36  case eAddressTypeLoad: {
37  ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
38 
39  Address so_addr;
40  Target *target = exe_ctx.GetTargetPtr();
41  if (target && !target->GetSectionLoadList().IsEmpty()) {
42  target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
43  so_addr);
44  if (so_addr.GetSection() == nullptr) {
45  // If we have an address that doesn't correspond to any symbol,
46  // it might have authentication bits. Strip them & see if it
47  // now points to a symbol -- if so, do the SymbolContext lookup
48  // based on the stripped address.
49  // If we find a symbol with the ptrauth bits stripped, print the
50  // raw value into the stream, and replace the Address with the
51  // one that points to a symbol for a fuller description.
52  if (Process *process = exe_ctx.GetProcessPtr()) {
53  if (ABISP abi_sp = process->GetABI()) {
54  addr_t fixed_addr = abi_sp->FixCodeAddress(func_ptr_address);
55  if (fixed_addr != func_ptr_address) {
56  Address test_address;
57  test_address.SetLoadAddress(fixed_addr, target);
58  if (test_address.GetSection() != nullptr) {
59  int addrsize = target->GetArchitecture().GetAddressByteSize();
60  sstr.Printf("actual=0x%*.*" PRIx64 " ", addrsize * 2,
61  addrsize * 2, fixed_addr);
62  so_addr = test_address;
63  }
64  }
65  }
66  }
67  }
68 
69  if (so_addr.IsValid()) {
70  so_addr.Dump(&sstr, exe_ctx.GetBestExecutionContextScope(),
71  Address::DumpStyleResolvedDescription,
72  Address::DumpStyleSectionNameOffset);
73  }
74  }
75  } break;
76  }
77  }
78  if (sstr.GetSize() > 0) {
79  stream.Printf("(%s)", sstr.GetData());
80  return true;
81  } else
82  return false;
83 }
lldb_private::Address::SetLoadAddress
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition: Address.cpp:1040
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::Address::IsValid
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:345
lldb_private::ExecutionContext::GetProcessPtr
Process * GetProcessPtr() const
Returns a pointer to the process object.
Definition: ExecutionContext.cpp:206
lldb_private::AddressType
AddressType
Definition: lldb-private-enumerations.h:30
lldb_private::Process
Definition: Process.h:338
lldb_private::eAddressTypeHost
@ eAddressTypeHost
Address is an address in the process that is running this code.
Definition: lldb-private-enumerations.h:36
lldb_private::ValueObject::GetPointerValue
lldb::addr_t GetPointerValue(AddressType *address_type=nullptr)
Definition: ValueObject.cpp:1436
SectionLoadList.h
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::Target
Definition: Target.h:473
ABI.h
Target.h
lldb_private::StreamString::GetSize
size_t GetSize() const
Definition: StreamString.cpp:38
lldb_private::eAddressTypeInvalid
@ eAddressTypeInvalid
Definition: lldb-private-enumerations.h:31
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::ValueObject::GetExecutionContextRef
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:330
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::eAddressTypeLoad
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
Definition: lldb-private-enumerations.h:34
lldb_private::Address::GetSection
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:429
lldb_private::SectionLoadList::ResolveLoadAddress
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
Definition: SectionLoadList.cpp:209
ValueObject.h
lldb_private::ArchSpec::GetAddressByteSize
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:684
lldb_private::SectionLoadList::IsEmpty
bool IsEmpty() const
Definition: SectionLoadList.cpp:38
lldb_private::Target::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: Target.h:989
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::Address::Dump
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX, bool all_ranges=false) const
Dump a description of this object to a Stream.
Definition: Address.cpp:406
lldb_private::ExecutionContext::GetBestExecutionContextScope
ExecutionContextScope * GetBestExecutionContextScope() const
Definition: ExecutionContext.cpp:214
lldb_private::Address
Definition: Address.h:59
lldb_private::eAddressTypeFile
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
Definition: lldb-private-enumerations.h:32
lldb_private::TypeSummaryOptions
Definition: TypeSummary.h:26
lldb_private::Target::GetSectionLoadList
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1097
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::formatters
Definition: CXXFunctionPointer.h:15
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::formatters::CXXFunctionPointerSummaryProvider
bool CXXFunctionPointerSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: CXXFunctionPointer.cpp:23
Stream.h
CXXFunctionPointer.h
lldb
Definition: SBAddress.h:15
lldb_private::ExecutionContext::GetTargetPtr
Target * GetTargetPtr() const
Returns a pointer to the target object.
Definition: ExecutionContext.cpp:198