Welcome everyone
Today we will set up our environment to debug and work with AGE source code on VSCode Editor.
Prerequisites
- Postgresql source code installed
- AGE source code & installed
- VSCode for sure
- GDB
Our case here we will debug a function that we have added to the source code if you have missed adding some functions to AGE source code you can find that out on my blog, here is the link of it: https://dev.to/rrrokhtar/guide-to-age-contribution-and-modifying-the-source-code-to-add-new-functions-l7m
Lets set up our AGE git repository to exclude some of our new created directory which is .vscode
TLDR;
echo '/.vscode/*' >> .git/info/exclude
We will need to modify out local git repo to exclude that directory we are going to work with to setup the linkage of our source-codes and header files so that whenever we click on smth it gets navigation to that function/file
cd .git/info
sudo nano exclude
Add whatever you want to exclude just like .gitignore but it works on you local machine only.
REPLACE all /home/rrr/postgresql-14.7/
with corresponding postgresql directory on your machine
AND /usr/local/pgsql/
with your installed postgresl directory
- incase of you are having the source code and installation on same directory, they will be the same.
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/usr/include/**/**",
"${workspaceFolder}/**",
"/usr/include/**",
"/usr/local/pgsql/include/**",
"/usr/local/pgsql/include/server/**",
"/home/rrr/postgresql-14.7/src/**",
"/home/rrr/postgresql-14.7/**",
"/home/rrr/postgresql-14.7/src/backend/**",
"/usr/local/pgsql/lib/**",
"${workspaceFolder}/src/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/home/rrr/postgresql-14.7/bin/postgres",
"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
}
]
}
]
}
settings.json
{
"files.associations": {
"postgres.h": "c",
"genam.h": "c",
"heapam.h": "c",
"tableam.h": "c",
"table.h": "c",
"htup_details.h": "c",
"skey.h": "c",
"pg_operator.h": "c",
"namespace.h": "c"
}
}
Now you are supposed to have all of your headers and linkage works properly
LETS dive into the debugging
- START postgres server
- CONNECT through psql session
-
GET THE pid of that backend process through
SELECT pg_backend_pid();
SET your breakpoints on your function or anywhere you want
Get start with the debugging on VS code through click on F5 and write the process id you got from the psql session
Write commands to the psql session (call your function to get into that and reach the break points you have set
Have a good debugging day <3
Another debugging blog:
https://dev.to/rrrokhtar/gdb-debugging-session-postgresql-age-2b27
References & Resources
Top comments (0)