Re: Line number at segfault

Jens.Toerring_at_physik.fu-berlin.de
Date: 05/19/04


Date: 19 May 2004 15:40:35 GMT

Francis <fDONTSPAMgudin@nerreallydontim.net> wrote:
> Le 19-05-2004, Russell Shaw <rjshawN_o@s_pam.netspace.net.au> a écrit :
>> I'm using gcc 3.3.3 on debian.
>>
>> Is there any way to make the segfault of a C program
>> print out the file and line number it happened at?

If you can't load the core file into your debugger you can install
a signal handler for SIGSEGV and then use the backtrace() and
backtrace_symbols_fd( ) functions (see the info pages for libc)
to stderr (i.e. file descriptor 2). But of course you need to have
to program compiled with the '-g' option, otherwise all you can
get is a list of addresses, but no line numbers. And also note
that optimization can mess up the results.

                                  Regards, Jens

-- 
  \   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
   \__________________________  http://www.toerring.de


Relevant Pages

  • Re: Line number at segfault
    ... > I'm using gcc 3.3.3 on debian. ... > Is there any way to make the segfault of a C program ... -g flag at compile time? ...
    (comp.unix.programmer)
  • Re: Line number at segfault
    ... [This followup was posted to comp.unix.programmer] ... > I'm using gcc 3.3.3 on debian. ... Aftedr your program dies with a "segfault", ...
    (comp.unix.programmer)
  • Re: Line number at segfault
    ... Web Surfer wrote: ... >>I'm using gcc 3.3.3 on debian. ... so i can pinpoint the segfault. ...
    (comp.unix.programmer)
  • Re: SAL, Auto_Text_IO release
    ... When we started the project there was no GCC 4.1 and GCC 3.x Ada ... one more reason to use Debian or, alternatively, one of GNU Ada's ... Debian is a good development platform, but also a good, ... various bugs in the runtime and have not reproduced them with newer ...
    (comp.lang.ada)
  • Re: GNAT GPL 2005 Edition is now available
    ... Is it better than the GCC 3.4 one? ... * The target release date for Debian Etch is 18 months after Sarge, ... * It is likely that Debian Etch will switch again from GCC 4.0 to GCC ... ABI will not change, so the transition should be much ...
    (comp.lang.ada)