-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
How can i attach to a remote C++ application? #78
Comments
Hi kevinchee. To attach to a remote application, Launch an instance of gdbserver on the target machine using an open port number. Get the target machine's ip address and set "miDebuggerServerAddress" : "ipaddress:port" in the launch.json file where ipaddress is replaced by the remote machines ip address, and port is replaced by the port you launch gdbserver with. Then, get the process id of the remote process (using ps -e over ssh or whatever your favorite access mechanism is) and set the processId field in the launch options to that process. |
@jacdavis, If I try what you said Simple examplegdbserver localhost:6666 ./hello {
"name": "C++ Attach",
"type": "cppdbg",
"request": "attach",
"miDebuggerServerAddress": "localhost:6666",
"program": "${workspaceRoot}/hello",
"processId": "13467",
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
} I get this on the gdbserver side
and code errors out saying
Process 13467 did exist, but as soon as it connects to the gdbserver, it disconnects and stops the process Simple workaroundHowever, if I use the (partially undocumented) feature {
"name": "C++ Attach",
"type": "cppdbg",
"request": "attach",
"miDebuggerServerAddress": "localhost:6666",
"program": "${workspaceRoot}/hello",
"processName": "hello",
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
} it does work. I'm able to set and use breakpoints
|
This is my solution which works fine: 1.) run app on remote host 2.) configure launch.json for remote debugging
3.) Hit F5 have FUN! |
all of these examples use the localhost. Im trying to get debugging working on my orangePi but "program" cannot be resolved because it looks for this on the local computer. This dose not exist. |
Actually in my tests I do attach the remote debugging session to a an application which is running in a Docker Container. Therefore it is an isolated environment which is really close to a remote debbugging session where the app runs on a target. However I have also recognized that the whole remote debugging steps arranged in tasks like: build->deploy->stop app process if still running->launch gdb server with deployed app->attach vscode debugger does not work pefect because launching the gdb server does somehow block the attachment of vscode debugger to the gdb server and the debugging does not start. When I press F5 again the vscode debugger attach to the gdbserver and the debugging starts. This is confusing... Additionaly the stopping of the remote debugging session does ofte lead to some error messages. I'm still experementing with the remote debugging capabilities of vscode with the hope to use it as my main ide for my embedded projects. |
@daniel-brosche I too am mostly interested in debugging in a docker. And I can say that the Both attach and launch work for me without any issue. You won't need to install The only gotcha is that the symbols for "linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Auto load symbols when loading an .so file",
"text": "set auto-solib-add",
"ignoreFailures": false
}
]
},
"osx": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Auto load symbols when loading an .so file",
"text": "set auto-solib-add",
"ignoreFailures": false
}
]
},
"windows": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Auto load symbols when loading an .so file",
"text": "set auto-solib-add",
"ignoreFailures": false
}
]
} Note: Even though the docker is running in Linux, VS Code wouldn't know this, so the |
@justin-romano When remote debugging, you need to copy the program executable to your local machine. I recently looked at a bunch of other debuggers that support I looked into using
However, all the IDEs out there do not take advantage of this. It would be a nice feature request to support this though ;)
gdb -ex 'target remote 127.0.0.1:3333' -ex 'remote get /proc/12345/exe /tmp/program'
#or if you are using: gdbserver --multi
gdb -ex 'target extended-remote 127.0.0.1:3333' -ex 'remote get /proc/12345/exe /tmp/program' Where Also, you might want to consider using |
Wondering if i could to this with a prelaunchTask |
With this discussion maybe VSCode should be added here: https://sourceware.org/gdb/wiki/GDB%20Front%20Ends |
https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools says we can debug code locally or remotely.
I don't see how i can configure to attach to a remote application in
launch.json
.Is this possible? If so, can i get help with an example of the
launch.json
?The text was updated successfully, but these errors were encountered: