Skip to content

Enhancement for extended-remote target #91

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

Closed
mdelete opened this issue Jan 8, 2017 · 6 comments · May be fixed by #195
Closed

Enhancement for extended-remote target #91

mdelete opened this issue Jan 8, 2017 · 6 comments · May be fixed by #195

Comments

@mdelete
Copy link

mdelete commented Jan 8, 2017

Hi @WebFreak001! Great work on your VS Code plugin! I am trying to replace the dreaded Eclipse for debugging microcontrollers and stumbled upon VS Code and Native Debug. However, the configuration options available did not support the extended-remote target of GDB, which would be nice to have for some debugging hardware.

The following is a works-for-me style hack that enables me to happily debug Cortex M microcontrollers using an external USB debugger like Black Magic Probe:

backend/mi2/mi2.js:176 ff.

attach(cwd, executable, target) {
    this.log("stdout", "attaching " + target); // added
    return new Promise((resolve, reject) => {
        let args = [];
        if (executable && !nativePath.isAbsolute(executable))
            executable = nativePath.join(cwd, executable);
        if (!executable)
            executable = "-p";
        if (target.startsWith("extended-remote")) // added
            args = this.preargs; // added
        else // added
            args = args.concat([executable, target], this.preargs);
        this.process = ChildProcess.spawn(this.application, args, { cwd: cwd });
        this.process.stdout.on("data", this.stdout.bind(this));
        this.process.stderr.on("data", this.stderr.bind(this));
        this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
        Promise.all([
            this.sendCommand("gdb-set target-async on"),
            this.sendCommand("environment-directory \"" + escape(cwd) + "\""), // appended comma
            this.sendCommand("target-select " + escape(target)), // added (this should only be here for extended-remote)
            this.sendCommand("file-symbol-file \"" + escape(executable) + "\"") // added (this should only be here for extended-remote)
        ]).then(() => {
            this.emit("debug-ready");
            resolve();
        }, reject);
    });
}

launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "BMPv2",
      "type": "gdb",
      "request": "attach",
      "gdbpath": "~/gcc-arm-none-eabi-5_2-2015q4/bin/arm-none-eabi-gdb",
      "target": "extended-remote /dev/cu.usbmodemXXXXXXXX",
      "executable": "my-arm-executable.elf",
      "cwd": "${workspaceRoot}",
      "autorun": [
        "monitor tpwr enable",
        "monitor swdp_scan",
        "attach 1",
        "load my-arm-executable.elf"
      ]
    }
  ]
}
@WebFreak001
Copy link
Owner

WebFreak001 commented Jan 8, 2017

Does it still work if you change this.sendCommand("target-select " + escape(target)), to this.sendCommand("target-select extended-remote "" + escape(target.substr(16)) + """),?

Nvm, I am going to remove that escape there because the user should have control over the target if he starts it with extended-remote already

@mdelete
Copy link
Author

mdelete commented Jan 9, 2017

It would not work if you put the parameter after extended-remote in quotes, even if properly escaped with backslashes ;). The escape() is fine, though.

@WebFreak001
Copy link
Owner

WebFreak001 commented Jan 10, 2017

The escape will replace " with \" and replace \ with \\, so unless in quotes it will break things

@DeadRabbits307
Copy link

DeadRabbits307 commented Jul 3, 2019

Is a extended-remote support now possible with native debug? I still can not get a setup with a working "restart" functionality in the VS Code debugger. If I am wrong, how would a correct launch.json look like?

On the target I start gdbserver as following:
gdbserver --multi :2345

My launch.json:

{   
            "type": "gdb",
            "request": "attach",
            "name": "myprogdebug via gdbserver",
            "executable": "./myprog",
            "target": "extended-remote xx.xx.xx.xx:2345",
            "remote": false,
            "cwd": "${workspaceRoot}",
            "valuesFormatting": "parseText",
            "gdbpath": "aarch64-linux-gdb",
            "env": {
                "PATH": "/path/to/cross-compiler:${env:PATH}"
             },
            "printCalls": true,
            "autorun": ["b 27", "set remote exec-file myprog"]
}

@WebFreak001
Copy link
Owner

here is the example config I added with the commit: 318ece4#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R373

if you have more questions, make a separate issue

@DeadRabbits307
Copy link

DeadRabbits307 commented Jul 3, 2019

Thank you for your quick reply.

Unfortunately this config for Microcontrollers does not help. I use a target running an embedded OS build with buildroot.

I will open a new issue with more information. --> #183

esben added a commit to geanix/code-debug that referenced this issue Nov 21, 2019
This extends gdb launch configurations to support extended-remote.
It can be used for remote debugging where code is compiled on host, and
transferred and debugged on target using a remote gdbserver (or something
else speaking GDB/MI).

Note, this is not touching the code added in commit
318ece4 ("Added special commands for extended-remote fix WebFreak001#91"),
as that is only related to gdb attach configuration, although the
example in package.json is confusingly put with launch, which is
opposite of the code change.
I did not fixup that change, as I am not sure exactly what to put
instead.
esben added a commit to geanix/code-debug that referenced this issue Nov 21, 2019
This extends gdb launch configurations to support extended-remote.
It can be used for remote debugging where code is compiled on host, and
transferred and debugged on target using a remote gdbserver (or something
else speaking GDB/MI).

Note, this is not touching the code added in commit
318ece4 ("Added special commands for extended-remote fix WebFreak001#91"),
as that is only related to gdb attach configuration, although the
example in package.json is confusingly put with launch, which is
opposite of the code change.
I did not fixup that change, as I am not sure exactly what to put
instead.
esben added a commit to geanix/code-debug that referenced this issue Nov 22, 2019
This extends gdb launch configurations to support extended-remote.
It can be used for remote debugging where code is compiled on host, and
transferred and debugged on target using a remote gdbserver (or something
else speaking GDB/MI).

Note, this is not touching the code added in commit
318ece4 ("Added special commands for extended-remote fix WebFreak001#91"),
as that is only related to gdb attach configuration, although the
example in package.json is confusingly put with launch, which is
opposite of the code change.
I did not fixup that change, as I am not sure exactly what to put
instead.
esben added a commit to geanix/code-debug that referenced this issue Jan 7, 2020
This extends gdb launch configurations to support extended-remote.
It can be used for remote debugging where code is compiled on host, and
transferred and debugged on target using a remote gdbserver (or something
else speaking GDB/MI).

Note, this is not touching the code added in commit
318ece4 ("Added special commands for extended-remote fix WebFreak001#91"),
as that is only related to gdb attach configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants