Hi,
Time to activate this list into action........
One of the normal pitfalls of programming in a C language is the
dreaded segfault..
Normally, one would:
compile in debug mode, generate a core dump with the segfault, and
then load the core dump and executable into the debugger. This
normally takes you
the point of the failure.
Alternatively, one would compile in debug mode, and just run it in
the debugger.
=====================
However, there are times when code compiled without debugging (-g, or
-g3) fails and generates
a core dump. Is there a way to "reverse engineer" and figure out the
faulty line of code?
Indeed, I have seen where code compiled with debug options does not
segfault,
but the same code compiled without debug fails. Turned out in that case
that the debug code had larger stack sizes
and could cope with very large arrays being placed on the stack.
So far, I have seen that one can load the core dump into the debugger,
and type in
info symbol offending_hex_address
and it will tell you how far through a method/function the problem
happens at. At this stage, one has to utilise
all assembly knowledge and determine the offending line of code.
The question is: does anyone know of a way of taking a segfault address
(from release version code) and determing the
offending line of C code? Can one generate a map (at compile time) that
relates addresses to lines of code...
You can put
-Wl,-Map=mapfile
into the link command, but this shows how the final executable is
layed out, and does not allow for a correlation to individual lines.
It seems that one should create a map at the time of compile each source
file - but have not seen such an option...
For sure, with optimisation turned on, the assembly instructions have no
direct correlation to lines of code - which makes it a doubly
hard question..
Thanks,
Derek.
--
========================================
Q How did you make it work?
A The usual story, got everything right.
_______________________________________________
Linux-users mailing list
[email protected]
http://lists.canterbury.ac.nz/mailman/listinfo/linux-users