25#include "llvm/Support/Endian.h"
34 "Arm-specific algorithms",
82 const uint32_t cpsr = reg_ctx_sp->GetFlags(0);
87 const uint32_t J =
Bit32(cpsr, 24);
88 const uint32_t T =
Bit32(cpsr, 5);
89 const uint32_t ISETSTATE = J << 1 | T;
102 const addr_t pc = reg_ctx_sp->GetPC();
106 const uint64_t opcode = thread.GetProcess()->ReadUnsignedIntegerFromMemory(
pc, 4,
UINT64_MAX,
error);
109 const uint32_t condition =
Bits32((uint32_t)opcode, 31, 28);
119 }
else if (ISETSTATE == 1) {
121 const uint32_t ITSTATE =
Bits32(cpsr, 15, 10) << 2 |
Bits32(cpsr, 26, 25);
123 const uint32_t condition =
Bits32(ITSTATE, 7, 4);
136 bool is_alternate_isa =
false;
138 switch (addr_class) {
143 is_alternate_isa =
true;
148 if ((code_addr & 2u) || is_alternate_isa)
149 return code_addr | 1u;
155 switch (addr_class) {
161 return opcode_addr & ~(1ull);
181 std::shared_ptr<const UnwindPlan> current_unwindplan) {
183 ProcessSP process_sp = thread.GetProcess();
187 const ArchSpec arch = process_sp->GetTarget().GetArchitecture();
201 bool got_concrete_location =
false;
204 got_concrete_location =
true;
211 got_concrete_location =
true;
214 if (!got_concrete_location)
245 const uint32_t exception_return = -1U & ~0b11111U;
247 const uint32_t gprs_only = 0b10000;
249 const uint32_t lowbits = 0b01;
251 if ((callers_return_address & exception_return) != exception_return)
253 if ((callers_return_address & lowbits) != lowbits)
256 const bool fp_regs_saved = !(callers_return_address & gprs_only);
258 const RegisterKind plan_regkind = current_unwindplan->GetRegisterKind();
259 UnwindPlanSP new_plan = std::make_shared<UnwindPlan>(plan_regkind);
260 new_plan->SetSourceName(
"Arm Cortex-M exception return UnwindPlan");
262 new_plan->SetUnwindPlanValidAtAllInstructions(
eLazyBoolYes);
265 int stored_regs_size = fp_regs_saved ? 0x68 : 0x20;
269 const int gpr_reg_count = std::size(gpr_regs);
274 const int fpr_reg_count = std::size(fpr_regs);
277 std::vector<uint32_t> saved_regs;
278 for (
int i = 0; i < gpr_reg_count; i++) {
279 uint32_t regno = gpr_regs[i];
281 plan_regkind, regno);
282 saved_regs.push_back(regno);
285 for (
int i = 0; i < fpr_reg_count; i++) {
286 uint32_t regno = fpr_regs[i];
288 plan_regkind, regno);
289 saved_regs.push_back(regno);
303 uint32_t callers_xPSR =
304 process_sp->ReadUnsignedIntegerFromMemory(cfa + 0x1c, 4, 0,
error);
305 const bool align_stack = callers_xPSR & (1U << 9);
306 uint32_t callers_sp = cfa + stored_regs_size;
312 "ArchitectureArm::GetArchitectureUnwindPlan found caller return "
313 "addr of 0x%" PRIx64
", for frame with CFA 0x%" PRIx64
314 ", fp_regs_saved %d, stored_regs_size 0x%x, align stack %d",
315 callers_return_address, cfa, fp_regs_saved, stored_regs_size,
320 plan_regkind, sp_regnum);
322 const int row_count = current_unwindplan->GetRowCount();
323 for (
int i = 0; i < row_count; i++) {
326 const size_t saved_reg_count = saved_regs.size();
327 for (
size_t j = 0; j < saved_reg_count; j++) {
337 new_plan->AppendRow(row);
343 llvm::ArrayRef<uint8_t> reference, llvm::ArrayRef<uint8_t> observed)
const {
344 if (reference.size() > observed.size())
347 if (reference.size() == 2) {
348 auto ref_bytes = llvm::support::endian::read16le(reference.data());
349 auto obs_bytes = llvm::support::endian::read16le(observed.data());
350 if (ref_bytes == obs_bytes)
354 uint16_t mask = 0xFF00;
355 if ((obs_bytes & mask) == 0xBE00)
357 }
else if (reference.size() == 4) {
358 auto ref_bytes = llvm::support::endian::read32le(reference.data());
359 auto obs_bytes = llvm::support::endian::read32le(observed.data());
360 if (ref_bytes == obs_bytes)
362 uint32_t mask = 0xFFF000F0;
363 uint32_t bkpt_pattern = 0xE1200070;
364 if ((obs_bytes & mask) == bkpt_pattern)
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
A class to represent register numbers, and able to convert between different register numbering schem...
uint32_t GetAsKind(lldb::RegisterKind kind)
An architecture specification class.
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
llvm::Triple & GetTriple()
Architecture triple accessor.
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
bool IsValidTrapInstruction(llvm::ArrayRef< uint8_t > reference, llvm::ArrayRef< uint8_t > observed) const override
Returns whether a given byte sequence is a valid trap instruction for the architecture.
static std::unique_ptr< Architecture > Create(const ArchSpec &arch)
lldb::addr_t GetCallableLoadAddress(lldb::addr_t load_addr, AddressClass addr_class) const override
Get load_addr as a callable code load address for this target.
ArchitectureArm()=default
static llvm::StringRef GetPluginNameStatic()
void OverrideStopInfo(Thread &thread) const override
This is currently intended to handle cases where a program stops at an instruction that won't get exe...
lldb::addr_t GetOpcodeLoadAddress(lldb::addr_t load_addr, AddressClass addr_class) const override
Get load_addr as an opcode for this target.
lldb::UnwindPlanSP GetArchitectureUnwindPlan(lldb_private::Thread &thread, lldb_private::RegisterContextUnwind *regctx, std::shared_ptr< const UnwindPlan > current_unwindplan) override
Return an UnwindPlan that allows architecture-defined rules for finding saved registers,...
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
bool GetCFA(lldb::addr_t &cfa)
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
bool ReadRegisterValueFromRegisterLocation(lldb_private::UnwindLLDB::ConcreteRegisterLocation regloc, const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value)
lldb_private::UnwindLLDB::RegisterSearchResult SavedLocationForRegister(uint32_t lldb_regnum, lldb_private::UnwindLLDB::ConcreteRegisterLocation ®loc)
uint32_t GetAsUInt32(uint32_t fail_value=UINT32_MAX, bool *success_ptr=nullptr) const
bool SetRegisterLocationToIsCFAPlusOffset(uint32_t reg_num, int32_t offset, bool can_replace)
bool SetRegisterLocationToAtCFAPlusOffset(uint32_t reg_num, int32_t offset, bool can_replace)
#define LLDB_REGNUM_GENERIC_RA
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_REGNUM
#define LLDB_REGNUM_GENERIC_PC
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
static bool ARMConditionPassed(const uint32_t condition, const uint32_t cpsr)
static uint32_t Bits32(const uint32_t bits, const uint32_t msbit, const uint32_t lsbit)
static uint32_t Bit32(const uint32_t bits, const uint32_t bit)
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
RegisterKind
Register numbering types.
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindLLDB
lldb's internal register numbers
@ eRegisterKindDWARF
the register numbers seen DWARF
Every register is described in detail including its name, alternate name (optional),...
An UnwindPlan::Row::AbstractRegisterLocation, combined with the register context and memory for a spe...