linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* stack trace
@ 2003-08-21  3:59 Singh, Umesh K (MED)
  2003-08-21  5:07 ` Glynn Clements
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Singh, Umesh K (MED) @ 2003-08-21  3:59 UTC (permalink / raw)
  To: linux-c-programming

is it possible to get the stack trace without attaching the process to debugger. For Ex. can i write a func let's say "print_stack_trace()" and call it anywhere in my program to print the stack trace at that point of time.

i thot it will be helpful in my big programs.

if it is possible, any direction/pointers???

thanks,
-umesh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: stack trace
  2003-08-21  3:59 stack trace Singh, Umesh K (MED)
@ 2003-08-21  5:07 ` Glynn Clements
  2003-08-21  6:12 ` Fekete Gabor
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Glynn Clements @ 2003-08-21  5:07 UTC (permalink / raw)
  To: Singh, Umesh K (MED); +Cc: linux-c-programming


Singh, Umesh K (MED) wrote:

> is it possible to get the stack trace without attaching the process to
> debugger. For Ex. can i write a func let's say "print_stack_trace()"
> and call it anywhere in my program to print the stack trace at that
> point of time.
> 
> i thot it will be helpful in my big programs.
> 
> if it is possible, any direction/pointers???

Sure it's possible, but it's a fair amount of work. If your programs
is released under the GPL, the easiest solution would be to take the
relevant code from gdb. Otherwise, look at the "stabs" Info file for
the details of the format of the debug information.

However, in order to get meaningful output, you will need to compile
your program with debug info, and ideally without any optimisation
(i.e. without -O, and definitely without -fomit-frame-pointer).

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: stack trace
  2003-08-21  3:59 stack trace Singh, Umesh K (MED)
  2003-08-21  5:07 ` Glynn Clements
@ 2003-08-21  6:12 ` Fekete Gabor
  2003-08-21  7:57 ` (F)stack trace Steven
  2003-08-21 10:57 ` stack trace Luciano Miguel Ferreira Rocha
  3 siblings, 0 replies; 5+ messages in thread
From: Fekete Gabor @ 2003-08-21  6:12 UTC (permalink / raw)
  To: linux-c-programming



On Thu, 21 Aug 2003, Singh, Umesh K (MED) wrote:

> is it possible to get the stack trace without attaching the process to debugger. For Ex. can i write a func let's say "print_stack_trace()" and call it anywhere in my program to print the stack trace at that point of time.

read this:
http://www.linuxjournal.com/article.php?sid=6391
it might help.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: (F)stack trace
  2003-08-21  3:59 stack trace Singh, Umesh K (MED)
  2003-08-21  5:07 ` Glynn Clements
  2003-08-21  6:12 ` Fekete Gabor
@ 2003-08-21  7:57 ` Steven
  2003-08-21 10:57 ` stack trace Luciano Miguel Ferreira Rocha
  3 siblings, 0 replies; 5+ messages in thread
From: Steven @ 2003-08-21  7:57 UTC (permalink / raw)
  To: Singh, Umesh K (MED); +Cc: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 459 bytes --]

> is it possible to get the stack trace without attaching the process
> to debugger. For Ex. can i write a func let's say
> "print_stack_trace()" and call it anywhere in my program to print
> the stack trace at that point of time.
If you're using glibc, it's reasonably easy:

#include <execinfo.h>

void print_stack_trace(void)
{
	void *buffer[100];
	int x;
	x = backtrace(buffer, 100);
	backtrace_symbols_fd(buffer, x, 1);
}

Steven Smith,
sos22@cam.ac.uk.

[-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: stack trace
  2003-08-21  3:59 stack trace Singh, Umesh K (MED)
                   ` (2 preceding siblings ...)
  2003-08-21  7:57 ` (F)stack trace Steven
@ 2003-08-21 10:57 ` Luciano Miguel Ferreira Rocha
  3 siblings, 0 replies; 5+ messages in thread
From: Luciano Miguel Ferreira Rocha @ 2003-08-21 10:57 UTC (permalink / raw)
  To: Singh, Umesh K (MED); +Cc: linux-c-programming

On Thu, Aug 21, 2003 at 09:29:56AM +0530, Singh, Umesh K (MED) wrote:
> is it possible to get the stack trace without attaching the process to debugger. For Ex. can i write a func let's say "print_stack_trace()" and call it anywhere in my program to print the stack trace at that point of time.
> 
> i thot it will be helpful in my big programs.
> 
> if it is possible, any direction/pointers???

Other people pointed to backtrace(), but I normally use in my programs,
for debugging purposes, assert(3) or abort(2) directly. The program is
also then terminated.

Thus I get a core file with the state of the program at that time. (Don't
forget to check the ulimit for core file size.)

Regards,
Luciano Rocha

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-08-21 10:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-21  3:59 stack trace Singh, Umesh K (MED)
2003-08-21  5:07 ` Glynn Clements
2003-08-21  6:12 ` Fekete Gabor
2003-08-21  7:57 ` (F)stack trace Steven
2003-08-21 10:57 ` stack trace Luciano Miguel Ferreira Rocha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).