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

* Re: How to get a backtrace from a C module
  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
  0 siblings, 1 reply; 6+ messages in thread
From: John Love-Jensen @ 2006-12-04 13:12 UTC (permalink / raw)
  To: biju64, MSX to GCC

Hi Alex,

Isn't backtrace and backtrace_symbols part of the GNU C Library?

q.v. http://www.delorie.com/gnu/docs/glibc/libc_665.html

Are you using the GNU C Library, or the Sun C Library?

--Eljay


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

* Re: How to get a backtrace from a C module
  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 14:34     ` Brian Dessent
  0 siblings, 2 replies; 6+ messages in thread
From: biju64 @ 2006-12-04 14:06 UTC (permalink / raw)
  To: gcc-help



John Love-Jensen wrote:
> 
> Hi Alex,
> 
> Isn't backtrace and backtrace_symbols part of the GNU C Library?
> 
> q.v. http://www.delorie.com/gnu/docs/glibc/libc_665.html
> 
> Are you using the GNU C Library, or the Sun C Library?
> 
> --Eljay
> 

Hi Eljay,
Thanks for the reply. I thought so too...that's where I discovered the
example etc.
I am using the GNU C library (I think)...When I do a ldd on an executable
thus created I see the following:

        ....
        librt.so.1 =>    /usr/lib/librt.so.1
        libm.so.2 =>     /usr/lib/libm.so.2
        libsocket.so.1 =>        /usr/lib/libsocket.so.1
        libz.so.1 =>     /usr/lib/libz.so.1
        libnsl.so.1 =>   /usr/lib/libnsl.so.1
        libpthread.so.1 =>       /usr/lib/libpthread.so.1
        libc.so.1 =>     /usr/lib/libc.so.1        libaio.so.1 =>  
/usr/lib/libaio.so.1
        libmd5.so.1 =>   /usr/lib/libmd5.so.1
        libgcc_s.so.1 =>         /usr/sfw/lib/libgcc_s.so.1
        libmp.so.2 =>    /usr/lib/libmp.so.2
        libscf.so.1 =>   /usr/lib/libscf.so.1
        libdoor.so.1 =>  /usr/lib/libdoor.so.1
        libuutil.so.1 =>         /usr/lib/libuutil.so.1
        /platform/SUNW,Sun-Blade-2500/lib/libc_psr.so.1
        /platform/SUNW,Sun-Blade-2500/lib/libmd5_psr.so.1

As libgcc_s.so.1 is in the path I would assume it is.  But the compiler
can't find the execinfo.h file either that describes the prototype for these
functions let alone the functions themselves. Please help...

Alex
-- 
View this message in context: http://www.nabble.com/How-to-get-a-backtrace-from-a-C-module-tf2740773.html#a7678076
Sent from the gcc - Help mailing list archive at Nabble.com.

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

* Re: How to get a backtrace from a C module
  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
  1 sibling, 1 reply; 6+ messages in thread
From: John Love-Jensen @ 2006-12-04 14:16 UTC (permalink / raw)
  To: biju64, MSX to GCC

Hi Alex,

As I understand it, libgcc_s.so.1 is not the GNU C Library, rather it is the
GCC Support library, containing things like soft float, abort, pow,
trampoline support, stack unwinding, malloc/calloc/free, strlen, and perhaps
other stuff (depending on platform).

Keep in mind that the GNU C Library (glibc) is a separate project from GNU
Compiler Collection (GCC).

--Eljay

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

* Re: How to get a backtrace from a C module
  2006-12-04 14:06   ` biju64
  2006-12-04 14:16     ` John Love-Jensen
@ 2006-12-04 14:34     ` Brian Dessent
  1 sibling, 0 replies; 6+ messages in thread
From: Brian Dessent @ 2006-12-04 14:34 UTC (permalink / raw)
  To: gcc-help

biju64 wrote:

> I am using the GNU C library (I think)...When I do a ldd on an executable

No, you're not if you're on Solaris.  You're using Sun's C library.

>         libc.so.1 =>     /usr/lib/libc.so.1

This is the C library.  It is not part of gcc.

>         libgcc_s.so.1 =>         /usr/sfw/lib/libgcc_s.so.1

This is libgcc.  It is part of gcc, but it is only a small support
library containing things like multiplication routines for systems
without hardware floating point.

As Eljay already pointed out, the feature you're trying to use is part
of glibc, so there is no point trying to use it if you are not on a
GNU/Linux or GNU/Hurd system.  There may still be other ways to get a
backtrace, but you would have to consult the system documentation for
Solaris.

Brian

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

* Re: How to get a backtrace from a C module
  2006-12-04 14:16     ` John Love-Jensen
@ 2006-12-04 18:51       ` biju64
  0 siblings, 0 replies; 6+ messages in thread
From: biju64 @ 2006-12-04 18:51 UTC (permalink / raw)
  To: gcc-help


Thank you very much all for the replies.
I can see the 'error' of my ways :-)
Will look further into this...



John Love-Jensen wrote:
> 
> Hi Alex,
> 
> As I understand it, libgcc_s.so.1 is not the GNU C Library, rather it is
> the
> GCC Support library, containing things like soft float, abort, pow,
> trampoline support, stack unwinding, malloc/calloc/free, strlen, and
> perhaps
> other stuff (depending on platform).
> 
> Keep in mind that the GNU C Library (glibc) is a separate project from GNU
> Compiler Collection (GCC).
> 
> --Eljay
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-get-a-backtrace-from-a-C-module-tf2740773.html#a7684463
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).