Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- AArch66.h ---------------------------------------------------------===//
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 "ABIAArch64.h"
10
#include "ABIMacOSX_arm64.h"
11
#include "ABISysV_arm64.h"
12
#include "Utility/ARM64_DWARF_Registers.h"
13
#include "lldb/Core/PluginManager.h"
14
#include "lldb/Target/Process.h"
15
16
#include <bitset>
17
18
LLDB_PLUGIN_DEFINE(ABIAArch64)
19
20
3.44k
void ABIAArch64::Initialize() {
21
3.44k
  ABISysV_arm64::Initialize();
22
3.44k
  ABIMacOSX_arm64::Initialize();
23
3.44k
}
24
25
3.43k
void ABIAArch64::Terminate() {
26
3.43k
  ABISysV_arm64::Terminate();
27
3.43k
  ABIMacOSX_arm64::Terminate();
28
3.43k
}
29
30
6
lldb::addr_t ABIAArch64::FixCodeAddress(lldb::addr_t pc) {
31
6
  if (lldb::ProcessSP process_sp = GetProcessSP())
32
6
    return FixAddress(pc, process_sp->GetCodeAddressMask());
33
0
  return pc;
34
6
}
35
36
0
lldb::addr_t ABIAArch64::FixDataAddress(lldb::addr_t pc) {
37
0
  if (lldb::ProcessSP process_sp = GetProcessSP())
38
0
    return FixAddress(pc, process_sp->GetDataAddressMask());
39
0
  return pc;
40
0
}
41
42
std::pair<uint32_t, uint32_t>
43
267
ABIAArch64::GetEHAndDWARFNums(llvm::StringRef name) {
44
267
  if (name == "pc")
45
6
    return {LLDB_INVALID_REGNUM, arm64_dwarf::pc};
46
261
  if (name == "cpsr")
47
5
    return {LLDB_INVALID_REGNUM, arm64_dwarf::cpsr};
48
256
  return MCBasedABI::GetEHAndDWARFNums(name);
49
261
}
50
51
256
std::string ABIAArch64::GetMCName(std::string reg) {
52
256
  MapRegisterName(reg, "v", "q");
53
256
  MapRegisterName(reg, "x29", "fp");
54
256
  MapRegisterName(reg, "x30", "lr");
55
256
  return reg;
56
256
}
57
58
267
uint32_t ABIAArch64::GetGenericNum(llvm::StringRef name) {
59
267
  return llvm::StringSwitch<uint32_t>(name)
60
267
      .Case("pc", LLDB_REGNUM_GENERIC_PC)
61
267
      .Cases("lr", "x30", LLDB_REGNUM_GENERIC_RA)
62
267
      .Cases("sp", "x31", LLDB_REGNUM_GENERIC_SP)
63
267
      .Cases("fp", "x29", LLDB_REGNUM_GENERIC_FP)
64
267
      .Case("cpsr", LLDB_REGNUM_GENERIC_FLAGS)
65
267
      .Case("x0", LLDB_REGNUM_GENERIC_ARG1)
66
267
      .Case("x1", LLDB_REGNUM_GENERIC_ARG2)
67
267
      .Case("x2", LLDB_REGNUM_GENERIC_ARG3)
68
267
      .Case("x3", LLDB_REGNUM_GENERIC_ARG4)
69
267
      .Case("x4", LLDB_REGNUM_GENERIC_ARG5)
70
267
      .Case("x5", LLDB_REGNUM_GENERIC_ARG6)
71
267
      .Case("x6", LLDB_REGNUM_GENERIC_ARG7)
72
267
      .Case("x7", LLDB_REGNUM_GENERIC_ARG8)
73
267
      .Default(LLDB_INVALID_REGNUM);
74
267
}
75
76
static void addPartialRegisters(
77
    std::vector<lldb_private::DynamicRegisterInfo::Register> &regs,
78
    llvm::ArrayRef<llvm::Optional<uint32_t>> full_reg_indices,
79
    uint32_t full_reg_size, const char *partial_reg_format,
80
12
    uint32_t partial_reg_size, lldb::Encoding encoding, lldb::Format format) {
81
198
  for (auto it : llvm::enumerate(full_reg_indices)) {
82
198
    llvm::Optional<uint32_t> full_reg_index = it.value();
83
198
    if (!full_reg_index ||
84
198
        
regs[full_reg_index.getValue()].byte_size != full_reg_size192
)
85
6
      return;
86
87
192
    lldb_private::DynamicRegisterInfo::Register partial_reg{
88
192
        lldb_private::ConstString(
89
192
            llvm::formatv(partial_reg_format, it.index()).str()),
90
192
        lldb_private::ConstString(),
91
192
        lldb_private::ConstString("supplementary registers"),
92
192
        partial_reg_size,
93
192
        LLDB_INVALID_INDEX32,
94
192
        encoding,
95
192
        format,
96
192
        LLDB_INVALID_REGNUM,
97
192
        LLDB_INVALID_REGNUM,
98
192
        LLDB_INVALID_REGNUM,
99
192
        LLDB_INVALID_REGNUM,
100
192
        {full_reg_index.getValue()},
101
192
        {}};
102
192
    addSupplementaryRegister(regs, partial_reg);
103
192
  }
104
12
}
105
106
void ABIAArch64::AugmentRegisterInfo(
107
6
    std::vector<lldb_private::DynamicRegisterInfo::Register> &regs) {
108
6
  lldb_private::MCBasedABI::AugmentRegisterInfo(regs);
109
110
6
  lldb_private::ConstString sp_string{"sp"};
111
112
6
  std::array<llvm::Optional<uint32_t>, 32> x_regs;
113
6
  std::array<llvm::Optional<uint32_t>, 32> v_regs;
114
115
239
  for (auto it : llvm::enumerate(regs)) {
116
239
    lldb_private::DynamicRegisterInfo::Register &info = it.value();
117
    // GDB sends x31 as "sp".  Add the "x31" alt_name for convenience.
118
239
    if (info.name == sp_string && 
!info.alt_name6
)
119
6
      info.alt_name.SetCString("x31");
120
121
239
    unsigned int reg_num;
122
327
    auto get_reg = [&info, &reg_num](const char *prefix) {
123
327
      llvm::StringRef reg_name = info.name.GetStringRef();
124
327
      llvm::StringRef alt_name = info.alt_name.GetStringRef();
125
327
      return (reg_name.consume_front(prefix) &&
126
327
              
llvm::to_integer(reg_name, reg_num, 10)220
&&
reg_num < 32220
) ||
127
327
             
(107
alt_name.consume_front(prefix)107
&&
128
107
              
llvm::to_integer(alt_name, reg_num, 10)6
&&
reg_num < 326
);
129
327
    };
130
131
239
    if (get_reg("x"))
132
192
      x_regs[reg_num] = it.index();
133
47
    else if (get_reg("v"))
134
32
      v_regs[reg_num] = it.index();
135
    // if we have at least one subregister, abort
136
15
    else if (get_reg("w") || 
get_reg("s")13
||
get_reg("d")13
)
137
2
      return;
138
239
  }
139
140
  // Create aliases for partial registers: wN for xN, and sN/dN for vN.
141
4
  addPartialRegisters(regs, x_regs, 8, "w{0}", 4, lldb::eEncodingUint,
142
4
                      lldb::eFormatHex);
143
4
  addPartialRegisters(regs, v_regs, 16, "s{0}", 4, lldb::eEncodingIEEE754,
144
4
                      lldb::eFormatFloat);
145
4
  addPartialRegisters(regs, v_regs, 16, "d{0}", 8, lldb::eEncodingIEEE754,
146
4
                      lldb::eFormatFloat);
147
4
}