1
votes

Program received signal SIGSEGV, Segmentation fault. 0x08049795 in execute_jobs () Current language: auto; currently asm

(gdb) info symbol 0x08049795 execute_jobs + 22 in section .text

(gdb) ptype 0x08049795 type = int

How to get the line number at which the error occurred?

2
First, you'll want to compile with -ggdb3, then GDB will give you that info. - Chris Tonkinson
Compile with debugging symbols and no optimization then run it through valgrind. You will immediately see the cause of the segfault, just by watching the fireworks :) See valgrind.org - Tim Post

2 Answers

7
votes

Your binary was not compiled with debugging information. Rebuild with at least -g (or -ggdb, or -ggdb -g3, see GCC manual.)

The exact lines from GDB output:

(gdb) info symbol 0x08049795 execute_jobs + 22 in section .text

means that instruction at address 0x08049795, which is 22 bytes from beginning of function execute_jobs, generated the segmentation fault.

(gdb) ptype 0x08049795 type = int

Here you are asking for type of an integer, and GDB happily replies. Do

(gdb) x/10i 0x08049795

or

(gdb) disassemble execute_jobs

to see actual instructions.

2
votes

The gdb command "bt" will show you a back trace. Unless you've corrupted the stack this should show the sequence of function calls that lead to the segfault. To get more meaningful information make sure that you've compiled your program with debug information by including -g on the gcc/g++ command line.