Is there a function to call a stack dump in C?

Can someone ask for an implementation of a C function that is called to flush the current stack? This is for x86 linux system. It can be called in two ways: explicitly using another function or after a crash (possibly as a trap / int handler). The output can be either on the screen or in a file, as indicated by the parameter (handle). Obviously, a clear explanation / comments on how the stack is unwound would be very helpful. Thank.

+3
source share
3 answers

following Adam's answer, the source code showing how to do the actual stack backtrack is in gnu libc backtrace (), in /libc/debug/backtrace.c - not sure if the full link below will be accepted by stackoverflow html filters ...

http://cvs.savannah.gnu.org/viewvc/*checkout*/libc/debug/backtrace.c?root=libc&revision=1.1.2.1&content-type=text%2Fplain

+2
source

The documentation for the backtrace () function is in the GNU LIBC MANUAL .

+2
source

, . . backtrace() . backtrace() glibc .

x86 CPU ebp ( ) esp ( ), . .

If you want to know more about how it works backtrace()and how to use it, I would recommend reading the Stack Backtracing Inside Your Program (LINUX Magazine).


Since you mentioned running a backtrace from a signal handler for the x86 platform, I would like to add Adam to my answer to the question that he linked, for more information on how to provide backtrace from the signal handler, points to The actual location of the error.

0
source

Source: https://habr.com/ru/post/1697870/


All Articles