[llvm-branch-commits] [lldb] [lldb][LoongArch] Function calls support in lldb expressions (PR #114742)
Lu Weining via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Nov 5 19:47:11 PST 2024
================
@@ -0,0 +1,672 @@
+//===-- ABISysV_loongarch.cpp----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "ABISysV_loongarch.h"
+
+#include <array>
+#include <limits>
+#include <sstream>
+
+#include "llvm/IR/DerivedTypes.h"
+
+#include "Utility/LoongArch_DWARF_Registers.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Value.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/RegisterValue.h"
+#include "lldb/ValueObject/ValueObjectConstResult.h"
+
+#define DEFINE_REG_NAME(reg_num) ConstString(#reg_num).GetCString()
+#define DEFINE_REG_NAME_STR(reg_name) ConstString(reg_name).GetCString()
+
+// The ABI is not a source of such information as size, offset, encoding, etc.
+// of a register. Just provides correct dwarf and eh_frame numbers.
+
+#define DEFINE_GENERIC_REGISTER_STUB(dwarf_num, generic_num) \
+ { \
+ DEFINE_REG_NAME(dwarf_num), \
+ DEFINE_REG_NAME_STR(nullptr), \
+ 0, \
+ 0, \
+ eEncodingInvalid, \
+ eFormatDefault, \
+ {dwarf_num, dwarf_num, generic_num, LLDB_INVALID_REGNUM, dwarf_num}, \
+ nullptr, \
+ nullptr, \
+ nullptr, \
+ }
+
+#define DEFINE_REGISTER_STUB(dwarf_num) \
+ DEFINE_GENERIC_REGISTER_STUB(dwarf_num, LLDB_INVALID_REGNUM)
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE_ADV(ABISysV_loongarch, ABILoongArch)
+
+namespace {
+namespace dwarf {
+enum regnums {
+ r0,
+ ra,
+ r1 = ra,
+ r2,
+ sp,
+ r3 = sp,
+ r4,
+ r5,
+ r6,
+ r7,
+ r8,
+ r9,
+ r10,
+ r11,
+ r12,
+ r13,
+ r14,
+ r15,
+ r16,
+ r17,
+ r18,
+ r19,
+ r20,
+ r21,
+ fp,
+ r22 = fp,
+ r23,
+ r24,
+ r25,
+ r26,
+ r27,
+ r28,
+ r29,
+ r30,
+ r31,
+ pc
+};
+
+static const std::array<RegisterInfo, 33> g_register_infos = {
+ {DEFINE_REGISTER_STUB(r0),
+ DEFINE_GENERIC_REGISTER_STUB(r1, LLDB_REGNUM_GENERIC_RA),
+ DEFINE_REGISTER_STUB(r2),
+ DEFINE_GENERIC_REGISTER_STUB(r3, LLDB_REGNUM_GENERIC_SP),
+ DEFINE_GENERIC_REGISTER_STUB(r4, LLDB_REGNUM_GENERIC_ARG1),
+ DEFINE_GENERIC_REGISTER_STUB(r5, LLDB_REGNUM_GENERIC_ARG2),
+ DEFINE_GENERIC_REGISTER_STUB(r6, LLDB_REGNUM_GENERIC_ARG3),
+ DEFINE_GENERIC_REGISTER_STUB(r7, LLDB_REGNUM_GENERIC_ARG4),
+ DEFINE_GENERIC_REGISTER_STUB(r8, LLDB_REGNUM_GENERIC_ARG5),
+ DEFINE_GENERIC_REGISTER_STUB(r9, LLDB_REGNUM_GENERIC_ARG6),
+ DEFINE_GENERIC_REGISTER_STUB(r10, LLDB_REGNUM_GENERIC_ARG7),
+ DEFINE_GENERIC_REGISTER_STUB(r11, LLDB_REGNUM_GENERIC_ARG8),
+ DEFINE_REGISTER_STUB(r12),
+ DEFINE_REGISTER_STUB(r13),
+ DEFINE_REGISTER_STUB(r14),
+ DEFINE_REGISTER_STUB(r15),
+ DEFINE_REGISTER_STUB(r16),
+ DEFINE_REGISTER_STUB(r17),
+ DEFINE_REGISTER_STUB(r18),
+ DEFINE_REGISTER_STUB(r19),
+ DEFINE_REGISTER_STUB(r20),
+ DEFINE_REGISTER_STUB(r21),
+ DEFINE_GENERIC_REGISTER_STUB(r22, LLDB_REGNUM_GENERIC_FP),
+ DEFINE_REGISTER_STUB(r23),
+ DEFINE_REGISTER_STUB(r24),
+ DEFINE_REGISTER_STUB(r25),
+ DEFINE_REGISTER_STUB(r26),
+ DEFINE_REGISTER_STUB(r27),
+ DEFINE_REGISTER_STUB(r28),
+ DEFINE_REGISTER_STUB(r29),
+ DEFINE_REGISTER_STUB(r30),
+ DEFINE_REGISTER_STUB(r31),
+ DEFINE_GENERIC_REGISTER_STUB(pc, LLDB_REGNUM_GENERIC_PC)}};
+} // namespace dwarf
+} // namespace
+
+// Number of argument registers (the base integer calling convention
+// provides 8 argument registers, a0-a7)
+static constexpr size_t g_regs_for_args_count = 8U;
+
+const RegisterInfo *ABISysV_loongarch::GetRegisterInfoArray(uint32_t &count) {
+ count = dwarf::g_register_infos.size();
+ return dwarf::g_register_infos.data();
+}
+
+//------------------------------------------------------------------
+// Static Functions
+//------------------------------------------------------------------
+
+ABISP
+ABISysV_loongarch::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) {
+ llvm::Triple::ArchType machine = arch.GetTriple().getArch();
+
+ if (llvm::Triple::loongarch32 != machine &&
+ llvm::Triple::loongarch64 != machine)
+ return ABISP();
+
+ ABISysV_loongarch *abi =
+ new ABISysV_loongarch(std::move(process_sp), MakeMCRegisterInfo(arch));
+ if (abi)
+ abi->SetIsLA64((llvm::Triple::loongarch64 == machine) ? true : false);
----------------
SixWeining wrote:
```suggestion
abi->SetIsLA64(llvm::Triple::loongarch64 == machine);
```
https://github.com/llvm/llvm-project/pull/114742
More information about the llvm-branch-commits
mailing list