forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldb][Process] Introduce LoongArch64 hw break/watchpoint support
This patch adds support for setting/clearing hardware watchpoints and breakpoints on LoongArch 64-bit hardware. Refer to the following document for the hw break/watchpoint: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#control-and-status-registers-related-to-watchpoints Fix Failed Tests: lldb-shell :: Subprocess/clone-follow-child-wp.test lldb-shell :: Subprocess/clone-follow-parent-wp.test lldb-shell :: Subprocess/fork-follow-child-wp.test lldb-shell :: Subprocess/fork-follow-parent-wp.test lldb-shell :: Subprocess/vfork-follow-child-wp.test lldb-shell :: Subprocess/vfork-follow-parent-wp.test lldb-shell :: Watchpoint/ExpressionLanguage.test Depends on: llvm#118043 Reviewed By: SixWeining Pull Request: llvm#118770
- Loading branch information
Showing
7 changed files
with
192 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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
65 changes: 65 additions & 0 deletions
65
lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_loongarch.cpp
This file contains 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,65 @@ | ||
//===-- NativeRegisterContextDBReg_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 "NativeRegisterContextDBReg_loongarch.h" | ||
|
||
#include "lldb/Utility/LLDBLog.h" | ||
#include "lldb/Utility/Log.h" | ||
#include "lldb/Utility/RegisterValue.h" | ||
|
||
using namespace lldb_private; | ||
|
||
uint32_t | ||
NativeRegisterContextDBReg_loongarch::GetWatchpointSize(uint32_t wp_index) { | ||
Log *log = GetLog(LLDBLog::Watchpoints); | ||
LLDB_LOG(log, "wp_index: {0}", wp_index); | ||
|
||
switch ((m_hwp_regs[wp_index].control >> 10) & 0x3) { | ||
case 0x0: | ||
return 8; | ||
case 0x1: | ||
return 4; | ||
case 0x2: | ||
return 2; | ||
case 0x3: | ||
return 1; | ||
default: | ||
return 0; | ||
} | ||
} | ||
|
||
std::optional<NativeRegisterContextDBReg::WatchpointDetails> | ||
NativeRegisterContextDBReg_loongarch::AdjustWatchpoint( | ||
const WatchpointDetails &details) { | ||
// LoongArch only needs to check the size; it does not need to check the | ||
// address. | ||
size_t size = details.size; | ||
if (size != 1 && size != 2 && size != 4 && size != 8) | ||
return std::nullopt; | ||
|
||
return details; | ||
} | ||
|
||
uint32_t | ||
NativeRegisterContextDBReg_loongarch::MakeBreakControlValue(size_t size) { | ||
// Return encoded hardware breakpoint control value. | ||
return m_hw_dbg_enable_bit; | ||
} | ||
|
||
uint32_t NativeRegisterContextDBReg_loongarch::MakeWatchControlValue( | ||
size_t size, uint32_t watch_flags) { | ||
// Encoding hardware watchpoint control value. | ||
// Size encoded: | ||
// case 1 : 0b11 | ||
// case 2 : 0b10 | ||
// case 4 : 0b01 | ||
// case 8 : 0b00 | ||
size_t encoded_size = (3 - llvm::Log2_32(size)) << 10; | ||
|
||
return m_hw_dbg_enable_bit | encoded_size | (watch_flags << 8); | ||
} |
34 changes: 34 additions & 0 deletions
34
lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_loongarch.h
This file contains 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,34 @@ | ||
//===-- NativeRegisterContextDBReg_loongarch.h ------------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef lldb_NativeRegisterContextDBReg_loongarch_h | ||
#define lldb_NativeRegisterContextDBReg_loongarch_h | ||
|
||
#include "Plugins/Process/Utility/NativeRegisterContextDBReg.h" | ||
|
||
namespace lldb_private { | ||
|
||
class NativeRegisterContextDBReg_loongarch : public NativeRegisterContextDBReg { | ||
public: | ||
NativeRegisterContextDBReg_loongarch() | ||
: NativeRegisterContextDBReg(/*enable_bit=*/0x10U) {} | ||
|
||
private: | ||
uint32_t GetWatchpointSize(uint32_t wp_index) override; | ||
|
||
std::optional<WatchpointDetails> | ||
AdjustWatchpoint(const WatchpointDetails &details) override; | ||
|
||
uint32_t MakeBreakControlValue(size_t size) override; | ||
|
||
uint32_t MakeWatchControlValue(size_t size, uint32_t watch_flags) override; | ||
}; | ||
|
||
} // namespace lldb_private | ||
|
||
#endif // #ifndef lldb_NativeRegisterContextDBReg_loongarch_h |
This file contains 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 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