* 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; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ messages in thread
* RE: stack trace
@ 2003-08-22 3:54 Singh, Umesh K (MED)
0 siblings, 0 replies; 6+ messages in thread
From: Singh, Umesh K (MED) @ 2003-08-22 3:54 UTC (permalink / raw)
To: linux-c-programming
thanks all of you, i think i got fair amount of homework. will try all
the suggestions and come back to you guys very soon if i have some
doubt. what i was looking is the trace equivalent to gdb or dbx output.
yeah, i am compiling with debug info and without optimization. i think
assert(3) or abort(2) is also a nice idea which will be useful in lot of
cases but in my case i won't prefer to terminate my program in most of
the cases.
thanks,
-umesh
-----Original Message-----
From: Fekete Gabor [mailto:feketga@delfin.unideb.hu]
Sent: Thursday, August 21, 2003 11:42 AM
To: linux-c-programming
Subject: Re: stack trace
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.
-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-08-22 3:54 UTC | newest]
Thread overview: 6+ 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
-- strict thread matches above, loose matches on Subject: below --
2003-08-22 3:54 Singh, Umesh K (MED)
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).