blob: 3b7b0bc27cf81e7e8bbc39392f244e2097de4e52 [file] [log] [blame]
Raphael Isemann80814282020-01-24 08:23:27 +01001//===-- CXXFunctionPointer.cpp---------------------------------------------===//
Enrico Granata419d7912015-09-04 00:33:51 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Enrico Granata419d7912015-09-04 00:33:51 +00006//
7//===----------------------------------------------------------------------===//
8
Enrico Granatac6bbb8b2015-09-04 21:22:54 +00009#include "lldb/DataFormatters/CXXFunctionPointer.h"
10
Enrico Granatad717cc92015-10-20 04:50:09 +000011#include "lldb/Core/ValueObject.h"
Enrico Granata419d7912015-09-04 00:33:51 +000012#include "lldb/Target/SectionLoadList.h"
13#include "lldb/Target/Target.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000014#include "lldb/Utility/Stream.h"
Enrico Granata419d7912015-09-04 00:33:51 +000015
16#include <string>
17
18using namespace lldb;
19using namespace lldb_private;
20using namespace lldb_private::formatters;
21
Kate Stoneb9c1b512016-09-06 20:57:50 +000022bool 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();
Jonas Devliegherea6682a42018-12-15 00:15:33 +000040 if (target && !target->GetSectionLoadList().IsEmpty()) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000041 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
42 so_addr)) {
43 so_addr.Dump(&sstr, exe_ctx.GetBestExecutionContextScope(),
44 Address::DumpStyleResolvedDescription,
45 Address::DumpStyleSectionNameOffset);
Enrico Granata419d7912015-09-04 00:33:51 +000046 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000047 }
48 } break;
Enrico Granata419d7912015-09-04 00:33:51 +000049 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 }
51 if (sstr.GetSize() > 0) {
52 stream.Printf("(%s)", sstr.GetData());
53 return true;
54 } else
55 return false;
Enrico Granata419d7912015-09-04 00:33:51 +000056}