[Lldb-commits] [lldb] [llvm] [lldb][lldb-dap] Implement jump to cursor (PR #130503)

John Harrison via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 26 15:43:46 PDT 2025


================
@@ -0,0 +1,91 @@
+//===-- GoToTargetsRequestHandler.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 "DAP.h"
+
+#include "JSONUtils.h"
+#include "Protocol/ProtocolRequests.h"
+#include "RequestHandler.h"
+
+#include <lldb/API/SBBreakpointLocation.h>
+#include <lldb/API/SBListener.h>
+#include <lldb/API/SBStream.h>
+
+namespace lldb_dap {
+
+static llvm::SmallVector<lldb::SBLineEntry>
+GetLineValidEntry(DAP &dap, const lldb::SBFileSpec &file_spec, uint32_t line) {
+  // Disable breakpoint listeners so they do not send events to the DAP client.
+  lldb::SBListener listener = dap.debugger.GetListener();
+  const lldb::SBBroadcaster broadcaster = dap.target.GetBroadcaster();
+  constexpr auto event_mask = lldb::SBTarget::eBroadcastBitBreakpointChanged;
+  listener.StopListeningForEvents(broadcaster, event_mask);
+
+  // Create a breakpoint to resolve the line if it is on an empty line.
+  lldb::SBBreakpoint goto_bp =
+      dap.target.BreakpointCreateByLocation(file_spec, line);
+  if (!goto_bp.IsValid())
+    return {};
+
+  llvm::SmallVector<lldb::SBLineEntry> entry_locations{};
+  const size_t resolved_count = goto_bp.GetNumResolvedLocations();
+  for (size_t idx = 0; idx < resolved_count; ++idx) {
+    lldb::SBBreakpointLocation location = goto_bp.GetLocationAtIndex(idx);
+    if (!location.IsValid())
+      continue;
+
+    lldb::SBAddress addr = location.GetAddress();
+    if (!addr.IsValid())
+      continue;
+
+    lldb::SBLineEntry line_entry = addr.GetLineEntry();
+    if (!line_entry.IsValid())
+      continue;
+
+    entry_locations.push_back(line_entry);
+  }
+
+  // clean up;
+  dap.target.BreakpointDelete(goto_bp.GetID());
+  listener.StartListeningForEvents(broadcaster, event_mask);
----------------
ashgti wrote:

Won't we miss this cleanup if we return on line 33?

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


More information about the lldb-commits mailing list