skip to Main Content

I am creating a new AGE CLI using lex/yacc, Makefiles, and several PostgreSQL files (project link). When executing the created interface ./agesql (similar to bin/psql for postgres) and entering a backslash command, I get the error:

ERROR: /* error message */
[1]    15675 segmentation fault  ./agesql

What does the ‘segmentation fault’ refer to, and what do the numbers represent? Is there a way to find the source causing the errors?

To replicate this error, have a postgres 15 server running and run the following lines of code to compile the makefile:

git checkout AGE_CLI
export PATH={path to pgsql-15}/bin/:$PATH
export USE_PGXS=TRUE
flex -b -Cfe -p -p -o 'cypher.c' cypher.l
bison -d cypher.y
make

After compilation, run the interface and then the backslash command:

./agesql

which will generate the segmentation fault error.

4

Answers


  1. "Segmentation fault" error means that the program is trying to access a not allowed memory location. You can find the source of the problem by using the debug.

    Since MainLoop() handles the backslash command, set up a breakpoint for the function and then run the backslash command to find which line causes the error. MainLoop is defined in the mainloop.c file. You can debug using gdb. Make sure you compiled the code with the debugging flag export CFLAGS='-g3 -O0'.

    Login or Signup to reply.
  2. Segmentation fault is caused when program to accesses memory which is out of its defined scope (Generally a programming error).

    While compiling, set "DEBUG FLAGS", to get debugging console output.

    Other things you can do are:

    1. Enable core dumps: To get memory image of program & then analyze it.
    2. Use Logging Statements to track program flow.
    3. Use Valgrind.
    Login or Signup to reply.
  3. Debugging techniques can be used to find the source of the segmentaion fault and one of the technique s to use gdb Debugger. To find and the siurce causing the segmentaion fault, try these steps.

    1. Enable your debuugging symbols and compile the program. Additionaly, add the -g flag in the makefile as follow:

    CFLAGS += -g

    1. Now run again to recompile.

    2. Initiate gdb and add it the program using this code

    gdb ./agesql

    1. After the initiation of gdb, tyoe run for running the program

    2. Hence now ehnerve the segmentation fault happens, gdb will interept the execution and will give the message regarding the crash.

    Analyze the line of code which is a source of it. Hope it helps!!

    Login or Signup to reply.
  4. The ‘Segmentation Fault’ is a specific error that occurs when program tries to access a memory location it is not permitted to.

    The number ‘[1]’ refers to a job or task number. When you have multiple processes running simultaneously, each process is given a number. In this scenario, the ‘[1]’ indicates that the error took place in the first task.

    ‘15675’ represent the process ID (PID) of the process that has undergone the error.

    To figure out how to fix this you could use debugging tools or check for uninitialised variables.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search