def _get_coroutine_stack(coro):
    """Extracts a list of stack frames from a chain of generator/coroutine
    calls.
    """
    frames = []
    while coro:
        if hasattr(coro, 'cr_frame'):
            f = coro.cr_frame
            coro = coro.cr_await
        elif hasattr(coro, 'ag_frame'):
            f = coro.ag_frame
            coro = coro.ag_await
        elif hasattr(coro, 'gi_frame'):
            f = coro.gi_frame
            coro = coro.gi_yieldfrom
        else:
            f = None
            coro = None
        if f is not None:
            frames.append(f)
    return frames
