Register to reply

Dealing with segmentation faults

by heartless
Tags: dealing, faults, segmentation
Share this thread:
heartless
#1
Jun27-06, 02:00 PM
P: 214
Hi everyone,
I'd like to know how to prompt gdb to show me where segmentation fault in an application occurs and why. Any ideas?
Phys.Org News Partner Science news on Phys.org
Scientists develop 'electronic nose' for rapid detection of C. diff infection
Why plants in the office make us more productive
Tesla Motors dealing as states play factory poker
chroot
#2
Jun27-06, 02:25 PM
Emeritus
Sci Advisor
PF Gold
chroot's Avatar
P: 10,427
Segfaults happen when your program tries to write to memory that doesn't belong to it. Common causes are:

1) Using uninitialized pointers.
2) Using uninitialized variables for pointer arithmentic (array indexing).
3) Letting a counter go beyond the boundaries of an array.

You should be able to use gdb to step through your code until you find the offending line.

- Warren
heartless
#3
Jun27-06, 02:35 PM
P: 214
Yepp, that's what wikipedia says. However do you have any ideas how to find specific line or lines that cause segmentation fault in an application. I tried gdb for "normal" aps, and everything works perfectly, but I can't debug any applications with segmentation faults.

For example:
adrian@ubuntu:~/files/asm$ gdb env_show --quiet
(no debugging symbols found)
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) r
Starting program: /home/adrian/files/asm/env_show

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
You can't do that without a process to debug.
(gdb) info registers
The program has no registers now.
(gdb) bt
No stack.
(gdb)

and so on, I'm not very experienced with gdb,
--Thanks,

chroot
#4
Jun27-06, 02:40 PM
Emeritus
Sci Advisor
PF Gold
chroot's Avatar
P: 10,427
Dealing with segmentation faults

Rather than just running your program, put a breakpoint in and step through it line by line.

- Warren
chroot
#5
Jun27-06, 02:43 PM
Emeritus
Sci Advisor
PF Gold
chroot's Avatar
P: 10,427
Also, I presume that you compiled your program with gcc -g to include debugging information in the executable.

- Warren
nmtim
#6
Jun28-06, 06:55 AM
P: 79
Or run gdb on the core dump. Never done it myself, but the core file should have the program state at the time of the segfault.


Register to reply

Related Discussions
Networking -Message Segmentation Engineering, Comp Sci, & Technology Homework 2
Dealing with Anomalies Advanced Physics Homework 0
Ground plane segmentation by Nick Pears General Math 0
Segmentation Fault Computing & Technology 5