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
9 #include "lldb/DataFormatters/CXXFunctionPointer.h"
10
11 #include "lldb/Core/ValueObject.h"
12 #include "lldb/Target/SectionLoadList.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
CXXFunctionPointerSummaryProvider(ValueObject & valobj,Stream & stream,const TypeSummaryOptions & options)22 bool lldb_private::formatters::CXXFunctionPointerSummaryProvider(
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) {
30 case eAddressTypeInvalid:
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 }
57