libunwind-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Libunwind-devel] When is it safe to call unw_get_reg


From: Kevin Modzelewski
Subject: [Libunwind-devel] When is it safe to call unw_get_reg
Date: Wed, 15 Apr 2015 19:26:26 -0700

Hi all, I'm running into an issue with unw_get_reg where I'm getting incorrect values back, since I am calling it later than it expects to get called.  In particular, I'm doing something like:


unw_cursor_t* getCursorForFrame(int depth);
int64_t getR12(unw_cursor_t*);

void foo() {
  unw_cursor_t* cursor = getCursorForFrame(1);
  int64_t r12 = getR12(cursor);
}


The issue is that foo() doesn't spill r12, but both getCursorForFrame() and getR12() do.  Things fail since they spill r12 to different locations, but the cursor we get from getCursorForFrame() only saves the memory location that r12 was spilled to, which in this case is a stack slot for the getCursorForFrame() stack frame.  Then getR12 spills something else to that stack slot, and then calls unw_get_reg, which returns an invalid value.

I can work around this for now (I'm saving all the registers in getCursorForFrame), but is there any straightforward set of restrictions on when one can call unw_get_reg?  Maybe something like "cursors are only valid for the duration of the last stack frame that called unw_init_local or unw_step".  But I'm not sure if that's even enough, since what if unw_step + unw_get_reg themselves have this issue?

This issue has only cropped up when we run in a very optimized mode, where there are very few stack frames between the one that we want to investigate and the one doing the investigation.

kmod

reply via email to

[Prev in Thread] Current Thread [Next in Thread]