1

I am using an iterator block as coroutine, that is, I have an enumerator IEnumerator e; e was initialized, and in the middle of an iterator block, yield return 1; was used to hold the execution of the coroutine temporarily.

For the purpose of debugging, it is desirable to get where e was yielded, i.e., the stack frame of e. It may be viewed in the debugger, or it may be logged for future inspection.

But all I have is IEnumerator interface, which has only three methods and one property. And I can't figure out how to relate them to, say, System.Diagnostics.StackTrace.

Is it possible, or should it be possible?

EDIT: After immediately receiving two comments clearing up my question I really want to ask, the correct question is:

You have a yielded IEnumerator e. Is there a way to get, for mostly debugging purpose, as much info as possible on what would be the resumed state? The MethodBase together with file name and line number would be perfect.

Jahwan Kim
  • 59
  • 3
  • It's not really clear what you mean - but while it's not executing, there *isn't* a stack trace... the closest you've got is the state field within the iterator, which tells it where to jump to next time you call MoveNext. – Jon Skeet Mar 22 '15 at 08:57
  • An iterator is a state machine, not a co-routine. It does not have a dedicated stack. You can *emulate* a co-routine with an iterator but that's where the buck stops, you get no extra help from the debugger. – Hans Passant Mar 22 '15 at 12:36

0 Answers0