Re: Exception Traceback / Frame Unwind 2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



try:

info libc


and look under "debugging"



--bud

Here is the example from the info page:


     #include <execinfo.h>
     #include <stdio.h>
     #include <stdlib.h>
                                                                                                                                    
     /* 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;
     }



On Thu, Mar 04, 2004 at 01:41:05PM +0000, Ben Clewett wrote:
> Bud,
> 
> This looks exactly what I am looking for.  Thanks for the reply.
> 
> Would you happen to know the name of the lib or include file so that I 
> can google some information on this?
> 
> Regards, Ben.
> 
> 
> Bud Davis wrote:
> 
> >If you are using glibc, they have a mechanism for retreiving the
> >call stack and printing out the information.  Here is a portion
> >of the info page:
> >
> >Backtraces
> >==========
> >                                                                                                                                                        
> >   A "backtrace" is a list of the function calls that are currently
> >active in a thread.  The usual way to inspect a backtrace of a program
> >is to use an external debugger such as gdb.  However, sometimes it is
> >useful to obtain a backtrace programmatically from within a program,
> >e.g., for the purposes of logging or diagnostics.
> >                                                                                                                                                        
> >
> >Is this what you are looking for ?
> >
> >
> >regards,
> >bud davis
> 
> 

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux