backtrace(3) BSD Library Functions Manual backtrace(3)NAME
backtrace, backtrace_symbols, backtrace_symbols_fd -- call stack backtrace and display functions
SYNOPSIS
#include <execinfo.h>
int
backtrace(void** array, int size);
char**
backtrace_symbols(void* const* array, int size);
void
backtrace_symbols_fd(void* const* array, int size, int fd);
DESCRIPTION
These routines provide a mechanism to examine the current thread's call stack.
backtrace() writes the function return addresses of the current call stack to the array of pointers referenced by array. At most, size
pointers are written. The number of pointers actually written to array is returned.
backtrace_symbols() attempts to transform a call stack obtained by backtrace() into an array of human-readable strings using dladdr(). The
array of strings returned has size elements. It is allocated using malloc() and should be released using free(). There is no need to free
the individual strings in the array.
backtrace_symbols_fd() performs the same operation as backtrace_symbols(), but the resulting strings are immediately written to the file
descriptor fd, and are not returned.
EXAMPLE
#include <execinfo.h>
#include <stdio.h>
...
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
printf("%s
", 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
Check Out this Related Man Page
backtrace(3) BSD Library Functions Manual backtrace(3)NAME
backtrace, backtrace_symbols, backtrace_symbols_fd -- call stack backtrace and display functions
SYNOPSIS
#include <execinfo.h>
int
backtrace(void** array, int size);
char**
backtrace_symbols(void* const* array, int size);
void
backtrace_symbols_fd(void* const* array, int size, int fd);
DESCRIPTION
These routines provide a mechanism to examine the current thread's call stack.
backtrace() writes the function return addresses of the current call stack to the array of pointers referenced by array. At most, size
pointers are written. The number of pointers actually written to array is returned.
backtrace_symbols() attempts to transform a call stack obtained by backtrace() into an array of human-readable strings using dladdr(). The
array of strings returned has size elements. It is allocated using malloc() and should be released using free(). There is no need to free
the individual strings in the array.
backtrace_symbols_fd() performs the same operation as backtrace_symbols(), but the resulting strings are immediately written to the file
descriptor fd, and are not returned.
EXAMPLE
#include <execinfo.h>
#include <stdio.h>
...
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
printf("%s
", 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
I am trying to print a stack trace programatically using backtrace and backtrace_symbols.
The problem is that the stack being printed in a mangled format. Is there a way to get the output in more of a human readable form?
I am using Red Hat and the program is written in c++. (2 Replies)
Hi,
I'm working in a MIPS processor and, since the function backtrace() is not implemented for this architecture, I would like to know if there is another way to do a stack backtrace in this processor.
Thanks a lot!!! (3 Replies)
Hi all,
Can anyone provide help with getting the right syntax regarding array/pointers in C in the following code? Can't locate a specific example which clarifies this...
Say I declare a typedef to an array of pointers to some type...
/**
* An array of ptrs to sections
*/
typedef... (4 Replies)
I put together a C function to add strings to a dynamic array of strings (mostly for educational purpose to explain pointers to my kid). It works, but sometimes one or two strings in the array becomes corrupted. Running example on 64 bit Ubuntu, gcc ver. 4.8.4
Hope my code is self-explanatory:
... (2 Replies)
I am attempting to create an array of function pointers. The examples I follow to do this are from:
support.microsoft.com/en-us/help/30580/how-to-declare-an-array-of-pointers-to-functions-in-visual-c
... (3 Replies)