microsoft / vscode-js-debug

A DAP-compatible JavaScript debugger. Used in VS Code, VS, + more
MIT License
1.67k stars 282 forks source link

Calling Debugger.resume instead of breaking on break points #2046

Closed BickfordA closed 3 months ago

BickfordA commented 3 months ago

I'm debugging ChakraCore with ChakraCore-Debugger. This is my launch config:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach",
      "request": "attach",
      "type": "node",
      "port": 9231,
      "trace": true,
      "sourceMaps": false,
      "outFiles": [], 
      "resolveSourceMapLocations":[],
    }
  ]
}

A breakpoint is triggered, but vscode-js-debug seems to be immediately sending a "Debugger.resume".

I have tried disabling source maps as I'm setting the breakpoints in the js directly. I can add a debug call to the script and execution breaks as expected. I can revert to an older version of the extension and it works as expected.

This is what I get in the logs (this seems like the relevant bit):

{"tag":"cdp.receive","timestamp":1721778174662,"metadata":{"connectionId":16,"message":{"method":"Debugger.paused","params":{"callFrames":[{"callFrameId":"{\"ordinal\":0}","functionName":"Module code","functionLocation":{"scriptId":"4","lineNumber":1,"columnNumber":1},"location":{"scriptId":"4","lineNumber":0,"columnNumber":0},"url":"file:///C:/Development/stable/vscore/Data/ReportTemplates/VCF Report Template/report_acmg.js","scopeChain":[{"type":"local","object":{"type":"object","className":"Object","description":"Object","objectId":"{\"ordinal\":0,\"name\":\"locals\"}"}},{"type":"global","object":{"type":"object","className":"global","description":"global","objectId":"{\"ordinal\":0,\"name\":\"globals\"}"}}],"this":{"type":"undefined","description":"undefined","objectId":"{\"handle\":34}"}}],"reason":"other","hitBreakpoints":["1"]}}},"level":0}
{"tag":"internal","timestamp":1721778174663,"message":"Blocked execution waiting for source-map","metadata":{"timeSpentWallClockInMs":0.1435,"sourceMapCumulativePause":10000},"level":0}
{"tag":"cdp.send","timestamp":1721778174663,"metadata":{"connectionId":16,"message":{"id":1018,"method":"Debugger.resume","params":{}}},"level":0}

I have attached the full logs here

vscode-debugadapter-d6b08f0c.json.gz

I have tried using an older version of the extension, and had luck with 2023.7.2117: image

So it seems this is a new change change, maybe related to source maps? Is there anything I can do to provide more diagnostic info?

Thanks!

connor4312 commented 3 months ago

I would take a PR to fix this if you find the issue but I'm not planning to spend time to fix it myself -- chakracore is not an engine we officially support or test against. One issue is that the breakpoint ID sent in its "paused" event is not valid; I'm not sure whether that can be easily worked around, and the chakracore-debugger project seems quite unmaintained for the last 5 years.

Code pointer: https://github.com/microsoft/vscode-js-debug/blob/14b430024ccadd5e573228214a39fac7781bd759/src/adapter/threads.ts#L944

BickfordA commented 3 months ago

@connor4312 Why do you say the breakpoint ID in the paused event is not valid? Is there something obviously wrong with that event? I could look into fixing that if that is what is required to maintain support.

Is the breakpoint ID "1" in the event? Or is that a field that should be there but it missing?

{
  "tag": "cdp.receive",
  "timestamp": 1721778174662,
  "metadata": {
    "connectionId": 16,
    "message": {
      "method": "Debugger.paused",
      "params": {
        "callFrames": [
          {
            "callFrameId": "{\"ordinal\":0}",
            "functionName": "Module code",
            "functionLocation": {
              "scriptId": "4",
              "lineNumber": 1,
              "columnNumber": 1
            },
            "location": {
              "scriptId": "4",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "url": "file:///C:/Development/stable/vscore/Data/ReportTemplates/VCF Report Template/report_acmg.js",
            "scopeChain": [
              {
                "type": "local",
                "object": {
                  "type": "object",
                  "className": "Object",
                  "description": "Object",
                  "objectId": "{\"ordinal\":0,\"name\":\"locals\"}"
                }
              },
              {
                "type": "global",
                "object": {
                  "type": "object",
                  "className": "global",
                  "description": "global",
                  "objectId": "{\"ordinal\":0,\"name\":\"globals\"}"
                }
              }
            ],
            "this": {
              "type": "undefined",
              "description": "undefined",
              "objectId": "{\"handle\":34}"
            }
          }
        ],
        "reason": "other",
        "hitBreakpoints": [
          "1"
        ]
      }
    }
  },
  "level": 0
}

chakracore-debugger hasn't seen many changes, so while unmaintained it is stable 😁 . The library used to work with this debugger it seems like it has only broken in the last year or so.

I'll see if I can dig into it more , but if there is an obvious issue with the event let me know and I can fix that as well/instead

connor4312 commented 3 months ago

The breakpoint in hitBreakpoints is not a valid ID. That should be a breakpointId previously returned from a setBreakpoint call in the session.

BickfordA commented 3 months ago

I see, so in this case, since this is the setBreakpoint call:

{
  "tag": "cdp.send",
  "timestamp": 1721778169245,
  "metadata": {
    "connectionId": 16,
    "message": {
      "id": 1013,
      "method": "Debugger.setBreakpointByUrl",
      "params": {
        "urlRegex": "[fF][iI][lL][eE]:\\/\\/\\/[cC]:\\/[dD][eE][vV][eE][lL][oO][pP][mM][eE][nN][tT]\\/[sS][tT][aA][bB][lL][eE]\\/[vV][sS][cC][oO][rR][eE]\\/[dD][aA][tT][aA]\\/[rR][eE][pP][oO][rR][tT][tT][eE][mM][pP][lL][aA][tT][eE][sS]\\/[vV][cC][fF](?: |%20)[rR][eE][pP][oO][rR][tT](?: |%20)[tT][eE][mM][pP][lL][aA][tT][eE]\\/[rR][eE][pP][oO][rR][tT]_[aA][cC][mM][gG]\\.[jJ][sS]($|\\?)|[cC]:\\\\[dD][eE][vV][eE][lL][oO][pP][mM][eE][nN][tT]\\\\[sS][tT][aA][bB][lL][eE]\\\\[vV][sS][cC][oO][rR][eE]\\\\[dD][aA][tT][aA]\\\\[rR][eE][pP][oO][rR][tT][tT][eE][mM][pP][lL][aA][tT][eE][sS]\\\\[vV][cC][fF](?: |%20)[rR][eE][pP][oO][rR][tT](?: |%20)[tT][eE][mM][pP][lL][aA][tT][eE]\\\\[rR][eE][pP][oO][rR][tT]_[aA][cC][mM][gG]\\.[jJ][sS]($|\\?)",
        "lineNumber": 0,
        "columnNumber": 0
      }
    }
  },
  "level": 0
}

Which gets this reply:

{
  "tag": "cdp.receive",
  "timestamp": 1721778169250,
  "metadata": {
    "connectionId": 16,
    "message": {
      "id": 1013,
      "result": {
        "breakpointId": "2:[fF][iI][lL][eE]:\\/\\/\\/[cC]:\\/[dD][eE][vV][eE][lL][oO][pP][mM][eE][nN][tT]\\/[sS][tT][aA][bB][lL][eE]\\/[vV][sS][cC][oO][rR][eE]\\/[dD][aA][tT][aA]\\/[rR][eE][pP][oO][rR][tT][tT][eE][mM][pP][lL][aA][tT][eE][sS]\\/[vV][cC][fF](?: |%20)[rR][eE][pP][oO][rR][tT](?: |%20)[tT][eE][mM][pP][lL][aA][tT][eE]\\/[rR][eE][pP][oO][rR][tT]_[aA][cC][mM][gG]\\.[jJ][sS]($|\\?)|[cC]:\\\\[dD][eE][vV][eE][lL][oO][pP][mM][eE][nN][tT]\\\\[sS][tT][aA][bB][lL][eE]\\\\[vV][sS][cC][oO][rR][eE]\\\\[dD][aA][tT][aA]\\\\[rR][eE][pP][oO][rR][tT][tT][eE][mM][pP][lL][aA][tT][eE][sS]\\\\[vV][cC][fF](?: |%20)[rR][eE][pP][oO][rR][tT](?: |%20)[tT][eE][mM][pP][lL][aA][tT][eE]\\\\[rR][eE][pP][oO][rR][tT]_[aA][cC][mM][gG]\\.[jJ][sS]($|\\?):0:0",
        "locations": []
      }
    }
  },
  "level": 0
}

and (after the script being debugged is loaded) this

{
  "tag": "cdp.receive",
  "timestamp": 1721778171964,
  "metadata": {
    "connectionId": 16,
    "message": {
      "method": "Debugger.breakpointResolved",
      "params": {
        "breakpointId": "2:[fF][iI][lL][eE]:\\/\\/\\/[cC]:\\/[dD][eE][vV][eE][lL][oO][pP][mM][eE][nN][tT]\\/[sS][tT][aA][bB][lL][eE]\\/[vV][sS][cC][oO][rR][eE]\\/[dD][aA][tT][aA]\\/[rR][eE][pP][oO][rR][tT][tT][eE][mM][pP][lL][aA][tT][eE][sS]\\/[vV][cC][fF](?: |%20)[rR][eE][pP][oO][rR][tT](?: |%20)[tT][eE][mM][pP][lL][aA][tT][eE]\\/[rR][eE][pP][oO][rR][tT]_[aA][cC][mM][gG]\\.[jJ][sS]($|\\?)|[cC]:\\\\[dD][eE][vV][eE][lL][oO][pP][mM][eE][nN][tT]\\\\[sS][tT][aA][bB][lL][eE]\\\\[vV][sS][cC][oO][rR][eE]\\\\[dD][aA][tT][aA]\\\\[rR][eE][pP][oO][rR][tT][tT][eE][mM][pP][lL][aA][tT][eE][sS]\\\\[vV][cC][fF](?: |%20)[rR][eE][pP][oO][rR][tT](?: |%20)[tT][eE][mM][pP][lL][aA][tT][eE]\\\\[rR][eE][pP][oO][rR][tT]_[aA][cC][mM][gG]\\.[jJ][sS]($|\\?):0:0",
        "location": {
          "scriptId": "4",
          "lineNumber": 0,
          "columnNumber": 0
        }
      }
    }
  },
  "level": 0
}

the breakpointID should be the "2::[fF][iI][lL][eE]..." value.

I'll try updating the chakracore side. Thanks so much!

BickfordA commented 3 months ago

I was able to update the breakpointIds returned from the chakracore debugger and it fixed the issue. @connor4312 Thanks again for pointing me in the right direction!