Skip to content

Commit 38da313

Browse files
committed
Remove HW breakpoint support
1 parent 8d064da commit 38da313

File tree

3 files changed

+17
-72
lines changed

3 files changed

+17
-72
lines changed

lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -491,42 +491,32 @@ NativeProcessWindows::OnDebugException(bool first_chance,
491491
return ExceptionResult::MaskException;
492492
}
493493
case DWORD(STATUS_BREAKPOINT):
494-
case STATUS_WX86_BREAKPOINT: {
495-
bool breakpoint_hit = false;
496-
NativeThreadWindows *stop_thread = GetThreadByID(record.GetThreadID());
494+
case STATUS_WX86_BREAKPOINT:
497495

498-
if (stop_thread) {
499-
uint32_t hw_id = LLDB_INVALID_INDEX32;
496+
if (NativeThreadWindows *stop_thread =
497+
GetThreadByID(record.GetThreadID())) {
500498
auto &reg_ctx = stop_thread->GetRegisterContext();
501-
reg_ctx.GetHardwareBreakHitIndex(hw_id, record.GetExceptionAddress());
502-
if (hw_id != LLDB_INVALID_INDEX32) {
503-
breakpoint_hit = true;
504-
LLDB_LOG(log, "Hit hardware breakpoint at address {0:x}.",
505-
record.GetExceptionAddress());
506-
} else if (FindSoftwareBreakpoint(record.GetExceptionAddress())) {
507-
breakpoint_hit = true;
499+
const auto exception_addr = record.GetExceptionAddress();
500+
const auto thread_id = record.GetThreadID();
501+
502+
if (FindSoftwareBreakpoint(exception_addr)) {
508503
LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
509-
record.GetExceptionAddress());
510-
uint32_t breakpoint_size = GetSoftwareBreakpointPCOffset();
511-
// The current PC is AFTER the BP opcode, on all architectures.
512-
uint64_t pc = reg_ctx.GetPC() - breakpoint_size;
513-
reg_ctx.SetPC(pc);
514-
}
504+
exception_addr);
515505

516-
if (breakpoint_hit) {
517-
StopThread(record.GetThreadID(), StopReason::eStopReasonBreakpoint);
506+
reg_ctx.SetPC(reg_ctx.GetPC() - GetSoftwareBreakpointPCOffset());
507+
StopThread(thread_id, StopReason::eStopReasonBreakpoint);
518508
SetState(eStateStopped, true);
519509
return ExceptionResult::MaskException;
520510
} else {
521511
const std::vector<ULONG_PTR> &args = record.GetExceptionArguments();
522512
if (args.size() >= 2) {
513+
uint32_t hw_id = LLDB_INVALID_INDEX32;
523514
reg_ctx.GetWatchpointHitIndex(hw_id, args[1]);
515+
524516
if (hw_id != LLDB_INVALID_INDEX32) {
525-
addr_t wp_pc = record.GetExceptionAddress();
526517
std::string desc =
527-
formatv("{0} {1} {2}", args[1], hw_id, wp_pc).str();
528-
StopThread(record.GetThreadID(), StopReason::eStopReasonWatchpoint,
529-
desc);
518+
formatv("{0} {1} {2}", args[1], hw_id, exception_addr).str();
519+
StopThread(thread_id, StopReason::eStopReasonWatchpoint, desc);
530520
SetState(eStateStopped, true);
531521
return ExceptionResult::MaskException;
532522
}
@@ -554,7 +544,6 @@ NativeProcessWindows::OnDebugException(bool first_chance,
554544
// Hit the initial stop. Continue the application.
555545
return ExceptionResult::BreakInDebugger;
556546
}
557-
}
558547

559548
[[fallthrough]];
560549
default:

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm64.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ NativeRegisterContextWindows_arm64::NativeRegisterContextWindows_arm64(
147147
// Currently, there is no API to query the maximum supported hardware
148148
// breakpoints and watchpoints on Windows. The values set below are based
149149
// on tests conducted on Windows 11 with Snapdragon Elite X hardware.
150-
m_max_hwp_supported = 1;
151-
m_max_hbp_supported = 6;
150+
m_max_hwp_supported = 2;
151+
m_max_hbp_supported = 0;
152152
}
153153

154154
bool NativeRegisterContextWindows_arm64::IsGPR(uint32_t reg_index) const {
@@ -726,10 +726,6 @@ llvm::Error NativeRegisterContextWindows_arm64::ReadHardwareDebugInfo() {
726726
m_hwp_regs[i].control = tls_context.Wcr[i];
727727
}
728728

729-
for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
730-
m_hbp_regs[i].address = tls_context.Bvr[i];
731-
m_hbp_regs[i].control = tls_context.Bcr[i];
732-
}
733729
return llvm::Error::success();
734730
}
735731

@@ -741,19 +737,11 @@ NativeRegisterContextWindows_arm64::WriteHardwareDebugRegs(DREGType hwbType) {
741737
if (error.Fail())
742738
return error.ToError();
743739

744-
switch (hwbType) {
745-
case eDREGTypeWATCH:
740+
if (hwbType == eDREGTypeWATCH) {
746741
for (uint32_t i = 0; i < m_max_hwp_supported; i++) {
747742
tls_context.Wvr[i] = m_hwp_regs[i].address;
748743
tls_context.Wcr[i] = m_hwp_regs[i].control;
749744
}
750-
break;
751-
case eDREGTypeBREAK:
752-
for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
753-
tls_context.Bvr[i] = m_hbp_regs[i].address;
754-
tls_context.Bcr[i] = m_hbp_regs[i].control;
755-
}
756-
break;
757745
}
758746

759747
return SetThreadContextHelper(GetThreadHandle(), &tls_context).ToError();

lldb/source/Plugins/Process/Windows/Common/NativeThreadWindows.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -178,41 +178,9 @@ Status NativeThreadWindows::RemoveWatchpoint(lldb::addr_t addr) {
178178

179179
Status NativeThreadWindows::SetHardwareBreakpoint(lldb::addr_t addr,
180180
size_t size) {
181-
#if defined(__aarch64__) || defined(_M_ARM64)
182-
if (m_state == eStateLaunching)
183-
return Status();
184-
185-
Status error = RemoveHardwareBreakpoint(addr);
186-
if (error.Fail())
187-
return error;
188-
189-
uint32_t bp_index = m_reg_context_up->SetHardwareBreakpoint(addr, size);
190-
191-
if (bp_index == LLDB_INVALID_INDEX32)
192-
return Status::FromErrorString("Setting hardware breakpoint failed.");
193-
194-
m_hw_breakpoint_index_map.insert({addr, bp_index});
195-
196-
return Status();
197-
#else
198181
return Status::FromErrorString("unimplemented.");
199-
#endif
200182
}
201183

202184
Status NativeThreadWindows::RemoveHardwareBreakpoint(lldb::addr_t addr) {
203-
#if defined(__aarch64__) || defined(_M_ARM64)
204-
auto bp = m_hw_breakpoint_index_map.find(addr);
205-
if (bp == m_hw_breakpoint_index_map.end())
206-
return Status();
207-
208-
uint32_t bp_index = bp->second;
209-
if (m_reg_context_up->ClearHardwareBreakpoint(bp_index)) {
210-
m_hw_breakpoint_index_map.erase(bp);
211-
return Status();
212-
}
213-
214-
return Status::FromErrorString("Clearing hardware breakpoint failed.");
215-
#else
216185
return Status::FromErrorString("unimplemented.");
217-
#endif
218186
}

0 commit comments

Comments
 (0)