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"
13 #include "lldb/Target/Target.h"
14 #include "lldb/Utility/Stream.h"
15 
16 #include <string>
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 using namespace lldb_private::formatters;
21 
23  ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
24  std::string destination;
25  StreamString sstr;
26  AddressType func_ptr_address_type = eAddressTypeInvalid;
27  addr_t func_ptr_address = valobj.GetPointerValue(&func_ptr_address_type);
28  if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) {
29  switch (func_ptr_address_type) {
31  case eAddressTypeFile:
32  case eAddressTypeHost:
33  break;
34 
35  case eAddressTypeLoad: {
36  ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
37 
38  Address so_addr;
39  Target *target = exe_ctx.GetTargetPtr();
40  if (target && !target->GetSectionLoadList().IsEmpty()) {
41  if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
42  so_addr)) {
43  so_addr.Dump(&sstr, exe_ctx.GetBestExecutionContextScope(),
44  Address::DumpStyleResolvedDescription,
45  Address::DumpStyleSectionNameOffset);
46  }
47  }
48  } break;
49  }
50  }
51  if (sstr.GetSize() > 0) {
52  stream.Printf("(%s)", sstr.GetData());
53  return true;
54  } else
55  return false;
56 }
lldb_private::ExecutionContext
Definition: ExecutionContext.h:291
lldb_private::AddressType
AddressType
Definition: lldb-private-enumerations.h:30
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:1433
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:447
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:38
lldb_private::eAddressTypeLoad
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
Definition: lldb-private-enumerations.h:34
lldb_private::SectionLoadList::ResolveLoadAddress
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
Definition: SectionLoadList.cpp:208
ValueObject.h
lldb_private::SectionLoadList::IsEmpty
bool IsEmpty() const
Definition: SectionLoadList.cpp:37
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::ExecutionContext::GetBestExecutionContextScope
ExecutionContextScope * GetBestExecutionContextScope() const
Definition: ExecutionContext.cpp:216
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::Address::Dump
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX) const
Dump a description of this object to a Stream.
Definition: Address.cpp:392
lldb_private::Target::GetSectionLoadList
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1036
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
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:22
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:200