-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[lldb][ARM] Port Arm Linux to use NativeRegisterContextDBReg #152284
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
Merged
DavidSpickett
merged 10 commits into
llvm:main
from
DavidSpickett:lldb-arm-bkpts-squashed-with-fn-fix
Aug 27, 2025
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b1a421f
[lldb][ARM] Port Arm Linux to use NativeRegisterContextDBReg
DavidSpickett 6246600
refactor write registers
DavidSpickett 9b066a6
formatting
DavidSpickett 8bccf5f
Remove redundant check
DavidSpickett 67a2c09
update comment
DavidSpickett df17ec4
Inline what AdjustBreakpoint was doing.
DavidSpickett 279dee7
No longer need address argument
DavidSpickett 54607cf
remove stray line
DavidSpickett 8093a60
more stray lines
DavidSpickett f8b65c4
Do in fact need adjustbreakpoint
DavidSpickett 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
557 changes: 57 additions & 500 deletions
557
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
116 changes: 116 additions & 0 deletions
116
lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_arm.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,116 @@ | ||
| //===-- NativeRegisterContextDBReg_arm.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_arm.h" | ||
|
|
||
| #include "lldb/Utility/LLDBLog.h" | ||
| #include "lldb/Utility/Log.h" | ||
| #include "lldb/Utility/RegisterValue.h" | ||
|
|
||
| using namespace lldb_private; | ||
|
|
||
| uint32_t NativeRegisterContextDBReg_arm::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 >> 5) & 0x0f) { | ||
| case 0x01: | ||
| return 1; | ||
| case 0x03: | ||
| return 2; | ||
| case 0x07: | ||
| return 3; | ||
| case 0x0f: | ||
| return 4; | ||
| default: | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| std::optional<NativeRegisterContextDBReg::BreakpointDetails> | ||
| NativeRegisterContextDBReg_arm::AdjustBreakpoint( | ||
| const BreakpointDetails &details) { | ||
| BreakpointDetails bd = details; | ||
| // Use size to get a hint of arm vs thumb modes. | ||
| switch (bd.size) { | ||
| case 2: | ||
| bd.addr &= ~1; | ||
| break; | ||
| case 4: | ||
| bd.addr &= ~3; | ||
| break; | ||
| default: | ||
| return {}; | ||
| } | ||
|
|
||
| return bd; | ||
| } | ||
|
|
||
| std::optional<NativeRegisterContextDBReg::WatchpointDetails> | ||
| NativeRegisterContextDBReg_arm::AdjustWatchpoint( | ||
| const WatchpointDetails &details) { | ||
| auto [size, addr] = details; | ||
|
|
||
| if (size == 0 || size > 4) | ||
| return {}; | ||
|
|
||
| // Check 4-byte alignment for hardware watchpoint target address. Below is a | ||
| // hack to recalculate address and size in order to make sure we can watch | ||
| // non 4-byte aligned addresses as well. | ||
| if (addr & 0x03) { | ||
| uint8_t watch_mask = (addr & 0x03) + size; | ||
| if (watch_mask > 0x04) | ||
| return {}; | ||
| else if (watch_mask <= 0x02) | ||
| size = 2; | ||
| else | ||
| size = 4; | ||
|
|
||
| addr = addr & (~0x03); | ||
| } | ||
|
|
||
| return WatchpointDetails{size, addr}; | ||
| } | ||
|
|
||
| uint32_t NativeRegisterContextDBReg_arm::MakeBreakControlValue(size_t size) { | ||
| switch (size) { | ||
| case 2: | ||
| return (0x3 << 5) | 7; | ||
| case 4: | ||
| return (0xfu << 5) | 7; | ||
| default: | ||
| // We assume that AdjustBreakpoint would have caught this earlier. | ||
| llvm_unreachable("Invalid breakpoint size."); | ||
| } | ||
| } | ||
|
|
||
| uint32_t NativeRegisterContextDBReg_arm::MakeWatchControlValue( | ||
| lldb::addr_t addr, size_t size, uint32_t watch_flags) { | ||
| uint32_t addr_word_offset = 0, byte_mask = 0; | ||
|
|
||
| // We can only watch up to four bytes that follow a 4 byte aligned address | ||
| // per watchpoint register pair, so make sure we can properly encode this. | ||
| addr_word_offset = addr % 4; | ||
DavidSpickett marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| byte_mask = ((1u << size) - 1u) << addr_word_offset; | ||
|
|
||
| // Check if we need multiple watchpoint register | ||
| if (byte_mask > 0xfu) | ||
| return LLDB_INVALID_INDEX32; | ||
|
|
||
| // Setup control value | ||
| // Make the byte_mask into a valid Byte Address Select mask | ||
| uint32_t control_value = byte_mask << 5; | ||
|
|
||
| // Turn on appropriate watchpoint flags read or write | ||
| control_value |= (watch_flags << 3); | ||
|
|
||
| // Enable this watchpoint and make it stop in privileged or user mode; | ||
| control_value |= 7; | ||
|
|
||
| return control_value; | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_arm.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,43 @@ | ||
| //===-- NativeRegisterContextDBReg_arm.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_arm_h | ||
| #define lldb_NativeRegisterContextDBReg_arm_h | ||
|
|
||
| #include "Plugins/Process/Utility/NativeRegisterContextDBReg.h" | ||
|
|
||
| namespace lldb_private { | ||
|
|
||
| class NativeRegisterContextDBReg_arm : public NativeRegisterContextDBReg { | ||
| public: | ||
| NativeRegisterContextDBReg_arm() | ||
| : NativeRegisterContextDBReg(/*enable_bit=*/0x1U) {} | ||
|
|
||
| private: | ||
| uint32_t GetWatchpointSize(uint32_t wp_index) override; | ||
|
|
||
| std::optional<WatchpointDetails> | ||
| AdjustWatchpoint(const WatchpointDetails &details) override; | ||
|
|
||
| std::optional<BreakpointDetails> | ||
| AdjustBreakpoint(const BreakpointDetails &details) override; | ||
|
|
||
| uint32_t MakeBreakControlValue(size_t size) override; | ||
|
|
||
| uint32_t MakeWatchControlValue(lldb::addr_t addr, size_t size, | ||
| uint32_t watch_flags) override; | ||
|
|
||
| bool ValidateBreakpoint(size_t size, lldb::addr_t addr) override { | ||
| // Break on 4 or 2 byte instructions. | ||
| return size == 4 || size == 2; | ||
| } | ||
| }; | ||
|
|
||
| } // namespace lldb_private | ||
|
|
||
| #endif // #ifndef lldb_NativeRegisterContextDBReg_arm_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
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
Oops, something went wrong.
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.