5

Is it possible to tell Visual Studio (or any other tool even on any other major operating system) to interpret an address as a beginning of a call stack?


What I'm trying to achieve: we have a library, which uses boost's make_fcontext / jump_fcontext and stores these contexts into a container in order to suspend some calls for later processing.

My question is - is it possible to somehow debug what are these suspended calls? I imagine, that I can tell a debugger/tool something like: "Here's this address, although it's not obvious, it actually points to a call stack, 'parse' it and show it to me like a standard call stack".

No idea if it's theoretically possible, as I don't know boost::context in details, but it sounds achievable.

Has anyone tried to deal with this?

Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187

1 Answers1

2

There's a few approaches I can think of, in various flavors of dissatisfying.

  • You could write your own debugging engine to plug into the IDE, which would allow the manual enumeration of fibers. (You probably don't want to do that.)

  • You can use a boost::context::fiber instead of a fcontext_t. On Windows, those can be implemented with win32 fibers, so they'll show up in the IDE automatically, with full stack/locals. (You may need to change your Boost config to get this to work, see the docs for details.)

  • You could look inside the fcontext_t struct, get the EIP and ESP, and copy them into your registers; at that point, the processor will kiiiind of think that it's executing as the fiber. (This is most likely NOT going to work very well.)

Personally I'd go with the second approach. fcontext_t is a bit too low-level to be using directly anyway, unless you have specific exotic needs you haven't mentioned.

Sneftel
  • 40,271
  • 12
  • 71
  • 104
  • You mention windows fibers show up in the IDE automatically, what IDE are you talking about? I have never been able to inspect the callstack of a suspended windows fiber without saving the callstack function pointers myself somewhere. Perhaps that's what you meant, but I had the impression OP just has the fiber handle. – Selmar Aug 28 '21 at 12:04
  • It was WinDbg, as I recall.. I don’t think MSVC had it. Been a while, though. – Sneftel Aug 28 '21 at 17:52
  • Interesting. Indeed, it seems to have a .fiber command which displays some information. It won't show the callstacks, but that's probably because I don't have all the symbols set up (I get some errors instead: Unable to read dynamic function table entry at 00000000`00a2b6e0). – Selmar Aug 31 '21 at 17:04