Skip to content

Commit a3be778

Browse files
seehearfeelDavidSpickett
authored andcommitted
[LLDB] [LoongArch] Add minimal LoongArch support
Add as little code as possible to allow compiling lldb on LoongArch. Actual functionality will be implemented later. Reviewed By: SixWeining, DavidSpickett Differential Revision: https://reviews.llvm.org/D136578
1 parent 76745d2 commit a3be778

File tree

6 files changed

+293
-0
lines changed

6 files changed

+293
-0
lines changed

lldb/source/Plugins/Process/Linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_lldb_library(lldbPluginProcessLinux
88
NativeRegisterContextLinux.cpp
99
NativeRegisterContextLinux_arm.cpp
1010
NativeRegisterContextLinux_arm64.cpp
11+
NativeRegisterContextLinux_loongarch64.cpp
1112
NativeRegisterContextLinux_ppc64le.cpp
1213
NativeRegisterContextLinux_riscv64.cpp
1314
NativeRegisterContextLinux_s390x.cpp
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//===-- NativeRegisterContextLinux_loongarch64.cpp ------------------------===//
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+
#if defined(__loongarch__) && __loongarch_grlen == 64
10+
11+
#include "NativeRegisterContextLinux_loongarch64.h"
12+
13+
#include "lldb/Host/HostInfo.h"
14+
#include "lldb/Utility/DataBufferHeap.h"
15+
#include "lldb/Utility/Log.h"
16+
#include "lldb/Utility/RegisterValue.h"
17+
#include "lldb/Utility/Status.h"
18+
19+
#include "Plugins/Process/Linux/NativeProcessLinux.h"
20+
#include "Plugins/Process/Linux/Procfs.h"
21+
22+
using namespace lldb;
23+
using namespace lldb_private;
24+
using namespace lldb_private::process_linux;
25+
26+
std::unique_ptr<NativeRegisterContextLinux>
27+
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
28+
const ArchSpec &target_arch, NativeThreadLinux &native_thread) {
29+
switch (target_arch.GetMachine()) {
30+
case llvm::Triple::loongarch64: {
31+
Flags opt_regsets;
32+
auto register_info_up = std::make_unique<RegisterInfoPOSIX_loongarch64>(
33+
target_arch, opt_regsets);
34+
return std::make_unique<NativeRegisterContextLinux_loongarch64>(
35+
target_arch, native_thread, std::move(register_info_up));
36+
}
37+
default:
38+
llvm_unreachable("have no register context for architecture");
39+
}
40+
}
41+
42+
llvm::Expected<ArchSpec>
43+
NativeRegisterContextLinux::DetermineArchitecture(lldb::tid_t tid) {
44+
return HostInfo::GetArchitecture();
45+
}
46+
47+
NativeRegisterContextLinux_loongarch64::NativeRegisterContextLinux_loongarch64(
48+
const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
49+
std::unique_ptr<RegisterInfoPOSIX_loongarch64> register_info_up)
50+
: NativeRegisterContextRegisterInfo(native_thread,
51+
register_info_up.release()),
52+
NativeRegisterContextLinux(native_thread) {
53+
::memset(&m_fpr, 0, sizeof(m_fpr));
54+
::memset(&m_gpr, 0, sizeof(m_gpr));
55+
}
56+
57+
const RegisterInfoPOSIX_loongarch64 &
58+
NativeRegisterContextLinux_loongarch64::GetRegisterInfo() const {
59+
return static_cast<const RegisterInfoPOSIX_loongarch64 &>(
60+
NativeRegisterContextRegisterInfo::GetRegisterInfoInterface());
61+
}
62+
63+
uint32_t NativeRegisterContextLinux_loongarch64::GetRegisterSetCount() const {
64+
return GetRegisterInfo().GetRegisterSetCount();
65+
}
66+
67+
const RegisterSet *NativeRegisterContextLinux_loongarch64::GetRegisterSet(
68+
uint32_t set_index) const {
69+
return GetRegisterInfo().GetRegisterSet(set_index);
70+
}
71+
72+
Status NativeRegisterContextLinux_loongarch64::ReadRegister(
73+
const RegisterInfo *reg_info, RegisterValue &reg_value) {
74+
return Status("Failed to read register value");
75+
}
76+
77+
Status NativeRegisterContextLinux_loongarch64::WriteRegister(
78+
const RegisterInfo *reg_info, const RegisterValue &reg_value) {
79+
return Status("Failed to write register value");
80+
}
81+
82+
Status NativeRegisterContextLinux_loongarch64::ReadAllRegisterValues(
83+
lldb::WritableDataBufferSP &data_sp) {
84+
return Status("Failed to read all register values");
85+
}
86+
87+
Status NativeRegisterContextLinux_loongarch64::WriteAllRegisterValues(
88+
const lldb::DataBufferSP &data_sp) {
89+
return Status("Failed to write all register values");
90+
}
91+
92+
#endif // defined(__loongarch__) && __loongarch_grlen == 64
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//===-- NativeRegisterContextLinux_loongarch64.h ----------------*- C++ -*-===//
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+
#if defined(__loongarch__) && __loongarch_grlen == 64
10+
11+
#ifndef lldb_NativeRegisterContextLinux_loongarch64_h
12+
#define lldb_NativeRegisterContextLinux_loongarch64_h
13+
14+
#include "Plugins/Process/Linux/NativeRegisterContextLinux.h"
15+
#include "Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.h"
16+
17+
#include <asm/ptrace.h>
18+
19+
namespace lldb_private {
20+
namespace process_linux {
21+
22+
class NativeProcessLinux;
23+
24+
class NativeRegisterContextLinux_loongarch64
25+
: public NativeRegisterContextLinux {
26+
public:
27+
NativeRegisterContextLinux_loongarch64(
28+
const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
29+
std::unique_ptr<RegisterInfoPOSIX_loongarch64> register_info_up);
30+
31+
uint32_t GetRegisterSetCount() const override;
32+
33+
const RegisterSet *GetRegisterSet(uint32_t set_index) const override;
34+
35+
Status ReadRegister(const RegisterInfo *reg_info,
36+
RegisterValue &reg_value) override;
37+
38+
Status WriteRegister(const RegisterInfo *reg_info,
39+
const RegisterValue &reg_value) override;
40+
41+
Status ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override;
42+
43+
Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
44+
45+
protected:
46+
void *GetGPRBuffer() override { return &m_gpr; }
47+
48+
void *GetFPRBuffer() override { return &m_fpr; }
49+
50+
size_t GetGPRSize() const override { return GetRegisterInfo().GetGPRSize(); }
51+
52+
size_t GetFPRSize() override { return GetRegisterInfo().GetFPRSize(); }
53+
54+
private:
55+
RegisterInfoPOSIX_loongarch64::GPR m_gpr;
56+
57+
RegisterInfoPOSIX_loongarch64::FPR m_fpr;
58+
59+
const RegisterInfoPOSIX_loongarch64 &GetRegisterInfo() const;
60+
};
61+
62+
} // namespace process_linux
63+
} // namespace lldb_private
64+
65+
#endif // #ifndef lldb_NativeRegisterContextLinux_loongarch64_h
66+
67+
#endif // defined(__loongarch__) && __loongarch_grlen == 64

lldb/source/Plugins/Process/Utility/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ add_lldb_library(lldbPluginProcessUtility
4949
RegisterContextWindows_x86_64.cpp
5050
RegisterInfoPOSIX_arm.cpp
5151
RegisterInfoPOSIX_arm64.cpp
52+
RegisterInfoPOSIX_loongarch64.cpp
5253
RegisterInfoPOSIX_ppc64le.cpp
5354
RegisterInfoPOSIX_riscv64.cpp
5455
StopInfoMachException.cpp
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//===-- RegisterInfoPOSIX_loongarch64.cpp --------------------------------===//
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+
#include <cassert>
10+
#include <lldb/Utility/Flags.h>
11+
#include <stddef.h>
12+
13+
#include "lldb/lldb-defines.h"
14+
#include "llvm/Support/Compiler.h"
15+
16+
#include "RegisterInfoPOSIX_loongarch64.h"
17+
18+
const lldb_private::RegisterInfo *
19+
RegisterInfoPOSIX_loongarch64::GetRegisterInfoPtr(
20+
const lldb_private::ArchSpec &target_arch) {
21+
switch (target_arch.GetMachine()) {
22+
default:
23+
assert(false && "Unhandled target architecture.");
24+
return nullptr;
25+
}
26+
}
27+
28+
uint32_t RegisterInfoPOSIX_loongarch64::GetRegisterInfoCount(
29+
const lldb_private::ArchSpec &target_arch) {
30+
switch (target_arch.GetMachine()) {
31+
default:
32+
assert(false && "Unhandled target architecture.");
33+
return 0;
34+
}
35+
}
36+
37+
RegisterInfoPOSIX_loongarch64::RegisterInfoPOSIX_loongarch64(
38+
const lldb_private::ArchSpec &target_arch, lldb_private::Flags flags)
39+
: lldb_private::RegisterInfoAndSetInterface(target_arch),
40+
m_register_info_p(GetRegisterInfoPtr(target_arch)),
41+
m_register_info_count(GetRegisterInfoCount(target_arch)) {}
42+
43+
uint32_t RegisterInfoPOSIX_loongarch64::GetRegisterCount() const { return 0; }
44+
45+
size_t RegisterInfoPOSIX_loongarch64::GetGPRSize() const {
46+
return sizeof(struct RegisterInfoPOSIX_loongarch64::GPR);
47+
}
48+
49+
size_t RegisterInfoPOSIX_loongarch64::GetFPRSize() const {
50+
return sizeof(struct RegisterInfoPOSIX_loongarch64::FPR);
51+
}
52+
53+
const lldb_private::RegisterInfo *
54+
RegisterInfoPOSIX_loongarch64::GetRegisterInfo() const {
55+
return m_register_info_p;
56+
}
57+
58+
size_t RegisterInfoPOSIX_loongarch64::GetRegisterSetCount() const { return 0; }
59+
60+
size_t RegisterInfoPOSIX_loongarch64::GetRegisterSetFromRegisterIndex(
61+
uint32_t reg_index) const {
62+
return LLDB_INVALID_REGNUM;
63+
}
64+
65+
const lldb_private::RegisterSet *
66+
RegisterInfoPOSIX_loongarch64::GetRegisterSet(size_t set_index) const {
67+
return nullptr;
68+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//===-- RegisterInfoPOSIX_loongarch64.h -------------------------*- C++ -*-===//
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_PROCESS_UTILITY_REGISTERINFOPOSIX_LOONGARCH64_H
10+
#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERINFOPOSIX_LOONGARCH64_H
11+
12+
#include "RegisterInfoAndSetInterface.h"
13+
#include "lldb/Target/RegisterContext.h"
14+
#include "lldb/lldb-private.h"
15+
#include <map>
16+
17+
class RegisterInfoPOSIX_loongarch64
18+
: public lldb_private::RegisterInfoAndSetInterface {
19+
public:
20+
static const lldb_private::RegisterInfo *
21+
GetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch);
22+
static uint32_t
23+
GetRegisterInfoCount(const lldb_private::ArchSpec &target_arch);
24+
25+
public:
26+
struct GPR {
27+
uint64_t gpr[32];
28+
29+
uint64_t orig_a0;
30+
uint64_t csr_era;
31+
uint64_t csr_badv;
32+
uint64_t reserved[10];
33+
};
34+
35+
struct FPR {
36+
uint64_t fpr[32];
37+
uint64_t fcc;
38+
uint32_t fcsr;
39+
};
40+
41+
RegisterInfoPOSIX_loongarch64(const lldb_private::ArchSpec &target_arch,
42+
lldb_private::Flags flags);
43+
44+
size_t GetGPRSize() const override;
45+
46+
size_t GetFPRSize() const override;
47+
48+
const lldb_private::RegisterInfo *GetRegisterInfo() const override;
49+
50+
uint32_t GetRegisterCount() const override;
51+
52+
const lldb_private::RegisterSet *
53+
GetRegisterSet(size_t reg_set) const override;
54+
55+
size_t GetRegisterSetCount() const override;
56+
57+
size_t GetRegisterSetFromRegisterIndex(uint32_t reg_index) const override;
58+
59+
private:
60+
const lldb_private::RegisterInfo *m_register_info_p;
61+
uint32_t m_register_info_count;
62+
};
63+
64+
#endif

0 commit comments

Comments
 (0)