public void SetUp() { var taskContext = new JoinableTaskContext(); remoteThread = Substitute.For <RemoteThread>(); mockThread = Substitute.For <IDebugThread>(); mockThread.GetRemoteThread().Returns(remoteThread); mockDebugEngineHandler = Substitute.For <IDebugEngineHandler>(); mockDebugThreadCreator = Substitute.For <DebugProgram.ThreadCreator>(); mockDebugDisassemblyStreamFactory = Substitute.For <DebugDisassemblyStream.Factory>(); mockProcess = Substitute.For <IDebugProcess2>(); var guid = new Guid(); mockSbProcess = Substitute.For <SbProcess>(); mockRemoteTarget = Substitute.For <RemoteTarget>(); mockDocumentContextFactory = Substitute.For <DebugDocumentContext.Factory>(); mockCodeContextFactory = Substitute.For <DebugCodeContext.Factory>(); threadEnumFactory = new ThreadEnumFactory(); moduleEnumFactory = new ModuleEnumFactory(); codeContextEnumFactory = new CodeContextEnumFactory(); mockDebugModuleCache = Substitute.For <IDebugModuleCache>(); program = new DebugProgram.Factory(taskContext, mockDebugDisassemblyStreamFactory, mockDocumentContextFactory, mockCodeContextFactory, threadEnumFactory, moduleEnumFactory, codeContextEnumFactory) .Create(mockDebugEngineHandler, mockDebugThreadCreator, mockProcess, guid, mockSbProcess, mockRemoteTarget, mockDebugModuleCache, false); }
public void EnumFrameInfoTest() { RemoteThread mockThread = Substitute.For <RemoteThread>(); IDebugThread debugThread = CreateDebugThread <IDebugThread>(mockThread); IList <FRAMEINFO> framesList = new List <FRAMEINFO> { new FRAMEINFO { m_bstrFuncName = "func1" }, new FRAMEINFO { m_bstrFuncName = "func2" } }; _stackFramesProvider.GetRange(Arg.Any <enum_FRAMEINFO_FLAGS>(), debugThread.Self, 0, uint.MaxValue).Returns(framesList); IEnumDebugFrameInfo2 enumDebugFrameInfo2; int result = debugThread.EnumFrameInfo( enum_FRAMEINFO_FLAGS.FIF_ARGS, 10, out enumDebugFrameInfo2); _stackFramesProvider.ReceivedWithAnyArgs(0) .GetRange(Arg.Any <enum_FRAMEINFO_FLAGS>(), Arg.Any <IDebugThread>(), Arg.Any <uint>(), Arg.Any <uint>()); Assert.That(result, Is.EqualTo(VSConstants.S_OK)); Assert.IsNotNull(enumDebugFrameInfo2); uint count; Assert.That(enumDebugFrameInfo2.GetCount(out count), Is.EqualTo(VSConstants.S_OK)); Assert.That(count, Is.EqualTo(2)); _stackFramesProvider.ReceivedWithAnyArgs(1).GetRange( Arg.Any <enum_FRAMEINFO_FLAGS>(), Arg.Any <IDebugThread>(), 0, uint.MaxValue); }
List <FRAMEINFO> ToFrameInfo(List <FrameInfoPair> framesInfo, IDebugThread debugThread, uint startIndex) { if (framesInfo == null) { return(null); } var ad7FramesInfo = new List <FRAMEINFO>(); for (int i = 0; i < framesInfo.Count; ++i) { var frame = _stackFrameCreator(framesInfo[i].Frame, debugThread, _debugProgram); ad7FramesInfo.Add(_ad7FrameInfoCreator.Create(frame, framesInfo[i].Info, _program)); } if (startIndex + ad7FramesInfo.Count > MaxStackDepth) { int lastIndex = ad7FramesInfo.Count - 1; // Create an entry to indicate that the maximum number is exceeded. var info = new FrameInfo <SbModule>() { FuncName = "The maximum number of stack frames supported by the Stadia " + "debugger has been exceeded.", HasDebugInfo = 0, // for clarity, grays the entry out in the UI ValidFields = FrameInfoFlags.FIF_FUNCNAME | FrameInfoFlags.FIF_DEBUGINFO, }; ad7FramesInfo[lastIndex] = _ad7FrameInfoCreator.Create(null, info, _program); } return(ad7FramesInfo); }
public virtual async Task <IList <FRAMEINFO> > GetAllAsync(enum_FRAMEINFO_FLAGS fieldSpec, IDebugThread debugThread) { var framesInfo = new List <FrameInfoPair>(); while (framesInfo.Count < MaxFramesNumberToLoad) { long maxBatchSize = Math.Min( FramesBatchSize, MaxFramesNumberToLoad - framesInfo.Count); List <FrameInfoPair> framesBatch = await _remoteThread.GetFramesWithInfoAsync( (FrameInfoFlags)fieldSpec, (uint)framesInfo.Count, (uint)maxBatchSize); if (framesBatch == null) { Trace.TraceError("Error on loading Frames With Info. " + $"Thread Id: {debugThread.GetRemoteThread().GetThreadId()}; " + $"Start index: {framesInfo.Count}; Max Count: {maxBatchSize}"); break; } framesInfo.AddRange(framesBatch); if (framesBatch.Count < maxBatchSize) { break; } } return(ToFrameInfo(framesInfo, debugThread, 0)); }
public void Setup() { _stackFramesProvider = Substitute.ForPartsOf <StackFramesProvider>(null, null, null, null, null); _debugThread = Substitute.For <IDebugThread>(); _frameInfoEnum = new FrameInfoEnum( _stackFramesProvider, _fieldSpec, _debugThread); }
public virtual IDebugStackFrame Create(AD7FrameInfoCreator ad7FrameInfoCreator, RemoteFrame frame, IDebugThread thread, IDebugEngineHandler debugEngineHandler, IGgpDebugProgram debugProgram) => new DebugStackFrame(debugDocumentContextFactory, childrenProviderFactory, debugCodeContextFactory, createExpressionDelegate, varInfoFactory, varInfoEnumFactory, ad7FrameInfoCreator, registerSetsBuilderFactory.Create(frame), debugEngineHandler, frame, thread, debugProgram, taskExecutor);
public FrameInfoEnum(StackFramesProvider stackFramesProvider, enum_FRAMEINFO_FLAGS fieldSpec, IDebugThread debugThread) { _data = new List <FRAMEINFO>(); _stackFramesProvider = stackFramesProvider; _fieldSpec = fieldSpec; _debugThread = debugThread; _position = 0; _allStacksLoaded = false; }
public AsyncGetStackFramesOperation(IDebugThread debugThread, StackFramesProvider stackFramesProvider, enum_FRAMEINFO_FLAGS fieldSpec, IAsyncDebugGetFramesCompletionHandler completionHandler, ITaskExecutor taskExecutor) { _debugThread = debugThread; _stackFramesProvider = stackFramesProvider; _fieldSpec = fieldSpec; _completionHandler = completionHandler; _taskExecutor = taskExecutor; }
public void SetUp() { _completionHandler = Substitute.For <IAsyncDebugGetFramesCompletionHandler>(); _taskExecutor = Substitute.ForPartsOf <FakeTaskExecutor>(); _debugThread = Substitute.For <IDebugThread>(); _stackFramesProvider = Substitute.For <StackFramesProvider>(null, null, null, null, null); _getStackFramesOp = new AsyncGetStackFramesOperation(_debugThread, _stackFramesProvider, _fieldSpec, _completionHandler, _taskExecutor); }
public void GetName() { var THREAD_NAME = "thread-name"; var lldbThread = Substitute.For <RemoteThread>(); lldbThread.GetName().Returns(THREAD_NAME); IDebugThread thread = CreateDebugThread <IDebugThread>(lldbThread); string debugThreadName; thread.GetName(out debugThreadName); Assert.AreEqual(THREAD_NAME, debugThreadName); }
public void SetUp() { var taskContext = new JoinableTaskContext(); logSpy = new LogSpy(); logSpy.Attach(); program = Substitute.For <IGgpDebugProgram>(); debugEngine = Substitute.For <IDebugEngine2>(); callback = Substitute.For <IDebugEventCallback2>(); handler = new DebugEngineHandler(taskContext, debugEngine, callback); var idArg = Arg.Any <Guid>(); program.GetProgramId(out idArg) .Returns(x => { x[0] = programId; return(VSConstants.S_OK); }); var nameArg = Arg.Any <string>(); program.GetName(out nameArg) .Returns(x => { x[0] = programName; return(VSConstants.S_OK); }); thread = Substitute.For <IDebugThread>(); var threadNameArg = Arg.Any <string>(); thread.GetName(out threadNameArg) .Returns(x => { x[0] = threadName; return(VSConstants.S_OK); }); var threadIdArg = Arg.Any <uint>(); thread.GetThreadId(out threadIdArg) .Returns(x => { x[0] = threadId; return(VSConstants.S_OK); }); }
public void CanSetNextStatementFalse() { const ulong ADDRESS = 0xdeadbeef; const string NAME = "test"; const ulong ANOTHER_ADDRESS = 0xabcd; const string ANOTHER_NAME = "test1"; var threadId = 1u; var mockThread = Substitute.For <RemoteThread>(); mockThread.GetThreadId().Returns(threadId); var mockStackFrame = Substitute.For <IDebugStackFrame2>(); string name; mockStackFrame.GetName(out name).Returns(x => { x[0] = NAME; return(VSConstants.S_OK); }); IDebugThread2 outThread; IDebugThread thread = CreateDebugThread <IDebugThread>(mockThread); mockStackFrame.GetThread(out outThread).Returns(x => { x[0] = thread; return(VSConstants.S_OK); }); var mockCodeContext = Substitute.For <IDebugCodeContext2>(); var contextInfoFields = enum_CONTEXT_INFO_FIELDS.CIF_ADDRESS | enum_CONTEXT_INFO_FIELDS.CIF_FUNCTION; System.Action <CONTEXT_INFO[]> setContextInfo = infos => { infos[0].bstrFunction = ANOTHER_NAME; infos[0].bstrAddress = "0x" + ANOTHER_ADDRESS.ToString("x16"); infos[0].dwFields = contextInfoFields; }; mockCodeContext .GetInfo(contextInfoFields, Arg.Do(setContextInfo)) .Returns(VSConstants.S_OK); ((IDebugMemoryContext2)mockCodeContext) .GetInfo(Arg.Any <enum_CONTEXT_INFO_FIELDS>(), Arg.Do(setContextInfo)) .Returns(VSConstants.S_OK); var mockFrame = Substitute.For <RemoteFrame>(); mockFrame.GetPC().Returns(ADDRESS); mockThread.GetFrameAtIndex(0).Returns(mockFrame); Assert.AreEqual(VSConstants.S_FALSE, thread.CanSetNextStatement(mockStackFrame, mockCodeContext)); }
public virtual IList <FRAMEINFO> GetRange(enum_FRAMEINFO_FLAGS fieldSpec, IDebugThread debugThread, uint startIndex, uint count) { count = (uint)Math.Max(0, Math.Min(count, MaxFramesNumberToLoad - startIndex)); if (count == 0) { return(new List <FRAMEINFO>()); } List <FrameInfoPair> framesInfo = _remoteThread.GetFramesWithInfo( (FrameInfoFlags)fieldSpec, startIndex, count); return(ToFrameInfo(framesInfo, debugThread, startIndex)); }
public void SetUp() { _remoteThread = Substitute.For <RemoteThread>(); _debugProgram = Substitute.For <IGgpDebugProgram>(); _ad7FrameInfoCreator = Substitute.For <AD7FrameInfoCreator>( Substitute.For <IDebugModuleCache>()); _ad7FrameInfoCreator .Create(Arg.Any <IDebugStackFrame>(), Arg.Any <FrameInfo <SbModule> >(), _debugProgram) .ReturnsForAnyArgs(args => CreateFRAMEINFO((IDebugStackFrame)args[0], (FrameInfo <SbModule>)args[1])); _debugThread = Substitute.For <IDebugThread>(); _stackFramesProvider = new StackFramesProvider(_remoteThread, CreateStackFrame, _debugProgram, _ad7FrameInfoCreator, _debugProgram); }
public void SetUp() { lineEntry = new LineEntryInfo(); mockDocumentContext = Substitute.For <IDebugDocumentContext2>(); mockThread = Substitute.For <IDebugThread>(); mockDocumentContextFactory = Substitute.For <DebugDocumentContext.Factory>(); mockDocumentContextFactory.Create(lineEntry).Returns(mockDocumentContext); mockDebuggerStackFrame = Substitute.For <RemoteFrame>(); mockDebuggerStackFrame.GetLineEntry().Returns(lineEntry); mockDebuggerStackFrame.GetPC().Returns(TEST_PC); mockDebuggerStackFrame.GetFunctionName().Returns(NAME); mockDebuggerStackFrame.GetFunctionNameWithSignature().Returns(NAME); mockCodeContextFactory = Substitute.For <DebugCodeContext.Factory>(); mockExpressionFactory = Substitute.For <DebugExpression.Factory>(); mockModuleCache = Substitute.For <IDebugModuleCache>(); mockDebugEngineHandler = Substitute.For <IDebugEngineHandler>(); mockProgram = Substitute.For <IGgpDebugProgram>(); taskExecutor = new TaskExecutor(new JoinableTaskContext().Factory); var childAdapterFactory = new RemoteValueChildAdapter.Factory(); var varInfoFactory = new LLDBVariableInformationFactory(childAdapterFactory); var varInfoEnumFactory = new VariableInformationEnum.Factory(taskExecutor); var childrenProviderFactory = new ChildrenProvider.Factory(); var propertyFactory = new DebugProperty.Factory(varInfoEnumFactory, childrenProviderFactory, Substitute.For <DebugCodeContext.Factory>(), new VsExpressionCreator(), taskExecutor); childrenProviderFactory.Initialize(propertyFactory.Create); var registerSetsBuilderFactory = new RegisterSetsBuilder.Factory(varInfoFactory); stackFrame = new DebugStackFrame.Factory(mockDocumentContextFactory, childrenProviderFactory, mockCodeContextFactory, mockExpressionFactory.Create, varInfoFactory, varInfoEnumFactory, registerSetsBuilderFactory, taskExecutor) .Create(new AD7FrameInfoCreator(mockModuleCache), mockDebuggerStackFrame, mockThread, mockDebugEngineHandler, mockProgram); stackFrameAsync = new DebugStackFrameAsync.Factory(mockDocumentContextFactory, childrenProviderFactory, mockCodeContextFactory, mockExpressionFactory.Create, varInfoFactory, varInfoEnumFactory, registerSetsBuilderFactory, taskExecutor) .Create(new AD7FrameInfoCreator(mockModuleCache), mockDebuggerStackFrame, mockThread, mockDebugEngineHandler, mockProgram); }
public void CanSetNextStatementDifferentThread() { var threadId = 1u; var mockThread = Substitute.For <RemoteThread>(); mockThread.GetThreadId().Returns(threadId); var mockStackFrame = Substitute.For <IDebugStackFrame2>(); IDebugThread2 outThread; IDebugThread thread = CreateDebugThread <IDebugThread>(mockThread); mockStackFrame.GetThread(out outThread).Returns(x => { x[0] = Substitute.For <IDebugThread2>(); return(VSConstants.S_OK); }); var mockCodeContext = Substitute.For <IDebugCodeContext2>(); Assert.AreEqual(VSConstants.S_FALSE, thread.CanSetNextStatement(mockStackFrame, mockCodeContext)); }
public void CanSetNextStatementMatchingPc() { const ulong ADDRESS = 0xdeadbeef; const string NAME = "test"; var threadId = 1u; var mockThread = Substitute.For <RemoteThread>(); mockThread.GetThreadId().Returns(threadId); var mockStackFrame = Substitute.For <IDebugStackFrame2>(); string name; mockStackFrame.GetName(out name).Returns(x => { x[0] = NAME; return(VSConstants.S_OK); }); IDebugThread2 outThread; IDebugThread thread = CreateDebugThread <IDebugThread>(mockThread); mockStackFrame.GetThread(out outThread).Returns(x => { x[0] = thread; return(VSConstants.S_OK); }); var mockCodeContext = Substitute.For <IDebugCodeContext2>(); mockCodeContext .GetInfo(enum_CONTEXT_INFO_FIELDS.CIF_ADDRESS | enum_CONTEXT_INFO_FIELDS.CIF_FUNCTION, Arg.Do <CONTEXT_INFO[]>(infos => { infos[0].bstrAddress = "0x" + ADDRESS.ToString("x16"); infos[0].bstrFunction = NAME; })) .Returns(VSConstants.S_OK); var mockFrame = Substitute.For <RemoteFrame>(); mockFrame.GetPC().Returns(ADDRESS); mockThread.GetFrameAtIndex(0).Returns(mockFrame); Assert.AreEqual(VSConstants.S_OK, thread.CanSetNextStatement(mockStackFrame, mockCodeContext)); }
public void CanSetNextStatementSameFunction() { const string NAME = "test"; var threadId = 1u; var mockThread = Substitute.For <RemoteThread>(); mockThread.GetThreadId().Returns(threadId); var mockStackFrame = Substitute.For <IDebugStackFrame2>(); string name; mockStackFrame.GetName(out name).Returns(x => { x[0] = NAME; return(VSConstants.S_OK); }); IDebugThread2 outThread; IDebugThread thread = CreateDebugThread <IDebugThread>(mockThread); mockStackFrame.GetThread(out outThread).Returns(x => { x[0] = thread; return(VSConstants.S_OK); }); var mockCodeContext = Substitute.For <IDebugCodeContext2>(); var contextInfosDestination = Arg.Any <CONTEXT_INFO[]>(); mockCodeContext.GetInfo(enum_CONTEXT_INFO_FIELDS.CIF_ADDRESS | enum_CONTEXT_INFO_FIELDS.CIF_FUNCTION, contextInfosDestination).Returns(x => { var infos = x[1] as CONTEXT_INFO[]; infos[0] = new CONTEXT_INFO { bstrFunction = NAME, bstrAddress = "0xabcd", }; return(VSConstants.S_OK); }); Assert.AreEqual(VSConstants.S_OK, thread.CanSetNextStatement(mockStackFrame, mockCodeContext)); }
IDebugStackFrame CreateStackFrame(RemoteFrame frame, IDebugThread thread, IGgpDebugProgram debugProgram) { return(Substitute.For <IDebugStackFrame>()); }
public virtual IEnumDebugFrameInfo2 Create(StackFramesProvider stackFramesProvider, enum_FRAMEINFO_FLAGS fieldSpec, IDebugThread debugThread) { return(new FrameInfoEnum(stackFramesProvider, fieldSpec, debugThread)); }
public void SetNextStatementFailToJump() { // We need CanSetNextStatement() to pass in order to execute SetNexStatement(). const string NAME = "test"; const ulong ADDRESS = 0xabcd; var threadId = 1u; var mockThread = Substitute.For <RemoteThread>(); mockThread.GetThreadId().Returns(threadId); var mockStackFrame = Substitute.For <IDebugStackFrame2>(); string name; mockStackFrame.GetName(out name).Returns(x => { x[0] = NAME; return(VSConstants.S_OK); }); IDebugThread2 outThread; IDebugThread thread = CreateDebugThread <IDebugThread>(mockThread); mockStackFrame.GetThread(out outThread).Returns(x => { x[0] = thread; return(VSConstants.S_OK); }); var mockCodeContext = Substitute.For <IDebugCodeContext2>(); var contextInfoFields = enum_CONTEXT_INFO_FIELDS.CIF_ADDRESS | enum_CONTEXT_INFO_FIELDS.CIF_FUNCTION; System.Action <CONTEXT_INFO[]> setContext = (infos => { infos[0].bstrFunction = NAME; infos[0].bstrAddress = "0xabcd"; infos[0].dwFields = contextInfoFields; }); mockCodeContext .GetInfo(Arg.Any <enum_CONTEXT_INFO_FIELDS>(), Arg.Do(setContext)) .Returns(VSConstants.S_OK); ((IDebugMemoryContext2)mockCodeContext) .GetInfo(Arg.Any <enum_CONTEXT_INFO_FIELDS>(), Arg.Do(setContext)) .Returns(VSConstants.S_OK); const string DIR = "path\\to"; const string FILE_NAME = "file"; const uint LINE = 2; var mockProcess = Substitute.For <SbProcess>(); mockThread.GetProcess().Returns(mockProcess); var mockTarget = Substitute.For <RemoteTarget>(); mockProcess.GetTarget().Returns(mockTarget); var mockAddress = Substitute.For <SbAddress>(); var lineEntry = Substitute.For <LineEntryInfo>(); lineEntry.Directory = DIR; lineEntry.FileName = FILE_NAME; lineEntry.Line = LINE; var mockError = Substitute.For <SbError>(); mockError.Fail().Returns(true); mockError.GetCString().Returns("JumpToLine() failed for some reason."); mockThread.JumpToLine(Path.Combine(DIR, FILE_NAME), LINE).Returns(mockError); mockAddress.GetLineEntry().Returns(lineEntry); mockTarget.ResolveLoadAddress(ADDRESS).Returns(mockAddress); Assert.AreEqual(VSConstants.E_FAIL, thread.SetNextStatement(mockStackFrame, mockCodeContext)); }
public void SetNextStatement() { // We need CanSetNextStatement() to pass in order to execute SetNexStatement(). const string NAME = "test"; const ulong ADDRESS = 0xabcd; var threadId = 1u; var mockThread = Substitute.For <RemoteThread>(); mockThread.GetThreadId().Returns(threadId); var mockStackFrame = Substitute.For <IDebugStackFrame2>(); string name; mockStackFrame.GetName(out name).Returns(x => { x[0] = NAME; return(VSConstants.S_OK); }); IDebugThread2 outThread; IDebugThread thread = CreateDebugThread <IDebugThread>(mockThread); mockStackFrame.GetThread(out outThread).Returns(x => { x[0] = thread; return(VSConstants.S_OK); }); var mockCodeContext = Substitute.For <IDebugCodeContext2>(); var contextInfosDestination = Arg.Any <CONTEXT_INFO[]>(); mockCodeContext.GetInfo(enum_CONTEXT_INFO_FIELDS.CIF_ADDRESS | enum_CONTEXT_INFO_FIELDS.CIF_FUNCTION, contextInfosDestination).Returns(x => { var infos = x[1] as CONTEXT_INFO[]; infos[0] = new CONTEXT_INFO { bstrFunction = NAME, bstrAddress = "0x" + ADDRESS.ToString("x16"), }; return(VSConstants.S_OK); }); IDebugDocumentContext2 documentContext; var mockDocumentContext = Substitute.For <IDebugDocumentContext2>(); mockCodeContext.GetDocumentContext(out documentContext).Returns(x => { x[0] = mockDocumentContext; return(VSConstants.S_OK); }); const uint LINE = 2; const string PATH = "path\\to\\file"; string path; mockDocumentContext.GetName(enum_GETNAME_TYPE.GN_FILENAME, out path).Returns(x => { x[1] = PATH; return(VSConstants.S_OK); }); mockDocumentContext.GetStatementRange( Arg.Any <TEXT_POSITION[]>(), Arg.Any <TEXT_POSITION[]>()).Returns(x => { var startPosition = x[0] as TEXT_POSITION[]; startPosition[0].dwLine = LINE; return(VSConstants.S_OK); }); var mockError = Substitute.For <SbError>(); mockError.Fail().Returns(false); mockThread.JumpToLine(PATH, LINE).Returns(mockError); Assert.AreEqual(VSConstants.S_OK, thread.SetNextStatement(mockStackFrame, mockCodeContext)); mockThread.Received(1).JumpToLine(PATH, LINE + 1); }