blob: 3b7b0bc27cf81e7e8bbc39392f244e2097de4e52 [file] [log] [blame]
Raphael Isemann80814282020-01-24 07:23:271//===-- CXXFunctionPointer.cpp---------------------------------------------===//
Enrico Granata419d7912015-09-04 00:33:512//
Chandler Carruth2946cd72019-01-19 08:50:563// 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:516//
7//===----------------------------------------------------------------------===//
8
Enrico Granatac6bbb8b2015-09-04 21:22:549#include "lldb/DataFormatters/CXXFunctionPointer.h"
10
Enrico Granatad717cc92015-10-20 04:50:0911#include "lldb/Core/ValueObject.h"
Enrico Granata419d7912015-09-04 00:33:5112#include "lldb/Target/SectionLoadList.h"
13#include "lldb/Target/Target.h"
Zachary Turnerbf9a7732017-02-02 21:39:5014#include "lldb/Utility/Stream.h"
Enrico Granata419d7912015-09-04 00:33:5115
16#include <string>
17
18using namespace lldb;
19using namespace lldb_private;
20using namespace lldb_private::formatters;
21
Kate Stoneb9c1b512016-09-06 20:57:5022bool 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:3340 if (target && !target->GetSectionLoadList().IsEmpty()) {
Kate Stoneb9c1b512016-09-06 20:57:5041 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:5146 }
Kate Stoneb9c1b512016-09-06 20:57:5047 }
48 } break;
Enrico Granata419d7912015-09-04 00:33:5149 }
Kate Stoneb9c1b512016-09-06 20:57:5050 }
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:5156}