[Lldb-commits] [lldb] [lldb] Step over non-lldb breakpoints (PR #174348)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 2 07:46:40 PST 2026


================
@@ -82,6 +83,41 @@ bool StopInfo::HasTargetRunSinceMe() {
   return false;
 }
 
+void StopInfo::SkipOverTrapInstruction() {
+  Status error;
+  Log *log = GetLog(LLDBLog::Process);
+
+  // We don't expect to see byte sequences longer than four bytes long for
+  // any breakpoint instructions known to LLDB.
+  std::array<uint8_t, 4> bytes_at_pc = {0, 0, 0, 0};
+  auto reg_ctx_sp = GetThread()->GetRegisterContext();
+  auto process_sp = GetThread()->GetProcess();
+  addr_t pc = reg_ctx_sp->GetPC();
+  if (!process_sp->ReadMemory(pc, bytes_at_pc.data(), bytes_at_pc.size(),
+                              error)) {
+    // If this fails, we simply don't handle the step-over-break logic.
+    LLDB_LOG(log, "failed to read program bytes at pc address {}, error {}", pc,
+             error);
+    return;
+  }
+
+  auto &target = process_sp->GetTarget();
+  auto platform_sp = target.GetPlatform();
+  auto size_hint = platform_sp->GetTrapOpcodeSizeHint(target, pc, bytes_at_pc);
+  auto platform_opcode =
+      platform_sp->SoftwareTrapOpcodeBytes(target.GetArchitecture(), size_hint);
+
+  if (auto *arch_plugin = target.GetArchitecturePlugin();
+      arch_plugin &&
+      arch_plugin->IsValidTrapInstruction(
+          platform_opcode,
+          llvm::ArrayRef<uint8_t>(bytes_at_pc.data(), bytes_at_pc.size()))) {
+    LLDB_LOG(log, "stepping over breakpoint in inferior to new pc: {}",
+             pc + platform_opcode.size());
+    reg_ctx_sp->SetPC(pc + platform_opcode.size());
----------------
DavidSpickett wrote:

I see that this would work for platforms where we replace the whole instruction with the break.

Do you know how this works on Intel where we don't do that? At least, that's my impression is that we have a single byte break instruction that's placed on the first byte.....and there's my mistake I think.

Intel is the platform where this code is never used, precisely because it puts the PC after the break. So using the trap opcode size here is correct for any platform that would actually reach this code, and always replaces the whole instruction with the trap opcode.

Correct?

https://github.com/llvm/llvm-project/pull/174348


More information about the lldb-commits mailing list