A cool little bit of code...

Joseph E. Sacco, Ph.D. joseph_sacco at comcast.net
Wed Jan 19 07:52:52 MST 2005


Cute... 

A small correction:

Add

	#include <execinfo.h>


to the list of include files.


-Joseph

=================================================================

On Tue, 2005-01-18 at 21:55, Owen Stampflee wrote:
> I call it minidebugger... I dont have a proper debugger available during
> a real install (and the problem doesnt exist in the test environment),
> so I'm bundling this little code in. When the code segfaults, I get a
> nice little backtrace :).
> 
> #include <execinfo.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <signal.h>
>  
> /* Obtain a backtrace and print it to stdout. */
> void print_trace (int sig)
> {
>         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);
>         exit(-1);
> }
>  
> void kaboom()
> {
>         printf("Going kaboom...");
>         int *foo = NULL;
>         *foo = 42;
> }
>  
> int main (void)
> {
>         signal(SIGSEGV, print_trace);
>         kaboom();
>         return 0;
> }
> 
> 
> _______________________________________________
> yellowdog-general mailing list
> yellowdog-general at lists.terrasoftsolutions.com
> http://lists.terrasoftsolutions.com/mailman/listinfo/yellowdog-general
> HINT: to Google archives, try  '<keywords> site:terrasoftsolutions.com'
-- 
joseph_sacco[at]comcast[dot]net



More information about the yellowdog-general mailing list