NAME
bbaacckkttrraaccee, bbaacckkttrraacceessyymmbboollss, bbaacckkttrraacceessyymmbboollssffdd - call stack back-
trace and display functionsSYNOPSIS
##iinncclluuddee <
int bbaacckkttrraaccee(void** array, int size); char** bbaacckkttrraacceessyymmbboollss(void* const* array, int size); void bbaacckkttrraacceessyymmbboollssffdd(void* const* array, int size, int fd);> DESCRIPTION
These routines provide a mechanism to examine the current thread's call stack. bbaacckkttrraaccee() writes the function return addresses of the current callstack to the array of pointers referenced by array. At most, size point-
ers are written. The number of pointers actually written to array is returned. bbaacckkttrraacceessyymmbboollss() attempts to transform a call stack obtained bybbaacckkttrraaccee() into an array of human-readable strings using ddllaaddddrr(). The
array of strings returned has size elements. It is allocated using mmaalllloocc() and should be released using ffrreeee(). There is no need to free the individual strings in the array. bbaacckkttrraacceessyymmbboollssffdd() performs the same operation as bbaacckkttrraacceessyymmbboollss(), but the resulting strings are immediately written to the file descriptor fd, and are not returned. EEXXAAMMPPLLEE#include
#include
... void* callstack[128]; int i, frames = backtrace(callstack, 128); char** strs = backtracesymbols(callstack, frames); for (i = 0; i < frames; ++i) {printf("%s\n", strs[i]);
} free(strs); ... HISTORY These functions first appeared in Mac OS X 10.5.SEE ALSO
dladdr(3), malloc(3) Mac OS X February 15, 2007 Mac OS X