void Step(bool into) { if (stepper != null) { stepper.IsActive(); CorFrame frame = activeThread.ActiveFrame; ISymbolReader reader = GetReaderForModule(frame.Function.Module.Name); if (reader == null) { RawContinue(into); return; } ISymbolMethod met = reader.GetMethod(new SymbolToken(frame.Function.Token)); if (met == null) { RawContinue(into); return; } uint offset; CorDebugMappingResult mappingResult; frame.GetIP(out offset, out mappingResult); // Find the current line SequencePoint currentSeq = null; foreach (SequencePoint sp in met.GetSequencePoints()) { if (sp.Offset > offset) { break; } currentSeq = sp; } if (currentSeq == null) { RawContinue(into); return; } // Exclude all ranges belonging to the current line List <COR_DEBUG_STEP_RANGE> ranges = new List <COR_DEBUG_STEP_RANGE> (); SequencePoint lastSeq = null; foreach (SequencePoint sp in met.GetSequencePoints()) { if (lastSeq != null && lastSeq.Line == currentSeq.Line) { COR_DEBUG_STEP_RANGE r = new COR_DEBUG_STEP_RANGE(); r.startOffset = (uint)lastSeq.Offset; r.endOffset = (uint)sp.Offset; ranges.Add(r); } lastSeq = sp; } stepper.StepRange(into, ranges.ToArray()); ClearEvalStatus(); process.SetAllThreadsDebugState(CorDebugThreadState.THREAD_RUN, null); process.Continue(false); } }
public void _StepDirect(bool stepInto, bool User) { bool stepped = false; lock (this) { if (User) { if (IsStepping) { #if DEBUG dout.WriteLine("DEBUG: Cannot Step(stepInto={0}) (IsStepping)", (stepInto ? "true" : "false")); #endif return; } } //idbgthd.GetActiveFrame(out idbgfrm); ICorDebugStepper stepper; idbgfrm.CreateStepper(out stepper); stepper.SetUnmappedStopMask(0); //STOP_NONE ICorDebugILFrame ilframe = idbgfrm as ICorDebugILFrame; uint ip; CorDebugMappingResult mappingresults; ilframe.GetIP(out ip, out mappingresults); ICorDebugFunction f; idbgfrm.GetFunction(out f); ICorDebugModule imod; f.GetModule(out imod); UInt32 ftoken; f.GetToken(out ftoken); Guid CLSID_CorSymBinder = new Guid("0A29FF9E-7F9C-4437-8B11-F424491E3931"); ISymUnmanagedBinder binder = (ISymUnmanagedBinder)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_CorSymBinder)); { ICorDebugAssembly iasm; imod.GetAssembly(out iasm); string assemblyname; { IntPtr pasmnamebuf = Marshal.AllocHGlobal(PATH_BUFFER_LENGTH * 2); uint asmnamelen = (uint)PATH_BUFFER_LENGTH; imod.GetName(asmnamelen, out asmnamelen, pasmnamebuf); if (asmnamelen > PATH_BUFFER_LENGTH) { throw new Exception("Assembly path too long"); } asmnamelen--; // Remove nul. assemblyname = Marshal.PtrToStringUni(pasmnamebuf, (int)asmnamelen); Marshal.FreeHGlobal(pasmnamebuf); } Guid CLSID_IMetaDataDispenser = new Guid(0xe5cb7a31, 0x7512, 0x11d2, 0x89, 0xce, 0x00, 0x80, 0xc7, 0x92, 0xe5, 0xd8); IMetaDataDispenser disp = (IMetaDataDispenser)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_IMetaDataDispenser)); Guid CLSID_IMetaDataImport = new Guid(0x7dac8207, 0xd3ae, 0x4c75, 0x9b, 0x67, 0x92, 0x80, 0x1a, 0x49, 0x7d, 0x44); object oimporter; disp.OpenScope(assemblyname, 0 /* OPEN_READ */, ref CLSID_IMetaDataImport, out oimporter); IntPtr pimporter = IntPtr.Zero; try { pimporter = Marshal.GetComInterfaceForObject(oimporter, typeof(IMMImport)); ISymUnmanagedReader reader; int hrreader = binder.GetReaderForFile(pimporter, assemblyname, null, out reader); if (0 == hrreader) { ISymUnmanagedMethod unmMethod; if (0 == reader.GetMethod(new System.Diagnostics.SymbolStore.SymbolToken((int)ftoken), out unmMethod)) { int seqptscount; unmMethod.GetSequencePointCount(out seqptscount); int[] spoffsets = new int[seqptscount]; ISymUnmanagedDocument[] spdocs = new ISymUnmanagedDocument[seqptscount]; int[] spstartlines = new int[seqptscount]; int[] spendlines = new int[seqptscount]; int[] spstartcols = new int[seqptscount]; int[] spendcols = new int[seqptscount]; int cPoints; unmMethod.GetSequencePoints(seqptscount, out cPoints, spoffsets, spdocs, spstartlines, spstartcols, spendlines, spendcols); COR_DEBUG_STEP_RANGE[] ranges = null; for (int j = 0; j < seqptscount; j++) { if (spoffsets[j] > ip) { ranges = new COR_DEBUG_STEP_RANGE[1]; ranges[0].endOffset = (uint)spoffsets[j]; ranges[0].startOffset = (uint)spoffsets[j - 1]; break; } } if (ranges == null && seqptscount > 0) { ranges = new COR_DEBUG_STEP_RANGE[1]; ranges[0].startOffset = (uint)spoffsets[seqptscount - 1]; ICorDebugCode icode; f.GetILCode(out icode); uint codesize; icode.GetSize(out codesize); ranges[0].endOffset = codesize; } if (ranges != null) { IsStepping = true; stepper.StepRange(stepInto ? 1 : 0, ref ranges[0], (uint)ranges.Length); stepped = true; } } } } finally { if (IntPtr.Zero != pimporter) { Marshal.Release(pimporter); pimporter = IntPtr.Zero; } } } if(!stepped) { IsStepping = true; stepper.Step(0); // Step over non-IL. stepped = true; } } if (stepped) { if (User) { ContinueUntil("StepComplete"); lock (this) { #if DEBUG if (IsStepping) { dout.WriteLine("DEBUG: Step: whoops, should be still stepping (ignore at exit)"); } #endif IsStepping = false; } } else { idbgproc.Continue(0); } } }
int ICorDebugStepper.StepRange( int bStepIn, COR_DEBUG_STEP_RANGE[] ranges, uint cRangeCount ) { //This isn't a correct method signature. However, since we don't support this (yet), it doesn't really matter //Add CorDebugStepper.StepRange is not implemented m_ranges = ranges; Debug.Assert( cRangeCount == 1 ); for(int iRange = 0; iRange < m_ranges.Length; iRange++) { COR_DEBUG_STEP_RANGE range = m_ranges[iRange]; m_ranges[iRange].startOffset = this.m_frame.Function.GetILTinyCLRFromILCLR( range.startOffset ); m_ranges[iRange].endOffset = this.m_frame.Function.GetILTinyCLRFromILCLR( range.endOffset ); } Activate( Utility.Boolean.IntToBool( bStepIn ) ? BreakpointDef.c_STEP_IN : BreakpointDef.c_STEP_OVER ); return Utility.COM_HResults.S_OK; }