How to debug remote gdb in vscode? The following article will introduce to you the method of remote gdb debugging of vscode. I hope it will be helpful to you!

Recently, with the guidance of a colleague, I tried using vscode for gdb debugging. After using it, it felt "really good".
Without further ado, what this article is going to achieve is: remote debugging the c code on the linux server and arm embedded device on the windows side, and sorting out the configuration and use of gdb debugging.
1. Remote connection
First you need to achieve remote connection to the server, search for "remote-ssh" in the plug-in library, double-click to download and install it (in the picture below I Already installed), after installation, the remote resource manager will appear in the sidebar. [Recommended learning: vscode tutorial, Programming teaching]

Click the + sign and enter ssh in the pop-up command window to log in command, follow the prompts, enter the password and confirm, the connection will be successful

2. Configure the GDB environment
Create on the server A c code, here is the code in "Linux C Get System User Name" as an example, it is very simple
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # include <unistd.h>
# include <pwd.h>
# include <iostream>
int main()
{
struct passwd* pwd;
uid_t userid;
userid = getuid();
pwd = getpwuid(userid);
std::cout << "pw_name:" << pwd->pw_name << std::endl;
std::cout << "pw_passwd:" << pwd->pw_passwd << std::endl;
std::cout << "pw_uid:" << pwd->pw_uid << std::endl;
std::cout << "pw_gid:" << pwd->pw_gid << std::endl;
std::cout << "pw_gecos:" << pwd->pw_gecos << std::endl;
std::cout << "pw_dir:" << pwd->pw_dir << std::endl;
std::cout << "pw_shell:" << pwd->pw_shell << std::endl;
return 0;
}
|
Copy after login
The compilation method is as follows, be sure to add the -g command, otherwise Unable to debug with gdb
Then click File-Open Folder and find the created code path. After confirmation, you can see the code file in the resource manager on the left.
You need to install the c extension for the first run. In the extension page, install C/C

## Also search for GDB Debug and install it

After installation, click the "Run and Debug" button, "Create launch.json" file,

Select C (GDB /LLDB) item, automatically generate launch.json file, the content is as follows
1 2 3 4 5 6 7 | {
"version" : "0.2.0" ,
"configurations" : []
}
|
Copy after login
Follow the content below and modify it accordingly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | {
"version" : "0.2.0" ,
"configurations" : [
{
"name" : "(gdb) 启动" ,
"type" : "cppdbg" ,
"request" : "launch" ,
"program" : "${workspaceFolder}/test" ,
"args" : [],
"stopAtEntry" : false,
"cwd" : "${workspaceFolder}" ,
"environment" : [],
"externalConsole" : false,
"MIMode" : "gdb" ,
"setupCommands" : [
{
"description" : "为 gdb 启用整齐打印" ,
"text" : "-enable-pretty-printing" ,
"ignoreFailures" : true
}
]
}
]
}
|
Copy after login
The environment configuration is now complete
3. GDB debugging method
In the source code, click directly to the left of the line number to add a breakpoint. After setting the breakpoint, click "Run and Debugging"--(gdb) to start, You can enter the debugging page as follows


You can directly see the variable value in the variable area to complete the debugging purpose.
Commonly used debugging keys are as follows
F5 Start debuggingF10 Single step skipF11 Single step debugging shift F11 Single step outctrl shift F5 Restart debuggingshift F5 Stop debugging
4. Problem summary
If you have connected to a certain device before, and the subsequent replacement of the device has the same IP, or the device has been reinstalled but the IP has not changed, an error will be reported when reconnecting. The reason is that the host lists the server IP as known_host

We find, modify, delete the IP and then reconnect

For more knowledge about VSCode, please visit:
vscodeBasic Tutorial!
The above is the detailed content of How to debug remote gdb in vscode? Detailed explanation of method. For more information, please follow other related articles on the PHP Chinese website!