summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp')
-rw-r--r--lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp59
1 files changed, 26 insertions, 33 deletions
diff --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
index 3e06fca2504c..9b0c06bcccab 100644
--- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
+++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
@@ -1,4 +1,4 @@
-//===-- EmulateInstructionARM64.cpp ------------------------------*- C++-*-===//
+//===-- EmulateInstructionARM64.cpp ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,6 @@
#include "EmulateInstructionARM64.h"
-#include <stdlib.h>
-
#include "lldb/Core/Address.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Symbol/UnwindPlan.h"
@@ -18,10 +16,14 @@
#include "lldb/Utility/RegisterValue.h"
#include "lldb/Utility/Stream.h"
+#include "llvm/Support/CheckedArithmetic.h"
+
#include "Plugins/Process/Utility/ARMDefines.h"
#include "Plugins/Process/Utility/ARMUtils.h"
#include "Plugins/Process/Utility/lldb-arm64-register-enums.h"
+#include <cstdlib>
+
#define GPR_OFFSET(idx) ((idx)*8)
#define GPR_OFFSET_NAME(reg) 0
#define FPU_OFFSET(idx) ((idx)*16)
@@ -47,6 +49,8 @@
using namespace lldb;
using namespace lldb_private;
+LLDB_PLUGIN_DEFINE_ADV(EmulateInstructionARM64, InstructionARM64)
+
static bool LLDBTableGetRegisterInfo(uint32_t reg_num, RegisterInfo &reg_info) {
if (reg_num >= llvm::array_lengthof(g_register_infos_arm64_le))
return false;
@@ -83,23 +87,6 @@ static inline uint64_t LSL(uint64_t x, integer shift) {
return x << shift;
}
-// AddWithCarry()
-// ===============
-static inline uint64_t
-AddWithCarry(uint32_t N, uint64_t x, uint64_t y, bit carry_in,
- EmulateInstructionARM64::ProcState &proc_state) {
- uint64_t unsigned_sum = UInt(x) + UInt(y) + UInt(carry_in);
- int64_t signed_sum = SInt(x) + SInt(y) + UInt(carry_in);
- uint64_t result = unsigned_sum;
- if (N < 64)
- result = Bits64(result, N - 1, 0);
- proc_state.N = Bit64(result, N - 1);
- proc_state.Z = IsZero(result);
- proc_state.C = UInt(result) == unsigned_sum;
- proc_state.V = SInt(result) == signed_sum;
- return result;
-}
-
// ConstrainUnpredictable()
// ========================
@@ -415,20 +402,12 @@ bool EmulateInstructionARM64::EvaluateInstruction(uint32_t evaluate_options) {
if (opcode_data == nullptr)
return false;
- // printf ("opcode template for 0x%8.8x: %s\n", opcode, opcode_data->name);
const bool auto_advance_pc =
evaluate_options & eEmulateInstructionOptionAutoAdvancePC;
m_ignore_conditions =
evaluate_options & eEmulateInstructionOptionIgnoreConditions;
bool success = false;
- // if (m_opcode_cpsr == 0 || m_ignore_conditions == false)
- // {
- // m_opcode_cpsr = ReadRegisterUnsigned (eRegisterKindLLDB,
- // gpr_cpsr_arm64,
- // 0,
- // &success);
- // }
// Only return false if we are unable to read the CPSR if we care about
// conditions
@@ -454,7 +433,7 @@ bool EmulateInstructionARM64::EvaluateInstruction(uint32_t evaluate_options) {
if (!success)
return false;
- if (auto_advance_pc && (new_pc_value == orig_pc_value)) {
+ if (new_pc_value == orig_pc_value) {
EmulateInstruction::Context context;
context.type = eContextAdvancePC;
context.SetNoArgs();
@@ -588,6 +567,24 @@ bool EmulateInstructionARM64::ConditionHolds(const uint32_t cond) {
return result;
}
+uint64_t EmulateInstructionARM64::
+AddWithCarry(uint32_t N, uint64_t x, uint64_t y, bit carry_in,
+ EmulateInstructionARM64::ProcState &proc_state) {
+ uint64_t unsigned_sum = UInt(x) + UInt(y) + UInt(carry_in);
+ llvm::Optional<int64_t> signed_sum = llvm::checkedAdd(SInt(x), SInt(y));
+ bool overflow = !signed_sum;
+ if (!overflow)
+ overflow |= !llvm::checkedAdd(*signed_sum, SInt(carry_in));
+ uint64_t result = unsigned_sum;
+ if (N < 64)
+ result = Bits64(result, N - 1, 0);
+ proc_state.N = Bit64(result, N - 1);
+ proc_state.Z = IsZero(result);
+ proc_state.C = UInt(result) != unsigned_sum;
+ proc_state.V = overflow;
+ return result;
+}
+
bool EmulateInstructionARM64::EmulateADDSUBImm(const uint32_t opcode) {
// integer d = UInt(Rd);
// integer n = UInt(Rn);
@@ -783,10 +780,6 @@ bool EmulateInstructionARM64::EmulateLDPSTP(const uint32_t opcode) {
RegisterValue data_Rt;
RegisterValue data_Rt2;
-
- // if (vector)
- // CheckFPEnabled(false);
-
RegisterInfo reg_info_base;
RegisterInfo reg_info_Rt;
RegisterInfo reg_info_Rt2;