Hi, In today's blog we will be exploring how we can setup our working environment to attach a debugger and debug AGE source code.
We will be adding some breakpoints at random files in the code just to make sure that debugger has been attached. In further blogs we will see how we can debug custom functions.
Prerequisites
- AGE and PostgreSQL Source code/installed
- VSCode
- GDB
You can checkout this blog to install AGE and PostgreSQL on you machine.
STEP 1
First of all go to the directory where postgres is installed. And start postgres. In my case its the folder named, postgresql-16beta1 So,
cd postgresql-16beta1
Then initialize a database cluster.
bin/initdb demo
Start the server using the command.
bin/pg_ctl -D demo -l logfile start
Now create a database named demodb.
bin/createdb demodb
Start the PostgreSQL server.
bin/psql demodb
After running above commands you will see a terminal like this.
Now run the command to check the backendId where postgres is running.
SELECT pg_backend_pid();
For now we are done with PostgreSQL directory.
STEP 2
Open AGE directory in the VS-Code.
Install these two VS-Code extensions if you don't have.
After installing these extensions press F5. You will be directed to Configure Debugger for the code. It will open
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/zeeshan/age16/pg/postgresql-16beta1/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
}
]
}
]
}
Edit this line in the Launch.json file.
"program": "/home/zeeshan/age16/pg/postgresql-16beta1/bin/postgres",
In my case postgres16-beta is installed in age16 and then in pg directory. Change it with path where you have installed PostgreSQL.
Save changes,
STEP 3
Again press F5, this time you will be asked to add process Id. Paste the backend-id that you copied from PostgreSQL after running command SELECT pg_backend_pid();
.
If it successful you will be asked to enter your device password. Enter the password.
Now add some random breakpoints in cypher_clause.c and cypher_analyze.c file(These files are in AGE's folder under src->backend->parser).
Step 4
Head back to PostgreSQL terminal where you are in demodb database.
Load Age extension.
CREATE EXTENSION age;
LOAD 'age';
SET search_path = ag_catalog, "$user", public;
Try some cypher queries.
SELECT create_graph('demo_graph');
SELECT * FROM cypher('demo_graph', $$ CREATE (n:Person {name : "james", bornIn : "US"}) $$) AS (a agtype);
SELECT * FROM cypher('demo_graph', $$ MATCH (v) RETURN v $$) as (v agtype);
During each command debugger will start and ask you to move forward you can move into specific function and move forward using the debugger.
You have successfully attached the debugger. Happy debugging :)
REFERENCES
https://dev.to/rrrokhtar/how-to-debug-age-source-code-on-vscode-3op7
https://imranzaheer.hashnode.dev/install-age-psql-from-source
Top comments (0)