1

I am starting the database cluster by typing this in the terminal: bin/pg_ctl -D <cluster_name> -l logfile start Then moving into a particular database: bin/psql <databse_name> I am getting the process id of the PostgreSQL Backend process by SELECT pg_backend_id() . Then I am attaching that process id to GDB.

But then how do I debug for a particular function of Apache AGE?

  • You can use the **breakpoints** at a function as discussed at the following link. It is briefly discussed in this thread. https://stackoverflow.com/questions/75675795/process-to-connect-age-code-to-gdb-debugger/75675857#75675857 – Kamlesh Kumar Mar 16 '23 at 17:54

9 Answers9

1

You can set a breakpoint at a function with GBD by typing b function_name and then type c to continue to use postgres. Then, inside postgres (which should be in another terminal tab), type the query that will trigger the funcion that you set as a breakpoint. But notice that it will not show the output yet and you'll see that GDB will have stopped the execution at the breakpoint.

Matheus Farias
  • 716
  • 1
  • 10
1

In addition to the tips in the other answers, I also recommend that you look for a tutorial on how to use gdb to debug C code, such as this one: https://u.osu.edu/cstutorials/2018/09/28/how-to-debug-c-program-using-gdb-in-6-simple-steps/

There are other useful commands like:

  • l - prints the source code in debug mode.
  • l [line number] - prints a specific line of code.
  • p [variable] - prints the value of a specific variable.
  • n - executes the next line of code.
  • s - if the next line of code is a function, it will step into the function and execute it line by line.
Carla
  • 326
  • 1
  • 7
1

After loading AGE on the postgres session and attaching it to GDB, set a breakpoint:

  1. type layout src on GDB, for easier viewing;
  2. get the function's file location and line number,
  3. then type b file_location:line_number on GDB, where b is for breakpoint.

An example usage would be b /home/age/src/backend/example.c:100.

Then, on psql, insert a command which uses your function.


Now to actually see what's happening, follow the commands:

  • c - "continue" execute the program until a set breakpoint;

  • p variable_name - "prints" the variable value; try p* for pointers;

  • n - "next" line of code, it 'jumps' over a function if called in that line;

  • s - "steps" into a function, in contrast to the prior command.

Marco Souza
  • 296
  • 7
1

I used this tutorial from dev.to to setup and use the debugger. Refer to section 3, hope this will be helpful: - https://dev.to/moeedk/set-up-apache-age-for-development-installing-and-modifying-the-source-5889

Once you're done attaching the process, you need to update the search path of gdb to tell it where the files are.

dir /path/to/age

GDB commands for debugging: - b for breakpoint, (b ) c for continue - continues to the next breakpoint n for next line s for step into p for print, (p *) for pointers bt for call stack d for delete all breakpoints list for context q for quit

To set up a breakpoint for a function write: -

b <function_name>

When the breakpoint is set, run the query. But since you've attached the process to GDB, the code should go into a blocked state.

Press c (continue) to continue the code until the breakpoint. finish will run the code till the end of the function. command bt (backtrace) can be used to checkout the stack so far. list can tell you where you are in the code.

Check the link for more detailed example.

1

After setup open the source code in any code editor. And then mark a break point to the code or function that you want to debug. Attach a debugger. You can setup GDB for this.

You need to execute the command that involve the execution of that function. After running the command your execution will stop at the point where you put the breakpoint. And as mentioned by others you can use different GDB commands to check or debug function.

Zeeshan
  • 71
  • 2
0

Have Postgres configured with enabling debugging flags and a running Postgres instance. An open session running. Know the process of the session that you will be debugging ps -C postgres

Execute the command gdb -p

the following are The basic GDB commands:

  • b for breakpoint, (b <function_name>)
  • c for continue - continues to the next breakpoint
  • n for next line
  • s for step into
  • p for print, (p *) for pointers
  • d for delete all breakpoints
  • q for quit
0

You can use GDB and Visual Studio Code to debug Apache AGE code. Have GDB and VS code installed. Enable gdb through VS code. Then open the source code in VS code and give it the pid. After that you can set break point through out the code and execute those function through AGE. The terminal in VS code will show you the debug log. For an in depth learning you can follow this blog post https://dev.to/rrrokhtar/how-to-debug-age-source-code-on-vscode-3op7

toyota Supra
  • 3,181
  • 4
  • 15
  • 19
0

Steps to debug a function of Apache AGE using GDB

  • Type this command in terminal: bin/pg_ctl -D <cluster_name> -l logfile start
  • Move into a particular database by typing: bin/psql <database_name>
  • Get the process ID of the PostgreSQL Backend process by typing: SELECT pg_backend_id()
  • Attach that process ID to GDB
  • Set a breakpoint at the function you want to debug by typing b function_name
  • Continue using PostgreSQL by typing c
  • Inside PostgreSQL, type the query that will trigger the function that you set as a breakpoint
  • GDB will stop the execution at the breakpoint and you can use commands such as p variable_name to print the value of a specific variable or n to execute the next line of code.
  • You can also use s to step into a function.
-1

First of all be sure you have correctly installed the software, you could refer to this blog for correct configuration.

After completing the installation, start by setting a breakpoint with GBD by using the command b function_name and then type c to continue using postgres. Next switch to the postgres terminal and execute the function, using its query, that you set as a breakpoint.