public AD7DocumentContext(string fileName, TEXT_POSITION begPos, TEXT_POSITION endPos, AD7MemoryAddress codeContext, FrameKind frameKind) { _fileName = fileName; _begPos = begPos; _endPos = endPos; _codeContext = codeContext; _frameKind = frameKind; }
// Retrieves a list of all code contexts associated with this document context. // The engine sample only supports one code context per document context and // the code contexts are always memory addresses. int IDebugDocumentContext2.EnumCodeContexts(out IEnumDebugCodeContexts2 ppEnumCodeCxts) { ppEnumCodeCxts = null; AD7MemoryAddress[] codeContexts = new AD7MemoryAddress[1]; codeContexts[0] = _codeContext; ppEnumCodeCxts = new AD7CodeContextEnum(codeContexts); return VSConstants.S_OK; }
// Get the document context for this pending breakpoint. A document context is a abstract representation of a source file // location. public AD7DocumentContext GetDocumentContext(PythonBreakpoint address) { IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(_bpRequestInfo.bpLocation.unionmember2)); string documentName; EngineUtils.CheckOk(docPosition.GetFileName(out documentName)); // Get the location in the document that the breakpoint is in. TEXT_POSITION[] startPosition = new TEXT_POSITION[1]; TEXT_POSITION[] endPosition = new TEXT_POSITION[1]; EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition)); AD7MemoryAddress codeContext = new AD7MemoryAddress(_engine, documentName, startPosition[0].dwLine); return new AD7DocumentContext(documentName, startPosition[0], startPosition[0], codeContext, FrameKind.Python); }
// Gets the breakpoint resolution information that describes this breakpoint. int IDebugBreakpointResolution2.GetResolutionInfo(enum_BPRESI_FIELDS dwFields, BP_RESOLUTION_INFO[] pBPResolutionInfo) { if ((dwFields & enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION) != 0) { // The sample engine only supports code breakpoints. BP_RESOLUTION_LOCATION location = new BP_RESOLUTION_LOCATION(); location.bpType = (uint)enum_BP_TYPE.BPT_CODE; // The debugger will not QI the IDebugCodeContex2 interface returned here. We must pass the pointer // to IDebugCodeContex2 and not IUnknown. AD7MemoryAddress codeContext = new AD7MemoryAddress(m_engine, m_address.Filename, (uint)m_address.LineNo); codeContext.SetDocumentContext(m_documentContext); location.unionmember1 = Marshal.GetComInterfaceForObject(codeContext, typeof(IDebugCodeContext2)); pBPResolutionInfo[0].bpResLocation = location; pBPResolutionInfo[0].dwFields |= enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION; } if ((dwFields & enum_BPRESI_FIELDS.BPRESI_PROGRAM) != 0) { pBPResolutionInfo[0].pProgram = (IDebugProgram2)m_engine; pBPResolutionInfo[0].dwFields |= enum_BPRESI_FIELDS.BPRESI_PROGRAM; } return VSConstants.S_OK; }
// Gets the code context for this stack frame. The code context represents the current instruction pointer in this stack frame. int IDebugStackFrame2.GetCodeContext(out IDebugCodeContext2 memoryAddress) { memoryAddress = new AD7MemoryAddress(_engine, _stackFrame.FileName, (uint)_stackFrame.LineNo, _stackFrame); return VSConstants.S_OK; }
// Adds a specified value to the current context's address to create a new context. public int Add(ulong dwCount, out IDebugMemoryContext2 newAddress) { newAddress = new AD7MemoryAddress(_engine, _filename, (uint)dwCount + _lineNo); return VSConstants.S_OK; }
// Subtracts a specified value from the current context's address to create a new context. public int Subtract(ulong dwCount, out IDebugMemoryContext2 ppMemCxt) { ppMemCxt = new AD7MemoryAddress(_engine, _filename, (uint)dwCount - _lineNo); return VSConstants.S_OK; }
// Gets the code context for this stack frame. The code context represents the current instruction pointer in this stack frame. int IDebugStackFrame2.GetCodeContext(out IDebugCodeContext2 memoryAddress) { memoryAddress = new AD7MemoryAddress(_engine, _stackFrame.FileName, (uint)_stackFrame.LineNo, _stackFrame); return(VSConstants.S_OK); }
// Compares the memory context to each context in the given array in the manner indicated by compare flags, // returning an index of the first context that matches. public int Compare(enum_CONTEXT_COMPARE uContextCompare, IDebugMemoryContext2[] compareToItems, uint compareToLength, out uint foundIndex) { foundIndex = uint.MaxValue; enum_CONTEXT_COMPARE contextCompare = (enum_CONTEXT_COMPARE)uContextCompare; for (uint c = 0; c < compareToLength; c++) { AD7MemoryAddress compareTo = compareToItems[c] as AD7MemoryAddress; if (compareTo == null) { continue; } if (!AD7Engine.ReferenceEquals(this._engine, compareTo._engine)) { continue; } bool result; switch (contextCompare) { case enum_CONTEXT_COMPARE.CONTEXT_EQUAL: result = (this._lineNo == compareTo._lineNo); break; case enum_CONTEXT_COMPARE.CONTEXT_LESS_THAN: result = (this._lineNo < compareTo._lineNo); break; case enum_CONTEXT_COMPARE.CONTEXT_GREATER_THAN: result = (this._lineNo > compareTo._lineNo); break; case enum_CONTEXT_COMPARE.CONTEXT_LESS_THAN_OR_EQUAL: result = (this._lineNo <= compareTo._lineNo); break; case enum_CONTEXT_COMPARE.CONTEXT_GREATER_THAN_OR_EQUAL: result = (this._lineNo >= compareTo._lineNo); break; case enum_CONTEXT_COMPARE.CONTEXT_SAME_SCOPE: case enum_CONTEXT_COMPARE.CONTEXT_SAME_FUNCTION: if (_frame != null) { result = compareTo._filename == _filename && (compareTo._lineNo + 1) >= _frame.StartLine && (compareTo._lineNo + 1) <= _frame.EndLine; } else if (compareTo._frame != null) { result = compareTo._filename == _filename && (_lineNo + 1) >= compareTo._frame.StartLine && (compareTo._lineNo + 1) <= compareTo._frame.EndLine; } else { result = this._lineNo == compareTo._lineNo && this._filename == compareTo._filename; } break; case enum_CONTEXT_COMPARE.CONTEXT_SAME_MODULE: result = _filename == compareTo._filename; break; case enum_CONTEXT_COMPARE.CONTEXT_SAME_PROCESS: result = true; break; default: // A new comparison was invented that we don't support return(VSConstants.E_NOTIMPL); } if (result) { foundIndex = c; return(VSConstants.S_OK); } } return(VSConstants.S_FALSE); }
// Adds a specified value to the current context's address to create a new context. public int Add(ulong dwCount, out IDebugMemoryContext2 newAddress) { newAddress = new AD7MemoryAddress(_engine, _filename, (uint)dwCount + _lineNo); return(VSConstants.S_OK); }
// Subtracts a specified value from the current context's address to create a new context. public int Subtract(ulong dwCount, out IDebugMemoryContext2 ppMemCxt) { ppMemCxt = new AD7MemoryAddress(_engine, _filename, (uint)dwCount - _lineNo); return(VSConstants.S_OK); }