1435933ddSDimitry Andric //===-- CXXFunctionPointer.cpp-----------------------------------*- C++ -*-===//
29f2f44ceSEd Maste //
39f2f44ceSEd Maste //                     The LLVM Compiler Infrastructure
49f2f44ceSEd Maste //
59f2f44ceSEd Maste // This file is distributed under the University of Illinois Open Source
69f2f44ceSEd Maste // License. See LICENSE.TXT for details.
79f2f44ceSEd Maste //
89f2f44ceSEd Maste //===----------------------------------------------------------------------===//
99f2f44ceSEd Maste 
109f2f44ceSEd Maste #include "lldb/DataFormatters/CXXFunctionPointer.h"
119f2f44ceSEd Maste 
129f2f44ceSEd Maste #include "lldb/Core/ValueObject.h"
139f2f44ceSEd Maste #include "lldb/Target/SectionLoadList.h"
149f2f44ceSEd Maste #include "lldb/Target/Target.h"
15f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
169f2f44ceSEd Maste 
179f2f44ceSEd Maste #include <string>
189f2f44ceSEd Maste 
199f2f44ceSEd Maste using namespace lldb;
209f2f44ceSEd Maste using namespace lldb_private;
219f2f44ceSEd Maste using namespace lldb_private::formatters;
229f2f44ceSEd Maste 
CXXFunctionPointerSummaryProvider(ValueObject & valobj,Stream & stream,const TypeSummaryOptions & options)23435933ddSDimitry Andric bool lldb_private::formatters::CXXFunctionPointerSummaryProvider(
24435933ddSDimitry Andric     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
259f2f44ceSEd Maste   std::string destination;
269f2f44ceSEd Maste   StreamString sstr;
279f2f44ceSEd Maste   AddressType func_ptr_address_type = eAddressTypeInvalid;
289f2f44ceSEd Maste   addr_t func_ptr_address = valobj.GetPointerValue(&func_ptr_address_type);
29435933ddSDimitry Andric   if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) {
30435933ddSDimitry Andric     switch (func_ptr_address_type) {
319f2f44ceSEd Maste     case eAddressTypeInvalid:
329f2f44ceSEd Maste     case eAddressTypeFile:
339f2f44ceSEd Maste     case eAddressTypeHost:
349f2f44ceSEd Maste       break;
359f2f44ceSEd Maste 
36435933ddSDimitry Andric     case eAddressTypeLoad: {
379f2f44ceSEd Maste       ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
389f2f44ceSEd Maste 
399f2f44ceSEd Maste       Address so_addr;
409f2f44ceSEd Maste       Target *target = exe_ctx.GetTargetPtr();
41*b5893f02SDimitry Andric       if (target && !target->GetSectionLoadList().IsEmpty()) {
42435933ddSDimitry Andric         if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
43435933ddSDimitry Andric                                                             so_addr)) {
44435933ddSDimitry Andric           so_addr.Dump(&sstr, exe_ctx.GetBestExecutionContextScope(),
459f2f44ceSEd Maste                        Address::DumpStyleResolvedDescription,
469f2f44ceSEd Maste                        Address::DumpStyleSectionNameOffset);
479f2f44ceSEd Maste         }
489f2f44ceSEd Maste       }
49435933ddSDimitry Andric     } break;
509f2f44ceSEd Maste     }
519f2f44ceSEd Maste   }
52435933ddSDimitry Andric   if (sstr.GetSize() > 0) {
539f2f44ceSEd Maste     stream.Printf("(%s)", sstr.GetData());
549f2f44ceSEd Maste     return true;
55435933ddSDimitry Andric   } else
569f2f44ceSEd Maste     return false;
579f2f44ceSEd Maste }
58