Given the FRAMEINFO obtained with IEnumDebugFrameInfo2.Next , you can use the following code to get the file name, the first line of code of the current frame, and the current line of code:
IDebugStackFrame2 stackFrame = frmInfo.m_pFrame; if (stackFrame != null) { TEXT_POSITION[] begin = new TEXT_POSITION[1]; TEXT_POSITION[] end = new TEXT_POSITION[1]; IDebugDocumentContext2 debugDocumentContext2; stackFrame.GetDocumentContext(out debugDocumentContext2); if (debugDocumentContext2 != null) { string fileName; debugDocumentContext2.GetName((uint)enum_GETNAME_TYPE.GN_FILENAME, out fileName); debugDocumentContext2.GetSourceRange(begin, end); } }
FWIW, the IDebugDocumentContext2 interface has a Seek method that allows you to push lines or code instructions in a stack frame. I think you can move on until you get the final line of code for the stack frame.
To get information about code elements and start / end points using the project system (and without Roslyn), you need to use the automation model (EnvDTE.ProjectItem.FileCodeModel). Given the EnvDTE.ProjectItem object and the line of code, you can use, for example: HOWTO: Get the code element in the cursor from the Visual Studio.NET macro or add -to
source share