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
"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 themainloop.c
file. You can debug using gdb. Make sure you compiled the code with the debugging flagexport CFLAGS='-g3 -O0'
.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:
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.
Now run again to recompile.
Initiate gdb and add it the program using this code
After the initiation of gdb, tyoe run for running the program
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!!
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.