当前位置:网站首页>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
边栏推荐
- Two expressions of string
- [MySQL learning notes 25] SQL statement optimization
- 【mysql学习笔记25】sql语句优化
- 如何使用layui将数据库中的数据以表格的形式展现出来
- [chapter 72 of the flutter problem series] a solution to the problem that pictures taken in the flutter using the camera plug-in are stretched
- Microsoft stream - how to modify video subtitles
- 关系数据库如何工作
- Redisson utilise la solution complète - redisson Documents officiels + commentaires (Partie 1)
- Todolist classic case ①
- Source code analysis of open source API gateway APIs IX
猜你喜欢

Introduction to kubernetes resource objects and common commands (II)

【无标题】

redisson使用全解——redisson官方文檔+注釋(上篇)

LM08丨网格系列之网格反转(精)

2022 test question bank and simulation test of tea master (primary) operation certificate

base64

Latex table

2022年茶艺师(中级)复训题库及答案
![[programming training 2] sorting subsequence + inverted string](/img/96/87750c5d3954ef6c39cce073e8b9ae.png)
[programming training 2] sorting subsequence + inverted string

How to check ad user information?
随机推荐
[microservice openfeign] feign's log record
[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
力扣——求一组字符中的第一个回文字符
Wang Yingqi, founder of ones, talks to fortune (Chinese version): is there any excellent software in China?
Gru of RNN
Detailed explanation of weback5 basic configuration
三极管是一项伟大的发明
How to troubleshoot SharePoint online map network drive failure?
Thesis learning -- Analysis and Research on similarity query of hydrological time series
[R language] age sex frequency matching select samples for case-control study, and perform frequency matching on age and sex
Custom events of components ②
redisson使用全解——redisson官方文档+注释(上篇)
力扣每日一题-第31天-202.快乐数
ONES 创始人王颖奇对话《财富》(中文版):中国有没有优秀的软件?
力扣每日一题-第31天-1502.判断能否形成等差数列
2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation
QT -- 1. QT connection database
【R语言】两个/N个数据合并merge函数
【mysql学习笔记27】存储过程
Discussion on several research hotspots of cvpr2022