blob: 41e9d4b382b38a58bbe4d933acd03add4761e783 [file] [log] [blame]
Alexander Shaposhnikov696bd632016-11-26 05:23:44 +00001//===-- CXXFunctionPointer.cpp-----------------------------------*- C++ -*-===//
Enrico Granata419d7912015-09-04 00:33:51 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Enrico Granatac6bbb8b2015-09-04 21:22:54 +000010#include "lldb/DataFormatters/CXXFunctionPointer.h"
11
Enrico Granatad717cc92015-10-20 04:50:09 +000012#include "lldb/Core/Stream.h"
13#include "lldb/Core/ValueObject.h"
Enrico Granata419d7912015-09-04 00:33:51 +000014#include "lldb/Target/SectionLoadList.h"
15#include "lldb/Target/Target.h"
16
17#include <string>
18
19using namespace lldb;
20using namespace lldb_private;
21using namespace lldb_private::formatters;
22
Kate Stoneb9c1b512016-09-06 20:57:50 +000023bool lldb_private::formatters::CXXFunctionPointerSummaryProvider(
24 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
25 std::string destination;
26 StreamString sstr;
27 AddressType func_ptr_address_type = eAddressTypeInvalid;
28 addr_t func_ptr_address = valobj.GetPointerValue(&func_ptr_address_type);
29 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) {
30 switch (func_ptr_address_type) {
31 case eAddressTypeInvalid:
32 case eAddressTypeFile:
33 case eAddressTypeHost:
34 break;
35
36 case eAddressTypeLoad: {
37 ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
38
39 Address so_addr;
40 Target *target = exe_ctx.GetTargetPtr();
41 if (target && target->GetSectionLoadList().IsEmpty() == false) {
42 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
43 so_addr)) {
44 so_addr.Dump(&sstr, exe_ctx.GetBestExecutionContextScope(),
45 Address::DumpStyleResolvedDescription,
46 Address::DumpStyleSectionNameOffset);
Enrico Granata419d7912015-09-04 00:33:51 +000047 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 }
49 } break;
Enrico Granata419d7912015-09-04 00:33:51 +000050 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 }
52 if (sstr.GetSize() > 0) {
53 stream.Printf("(%s)", sstr.GetData());
54 return true;
55 } else
56 return false;
Enrico Granata419d7912015-09-04 00:33:51 +000057}