Vscode-cpptools: Error using vscode.debug.startDebugging with 0.14.6

Created on 19 Jan 2018  路  10Comments  路  Source: microsoft/vscode-cpptools

I have a small custom extension that tries to launch a debugging session with vscode.debug.startDebugging as follows:

    vscode.debug.startDebugging(rootPath, {
      name: "(gdb) Launch",
      type: "cppdbg",
      request: "launch",
      program: program,
      args: args,
      stopAtEntry: true,
      cwd: cwd,
      externalConsole: false,
      MIMode: "gdb",
      setupCommands: [
        {
          description: "Set inferior terminal for gdb",
          text: "-inferior-tty-set " + tty,
          ignoreFailures: false
        },
        {
          description: "Enable pretty-printing for gdb",
          text: "-enable-pretty-printing",
          ignoreFailures: true
        }

      ]
    });

This was working fine with 0.14.5 but since the update to 0.14.6 it fails every time with:

Cannot determine executable for debug adapter '{0}'.

My configuration still seems to match the default launch.json ones so it doesn't look like there's anything new I need to add to it.

Is this a bug? Am I doing something wrong here?

debugger external

Most helpful comment

Thanks for all your help - this is all working for me again now. In case anybody else runs across this I'll just point out that I also had to make sure the folder was open first:

const uri = vscode.Uri.file(path);
vscode.commands.executeCommand("vscode.openFolder", uri);
const workspace = vscode.workspace.getWorkspaceFolder(uri);

and then use workspace as the argument when launching the debugger.

The API documentation does actually say that the first argument to startDebugging can be undefined but that didn't seem to work for me - if getWorkspaceFolder returned undefined because the folder wasn't open then I still got the error.

All 10 comments

@pieandcakes @WardenGnaw probably know more, but if you feel like debugging our typescript the code that registers cppdbg is at https://github.com/Microsoft/vscode-cpptools/blob/release/Extension/src/Debugger/extension.ts, or you might try using 0.14.6-beta1 (https://github.com/Microsoft/vscode-cpptools/releases/tag/v0.14.6-insiders ) if there was some regression with the typescript changes that were made after that.

Well I can confirm that 0.14.6-beta1 behaves the same as 0.14.6 at least.

@tomhughes: @WardenGnaw made a change to dynamically determine the debugger entrypoint to prevent our required second reload and improve the user experience. It seems in this instance it isn't able to determine the debug executable. VSCode made a change to support providing a provider to tell VSCode what to launch but our extension needs to be activated and registered at that time.

The code for our provider registration can be found in this repo, here

You may want to debug and see if this is getting called before you call StartDebugging but I suspect that it is not. Otherwise, if you can provide a small sample repro of this issue we can take a look.

You could also try adding code like the following before the startDebugging.
let extension = vscode.extensions.getExtension("ms-vscode.cpptools"); if (!extension.isActive) { await extension.activate(); }
like our tests do at:
https://github.com/Microsoft/vscode-cpptools/blob/master/Extension/test/integrationTests/debug.integration.test.ts

Did you add a dependency to the cpptools extension?

When depending on the API of another extension add an extensionDependency-entry to package.json, and use the getExtension-function and the exports-property, source

I did already have a dependency on the cpptools extension but I've tried await the activation as well now and that doesn't seem to help.

I also tried changing my extension so that instead of starting the debug session from it's activation function it does it from a command so that I can trigger it later but that doesn't seem to help either and so far I haven't managed to find any way to debug it.

I have created a test case for you - just drop the contents of the zip in your extensions directory and then invoke the Demonstrate Issue 1471 command from the command palette.

Thank you for the repro!

In the test case you passed a string as the first parameter, vscode.debug.startDebugging expects a WorkspaceFolder. See https://github.com/Microsoft/vscode/blob/81d6f2b1d3f350d3fae0750052b9cc100f166283/src/vs/vscode.d.ts#L6244

I got the test case to run the configuration by switching out "/" to vscode.workspace.workspaceFolders[0].

So is there a way to construct a workspace folder from a path? I'm guessing vscode.workspace.getWorkspaceFolder is the thing to use if I turn the path into a file: URl first...

You can create a workspace folder from a string with:

const fileName = "file";
const workspaceFolder = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(fileName));

I will be closing this issue for now. If you have any other questions or you are still encountering this issue, please reopen this issue or continue the conversation here.

Thanks for all your help - this is all working for me again now. In case anybody else runs across this I'll just point out that I also had to make sure the folder was open first:

const uri = vscode.Uri.file(path);
vscode.commands.executeCommand("vscode.openFolder", uri);
const workspace = vscode.workspace.getWorkspaceFolder(uri);

and then use workspace as the argument when launching the debugger.

The API documentation does actually say that the first argument to startDebugging can be undefined but that didn't seem to work for me - if getWorkspaceFolder returned undefined because the folder wasn't open then I still got the error.

Was this page helpful?
0 / 5 - 0 ratings