Coverage Report

Created: 2023-09-21 18:56

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h
Line
Count
Source (jump to first uncovered line)
1
//===-- EmulateInstructionRISCV.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
#ifndef LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_EMULATEINSTRUCTIONRISCV_H
10
#define LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_EMULATEINSTRUCTIONRISCV_H
11
12
#include "RISCVInstructions.h"
13
14
#include "lldb/Core/EmulateInstruction.h"
15
#include "lldb/Interpreter/OptionValue.h"
16
#include "lldb/Utility/Log.h"
17
#include "lldb/Utility/RegisterValue.h"
18
#include "lldb/Utility/Status.h"
19
#include <optional>
20
21
namespace lldb_private {
22
23
class EmulateInstructionRISCV : public EmulateInstruction {
24
public:
25
3.92k
  static llvm::StringRef GetPluginNameStatic() { return "riscv"; }
26
27
3.92k
  static llvm::StringRef GetPluginDescriptionStatic() {
28
3.92k
    return "Emulate instructions for the RISC-V architecture.";
29
3.92k
  }
30
31
16.7k
  static bool SupportsThisInstructionType(InstructionType inst_type) {
32
16.7k
    switch (inst_type) {
33
0
    case eInstructionTypeAny:
34
0
    case eInstructionTypePCModifying:
35
0
      return true;
36
16.7k
    case eInstructionTypePrologueEpilogue:
37
16.7k
    case eInstructionTypeAll:
38
16.7k
      return false;
39
16.7k
    }
40
0
    llvm_unreachable("Fully covered switch above!");
41
0
  }
42
43
  static bool SupportsThisArch(const ArchSpec &arch);
44
45
  static lldb_private::EmulateInstruction *
46
  CreateInstance(const lldb_private::ArchSpec &arch, InstructionType inst_type);
47
48
  static void Initialize();
49
50
  static void Terminate();
51
52
public:
53
37
  EmulateInstructionRISCV(const ArchSpec &arch) : EmulateInstruction(arch) {}
54
55
0
  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
56
57
0
  bool SupportsEmulatingInstructionsOfType(InstructionType inst_type) override {
58
0
    return SupportsThisInstructionType(inst_type);
59
0
  }
60
61
  bool SetTargetTriple(const ArchSpec &arch) override;
62
  bool ReadInstruction() override;
63
  bool EvaluateInstruction(uint32_t options) override;
64
  bool TestEmulation(Stream &out_stream, ArchSpec &arch,
65
                     OptionValueDictionary *test_data) override;
66
  std::optional<RegisterInfo> GetRegisterInfo(lldb::RegisterKind reg_kind,
67
                                              uint32_t reg_num) override;
68
69
  std::optional<lldb::addr_t> ReadPC();
70
  bool WritePC(lldb::addr_t pc);
71
72
  std::optional<DecodeResult> ReadInstructionAt(lldb::addr_t addr);
73
  std::optional<DecodeResult> Decode(uint32_t inst);
74
  bool Execute(DecodeResult inst, bool ignore_cond);
75
76
  template <typename T>
77
  std::enable_if_t<std::is_integral_v<T>, std::optional<T>>
78
60
  ReadMem(uint64_t addr) {
79
60
    EmulateInstructionRISCV::Context ctx;
80
60
    ctx.type = EmulateInstruction::eContextRegisterLoad;
81
60
    ctx.SetNoArgs();
82
60
    bool success = false;
83
60
    T result = ReadMemoryUnsigned(ctx, addr, sizeof(T), T(), &success);
84
60
    if (!success)
85
0
      return {}; // aka return false
86
60
    return result;
87
60
  }
Unexecuted instantiation: std::__1::enable_if<std::is_integral_v<unsigned char>, std::__1::optional<unsigned char> >::type lldb_private::EmulateInstructionRISCV::ReadMem<unsigned char>(unsigned long long)
Unexecuted instantiation: std::__1::enable_if<std::is_integral_v<unsigned short>, std::__1::optional<unsigned short> >::type lldb_private::EmulateInstructionRISCV::ReadMem<unsigned short>(unsigned long long)
std::__1::enable_if<std::is_integral_v<unsigned long long>, std::__1::optional<unsigned long long> >::type lldb_private::EmulateInstructionRISCV::ReadMem<unsigned long long>(unsigned long long)
Line
Count
Source
78
25
  ReadMem(uint64_t addr) {
79
25
    EmulateInstructionRISCV::Context ctx;
80
25
    ctx.type = EmulateInstruction::eContextRegisterLoad;
81
25
    ctx.SetNoArgs();
82
25
    bool success = false;
83
25
    T result = ReadMemoryUnsigned(ctx, addr, sizeof(T), T(), &success);
84
25
    if (!success)
85
0
      return {}; // aka return false
86
25
    return result;
87
25
  }
std::__1::enable_if<std::is_integral_v<unsigned int>, std::__1::optional<unsigned int> >::type lldb_private::EmulateInstructionRISCV::ReadMem<unsigned int>(unsigned long long)
Line
Count
Source
78
35
  ReadMem(uint64_t addr) {
79
35
    EmulateInstructionRISCV::Context ctx;
80
35
    ctx.type = EmulateInstruction::eContextRegisterLoad;
81
35
    ctx.SetNoArgs();
82
35
    bool success = false;
83
35
    T result = ReadMemoryUnsigned(ctx, addr, sizeof(T), T(), &success);
84
35
    if (!success)
85
0
      return {}; // aka return false
86
35
    return result;
87
35
  }
88
89
38
  template <typename T> bool WriteMem(uint64_t addr, uint64_t value) {
90
38
    EmulateInstructionRISCV::Context ctx;
91
38
    ctx.type = EmulateInstruction::eContextRegisterStore;
92
38
    ctx.SetNoArgs();
93
38
    return WriteMemoryUnsigned(ctx, addr, value, sizeof(T));
94
38
  }
Unexecuted instantiation: bool lldb_private::EmulateInstructionRISCV::WriteMem<unsigned char>(unsigned long long, unsigned long long)
Unexecuted instantiation: bool lldb_private::EmulateInstructionRISCV::WriteMem<unsigned short>(unsigned long long, unsigned long long)
bool lldb_private::EmulateInstructionRISCV::WriteMem<unsigned int>(unsigned long long, unsigned long long)
Line
Count
Source
89
20
  template <typename T> bool WriteMem(uint64_t addr, uint64_t value) {
90
20
    EmulateInstructionRISCV::Context ctx;
91
20
    ctx.type = EmulateInstruction::eContextRegisterStore;
92
20
    ctx.SetNoArgs();
93
20
    return WriteMemoryUnsigned(ctx, addr, value, sizeof(T));
94
20
  }
bool lldb_private::EmulateInstructionRISCV::WriteMem<unsigned long long>(unsigned long long, unsigned long long)
Line
Count
Source
89
18
  template <typename T> bool WriteMem(uint64_t addr, uint64_t value) {
90
18
    EmulateInstructionRISCV::Context ctx;
91
18
    ctx.type = EmulateInstruction::eContextRegisterStore;
92
18
    ctx.SetNoArgs();
93
18
    return WriteMemoryUnsigned(ctx, addr, value, sizeof(T));
94
18
  }
95
96
  llvm::RoundingMode GetRoundingMode();
97
  bool SetAccruedExceptions(llvm::APFloatBase::opStatus);
98
99
private:
100
  /// Last decoded instruction from m_opcode
101
  DecodeResult m_decoded;
102
};
103
104
} // namespace lldb_private
105
106
#endif // LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_EMULATEINSTRUCTIONRISCV_H