public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to get a backtrace from a C module
@ 2006-12-01 22:06 biju64
  2006-12-04 13:12 ` John Love-Jensen
  0 siblings, 1 reply; 6+ messages in thread
From: biju64 @ 2006-12-01 22:06 UTC (permalink / raw)
  To: gcc-help


Hello,

I am trying to generate a backtrace into a file of the stack when a program
errors. I can see the gcc functions backtrace_symbols and backtrace. But
when I add it to a small C program and build I cannot find the execinfo.h
file and the two relevant functions. The progarm I use is reproduced below
(from the example):



#include 
#include 
#include 

/* Obtain a backtrace and print it to stdout. */
void
print_trace (void)
{
  void *array[10];
  size_t size;
  char **strings;
  size_t i;

  size = backtrace (array, 10);
  strings = backtrace_symbols (array, size);

  printf ("Obtained %zd stack frames.\n", size);

  for (i = 0; i < size; i++)
     printf ("%s\n", strings[i]);

  free (strings);
}

/* A dummy function to make the backtrace more interesting. */
void
dummy_function (void)
{
  print_trace ();
}

int
main (void)
{
  dummy_function ();
  return 0;
}




My version is:

gcc -v  
Reading specs from /usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/specs
Configured with:
/gates/sfw10/builds/sfw10-gate/usr/src/cmd/gcc/gcc-3.4.3/configure
--prefix=/usr/sfw --with-as=/usr/sfw/bin/gas --with-gnu-as
--with-ld=/usr/ccs/bin/ld --without-gnu-ld --enable-languages=c,c++
--enable-shared
Thread model: posix
gcc version 3.4.3 (csl-sol210-3_4-branch+sol_rpath)


Please help if you can...I just need to get a stack dump similar to the one
you see when analysing a core file using gdb.
Cheers,
Alex
-- 
View this message in context: http://www.nabble.com/How-to-get-a-backtrace-from-a-C-module-tf2740773.html#a7647122
Sent from the gcc - Help mailing list archive at Nabble.com.

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

end of thread, other threads:[~2006-12-04 18:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-01 22:06 How to get a backtrace from a C module biju64
2006-12-04 13:12 ` John Love-Jensen
2006-12-04 14:06   ` biju64
2006-12-04 14:16     ` John Love-Jensen
2006-12-04 18:51       ` biju64
2006-12-04 14:34     ` Brian Dessent

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 read-only IMAP folder(s) and NNTP newsgroup(s).