Raphael Isemann | 8081428 | 2020-01-24 07:23:27 | [diff] [blame] | 1 | //===-- CXXFunctionPointer.cpp---------------------------------------------===// |
Enrico Granata | 419d791 | 2015-09-04 00:33:51 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 | [diff] [blame] | 3 | // 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 Granata | 419d791 | 2015-09-04 00:33:51 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Enrico Granata | c6bbb8b | 2015-09-04 21:22:54 | [diff] [blame] | 9 | #include "lldb/DataFormatters/CXXFunctionPointer.h" |
| 10 | |
Enrico Granata | d717cc9 | 2015-10-20 04:50:09 | [diff] [blame] | 11 | #include "lldb/Core/ValueObject.h" |
Enrico Granata | 419d791 | 2015-09-04 00:33:51 | [diff] [blame] | 12 | #include "lldb/Target/SectionLoadList.h" |
| 13 | #include "lldb/Target/Target.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 | [diff] [blame] | 14 | #include "lldb/Utility/Stream.h" |
Enrico Granata | 419d791 | 2015-09-04 00:33:51 | [diff] [blame] | 15 | |
| 16 | #include <string> |
| 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | using namespace lldb_private::formatters; |
| 21 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 | [diff] [blame] | 22 | bool 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 Devlieghere | a6682a4 | 2018-12-15 00:15:33 | [diff] [blame] | 40 | if (target && !target->GetSectionLoadList().IsEmpty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 | [diff] [blame] | 41 | 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 Granata | 419d791 | 2015-09-04 00:33:51 | [diff] [blame] | 46 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 | [diff] [blame] | 47 | } |
| 48 | } break; |
Enrico Granata | 419d791 | 2015-09-04 00:33:51 | [diff] [blame] | 49 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 | [diff] [blame] | 50 | } |
| 51 | if (sstr.GetSize() > 0) { |
| 52 | stream.Printf("(%s)", sstr.GetData()); |
| 53 | return true; |
| 54 | } else |
| 55 | return false; |
Enrico Granata | 419d791 | 2015-09-04 00:33:51 | [diff] [blame] | 56 | } |