Path: blob/main/contrib/llvm-project/lldb/source/DataFormatters/CXXFunctionPointer.cpp
39587 views
//===-- CXXFunctionPointer.cpp---------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/DataFormatters/CXXFunctionPointer.h"910#include "lldb/Core/ValueObject.h"11#include "lldb/Target/ABI.h"12#include "lldb/Target/SectionLoadList.h"13#include "lldb/Target/Target.h"14#include "lldb/Utility/Stream.h"15#include "lldb/lldb-enumerations.h"1617#include <string>1819using namespace lldb;20using namespace lldb_private;21using namespace lldb_private::formatters;2223bool lldb_private::formatters::CXXFunctionPointerSummaryProvider(24ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {25std::string destination;26StreamString sstr;27AddressType func_ptr_address_type = eAddressTypeInvalid;28addr_t func_ptr_address = valobj.GetPointerValue(&func_ptr_address_type);29if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) {30switch (func_ptr_address_type) {31case eAddressTypeInvalid:32case eAddressTypeFile:33case eAddressTypeHost:34break;3536case eAddressTypeLoad: {37ExecutionContext exe_ctx(valobj.GetExecutionContextRef());3839Address so_addr;40Target *target = exe_ctx.GetTargetPtr();41if (target && !target->GetSectionLoadList().IsEmpty()) {42target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,43so_addr);44if (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 it47// now points to a symbol -- if so, do the SymbolContext lookup48// based on the stripped address.49// If we find a symbol with the ptrauth bits stripped, print the50// raw value into the stream, and replace the Address with the51// one that points to a symbol for a fuller description.52if (Process *process = exe_ctx.GetProcessPtr()) {53if (ABISP abi_sp = process->GetABI()) {54addr_t fixed_addr = abi_sp->FixCodeAddress(func_ptr_address);55if (fixed_addr != func_ptr_address) {56Address test_address;57test_address.SetLoadAddress(fixed_addr, target);58if (test_address.GetSection() != nullptr) {59int addrsize = target->GetArchitecture().GetAddressByteSize();60sstr.Printf("actual=0x%*.*" PRIx64 " ", addrsize * 2,61addrsize * 2, fixed_addr);62so_addr = test_address;63}64}65}66}67}6869if (so_addr.IsValid()) {70so_addr.Dump(&sstr, exe_ctx.GetBestExecutionContextScope(),71Address::DumpStyleResolvedDescription,72Address::DumpStyleSectionNameOffset);73}74}75} break;76}77}78if (sstr.GetSize() > 0) {79if (valobj.GetValueType() == lldb::eValueTypeVTableEntry)80stream.PutCString(sstr.GetData());81else82stream.Printf("(%s)", sstr.GetData());83return true;84} else85return false;86}878889