Re: generating stack dump in C++ application??

From: Qasim Zaidi (qasim_zaidi_at_agilent.com)
Date: 06/09/04


Date: Wed, 09 Jun 2004 10:20:48 +0500

Piping to an interactive program like gdb would not work because the pipe
can't mimic the behavior of stdin that well.
Instead you can do something like
sprintf(s, "gdb /home/m7000/m7600/m7k -x commands %d", getpid());

where commands will be a file containing the gdb commands, such as
$cat commands
where
detach
quit

This works on my system.
Qasim
On Tue, 08 Jun 2004 18:22:28 -0500, Daniel Miller wrote:

> I want to generate a stack dump in a C++ program, when it gets a SIGSEGV or
> GPF. I tried searching the archives for this newsgroup, and found a couple
> of suggestions, but none of them return useful results in my application!!
>
> ==========================================================================
>
> The Unix Programming FAQ (which hasn't been updated since 2000),
> recommended:
>
> sprintf(s, "/bin/echo 'where\ndetach' | gdb /home/m7000/m7600/m7k %d",
> getpid());
>
> When I run this in my signal handler, though, and force a fault by writing
> to a NULL pointer, it loads all the library symbols just fine, but it
> doesn't show anything:
>
> 0x40207d57 in waitpid () from /lib/libc.so.6
> (gdb) Hangup detected on fd 0
> error detected on stdin
> Detaching from program: /home/m7000/m7600/m7k, process 21304
> caught signal 11
>
> ==========================================================================
>
> I also found a stacktrace utility from Bjorn Reese:
> http://home1.stofanet.dk/breese/debug/debug.tar.gz
> When I run this in STANDALONE mode, it produces a *beautiful* and accurate
> stack dump...
>
> But when I run it, it *also* shows no stack contents or symbol data.
>
> I've compiled all my modules with -ggdb, so the data *should* be
> available... And I'm generating the fault from two levels down in function
> calls, so there should be data on the stack.
>
> Does anyone have any idea what I'm doing wrong?? Is there some simpler way
> to solve this problem??
>
> Dan Miller



Relevant Pages

  • Re: Freescales Idea of Open Source JTAG
    ... JTAG specifies one or maybe two layers, the transport of commands ... How is GDB used without OpenOCD? ... a remote target, I tell it to invoke a gdb which has been built as part ...
    (comp.arch.embedded)
  • Re: Check Pop3 or IMAP4
    ... I read somewhere that telnet does not support stdin and stdout. ... to send commands to the port 110. ... This works only if the server doesn't require the encoding of the password, ...
    (microsoft.public.scripting.vbscript)
  • Re: queuing up user input via writes to STDIN
    ... ReadMode 0; # Reset tty mode before exiting ... I have a program that reads STDIN for user commands while the program is ...
    (perl.beginners)
  • Re: While loop and commands that read from std input
    ... the arguments of the loop and the usage of '/dev/null' to prevent such ... difference between such commands and others that don't read std input. ... they obviously read stdin. ... While it's pretty obvious that ssh reads from stdin if you don't provide ...
    (comp.unix.shell)
  • STDIN on the fileevent handle
    ... I am using STDIN to feed a fileevent handle and populate a status ... So, for example, if I type in one of four acceptable commands ... # Configure the top level widgets ... chomp $value; ...
    (comp.lang.perl.tk)