Coverage Report

Created: 2023-11-11 10:31

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/DataFormatters/CXXFunctionPointer.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- CXXFunctionPointer.cpp---------------------------------------------===//
2
//
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
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "lldb/DataFormatters/CXXFunctionPointer.h"
10
11
#include "lldb/Core/ValueObject.h"
12
#include "lldb/Target/ABI.h"
13
#include "lldb/Target/SectionLoadList.h"
14
#include "lldb/Target/Target.h"
15
#include "lldb/Utility/Stream.h"
16
#include "lldb/lldb-enumerations.h"
17
18
#include <string>
19
20
using namespace lldb;
21
using namespace lldb_private;
22
using namespace lldb_private::formatters;
23
24
bool lldb_private::formatters::CXXFunctionPointerSummaryProvider(
25
189
    ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
26
189
  std::string destination;
27
189
  StreamString sstr;
28
189
  AddressType func_ptr_address_type = eAddressTypeInvalid;
29
189
  addr_t func_ptr_address = valobj.GetPointerValue(&func_ptr_address_type);
30
189
  if (func_ptr_address != 0 && 
func_ptr_address != 171
LLDB_INVALID_ADDRESS171
) {
31
171
    switch (func_ptr_address_type) {
32
0
    case eAddressTypeInvalid:
33
0
    case eAddressTypeFile:
34
0
    case eAddressTypeHost:
35
0
      break;
36
37
171
    case eAddressTypeLoad: {
38
171
      ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
39
40
171
      Address so_addr;
41
171
      Target *target = exe_ctx.GetTargetPtr();
42
171
      if (target && !target->GetSectionLoadList().IsEmpty()) {
43
171
        target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
44
171
                                                        so_addr);
45
171
        if (so_addr.GetSection() == nullptr) {
46
          // If we have an address that doesn't correspond to any symbol,
47
          // it might have authentication bits.  Strip them & see if it
48
          // now points to a symbol -- if so, do the SymbolContext lookup
49
          // based on the stripped address.
50
          // If we find a symbol with the ptrauth bits stripped, print the
51
          // raw value into the stream, and replace the Address with the
52
          // one that points to a symbol for a fuller description.
53
23
          if (Process *process = exe_ctx.GetProcessPtr()) {
54
23
            if (ABISP abi_sp = process->GetABI()) {
55
23
              addr_t fixed_addr = abi_sp->FixCodeAddress(func_ptr_address);
56
23
              if (fixed_addr != func_ptr_address) {
57
0
                Address test_address;
58
0
                test_address.SetLoadAddress(fixed_addr, target);
59
0
                if (test_address.GetSection() != nullptr) {
60
0
                  int addrsize = target->GetArchitecture().GetAddressByteSize();
61
0
                  sstr.Printf("actual=0x%*.*" PRIx64 " ", addrsize * 2,
62
0
                              addrsize * 2, fixed_addr);
63
0
                  so_addr = test_address;
64
0
                }
65
0
              }
66
23
            }
67
23
          }
68
23
        }
69
70
171
        if (so_addr.IsValid()) {
71
148
          so_addr.Dump(&sstr, exe_ctx.GetBestExecutionContextScope(),
72
148
                       Address::DumpStyleResolvedDescription,
73
148
                       Address::DumpStyleSectionNameOffset);
74
148
        }
75
171
      }
76
171
    } break;
77
171
    }
78
171
  }
79
189
  if (sstr.GetSize() > 0) {
80
148
    if (valobj.GetValueType() == lldb::eValueTypeVTableEntry)
81
13
      stream.PutCString(sstr.GetData());
82
135
    else
83
135
      stream.Printf("(%s)", sstr.GetData());
84
148
    return true;
85
148
  } else
86
41
    return false;
87
189
}