blob: d12b4d2b4b8f5c91233c01562a638fdf200f4ebc [file] [log] [blame]
Enrico Granata419d7912015-09-04 00:33:51 +00001//===-- CXXFormatterFunctions.cpp---------------------------------*- C++ -*-===//
2//
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 Granata33e97e62015-09-04 21:01:18 +000010#include "CXXFunctionPointer.h"
Enrico Granata419d7912015-09-04 00:33:51 +000011#include "lldb/Target/SectionLoadList.h"
12#include "lldb/Target/Target.h"
13
14#include <string>
15
16using namespace lldb;
17using namespace lldb_private;
18using namespace lldb_private::formatters;
19
20bool
21lldb_private::formatters::CXXFunctionPointerSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
22{
23 std::string destination;
24 StreamString sstr;
25 AddressType func_ptr_address_type = eAddressTypeInvalid;
26 addr_t func_ptr_address = valobj.GetPointerValue (&func_ptr_address_type);
27 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
28 {
29 switch (func_ptr_address_type)
30 {
31 case eAddressTypeInvalid:
32 case eAddressTypeFile:
33 case eAddressTypeHost:
34 break;
35
36 case eAddressTypeLoad:
37 {
38 ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
39
40 Address so_addr;
41 Target *target = exe_ctx.GetTargetPtr();
42 if (target && target->GetSectionLoadList().IsEmpty() == false)
43 {
44 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
45 {
46 so_addr.Dump (&sstr,
47 exe_ctx.GetBestExecutionContextScope(),
48 Address::DumpStyleResolvedDescription,
49 Address::DumpStyleSectionNameOffset);
50 }
51 }
52 }
53 break;
54 }
55 }
56 if (sstr.GetSize() > 0)
57 {
58 stream.Printf("(%s)", sstr.GetData());
59 return true;
60 }
61 else
62 return false;
63}