-
Notifications
You must be signed in to change notification settings - Fork 16.2k
[lldb][Process/FreeBSDKernel] Add riscv64 support #180670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mchoo7
wants to merge
3
commits into
llvm:main
Choose a base branch
from
mchoo7:rvkern
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_riscv64.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| /// | ||
| /// \file | ||
| /// This file contains the definition of the | ||
| /// RegisterContextFreeBSDKernel_riscv64 class, which is used for reading | ||
| /// registers from PCB in riscv64 kernel dump. | ||
| /// | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "RegisterContextFreeBSDKernel_riscv64.h" | ||
|
|
||
| #include "lldb/Target/Process.h" | ||
| #include "lldb/Target/Thread.h" | ||
| #include "lldb/Utility/RegisterValue.h" | ||
| #include "llvm/Support/Endian.h" | ||
|
|
||
| using namespace lldb; | ||
| using namespace lldb_private; | ||
|
|
||
| RegisterContextFreeBSDKernel_riscv64::RegisterContextFreeBSDKernel_riscv64( | ||
| Thread &thread, std::unique_ptr<RegisterInfoPOSIX_riscv64> register_info_up, | ||
| lldb::addr_t pcb_addr) | ||
| : RegisterContextPOSIX_riscv64(thread, std::move(register_info_up)), | ||
| m_pcb_addr(pcb_addr) {} | ||
|
|
||
| bool RegisterContextFreeBSDKernel_riscv64::ReadGPR() { return true; } | ||
|
|
||
| bool RegisterContextFreeBSDKernel_riscv64::ReadFPR() { return true; } | ||
|
|
||
| bool RegisterContextFreeBSDKernel_riscv64::WriteGPR() { | ||
| assert(0); | ||
| return false; | ||
| } | ||
|
|
||
| bool RegisterContextFreeBSDKernel_riscv64::WriteFPR() { | ||
| assert(0); | ||
| return false; | ||
| } | ||
|
|
||
| bool RegisterContextFreeBSDKernel_riscv64::ReadRegister( | ||
| const RegisterInfo *reg_info, RegisterValue &value) { | ||
| if (m_pcb_addr == LLDB_INVALID_ADDRESS) | ||
| return false; | ||
|
|
||
| // https://cgit.freebsd.org/src/tree/sys/riscv/include/pcb.h | ||
| struct { | ||
| llvm::support::ulittle64_t ra; | ||
| llvm::support::ulittle64_t sp; | ||
| llvm::support::ulittle64_t gp; | ||
| llvm::support::ulittle64_t tp; | ||
| llvm::support::ulittle64_t s[12]; | ||
| } pcb; | ||
|
|
||
| Status error; | ||
| size_t rd = | ||
| m_thread.GetProcess()->ReadMemory(m_pcb_addr, &pcb, sizeof(pcb), error); | ||
| if (rd != sizeof(pcb)) | ||
| return false; | ||
|
|
||
| uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB]; | ||
| switch (reg) { | ||
| case gpr_pc_riscv: | ||
| case gpr_ra_riscv: | ||
| // Supply the RA as PC as well to simulate the PC as if the thread had just | ||
| // returned. | ||
| value = pcb.ra; | ||
| break; | ||
| case gpr_sp_riscv: | ||
| value = pcb.sp; | ||
| break; | ||
| case gpr_gp_riscv: | ||
| value = pcb.gp; | ||
| break; | ||
| case gpr_tp_riscv: | ||
| value = pcb.tp; | ||
| break; | ||
| case gpr_fp_riscv: | ||
| value = pcb.s[0]; | ||
| break; | ||
| case gpr_s1_riscv: | ||
| value = pcb.s[1]; | ||
| break; | ||
| case gpr_s2_riscv: | ||
| case gpr_s3_riscv: | ||
| case gpr_s4_riscv: | ||
| case gpr_s5_riscv: | ||
| case gpr_s6_riscv: | ||
| case gpr_s7_riscv: | ||
| case gpr_s8_riscv: | ||
| case gpr_s9_riscv: | ||
| case gpr_s10_riscv: | ||
| case gpr_s11_riscv: | ||
| value = pcb.s[reg - gpr_s2_riscv]; | ||
| break; | ||
| default: | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| bool RegisterContextFreeBSDKernel_riscv64::WriteRegister( | ||
| const RegisterInfo *reg_info, const RegisterValue &value) { | ||
| return false; | ||
| } | ||
49 changes: 49 additions & 0 deletions
49
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_riscv64.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| /// | ||
| /// \file | ||
| /// This file contains the declaration of the | ||
| /// RegisterContextFreeBSDKernel_riscv64 class, which is used for reading | ||
| /// registers from PCB in riscv64 kernel dump. | ||
| /// | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLDB_SOURCE_PLUGINS_PROCESS_FREEBSDKERNEL_REGISTERCONTEXTFREEBSDKERNEL_RISCV64_H | ||
| #define LLDB_SOURCE_PLUGINS_PROCESS_FREEBSDKERNEL_REGISTERCONTEXTFREEBSDKERNEL_RISCV64_H | ||
|
|
||
| #include "Plugins/Process/Utility/RegisterContextPOSIX_riscv64.h" | ||
| #include "Plugins/Process/elf-core/RegisterUtilities.h" | ||
|
|
||
| class RegisterContextFreeBSDKernel_riscv64 | ||
| : public RegisterContextPOSIX_riscv64 { | ||
| public: | ||
| RegisterContextFreeBSDKernel_riscv64( | ||
| lldb_private::Thread &thread, | ||
| std::unique_ptr<RegisterInfoPOSIX_riscv64> register_info_up, | ||
| lldb::addr_t pcb_addr); | ||
|
|
||
| bool ReadRegister(const lldb_private::RegisterInfo *reg_info, | ||
| lldb_private::RegisterValue &value) override; | ||
|
|
||
| bool WriteRegister(const lldb_private::RegisterInfo *reg_info, | ||
| const lldb_private::RegisterValue &value) override; | ||
|
|
||
| protected: | ||
| bool ReadGPR() override; | ||
|
|
||
| bool ReadFPR() override; | ||
|
|
||
| bool WriteGPR() override; | ||
|
|
||
| bool WriteFPR() override; | ||
|
|
||
| private: | ||
| lldb::addr_t m_pcb_addr; | ||
| }; | ||
|
|
||
| #endif // LLDB_SOURCE_PLUGINS_PROCESS_FREEBSDKERNEL_REGISTERCONTEXTFREEBSDKERNEL_RISCV64_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.