当前位置:网站首页>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
边栏推荐
- Sorting out tcp/udp communication problems
- Detailed explanation of weback5 basic configuration
- 【批处理DOS-CMD命令-汇总和小结】-Cmd窗口中常用操作符(<、<<、&<、>、>>、&>、&、&&、||、|、()、;、@)
- 良心安利万向轮 SolidWorks模型素材网站
- 浏览器本地存储
- ContentType所有类型对比
- Li Kou daily question - day 31 -202 Happy number
- 她就是那个「别人家的HR」|ONES 人物
- Download xshell and xftp
- Redisson watchdog mechanism, redisson watchdog performance problems, redisson source code analysis
猜你喜欢

Basic knowledge of MATLAB

web254

2022 electrician (intermediate) recurrent training question bank and answers

浏览器本地存储

Thesis learning -- Analysis and Research on similarity query of hydrological time series

The triode is a great invention

base64

How to check ad user information?

MATLAB之基础知识

Minecraft 1.16.5模组开发(五十一) 方块实体 (Tile Entity)
随机推荐
Caesar
2022 test question bank and simulation test of tea master (primary) operation certificate
How do the top ten securities firms open accounts? In addition, is it safe to open a mobile account?
论文学习——水文时间序列相似性查询的分析与研究
base64
LM08丨网格系列之网格反转(精)
How to make the two financial transactions faster
Aardio - 自己构造的getIconHandle的方法
【技能】创建.bat快速打开网页
[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
Li Kou daily question - day 31 -1790 Can a string exchange be performed only once to make two strings equal
关系数据库如何工作
redisson使用全解——redisson官方文档+注释(下篇)
Scala语言学习-07-构造器
Redisson watchdog mechanism, redisson watchdog performance problems, redisson source code analysis
[batch dos-cmd command - summary and summary] - Common operators in the CMD window (<, < <, & <,>, > >, & >, & >, & &, ||, (),;, @)
2022危险化学品经营单位主要负责人试题及模拟考试
良心安利万向轮 SolidWorks模型素材网站
凸印的印刷原理及工艺介绍
window c盘满了