2

I have red that eh_frame is needed for stack unwinding during debugging or when our code hits an exception.

Now my questions is, can't the debugger just walk the stack and figure out the boundaries between frames by looking for rbp being pushed or poped? Why do we need extra debugging information emitted?

  • There's more to stack unwinding than finding the next caller address. In C++, for example, one needs to call the destructors. Also, not all CPUs have an `rbp`-equivalent register. Also, what Florian is saying :) – Seva Alekseyev Feb 09 '20 at 01:32

2 Answers2

3

Not all functions have a frame pointer. In such functions, rbp can be used for something else, and DWARF data is used to describe how to obtain the canonical frame address and the return address. To some degree, DWARF also allows to describe non-standard calling conventions which some compilers use for local functions (which are not externally visible, so that the ABI does not matter).

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • how is stack walking done? i mean `rbp` value on the stack is just a memory address. how does it know its referring to the base pointer and not something else? –  Jan 19 '20 at 23:58
  • 2
    `rip` (the program counter) is used to find the DWARF data, and the DWARF data describes how to reconstruct the stack frame layout at the point of the program counter. On x86-64, immediately above the stack frame on the stack, there is the return address, which is the program counter of the caller's stack frame. The unwinding process can continue from that. – Florian Weimer Jan 20 '20 at 07:59
1

Probably you right, and this section is not so necessary for stack unwinding, please refer to this research. But eh_frame also used by some languages to handle exceptions, and I think that it is a real necessity to include it ewerywhere.

nnnsoft
  • 46
  • 3