Re: Stack unwinding in SMM
On Jul 1, 2021, at 4:08 AM, email@example.com wrote:Mick,
It might be possible to turn on frame pointers via: -fno-omit-frame-pointer
The Xcode flavor of clang defaults to emitting the frame pointer so __builtin_return_address() works as expected for N levels, and you can manually walk the stack in code.
The other option is to use the debugger to walk the unwind + debug info to get stack frames….
FYI for Xcode the pattern is:
movq %rsp, %rbp
So %rbp is a frame pointer, and the return address is on the stack from the call.
I was wondering whether there are better ways to perform this task, where I want to retrieve a call stack from arbitrary places in an SMM driver. I'm not sure where to start, I have looked online but I would likely need unwind tables (which seem to be enabled in EDK II https://github.com/tianocore/edk2/commit/77b738b36f5f19b33a77ff74ce822c9c5a050876), but I'm not sure how I should use them in the EDK II project or whether they are even present in my .efi file. The sections available in my .efi file are .text, .rdata, .data, and .reloc.Caveat emptor I’m speculating here…..
I’m not sure the unwind tables are part of the ABI, they are likely treated more like debugging info. I did find this . In olden time the MSFT PDB was a moving target and you needed a DLL to parse it, it might have gotten more stable over the years.
I think the unwind tables are to support partial debugging (walking a stack frame), but the unwind info is processed by something in the runtime or debugger. I don’t know of any edk2 to unwind. I did notice this , so you may want to look at that?