Skip to content

Instantly share code, notes, and snippets.

@toshok
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toshok/abf78446ce2adb59782d to your computer and use it in GitHub Desktop.
Save toshok/abf78446ce2adb59782d to your computer and use it in GitHub Desktop.
template <typename FrameFunc> bool onlyForUnwindStateNormal(PythonFrameIteratorImpl* frame_iter, FrameFunc f) {
bool rtn = false;
if (threading::ThreadStateInternal::getUnwindState() == UNWIND_STATE_NORMAL)
rtn = f();
threading::ThreadStateInternal::setUnwindState((bool)frame_iter->cf->entry_descriptor ? UNWIND_STATE_OSR
: UNWIND_STATE_NORMAL);
return rtn;
}
// usage:
void maybeTracebackHere(void* unw_cursor) {
unw_cursor_t* cursor = (unw_cursor_t*)unw_cursor;
unw_word_t ip = get_cursor_ip(cursor);
unw_word_t bp = get_cursor_bp(cursor);
BoxedTraceback** tb_loc
= reinterpret_cast<BoxedTraceback**>(&threading::ThreadStateInternal::getExceptionFerry()->traceback);
unwindProcessFrame(ip, bp, cursor, [&](PythonFrameIteratorImpl* frame_iter) {
return onlyForUnwindStateNormal(frame_iter, [&](PythonFrameIteratorImpl* frame_iter) {
BoxedTraceback::Here(lineInfoForFrame(frame_iter), tb_loc);
return false;
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment