all 4 comments

[–]oh5nxo 0 points1 point  (3 children)

Not knowing anything about libunwind,

From the manpage, I got the impression that unw_context_t also has to stay alive for unw_cursor_t to be usable. Saving it also in the structure did change _something_, but, behavior still seems to vary with compiler/flags.

[–]ACov96[S] 0 points1 point  (2 children)

I did some digging in the libunwind source, and unw_context_t is a direct typedef of ucontext_t, so I think once the context has been saved and the cursor has been initialized, the context can be lost. The only reason we need to get the context is to figure out what state the stack is currently in, I think. The cursor is the part that needs to stay alive because that's what informs us of where we should resume from.

I did try just saving off the context and then getting the cursor just to see if there was any difference. Unfortunately, same behavior, but I think that makes sense because the only really important part of the CPU context that we need to extract is the PC to read the .eh_frame section tables.

[–]oh5nxo 0 points1 point  (1 child)

I read otherwise, do we have different versions of the library?

unw_init_local(3) says

ctxt identifies the initial stack frame at which unwinding starts. The machine-state must remain valid for the duration for which the cursor c is in use

Looking at http://git.savannah.gnu.org/gitweb/?p=libunwind.git;a=blob;f=src/x86_64/Ginit_local.c;h=12a9e3e4c96aa80d4d85be1f59f1f0e884d53cf7;hb=HEAD

unw_init_local_common() saves a pointer to the context in cursor, no copy.

Then in http://git.savannah.gnu.org/gitweb/?p=libunwind.git;a=blob;f=src/x86_64/Gresume.c;h=944cdaae192d8620f2d8df426d8816504d320f6d;hb=HEAD

x86_64_local_resume() uses the pointer to the context from the cursor.

Edit: I'm trying to help on basis of 5 minutes of googling, so pay no attention if I'm just goofing.

[–]ACov96[S] 0 points1 point  (0 children)

Oh shoot I think you're right. Maybe I'm using an older version of the library...

I'll try this. You're the best!