code-debug icon indicating copy to clipboard operation
code-debug copied to clipboard

Does it support gdb extended remote connection for launch?

Open fbs2016 opened this issue 3 years ago • 6 comments

If submitting a bug please make sure

  • [ ] If you are using gdb
    • [ ] gdb --version >= 7.7.1
    • [ ] it works on the command line with gdb
    • [ ] cwd and target are properly set
  • [ ] If you are using lldb
    • [ ] lldb --version >= 3.7.1
    • [ ] it works on the command line with lldb-mi
    • [ ] cwd and target are properly set

Screenshots are helpful but not required

Does it support gdb extended remote connection for launch/attach? Thanks, I try to debug applicaiton with "gdbserver --multi", but it can't work.

fbs2016 avatar Jun 22 '22 11:06 fbs2016

Yes, that's supported, see #330 for the issue that currently documents how this is done (feel free to send a PR to add this to the README) and about how it likely will be adjusted.

GitMensch avatar Jun 22 '22 11:06 GitMensch

@GitMensch Thanks a lot. I try it between 2 linux host, it works well. And I try to debug our embedded os from my linux host, it can't work.

    {
        "type": "gdb",
        "request": "attach",
        "name": "Attach to gdbserver",
        "executable": "myexe",
        "target": "extended-remote 127.0.0.1:37303",
        "showDevDebugOutput": true,
        "remote": false,
        "cwd": "${workspaceRoot}",
        "gdbpath": "gdb",
        "autorun": [
            "b 11",
	"attach 2"
	],
        "printCalls": true,
    },

The log in debug console:

6-interpreter-exec console "b 11" 7-interpreter-exec console "attach 2" GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"Breakpoint 1 at 0x2005b0: file myexe, line 11.\n"}]} Breakpoint 1 at 0x2005b0: file myexe, line 11. GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"breakpoint-created","output":[["bkpt",[["number","1"],["type","breakpoint"],["disp","keep"],["enabled","y"],["addr","0x00000000002005b0"],["func","main"],["file","myexe"],["fullname","myexe"],["line","11"],["thread-groups",["i1"]],["times","0"],["original-location","myexe:11"]]]]}]} GDB -> App: {"token":6,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[]}} GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"Attaching to process 2\n"}]} Attaching to process 2 GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"log","content":"Attaching to process 2 failed\n"}]} Attaching to process 2 failed GDB -> App: {"token":7,"outOfBandRecord":[],"resultRecords":{"resultClass":"error","results":[["msg","Attaching to process 2 failed"]]}}

fbs2016 avatar Jun 27 '22 08:06 fbs2016

Hi @fbs2016:

Can you also post the logs and configuration from the scenario that did work? Also, I'm curious about your configuration. You mentioned your host is running Linux and you're attempting to debug your embedded OS. I assume your embedded OS is running on a different machine. With that expectation, I'd think that your IP address wouldn't be the loopback IP for the Linux host, but maybe I don't fully understand your configuration.

The response "Attaching to process 2 failed" is coming from GDB. Are you able to perform the same functionality from the GDB command line? If so, could you post the set of commands you use from the command line to accomplish this? That might help us understand if commands are being sent in different orders or something else that might be different between the command line and this extension.

If it's possible, can you post the complete logs for both setups?

brownts avatar Jun 27 '22 12:06 brownts

@brownts Thanks. I try my embedded os on QEMU, so the the ip is localhost. The attach can work well if I define the command in "autorun". And the launch can't work for remote debug I can't configure the remote address of launch, I see that the launch just support local debug, right?

I can launch the exe from customized gdb cmd in "autorun" of attach configuration, but I can't kill the process as attach just support disconnect.

fbs2016 avatar Jan 11 '23 06:01 fbs2016

https://github.com/WebFreak001/code-debug/pull/195

fbs2016 avatar Jan 11 '23 06:01 fbs2016

This extension doesn't support a "launch" configuration for the extended-remote, at least not at this time, however I'm pretty sure you can get what you want using the "attach" configuration.

I'm still a bit unclear on exactly how you are using this. Are you specifying the application to load on the command line as an option to gdbserver or are you expecting to load the file via the extension? I assume you want to specify the application to load in the extension configuration. If so, you can do this by specifying it in the autorun list and disabling the default "continue" behavior (i.e., by setting stopAtConnect to true) and adding in the "run" command:

stopAtConnect: true,
autorun: [
   "set remote exec-file /path/to/filename",
   "run"
]

You also mentioned that the default "disconnect" doesn't kill the process. Is it possible that using the --once option with your gdbserver command would address this? Again, it's not clear exactly what your debugging workflow looks like, so I'm not sure if this meets your needs.

brownts avatar Jan 15 '23 17:01 brownts