Question

In DWARF2 debugging format, stack unwinding is supported with the help of CFI(Call Frame Information) present in .debug_frame section. This is precisely a table that keeps a rule for every register to get its value in previous frame. However, all of these rules relies on the fact that the registers are saved on stack at some location. This is not true for getting value of stack pointer in previous frame register when there is no frame-pointer. In such cases, stack pointer may not be saved on stack but just managed by incrementing and decrementing its value. However, there is no way in dwarf2 (or dwarf format in general) to indicate that the register value is an expression over its current value. So, my question is, how can one get the value of stack pointer during stack unwinding with dwarf2 debugging format (when no frame-pointer is there).

-BV

Was it helpful?

Solution

It seems that dwarf3 supports DW_CFA_val_offset for such a case. So, this can be used to record value of SP in previous frame based on a arithmetic expression over current value. Another possible solution could be to save stack pointer on stack itself (will work with dwarf2). This can be done at -O0 optimization level where the code efficiency is not that important.

OTHER TIPS

See this discussion on what seems to be your problem. I am uncertain as to whether the proposals have yet made it into the current standard.

I went to this discussion. But, was just wondering if someone has ever tried to solve it through some other way. One way that I can think of is to an unnecessary save of stack-pointer on stack itself. Then use, this location to get the value of sp for previous frame.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top