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

Ebuka Ezike via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 13 15:12:55 PDT 2025


================
@@ -0,0 +1,120 @@
+//===-- 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 <lldb/API/SBStream.h>
+
+namespace lldb_dap {
+
+//  "GotoTargetsRequest": {
+//    "allOf": [ { "$ref": "#/definitions/Request" }, {
+//      "type": "object",
+//      "description": "This request retrieves the possible goto targets for the
+//      specified source location.\nThese targets can be used in the `goto`
+//      request.\nClients should only call this request if the corresponding
+//      capability `supportsGotoTargetsRequest` is true.", "properties": {
+//        "command": {
+//          "type": "string",
+//          "enum": [ "gotoTargets" ]
+//        },
+//        "arguments": {
+//          "$ref": "#/definitions/GotoTargetsArguments"
+//        }
+//      },
+//      "required": [ "command", "arguments"  ]
+//    }]
+//  },
+//  "GotoTargetsArguments": {
+//    "type": "object",
+//    "description": "Arguments for `gotoTargets` request.",
+//    "properties": {
+//      "source": {
+//        "$ref": "#/definitions/Source",
+//        "description": "The source location for which the goto targets are
+//        determined."
+//      },
+//      "line": {
+//        "type": "integer",
+//        "description": "The line location for which the goto targets are
+//        determined."
+//      },
+//      "column": {
+//        "type": "integer",
+//        "description": "The position within `line` for which the goto targets
+//        are determined. It is measured in UTF-16 code units and the client
+//        capability `columnsStartAt1` determines whether it is 0- or 1-based."
+//      }
+//    },
+//    "required": [ "source", "line" ]
+//  },
+//  "GotoTargetsResponse": {
+//    "allOf": [ { "$ref": "#/definitions/Response" }, {
+//      "type": "object",
+//      "description": "Response to `gotoTargets` request.",
+//      "properties": {
+//        "body": {
+//          "type": "object",
+//          "properties": {
+//            "targets": {
+//              "type": "array",
+//              "items": {
+//                "$ref": "#/definitions/GotoTarget"
+//              },
+//              "description": "The possible goto targets of the specified
+//              location."
+//            }
+//          },
+//          "required": [ "targets" ]
+//        }
+//      },
+//      "required": [ "body" ]
+//    }]
+//  },
+void GoToTargetsRequestHandler::operator()(
+    const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+  const auto *arguments = request.getObject("arguments");
+  const auto *source = arguments->getObject("source");
+  const std::string path = GetString(source, "path").str();
+
+  const auto goto_line = GetInteger<uint64_t>(arguments, "line").value_or(0u);
+  const auto goto_column =
+      GetInteger<uint64_t>(arguments, "column").value_or(0u);
+
+  lldb::SBLineEntry line_entry{};
+  const lldb::SBFileSpec file_spec(path.c_str(), true);
+  line_entry.SetFileSpec(file_spec);
+  line_entry.SetLine(goto_line);
+  line_entry.SetColumn(goto_column);
----------------
da-viper wrote:

@walter-erquinigo  @vogelsgesang 

I was thinking instead we only support jumps within a function for the same reason as above. 

it would be something like this 

```py
def is_line_in_func(fn, line) ->:
       s_addr = fn.addr
       e_addr = fn.end_addr 
       
       return (s_addr <= line.addr )and (line.addr <= e_addr)

def get_line_valid_entry(file_spec, line, target):

```

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


More information about the lldb-commits mailing list