//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public int GetCodeLocationId(IDebugCodeContext2 pCodeContext, out ulong puCodeLocationId) { // // Returns a code location identifier for a particular code context. // LoggingUtils.PrintFunction(); try { CONTEXT_INFO [] contextInfoArray = new CONTEXT_INFO [1]; LoggingUtils.RequireOk(pCodeContext.GetInfo(enum_CONTEXT_INFO_FIELDS.CIF_ADDRESSABSOLUTE, contextInfoArray)); if (contextInfoArray [0].bstrAddressAbsolute.StartsWith("0x")) { puCodeLocationId = ulong.Parse(contextInfoArray [0].bstrAddressAbsolute.Substring(2), NumberStyles.HexNumber); } else { puCodeLocationId = ulong.Parse(contextInfoArray [0].bstrAddressAbsolute, NumberStyles.HexNumber); } return(Constants.S_OK); } catch (Exception e) { LoggingUtils.HandleException(e); puCodeLocationId = 0ul; return(Constants.E_FAIL); } }
public void SetUp() { _codeContextFactory = Substitute.For <DebugCodeContext.Factory>(); _documentContextFactory = Substitute.For <DebugDocumentContext.Factory>(); _mockTarget = Substitute.For <RemoteTarget>(); _mockCodeContext = Substitute.For <IDebugCodeContext2>(); // Mock the address getters. Unfortunately this has to be done on both // the IDebugCodeContext2 and IDebugMemoryContext2 interfaces. Action <CONTEXT_INFO[]> setContextInfo = infos => { infos[0].bstrAddress = GetHexString(_testAddress); infos[0].dwFields = enum_CONTEXT_INFO_FIELDS.CIF_ADDRESS; }; ((IDebugMemoryContext2)_mockCodeContext) .GetInfo(Arg.Any <enum_CONTEXT_INFO_FIELDS>(), Arg.Do(setContextInfo)) .Returns(VSConstants.S_OK); _mockCodeContext.GetInfo(Arg.Any <enum_CONTEXT_INFO_FIELDS>(), Arg.Do(setContextInfo)) .Returns(VSConstants.S_OK); _disassemblyStream = (DebugDisassemblyStream) new DebugDisassemblyStream .Factory(_codeContextFactory, _documentContextFactory) .Create(_testScope, _mockCodeContext, _mockTarget); }
public int CanSetNextStatement(IDebugStackFrame2 stackFrameOrigin, IDebugCodeContext2 codeContextDestination) { stackFrameOrigin.GetThread(out IDebugThread2 threadOrigin); if (threadOrigin == null) { return(VSConstants.E_FAIL); } threadOrigin.GetThreadId(out uint threadIdOrigin); if (threadIdOrigin != _id) { return(VSConstants.S_FALSE); } var contextInfosDestination = new CONTEXT_INFO[1]; int result = codeContextDestination.GetInfo( enum_CONTEXT_INFO_FIELDS.CIF_ADDRESS | enum_CONTEXT_INFO_FIELDS.CIF_FUNCTION, contextInfosDestination); if (result != VSConstants.S_OK) { return(result); } string functionNameOrigin; if (!DebugEngineUtil.GetAddressFromString(contextInfosDestination[0].bstrAddress, out ulong addressPc)) { return(VSConstants.E_FAIL); } if (stackFrameOrigin is IDebugStackFrame stackFrameOriginCast) { stackFrameOriginCast.GetNameWithSignature(out functionNameOrigin); } else { stackFrameOrigin.GetName(out functionNameOrigin); } if (addressPc != _remoteThread.GetFrameAtIndex(0).GetPC() && contextInfosDestination[0].bstrFunction != functionNameOrigin) { return(VSConstants.S_FALSE); } return(VSConstants.S_OK); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public override int SetNextStatement(IDebugStackFrame2 stackFrame, IDebugCodeContext2 codeContext) { // // Sets the next statement to the given stack frame and code context. // LoggingUtils.PrintFunction(); try { CONTEXT_INFO [] contextInfo = new CONTEXT_INFO [1]; LoggingUtils.RequireOk(codeContext.GetInfo(enum_CONTEXT_INFO_FIELDS.CIF_ADDRESSABSOLUTE, contextInfo)); string location = "*" + contextInfo [0].bstrAddressAbsolute; m_debugProgram.AttachedEngine.NativeDebugger.RunInterruptOperation(delegate(CLangDebugger debugger) { // // Create a temporary breakpoint to stop -exec-jump continuing when we'd rather it didn't. // string command = string.Format("-break-insert -t \"{0}\"", location); MiResultRecord resultRecord = debugger.GdbClient.SendSyncCommand(command); MiResultRecord.RequireOk(resultRecord, command); // // Jump to the specified address location. // command = string.Format("-exec-jump --thread {0} \"{1}\"", m_threadId, location); resultRecord = debugger.GdbClient.SendSyncCommand(command); MiResultRecord.RequireOk(resultRecord, command); }); return(Constants.S_OK); } catch (Exception e) { LoggingUtils.HandleException(e); return(Constants.E_FAIL); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public override int SetNextStatement (IDebugStackFrame2 stackFrame, IDebugCodeContext2 codeContext) { // // Sets the next statement to the given stack frame and code context. // LoggingUtils.PrintFunction (); try { CONTEXT_INFO [] contextInfo = new CONTEXT_INFO [1]; LoggingUtils.RequireOk (codeContext.GetInfo (enum_CONTEXT_INFO_FIELDS.CIF_ADDRESSABSOLUTE, contextInfo)); string location = "*" + contextInfo [0].bstrAddressAbsolute; m_debugProgram.AttachedEngine.NativeDebugger.RunInterruptOperation (delegate (CLangDebugger debugger) { // // Create a temporary breakpoint to stop -exec-jump continuing when we'd rather it didn't. // string command = string.Format ("-break-insert -t \"{0}\"", location); MiResultRecord resultRecord = debugger.GdbClient.SendSyncCommand (command); MiResultRecord.RequireOk (resultRecord, command); // // Jump to the specified address location. // command = string.Format ("-exec-jump --thread {0} \"{1}\"", m_threadId, location); resultRecord = debugger.GdbClient.SendSyncCommand (command); MiResultRecord.RequireOk (resultRecord, command); }); return Constants.S_OK; } catch (Exception e) { LoggingUtils.HandleException (e); return Constants.E_FAIL; } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public int GetCodeLocationId (IDebugCodeContext2 pCodeContext, out ulong puCodeLocationId) { // // Returns a code location identifier for a particular code context. // LoggingUtils.PrintFunction (); try { CONTEXT_INFO [] contextInfoArray = new CONTEXT_INFO [1]; LoggingUtils.RequireOk (pCodeContext.GetInfo (enum_CONTEXT_INFO_FIELDS.CIF_ADDRESSABSOLUTE, contextInfoArray)); if (contextInfoArray [0].bstrAddressAbsolute.StartsWith ("0x")) { puCodeLocationId = ulong.Parse (contextInfoArray [0].bstrAddressAbsolute.Substring (2), NumberStyles.HexNumber); } else { puCodeLocationId = ulong.Parse (contextInfoArray [0].bstrAddressAbsolute, NumberStyles.HexNumber); } return Constants.S_OK; } catch (Exception e) { LoggingUtils.HandleException (e); puCodeLocationId = 0ul; return Constants.E_FAIL; } }