当前位置:网站首页>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
边栏推荐
- Vscode automatically formats code according to eslint specification
- Discussion on several research hotspots of cvpr2022
- [programming training] delete public characters (hash mapping) + team competition (greedy)
- [MySQL learning notes 25] SQL statement optimization
- TodoList经典案例①
- 2022危险化学品经营单位主要负责人试题及模拟考试
- Latex formula code
- Li Kou daily question - day 31 -1790 Can a string exchange be performed only once to make two strings equal
- LM08丨网格系列之网格反转(精)
- 浏览器本地存储
猜你喜欢

她就是那个「别人家的HR」|ONES 人物

2022电工(中级)复训题库及答案

PWN attack and defense world int_ overflow

下载Xshell和Xftp

Why some people earn nearly 10billion a year, while others earn 3000 a month: the details you ignore actually make the most money
![[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](/img/5e/068268857b8c7c2065ba552fd23dbb.png)
[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

奥迪AUDI EDI 项目中供应商需要了解哪些信息?

2022广东省安全员A证第三批(主要负责人)特种作业证考试题库模拟考试平台操作

How to make the two financial transactions faster

How to troubleshoot SharePoint online map network drive failure?
随机推荐
Scala语言学习-07-构造器
Cadence OrCAD capture "network name" is the same, but it is not connected or connected incorrectly. The usage of nodeName of liberation scheme
[MySQL learning notes27] stored procedure
2022年茶艺师(中级)复训题库及答案
2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation
【R语言】年龄性别频数匹配 挑选样本 病例对照研究,对年龄性别进行频数匹配
【批处理DOS-CMD-汇总】扩展变量-延迟变量cmd /v:on、cmd /v:off、setlocal enabledelayedexpansion、DisableDelayedExpansion
[kv260] generate chip temperature curve with xadc
Thesis learning -- Analysis and Research on similarity query of hydrological time series
她就是那个「别人家的HR」|ONES 人物
vscode 根据 ESLint 规范自动格式化代码
Apple account password auto fill
SharePoint - modify web application authentication using PowerShell
[R language] two /n data merge functions
[R language] age sex frequency matching select samples for case-control study, and perform frequency matching on age and sex
[recommendation system] breakthrough and imagination of deep location interactive network dpin for meituan takeout recommendation scenario
Array: question brushing record
Li Kou daily question - day 31 -1790 Can a string exchange be performed only once to make two strings equal
IMDB practice of emotion classification (simplernn, LSTM, Gru)
AUTOSAR learning record (1) – ECUM_ Init