当前位置:网站首页>PostgreSQL source code learning (26) -- windows vscode remote debugging PostgreSQL on Linux
PostgreSQL source code learning (26) -- windows vscode remote debugging PostgreSQL on Linux
2022-07-01 07:56:00 【Hehuyi_ In】
This article commemorates Xiaobai's success in debugging the source code with development tools for the first time ~
gdb There are still many inconveniences in using command line debugging , Originally, I wanted to find a simple way to debug directly Windows Under the pg Source code , I've been looking for it for a long time vs, Too heavy and complicated . Most actual environments still run in Linux Of , So it's better to debug Linux Under the pg Source code .
- Target end :centos 7+postgresql 14
- Source end :Windows 10 + vscode
One 、 postgresql 14 Source code compilation and installation
- Before written pg Source code installation method for debugging , It's the same here ( So if you have installed it before, you can use this environment ). Special attention should be paid to adding --enable-debug, Otherwise, it is impossible to debug .
Try the inside after installation gdb Examples of debugging , Because the later tools will also rely on gdb. If the execution is OK , Then we can go on .
Two 、 install vscode
Download link :Visual Studio Code - Code Editing. Redefined
If it's too slow , There are also a large number of websites in China that provide downloads , The next step in the installation process is the next step .
1. Local installation vscode plug-in unit
Under it 3 individual :
- C/C++
- C/C++ Runner: compile 、 function 、debug
- Remote Development: Remote development . It has three plug-ins installed :Remote-SSH,Remote-Container,Remote-WSL, If you only need ssh Connect , Only install Remote-SSH Can .
2. Test remote connection
stay Remote Development After the plug-in is installed , There will be a small computer icon in the lower left corner , Click it , Then build ssh Connect . Fill in the box as prompted ssh [email protected]
Click the small plus sign next to it after matching , A new interface will pop up to let you enter the password
The first time you go in, it will install vscode, It will be slow , It's in /root Now create a hidden Directory vscode.
If an error is reported during installation Resolver error: Error: XHR failed, It could be a network problem , hold linux Upper .vscode Delete the table of contents , Just try again a few times .
After the connection is successful, you can see Linux The command line
3、 ... and 、 Configure remote debugging pg
Open source src Catalog , establish .vscode Catalog , as well as launch.json file . Direct use Linux The command line can also , adopt vscode It's OK to build
launch.json The contents of the document are as follows
{
"version": "0.2.0",
"configurations": [
{
"name": "postgresql",
"type": "cppdbg",
"request": "attach",
"program": "/data/postgres/base/14.4/bin/postgres",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
The only thing to change is "program": "/data/postgres/base/14.4/bin/postgres", Change to the actual path .
in addition Distal vscode Need to install json plug-in unit , Otherwise, an error will be reported and the file cannot be parsed .
By the way, I looked at the plug-ins installed on the remote end , except json and C/C++ Extension Pack, Others seem to be installed automatically .
If you encounter this error , Say you can't recognize cppdbg, It's not installed C/C++ Runner plug-in unit , Just install it .
Four 、 Remote debugging test
We use the simplest begin Operation as an example , track StartTransactionCommand Function execution . This function is in the /root/postgresql-14.4/src/backend/access/transam/xact.c In file
vscode End :
find xact.c In the document StartTransactionCommand function , Set a breakpoint
linux End :
psql Create connection , Query process number
select pg_backend_pid();
vscode End :
Start debug, Shortcut key F5
attach Corresponding process
You will see this output in the lower right corner
linux End :
Execute one begin command , It will get stuck
vscode End :
The cursor jumps to the corresponding function , It indicates that debugging has started , You can click the small arrow above , Step by step .
The main areas of the debugging interface are as follows :
- variable: The variable value corresponding to the execution of each step , This is very useful
- call stack: The call stack , Look from the bottom up
- The line that lights up in the code is the currently executed line
Through the comparison of code and variable value , It's easy to see what to do next case, And then do something .
thus , Our debugging test is successful , Stepped out pg The first step in learning the source code of the long march ~
Reference resources
https://blog.csdn.net/loveoobaby/article/details/123765071?spm=1001.2014.3001.5501
https://blog.csdn.net/loveoobaby/article/details/123766468
https://blog.csdn.net/Hehuyi_In/article/details/110729822
https://blog.csdn.net/Hehuyi_In/article/details/124524307
https://blog.csdn.net/wangyjfrecky/article/details/124681577
Alibaba open source mirror site -OPSX Mirror station - Alicloud developer community
边栏推荐
- H5 页面设置了字体的粗细样式,但是在华为手机里微信打开访问样式不生效?
- [programming training 2] sorting subsequence + inverted string
- [programming compulsory training 3] find the longest consecutive number string in the string + the number that appears more than half of the times in the array
- Stepsister becomes stepmother, son breaks off relationship with himself, and musk, the world's richest man, why is it so miserable?
- Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
- 【批处理DOS-CMD命令-汇总和小结】-Cmd窗口中常用操作符(<、<<、&<、>、>>、&>、&、&&、||、|、()、;、@)
- 2022 electrician (intermediate) recurrent training question bank and answers
- 如何使用layui将数据库中的数据以表格的形式展现出来
- [R language] two /n data merge functions
- 组件的自定义事件②
猜你喜欢
Minecraft 1.16.5模组开发(五十一) 方块实体 (Tile Entity)
LSTM of RNN
Minecraft 1.16.5 module development (51) tile entity
奥迪AUDI EDI 项目中供应商需要了解哪些信息?
How outlook puts together messages with the same discussion
浏览器本地存储
base64
组件的自定义事件②
Custom events of components ①
2022 electrician (intermediate) recurrent training question bank and answers
随机推荐
Principle and process of embossing
Atguigu---- scaffold --02- use scaffold (2)
Autosar 学习记录(1) – EcuM_Init
Li Kou daily question - Day 32 -1822 Symbol of array element product
Li Kou daily question - day 31 -1790 Can a string exchange be performed only once to make two strings equal
【技能】创建.bat快速打开网页
Li Kou daily question - day 31 -202 Happy number
Thesis learning -- Analysis and Research on similarity query of hydrological time series
力扣每日一题-第31天-1790.仅执行一次字符串交换能否使两个字符串相等
How to use layui to display the data in the database in the form of tables
Huawei modelarts training alexnet model
TCP/UDP 通信问题整理
Implementation and encapsulation of go universal dynamic retry mechanism
下载Xshell和Xftp
力扣每日一题-第32天-1822.数组元素积的符号
论文学习——水文时间序列相似性查询的分析与研究
Li Kou daily question - day 31 -1502 Judge whether an arithmetic sequence can be formed
Inftnews | from "avalanche" to Baidu "xirang", 16 major events of the meta universe in 30 years
AUTOSAR learning record (1) – ECUM_ Init
IMDB practice of emotion classification (simplernn, LSTM, Gru)