Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSCode Debugging #4

Open
jeanlemotan opened this issue Oct 11, 2020 · 3 comments
Open

VSCode Debugging #4

jeanlemotan opened this issue Oct 11, 2020 · 3 comments

Comments

@jeanlemotan
Copy link

Hi,

Did you manage to make this work with VSCode node debugger?

I keep getting handshake errors and I cannot understand why.
Debugging in Chrome DevTools works just fine on the other hand.

Thanks!

@ahmadov
Copy link
Owner

ahmadov commented Oct 12, 2020

Hi @jeanleflambeur,

Currently, this example does not work with VSCode because VSCode sends additional GET HTTP request to get the version of the server and this example does not act as an HTTP Server.

As far as I remember VSCode sends /json and /json/version to the HTTP server to get the URL of WebSocket server and HTTP server responds something like as follows:

{
  "Browser": "V8Example/v1",
  "Protocol-Version": "1.1",
  "V8-Version": "8.110.9",
  "webSocketDebuggerUrl": "ws://127.0.0.1:9090/ws"
}

So, in order to make it work with VSCode or other IDEs, your server should support both HTTP and WebSocket requests.

@jeanlemotan
Copy link
Author

jeanlemotan commented Oct 12, 2020

Thanks for your response. In the mean time I managed to get it working fully using this launch params:

{
    "configurations": [
      {
        "name": "Attach",
        "port": 9006,
        "websocketAddress" : "ws://127.0.0.1:9006",
        "request": "attach",
        "skipFiles": [
          "<node_internals>/**"
        ],
        "type": "pwa-node",
        "localRoot": "${workspaceFolder}",
        "remoteRoot": "/scripts",
        "sourceMaps": true
      }
    ]
}

Turns out the node debugger supports setting the websocketAddress directly so you can skip the HTTP protocol entirely.
The other thing to do is to embed this in the global context:

const char* nodeDebuggerStuff = R"(
let process =
{ 
	pid: 1, 
	version: 16, 
	arch: "x86",
	env: {}
})";

Node.js adds this 'process' object to the global scope and the debugger tries to retrieve this info and if it's not there it gets stuck in a loop asking for this.

The next thing is to solve the relative/absolute paths between the vscode and the embedded V8. You do this with the localRoot/removeRoot keys in launch.json. They are used to convert between local vscode paths and remote (embedded) paths.

So now I have a very functional vscode debugging session for an embedded v8.
Thanks a lot for your code btw - it helped me a lot to get started.

@ahmadov
Copy link
Owner

ahmadov commented Oct 12, 2020

That's good to know that VSCode now supports WebSocket server directly! At that time, I created that example project that was not possible.

Good to hear that this example helped you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants