Skip to content

Commit a58dc83

Browse files
committed
Address @SixWeining's comments
Created using spr 1.3.5-bogner
1 parent 8363707 commit a58dc83

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <sstream>
1414

1515
#include "llvm/IR/DerivedTypes.h"
16+
#include "llvm/Support/MathExtras.h"
1617

1718
#include "Utility/LoongArch_DWARF_Registers.h"
1819
#include "lldb/Core/PluginManager.h"
@@ -56,11 +57,11 @@ namespace {
5657
namespace dwarf {
5758
enum regnums {
5859
r0,
59-
ra,
60-
r1 = ra,
60+
r1,
61+
ra = r1,
6162
r2,
62-
sp,
63-
r3 = sp,
63+
r3,
64+
sp = r3,
6465
r4,
6566
r5,
6667
r6,
@@ -79,8 +80,8 @@ enum regnums {
7980
r19,
8081
r20,
8182
r21,
82-
fp,
83-
r22 = fp,
83+
r22,
84+
fp = r22,
8485
r23,
8586
r24,
8687
r25,
@@ -154,7 +155,7 @@ ABISysV_loongarch::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) {
154155
ABISysV_loongarch *abi =
155156
new ABISysV_loongarch(std::move(process_sp), MakeMCRegisterInfo(arch));
156157
if (abi)
157-
abi->SetIsLA64((llvm::Triple::loongarch64 == machine) ? true : false);
158+
abi->SetIsLA64(llvm::Triple::loongarch64 == machine);
158159
return ABISP(abi);
159160
}
160161

@@ -211,11 +212,11 @@ bool ABISysV_loongarch::PrepareTrivialCall(Thread &thread, addr_t sp,
211212
for (auto [idx, arg] : enumerate(args)) {
212213
const RegisterInfo *reg_info = reg_ctx_sp->GetRegisterInfo(
213214
eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + idx);
214-
LLDB_LOG(log, "About to write arg{0} (0x{1:x}) into {2}", idx, arg,
215+
LLDB_LOG(log, "About to write arg{0} ({1:x}) into {2}", idx, arg,
215216
reg_info->name);
216217

217218
if (!reg_ctx_sp->WriteRegisterFromUnsigned(reg_info, arg)) {
218-
LLDB_LOG(log, "Failed to write arg{0} (0x{1:x}) into {2}", idx, arg,
219+
LLDB_LOG(log, "Failed to write arg{0} ({1:x}) into {2}", idx, arg,
219220
reg_info->name);
220221
return false;
221222
}
@@ -231,7 +232,7 @@ bool ABISysV_loongarch::PrepareTrivialCall(Thread &thread, addr_t sp,
231232
LLDB_REGNUM_GENERIC_RA, return_addr))
232233
return false;
233234

234-
LLDB_LOG(log, "ABISysV_riscv::{0}() success", __FUNCTION__);
235+
LLDB_LOG(log, "ABISysV_loongarch::{0}() success", __FUNCTION__);
235236
return true;
236237
}
237238

@@ -288,6 +289,10 @@ Status ABISysV_loongarch::SetReturnValueObject(StackFrameSP &frame_sp,
288289

289290
offset_t offset = 0;
290291
uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
292+
// According to psABI, i32 (no matter signed or unsigned) should be
293+
// sign-extended in register.
294+
if (4 == num_bytes && m_is_la64)
295+
raw_value = llvm::SignExtend64<32>(raw_value);
291296
auto reg_info =
292297
reg_ctx.GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1);
293298
if (!reg_ctx.WriteRegisterFromUnsigned(reg_info, raw_value)) {

lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ class ABISysV_loongarch : public lldb_private::RegInfoBasedABI {
9797

9898
using lldb_private::RegInfoBasedABI::RegInfoBasedABI; // Call CreateInstance
9999
// instead.
100-
bool m_is_la64; // true if target is loongarch64; false if target is
101-
// loongarch32
100+
bool m_is_la64;
102101
};
103102

104103
#endif // LLDB_SOURCE_PLUGINS_ABI_LOONGARCH_ABISYSV_LOONGARCH_H

0 commit comments

Comments
 (0)