Chris Jewell <vs0u8055@liv.ac.uk> wrote:
> Hi,
>
> I'm working on a frontend to a Postgresql database. I've chosen C in
> which to work, mainly because I wanted to learn the language. So, I'm
> using the pqlib frontend library. The C source I have is below. I
> compile it (on linux) with gcc -g -Wall -lpq -oantibug antibug.c. When
> I run the executable, it prints out the query to the screen ok, but also
> prints a "Segmentation Fault" on completion of the list. Does anyone
> know why?
This is really a C/Linux/gcc question. I haven't looked at your source, so
just some general remarks:
You'll want to compile your program with "-g" as an additional compiler
switch. Then you also want core dumps to be written to disk
"ulimit -c unlimited" in your shell.
You can then analyze the core dump using gdb:
$ gdb /path/to/your/app
gdb> core /path/to/corefile # usually just 'core'
gdb> bt # short for 'backtrace'
You'll then see where your program crashed.
Alternatively, run your app under gdb (or a GUI frontend like ddd/gvd/...)
in the first place to see where it crashes.
HTH,
-- Gerhard