Project

General

Profile

DebugPage » History » Version 3

matt, 10/22/2017 09:21 AM

1 2 matt
h1. Debugging Segmentation Faults
2 1 zecke
3
Of course, you are such a clever programmer that your code never aborts, but the code written by that other guy regularly crashes, so you get a "Segmentation Fault".
4
5
The GNU Radio Wiki page mentions a method of catching the error by running your application under GDB.  However I've found in some cases that GDB might slow down the app.  This page shows an alternative way of getting the stack backtrace.
6
7 3 matt
First you must enable core dumps (which are mostly disabled by default these days).  The @ulimit -a@ command queries the current limits:
8 1 zecke
9 2 matt
@
10 1 zecke
$ ulimit -a
11
core file size          (blocks, -c) 0
12 2 matt
@
13 1 zecke
14 2 matt
We use the @ulimit@ command to turn off the limit:
15 1 zecke
16 2 matt
@
17 1 zecke
$ ulimit -c unlimited
18
$ ulimit -a
19
core file size          (blocks, -c) unlimited
20 2 matt
@
21 1 zecke
22 2 matt
Now run the app, and wait for the crash.  It should generate a file called @core@ or @core.@PID in the current directory.  There are a few other obscure reasons that could also prevent the core file from appearing at this point (already a file with the same name but not owned by the user; user does not own the directory; executable is setuid, etc).
23 1 zecke
24 2 matt
For this example assume the core file is named @core.12345@.  Now do
25 1 zecke
26 2 matt
@gdb /usr/bin/python core.12345@
27 1 zecke
28
This should load the core dump into GDB.  Now you can do
29
30 2 matt
@i stack@
31 1 zecke
32
to display the call trace.
Add picture from clipboard (Maximum size: 48.8 MB)