0

I recently read the article ,Multi target Electron debugging with VSCode whose URL is https://kwonoj.github.io/en/post/multi-target-dbg-electron-vscode/ and got it to work seamlessly in an Oracle VM VirtuaBox Manager containing the RedHat Linux 7.1 operating system with electron 1.8.2 , node v8.9.4 , vscode 1.17 and firefox using the inspector protocol. Here is my launch.json which set breakpoints inside main.js and main.cpp , a C++ addon which calculates if an integer is a prime number.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type":"cppdbg",
            "program": "/home/hellodev/Downloads/node-v6.11.1-linux-x64/bin/node"
            "args": [
                "--inspect-brk=5858",
                "main.js"
            ],
            "request": "launch",
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "serverLaunchTimeout": 50000
        },
        {
            "type": "node",
            "request": "attach",
            "timeout":  10000,
            "name": "Attach Program",
            "port": 5858,
            "protocol": "inspector"
        },
        {
            "type":"node",
            "request":"launch",
            "name":"Electron Main",
            "runtimeExecutable":"/home/hellodev/node-cpp-addons/node_modules/electron/dist/electron"
            "protocol":"inspector"
         }

    ],
    "compounds": [
        {
            "name": "Server/Client",
            "configurations": ["Electron Main","(gdb) Launch","Attach Program"]
        }
    ]
}

How could I also extend this article in the same Oracle VM VirtuaBox Manager containing the RedHat Linux 7.1 operating system to use the legacy protocol, electron 1.6.7 , node v6.11.1, vscode 1.17 and firefox and what would the revised launch.json look like?

With no success, I tried an electron prelaunch task whose tasks.json is shown below, The reason I tried an prelaunch task is because runtimeExecutable is reserved for the inspector protocol rather than the legacy protocol. However, the prelaunch task causes a runtime error EADDRESSINUSE:port 5858.

{
    "version": "1.6.7",
    "command": "electron",
    "isShellCommand": true,
    "args": [

"--remote-debugging-port=5858",   
       "${workspaceRoot}/main.js",
    ]
}

and got the error message , "Cannot connect to runtime process: Reason: Socket ended by other party" when I used the following launch.json with the vscode green arrow to run an compound launch configuration.

"configurations": [
        {
            "name": "(gdb) Launch",
            "type":"cppdbg",
            "program": "/home/hellodev/Downloads/node-v6.11.1-linux-x64/bin/node"
            "args": [
               "--inspect-brk=5858",
                "main.js"
            ],
            "request": "launch",
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "serverLaunchTimeout": 50000
},
{
            "type": "node",
            "request": "attach",
            "timeout":  10000,
            "name": "Attach Program",
            "port": 5858,
            "protocol": "legacy"
         },
        {
            "type":"node",
            "request":"launch",
            "name":"Electron Main",
            "preLaunchTask": "electron",
            "protocol":"legacy", //Specify to use v8 inspector protocol
            "port": 5858,
            "timeout": 28000
         }


    ],
    "compounds": [
        {
            "name": "Server/Client",
            "configurations": ["Electron Main","(gdb) Launch","Attach Program"]
        }
    ]

}

[Fenruary 24 2018] @Andre Weinand, I show here my newest launch.json which causes the error message "Cannot connect to runtime; make sure that runtime is in 'legacy' debug mode." to display. I have tried to follow all of your earlier recommendations but I still am encountering problems. Therefore , when I click the vscode green arrow corresponding to the Server/Client compound launch configuration , it launches "Electron Main" but does not hit the GDB breakpoints I set in main.cpp which is a C++ addon. I understand what you are saying about placing debugger statements in the C++ addon source code but I would prefer not to do. How could I fix my launch.json?

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type":"cppdbg",
            "program": "/home/xyzdev/Downloads/node-v6.11.1-linux-x64/bin/node"
            "args": [
                "--debug=5858"
                "main.js"
            ],
            "request": "launch",
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
             "launchCompleteCommand": "None"

        },
        {
            "type": "node",
            "request": "attach",
            "timeout":  10000,
            "name": "Attach Program",
            "port": 5858,
            "protocol": "legacy"
        },
        {
            "type":"node",
            "request":"launch",
            "name":"Electron Main",
            "runtimeExecutable":"/home/xyzdev/node-cpp-addons/node_modules/electron/dist/electron",
            "runtimeArgs": [
                "${workspaceRoot}/main.js",
                "--remote-debugging-port" //Set debugging port for renderer process
            ],
            "protocol":"legacy"
         }


    ],
    "compounds": [
        {
            "name": "Server/Client",
            "configurations": ["Electron Main","(gdb) Launch","Attach Program"]
        }
    ]

}

[February 26 2018] @Andre Weinand, I read that you wrote on May 10 2017 in the github.com article https://github.com/Microsoft/vscode/issues/26411 that states: "You can use either "legacy" or "inspector" protocol for node version > 6.3 and < 8.0, but you have to make sure that you are using the matching "--debug" or "--inspect" argument.

BTW, this redundancy in the launch config will be fixed in the May release: you'll no longer have to specify a port at all, just the protocol will do the right thing." Since I am using node version 6.11.1 which is > 6.3 and < 8.0 , I was wondering whether I could switch our launch.json to the "inspector" protocol instead of the "legacy" protocol to attain "seamless" debugging as I was able to do with node 8.9.4? Thank you

2

The "protocol" attribute determines whether the "inspector" or "legacy" protocol is used. Please read our doc: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_supported-nodelike-runtimes.

You cannot run two debug sessions with the same debug port in parallel (which you do in the last debug configuration from above). And there is a "program" or "runtimeExecutable" missing.

I suggest to change the value of the "protocol" attribute in the top most debug configuration to "legacy" (assuming that the protocol is the only problem of that configuration).

  • I appreciate your detailed answer. I am wondering whether I need to assign the legacy protocol value to the top most (gdb) Launch debug configuration. Also, I was able to use the same debug port(i.e 5858) in parallel when running with the inspector protocol rather than the legacy protocol. May I ask what ports I should choose to avoid the EADDRESSINUSE error?Thank you. – Frank Feb 19 '18 at 2:29
  • In my haste to ask the original question, I may have omitted the fact that I used a compound launch configuration where Electron Main and (gdb) Launch and Attach Program take place sequentially rather than in parallel. Thank you for catching my mistake with the preLaunch task which occurs in parallel, – Frank Feb 19 '18 at 5:20
  • I just accepted your nice answer. Does one have to explicltly enable the Firefox browser to be devtools.chrome.enabled using about:config so vscode can capitalize on the v8 Chrome debugging legacy protocol ? Thank you, – Frank Feb 19 '18 at 6:58
  • Your "cppdbg" configuration does not involve node.js debugging. So, using the "protocol" attribute does not make any sense (and is not supported as you can find out by using it: you will see an error squiggly). However, the "cppdbg" configuration launches node.js and since you are passing a "--inspect-brk=5858" you've configured it for debugging in "inspector "mode. If you want to use another debug session with this node, you have to use matching protocols. So for "legacy" protocol do not start the first node with a "--inspect..." but use a "--debug" argument. – Andre Weinand Feb 19 '18 at 9:33
  • You can use any free debug port. For your first "cppdbg" configuration I suggest that you specify a port explicitly (what you already do) because it has to match a port in another launch config ("Attach Program" I assume). In your last "Electron Main" launch config I suggest not to specify a port. In this case VS Code picks a free port automatically. – Andre Weinand Feb 19 '18 at 9:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.