VSC 不会在正确的断点处中断

VSC does not break on correct breakpoint

我正在尝试在我自己的调试器之上实现 NodeJS 调试 API 服务器。我想使用任何能够调试 Node 的客户端通过我自己的调试器进行调试。我使用 Visual Studio 代码作为测试调试客户端,我能够实现足够的消息交换来附加、设置断点并通知 VSC 脚本在断点处暂停。问题是,Visual Studio 代码将 "Pause" 图标更改为 "Play" 以指示执行已暂停,但似乎无法理解代码在哪个断点处停止。没有突出显示断点。而且它不从服务器请求帧或堆栈跟踪。在上次 VSC 代码更新之前,它还会在堆栈跟踪的顶部显示执行暂停的消息 window,在上次更新之后,该消息不会显示,但执行仍然暂停。

这是服务器和VSC之间的消息交换日志(从断点请求开始):

Request:
 {
    "command": "setbreakpoint",
    "arguments": {
        "line": 4,
        "column": 0,
        "type": "scriptRegExp",
        "target": "^(.*[\/\\])?\/Users\/me\/Documents\/github\/test\/test\.js$"
    },
    "type": "request",
    "seq": 8
}
Response:
{
    "seq": 9,
    "type": "response",
    "success": true,
    "running": true,
    "request_seq": 8,
    "command": "setbreakpoint",
    "body": {
        "type": "scriptRegExp",
        "breakpoint": 1,
        "script_regexp": "^(.*[\/\\])?\/Users\/me\/Documents\/github\/test\/test\.js$",
        "line": 4,
        "column": 0,
        "actual_locations": [
            {
                "line": 4,
                "column": 4,
                "script_id": 42
            }
        ]
    }
}
Response:
 {
    "type": "event",
    "event": "break",
    "body": {
        "sourceLine": 4,
        "sourceColumn": 4,
        "sourceLineText": "    var product = Product.get(params.pid.stringValue);",
        "breakpoints": [
            1
        ],
        "script": {
            "id": 42,
            "name": "/Users/me/Documents/github/test/test.js",
            "lineOffset": 0,
            "columnOffset": 0,
            "lineCount": 458
        }
    }
}
Request:
{
    "command": "threads",
    "type": "request",
    "seq": 10
}
Response:
{
    "seq": 11,
    "type": "response",
    "success": true,
    "running": false,
    "request_seq": 10,
    "command": "threads",
    "body": {
        "totalThreads": 1,
        "threads": [
            {
                "current": true,
                "id": 4
            }
        ]
    }
}

在那之后,VSC 不再发送任何请求。我做错了吗?也许有人可以指出一些应该验证 VSC 节点调试的单元测试的位置?

此外,线程请求似乎不在 NodeJS 调试器 API 规范中,尽管 Node 响应它。它是新功能,还是只是未记录的功能?

https://code.visualstudio.com/docs/extensionAPI/api-debugging 中的以下部分解释了命中断点时发生的情况:

"Whenever the program stops (on program entry, because a breakpoint was hit, an exception occurred, or the user requested execution to be paused), the debug adapter has to send a stopped event with the appropriate reason and thread id. Upon receipt VS Code will request the stacktrace (a list of stack frames) for the given thread. If the user then drills into the stack frame, VS Code first requests the scopes for a stack frame, and then the variables for a scope. If a variable is itself structured, VS Code requests its properties through additional variables requests. This leads to the following hierarchy:..."

调试适配器测试在这里:https://github.com/Microsoft/vscode-node-debug/blob/master/src/tests/adapter.test.ts 他们测试典型的 VS 代码场景。您可能想查看 'should stop on a breakpoint' 测试(第 108 行)。

为了保存 space,"stop reason" 现在显示在 CALL STACK 视图的 header 中: