0

This question is just for understanding purpose.

What does _Unwind_Backtrace do internally to keep track of stack of function calls called.

Does some of unwind library code executes internally every time we call a function to keep track of the stack?

Or only when we call _Unwind_Backtrace, it collects the function stack and gives the information? If so, how does it collects the information.

I have googled for some time, but could not find any information on how unwinder works. If somebody knows, please explain.

3
  • I'd guess it simply knows the compilers format for the stack frame, and can simply check the stack (it should always contain a "pointer" to the calling function, at the very least the return address when the current function ends). Commented Oct 19, 2018 at 12:50
  • stackoverflow.com/a/2456882/1216776
    – stark
    Commented Oct 19, 2018 at 12:55
  • "Does some of unwind library code executes internally every time we call a function to keep track of the stack?" No. When frame pointer is not omitted, it's easy to unwind the stack, as all the needed information is there. If frame pointer is omitted, then additional information is needed usually, which is stored in the ".eh_frame" section in the elf (but I don't know, how _Unwind_Backtrack works actually. With ".eh_frame", stack can be unwound easily. It's main purpose is to make stack unwind possible, when an exception is thrown).
    – geza
    Commented Oct 19, 2018 at 13:02

1 Answer 1

0

The _Unwind_Backtrace function uses exidx and extable linker's sections defined by the compiler when the options -funwind-tables and -fexceptions are used.

These tables contain the informations about function call stack. ARM ehabi's documentation gives a clear description of the process of using these tables to unwind but in a few words :

  • exidx contains index of the functions in the call. stack. You can use it to access to the extable entry associated to a function.

  • extable contains informations about the registers pushed by each function, the register used as VFP (virtual frame pointer), and other complementary informations.

You will find the precise description of all the unwind process there :

https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst#index-table-entries

(the interesting sections for you are from section 6 to 8)

Have a nice day !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.