当前位置:网站首页>Master vscode remote GDB debugging
Master vscode remote GDB debugging
2022-04-23 15:52:00 【ZONG_ XP】
0 background
Recently, under the Amway of my colleagues , Tried to use vscode do gdb debugging , After use ,“ It's delicious ”.
Don't talk much , What this paper wants to achieve is : stay windows Terminal remote debugging linux The server and arm On embedded devices c++ Code , Yes gdb The configuration and use of debugging shall be sorted out .
Other :《 One article mastery vscode Remote debugging python Code 》
1 Remote connection
First, you need to realize remote connection to the server , Search in plug-in library “remote-ssh”, Double click to download and install ( In the figure below, I have installed ), After installation, remote Explorer appears in the sidebar

Click on + Number , In the pop-up command window, enter ssh Login instruction , Follow the instructions , Enter the password and confirm , You can connect successfully

2 To configure GDB Environmental Science
Create a c++ Code , Here we use 《Linux And C++ Get the system user name 》 For example, the code in , It's simple
#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;
}
Compile as follows , Be sure to add -g Instructions , Otherwise, we can't gdb debugging
g++ -g test.cpp -o test
And then click file - Open folder , Find the created code path , after , In the Explorer on the left, you can see the code file .
Installation is required for the first operation c++ An extension of , In the extension page , install C/C++

Simultaneous search GDB Debug And install

Once installed , Click on “ Operation and commissioning ” Button ,“ establish launch.json” file ,

choice C++(GDB/LLDB) term , Automatic generation launch.json file , The contents are as follows
{
// Use IntelliSense Learn about properties .
// Hover to see the description of an existing property .
// For more information , Please visit : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
Follow the content below , Modify the corresponding
{
// Use IntelliSense Learn about properties .
// Hover to see the description of an existing property .
// For more information , Please visit : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) start-up ", // Configuration name , Displayed in the configuration drop-down menu
"type": "cppdbg", // Configuration type
"request": "launch", // Request configuration type , It can be startup or additional
"program": "${workspaceFolder}/test", // The full path of the program executable ,${workspaceFolder} Indicates the initial path of the remote connection
"args": [], // Command line arguments passed to the program
"stopAtEntry": false,// Optional parameters , If true, The debugger should be at the entrance (main) Stop at
"cwd": "${workspaceFolder}", // Target's working directory
"environment": [], // Indicates the environment variable to be preset
"externalConsole": false,// If true, Start the console for the debug object
"MIMode": "gdb",// The console you want to connect to starts the program
"setupCommands": [ // One or more... Executed to install the base debugger GDB/LLDB command
{
"description": " by gdb Enable neat printing ",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
So far, the environment configuration is completed
3 GDB Debugging method
Click directly on the left side of the number of lines in the source code , You can add breakpoints , After setting the breakpoint , Click on “ Operation and commissioning ”--(gdb) start-up , as follows

You can enter the debug page

You can see the variable value directly in the variable area , Complete commissioning purpose .
Common debugging keys are as follows
F5 Start debugging
F10 Step over
F11 Step by step debugging
shift + F11 Step out
ctrl + shift + F5 Restart debugging
shift + F5 Stop debugging
版权声明
本文为[ZONG_ XP]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231547448963.html
边栏推荐
- Redis master-slave replication process
- 时序模型:门控循环单元网络(GRU)
- [split of recursive number] n points K, split of limited range
- leetcode-396 旋转函数
- 多级缓存使用
- Sortby use of spark operator
- One brush 314 sword finger offer 09 Implement queue (E) with two stacks
- 贫困的无网地区怎么有钱建设网络?
- MySQL Cluster Mode and application scenario
- 使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群
猜你喜欢
随机推荐
Neodynamic Barcode Professional for WPF V11.0
Go语言切片,范围,集合
使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群
字符串排序
Upgrade MySQL 5.1 to 5.66
负载均衡器
Modèle de Cluster MySQL et scénario d'application
CVPR 2022 quality paper sharing
王启亨谈Web3.0与价值互联网“通证交换”
R语言中实现作图对象排列的函数总结
Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)
Accumulation of applet knowledge points
The principle and common methods of multithreading and the difference between thread and runnable
Implement default page
提取不重复的整数
Leetcode-396 rotation function
【自娱自乐】构造笔记 week 2
Named in pytoch_ parameters、named_ children、named_ Modules function
MySQL集群模式與應用場景
PHP function









