Re: Stack unwinding in SMM


mick21@...
 

Hi Andrew,

Thank you for your reply :). I should have been more specific, I have instrumented an SMM driver and want to retrieve stack traces at arbitrary points in program execution from within the SMM driver, so a debugger is not an option. Currently, I'm building edk2 on Arch with LLVM 9.0.0, but I was unable to successfully use the __builtin_return_address(N) function to retrieve return addresses for N > 0. Interesting that it works for Xcode, I thought that edk2 forced the compiler to emit function pro/epilogues as described here [1] and that that was causing __builtin_return_address() to fail.

This is useful to know, I had assumed this was the case.

I’m not sure the unwind tables are part of the ABI, they are likely treated more like debugging info.
I'm unfamiliar with how Xcode works, but if you are able to use __builtin_return_address() successfully, then I should be able to change some of the commandline flags to get the same result, or might something else cause this difference? Retrieving the first four return addresses is what I would like to do.

I already tried to supply "-fno-omit-frame-pointer", but this results in a frame pointer in the following way [2], where I still would have to find out how many local variables the function is using (see the picture where the frame pointer of function B is below the return address and the variable amount of local variables and nonvolatile registers used in function B). Correct me if I'm wrong, but if I'm unable to use the function __builtin_return_address(), then I should use a manual implementation, assuming that unwind tables are no option.

Sincerely,

Mick

[1] https://docs.microsoft.com/en-us/cpp/build/prolog-and-epilog?view=msvc-160
[2] https://docs.microsoft.com/en-us/cpp/build/stack-usage?view=msvc-160

Join discuss@edk2.groups.io to automatically receive all group messages.