public void TestGetDocuments1() { var symReader = CreateSymReaderFromResource(TestResources.Documents.DllAndPdb); int actualCount; Assert.Equal(HResult.S_OK, symReader.GetDocuments(0, out actualCount, null)); Assert.Equal(11, actualCount); var actualDocuments = new ISymUnmanagedDocument[actualCount]; int actualCount2; Assert.Equal(HResult.S_OK, symReader.GetDocuments(actualCount, out actualCount2, actualDocuments)); Assert.Equal(11, actualCount2); ValidateDocument(actualDocuments[0], url: @"C:\Documents.cs", algorithmId: "ff1816ec-aa5e-4d10-87f7-6f4963833460", checksum: new byte[] { 0xDB, 0xEB, 0x2A, 0x06, 0x7B, 0x2F, 0x0E, 0x0D, 0x67, 0x8A, 0x00, 0x2C, 0x58, 0x7A, 0x28, 0x06, 0x05, 0x6C, 0x3D, 0xCE }); ValidateDocument(actualDocuments[1], url: @"C:\a\b\c\d\1.cs", algorithmId: null, checksum: null); ValidateDocument(actualDocuments[2], url: @"C:\a\b\c\D\2.cs", algorithmId: null, checksum: null); ValidateDocument(actualDocuments[3], url: @"C:\a\b\C\d\3.cs", algorithmId: null, checksum: null); ValidateDocument(actualDocuments[4], url: @"C:\a\b\c\d\x.cs", algorithmId: null, checksum: null); ValidateDocument(actualDocuments[5], url: @"C:\A\b\c\x.cs", algorithmId: null, checksum: null); ValidateDocument(actualDocuments[6], url: @"C:\a\b\x.cs", algorithmId: null, checksum: null); ValidateDocument(actualDocuments[7], url: @"C:\a\B\3.cs", algorithmId: null, checksum: null); ValidateDocument(actualDocuments[8], url: @"C:\a\B\c\4.cs", algorithmId: null, checksum: null); ValidateDocument(actualDocuments[9], url: @"C:\*\5.cs", algorithmId: null, checksum: null); ValidateDocument(actualDocuments[10], url: @":6.cs", algorithmId: null, checksum: null); }
private int[][] GetMethodTokensForEachLine(ISymUnmanagedReader symReader, ISymUnmanagedDocument symDocument, int minZeroBasedLine, int maxZeroBasedLine) { var result = new List<int[]>(); for (int line = minZeroBasedLine; line <= maxZeroBasedLine; line++) { int[] allMethodTokens = GetMethodTokensFromDocumentPosition(symReader, symDocument, line, 0); ISymUnmanagedMethod method; int hr = symReader.GetMethodFromDocumentPosition(symDocument, line, 1, out method); if (hr != HResult.S_OK) { Assert.Equal(HResult.E_FAIL, hr); Assert.Equal(0, allMethodTokens.Length); } else { int primaryToken; Assert.Equal(HResult.S_OK, method.GetToken(out primaryToken)); Assert.Equal(primaryToken, allMethodTokens.First()); } result.Add(allMethodTokens); } return result.ToArray(); }
public static void ValidateDocument(ISymUnmanagedDocument document, string url, string algorithmId, byte[] checksum) { ValidateDocumentUrl(document, url); int actualCount, actualCount2; if (checksum != null) { Assert.Equal(HResult.S_OK, document.GetChecksum(0, out actualCount, null)); byte[] actualChecksum = new byte[actualCount]; Assert.Equal(HResult.S_OK, document.GetChecksum(actualCount, out actualCount2, actualChecksum)); Assert.Equal(actualCount, actualCount2); AssertEx.Equal(checksum, actualChecksum); } else { Assert.Equal(HResult.S_FALSE, document.GetChecksum(0, out actualCount, null)); Assert.Equal(0, actualCount); } var guid = Guid.NewGuid(); Assert.Equal(HResult.S_OK, document.GetChecksumAlgorithmId(ref guid)); Assert.Equal(algorithmId != null ? new Guid(algorithmId) : default(Guid), guid); guid = Guid.NewGuid(); Assert.Equal(HResult.S_OK, document.GetLanguageVendor(ref guid)); Assert.Equal(new Guid("994b45c4-e6e9-11d2-903f-00c04fa302a1"), guid); guid = Guid.NewGuid(); Assert.Equal(HResult.S_OK, document.GetDocumentType(ref guid)); Assert.Equal(new Guid("5a869d0b-6611-11d3-bd2a-0000f80849bd"), guid); }
internal SymbolDocument(ISymUnmanagedDocument unmanagedDocument) { if (unmanagedDocument == null) { throw new ArgumentNullException("unmanagedDocument"); } this.unmanagedDocument = unmanagedDocument; }
internal SymbolDocument(ISymUnmanagedDocument document) { if (document == null) { throw new ArgumentNullException("document"); } m_unmanagedDocument = document; }
public static ISymUnmanagedMethod[] GetMethodsFromDocumentPosition(this CorSymReader_SxSClass instance, ISymUnmanagedDocument document, uint line, uint column) { uint count; instance.__GetMethodsFromDocumentPosition(document, line, column, 0, out count, new ISymUnmanagedMethod[0]); var methods = new ISymUnmanagedMethod[count]; instance.__GetMethodsFromDocumentPosition(document, line, column, count, out count, methods); ProcessOutParameter(methods); return methods; }
public static void ValidateDocumentUrl(ISymUnmanagedDocument document, string url) { int actualCount, actualCount2; Assert.Equal(HResult.S_OK, document.GetUrl(0, out actualCount, null)); char[] actualUrl = new char[actualCount]; Assert.Equal(HResult.S_OK, document.GetUrl(actualCount, out actualCount2, actualUrl)); Assert.Equal(url, new string(actualUrl, 0, actualUrl.Length - 1)); }
public static void GetSourceExtentInDocument(this ISymEncUnmanagedMethod method, ISymUnmanagedDocument document, out int startLine, out int endLine) { if (method == null) { throw new ArgumentNullException(nameof(method)); } ThrowExceptionForHR(method.GetSourceExtentInDocument(document, out startLine, out endLine)); }
public ISymbolDocument[] GetDocuments() { uint numDocs; reader.GetDocuments(0, out numDocs, null); var unDocs = new ISymUnmanagedDocument[numDocs]; reader.GetDocuments((uint)unDocs.Length, out numDocs, unDocs); var docs = new ISymbolDocument[numDocs]; for (uint i = 0; i < numDocs; i++) docs[i] = new SymbolDocument(unDocs[i]); return docs; }
private void TestGetMethodFromDocumentPosition( ISymUnmanagedReader symReader, ISymUnmanagedDocument symDocument, int zeroBasedLine, int zeroBasedColumn, int expectedToken) { ISymUnmanagedMethod method; Assert.Equal(HResult.S_OK, symReader.GetMethodFromDocumentPosition(symDocument, zeroBasedLine, zeroBasedColumn, out method)); int token; Assert.Equal(HResult.S_OK, method.GetToken(out token)); Assert.Equal(expectedToken, token); }
public ISymbolDocument[] GetDocuments() { int cDocs; unmanagedReader.GetDocuments(0, out cDocs, null); ISymUnmanagedDocument[] unmanagedDocuments = new ISymUnmanagedDocument[cDocs]; unmanagedReader.GetDocuments(cDocs, out cDocs, unmanagedDocuments); ISymbolDocument[] documents = new SymbolDocument[cDocs]; uint i; for (i = 0; i < cDocs; i++) { documents[i] = new SymbolDocument(unmanagedDocuments[i]); } return documents; }
public SymUnmanagedSequencePoint( int offset, ISymUnmanagedDocument document, int startLine, int startColumn, int endLine, int endColumn) { this.Offset = offset; this.Document = document; this.StartLine = startLine; this.StartColumn = startColumn; this.EndLine = endLine; this.EndColumn = endColumn; }
// ISymUnmanagedMethod public static SequencePoint[] GetSequencePoints(this ISymUnmanagedMethod symMethod, int codesize) { uint count = symMethod.GetSequencePointCount(); ISymUnmanagedDocument[] documents = new ISymUnmanagedDocument[count]; uint[] offsets = new uint[count]; uint[] lines = new uint[count]; uint[] columns = new uint[count]; uint[] endLines = new uint[count]; uint[] endColumns = new uint[count]; symMethod.GetSequencePoints( count, out count, offsets, documents, lines, columns, endLines, endColumns ); var sequencePoints = new SequencePoint[count]; var urls = documents.Distinct().ToDictionary(d => d, d => d.GetURL()); var sums = documents.Distinct().ToDictionary(d => d, d => d.GetCheckSum()); uint token = symMethod.GetToken(); for(int i = 0; i < count; i++) { sequencePoints[i] = new SequencePoint() { MethodDefToken = token, ILRanges = new [] { new ILRange((int)offsets[i], i + 1 < count ? (int)offsets[i + 1] : codesize) }, Filename = urls[documents[i]], FileCheckSum = sums[documents[i]], StartLine = (int)lines[i], StartColumn = (int)columns[i], EndLine = (int)endLines[i], EndColumn = (int)endColumns[i] }; } return sequencePoints; }
private int[] GetMethodTokensFromDocumentPosition( ISymUnmanagedReader symReader, ISymUnmanagedDocument symDocument, int zeroBasedLine, int zeroBasedColumn) { int count; Assert.Equal(HResult.S_OK, symReader.GetMethodsFromDocumentPosition(symDocument, zeroBasedLine, zeroBasedColumn, 0, out count, null)); var methods = new ISymUnmanagedMethod[count]; int count2; Assert.Equal(HResult.S_OK, symReader.GetMethodsFromDocumentPosition(symDocument, zeroBasedLine, zeroBasedColumn, count, out count2, methods)); Assert.Equal(count, count2); return methods.Select(m => { int token; Assert.Equal(HResult.S_OK, m.GetToken(out token)); return token; }).ToArray(); }
internal static ImmutableArray<SymUnmanagedSequencePoint> GetSequencePoints(this ISymUnmanagedMethod method) { // NB: method.GetSequencePoints(0, out numAvailable, ...) always returns 0. int numAvailable; int hr = method.GetSequencePointCount(out numAvailable); SymUnmanagedReaderExtensions.ThrowExceptionForHR(hr); if (numAvailable == 0) { return ImmutableArray<SymUnmanagedSequencePoint>.Empty; } int[] offsets = new int[numAvailable]; ISymUnmanagedDocument[] documents = new ISymUnmanagedDocument[numAvailable]; int[] startLines = new int[numAvailable]; int[] startColumns = new int[numAvailable]; int[] endLines = new int[numAvailable]; int[] endColumns = new int[numAvailable]; int numRead; hr = method.GetSequencePoints(numAvailable, out numRead, offsets, documents, startLines, startColumns, endLines, endColumns); SymUnmanagedReaderExtensions.ThrowExceptionForHR(hr); if (numRead != numAvailable) { throw new InvalidOperationException(string.Format("Read only {0} of {1} sequence points.", numRead, numAvailable)); } var builder = ArrayBuilder<SymUnmanagedSequencePoint>.GetInstance(numRead); for (int i = 0; i < numRead; i++) { builder.Add(new SymUnmanagedSequencePoint( offsets[i], documents[i], startLines[i], startColumns[i], endLines[i], endColumns[i])); } return builder.ToImmutableAndFree(); }
public static IEnumerable<SymUnmanagedSequencePoint> GetSequencePoints(this ISymUnmanagedMethod method) { if (method == null) { throw new ArgumentNullException(nameof(method)); } // NB: method.GetSequencePoints(0, out numAvailable, ...) always returns 0. int numAvailable; ThrowExceptionForHR(method.GetSequencePointCount(out numAvailable)); if (numAvailable == 0) { yield break; } int[] offsets = new int[numAvailable]; ISymUnmanagedDocument[] documents = new ISymUnmanagedDocument[numAvailable]; int[] startLines = new int[numAvailable]; int[] startColumns = new int[numAvailable]; int[] endLines = new int[numAvailable]; int[] endColumns = new int[numAvailable]; int numRead; ThrowExceptionForHR(method.GetSequencePoints(numAvailable, out numRead, offsets, documents, startLines, startColumns, endLines, endColumns)); ValidateItems(numRead, offsets.Length); for (int i = 0; i < numRead; i++) { yield return new SymUnmanagedSequencePoint( offsets[i], documents[i], startLines[i], startColumns[i], endLines[i], endColumns[i]); } }
bool _IsSourceAtSpecialPosition_unlocked() { bool isspecial = false; if (dbgproc.idbgfrm is ICorDebugILFrame) { ICorDebugILFrame ilframe = dbgproc.idbgfrm as ICorDebugILFrame; uint ip; CorDebugMappingResult mapresult; ilframe.GetIP(out ip, out mapresult); if (mapresult == CorDebugMappingResult.MAPPING_NO_INFO || mapresult == CorDebugMappingResult.MAPPING_UNMAPPED_ADDRESS) { return false; } ICorDebugFunction f; dbgproc.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); { if ((seqptscount > 0) && (spoffsets[0] <= ip)) { int i; for (i = 0; i < seqptscount; ++i) { if (spoffsets[i] >= ip) { break; } } if (i == seqptscount || spoffsets[i] != ip) { --i; } int specialseqpt =0xfeefee; if (spstartlines[i] == specialseqpt) { int j = i; while (j > 0) { --j; if (spstartlines[j] != specialseqpt) { isspecial = true; break; } } if (!isspecial) { j = i; while (++j < seqptscount) { if (spstartlines[j] != specialseqpt) { isspecial = true; break; } } } } } } } } } finally { if (IntPtr.Zero != pimporter) { Marshal.Release(pimporter); pimporter = IntPtr.Zero; } } } } return isspecial; }
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); } } }
public void Run() { if (null == idbg) { throw new ArgumentException("Critical error: Run: idbg is null"); } if (null == idbgproc) { throw new ArgumentException("Critical error: Run: idbgproc is null"); } #if DEBUG if (IsXDebug) { Console.WriteLine(" * Waiting for initial breakpoint and finish initializing"); } #endif //Until("LoadModule:this").WaitOne(); Until("Breakpoint").WaitOne(); FinishedInitializing = true; if (IsVerbose) { Console.WriteLine(" Finished initializing debug process"); } //System.Threading.Thread.Sleep(3000); lock (this) { ShowCurrentLine_unlocked(); } while(!ProcessExit) { System.GC.Collect(); try { dout.Write("(mrdebug) "); string origcmd; string cmd, args; { string line = null; lock (cmdq) { if (cmdq.Count > 0) { line = cmdq.Dequeue(); } } if (null == line) { for (; ; ) { //bool waited = cmde.WaitOne(1000, false); bool waited = cmde.WaitOne(); lock (cmdq) { if (cmdq.Count < 1) { continue; } #if DEBUG if (!waited) { Console.WriteLine("DEBUG: (!waited)"); } #endif line = cmdq.Dequeue(); break; } } } if (line.Length == 0) { line = lastcmdline; } else { lastcmdline = line; } int isp = line.IndexOf(' '); if (-1 == isp) { origcmd = line; args = ""; } else { origcmd = line.Substring(0, isp); args = line.Substring(isp + 1); } cmd = origcmd.ToLower(); } #if DEBUG if (IsXDebug) { Console.WriteLine(" * received command named '{0}' with args '{1}'", origcmd, args); } #endif if (ProcessExit) { switch (cmd) { case "quit": case "exit": break; default: dout.WriteLine("Error: Command '{0}' cannot be run at this time", origcmd); break; } continue; // Exits loop. } { switch (cmd) { case "go": case "cont": // continue { ContinueUntil("Breakpoint"); } break; case "delete": case "d": lock (this) { if (0 != args.Length) { dout.WriteLine("Error: delete only works with no parameters"); } else { for (int ibp = 0; ibp < ibreakpoints.Count; ibp++) { ibreakpoints[ibp].Activate(0); // Deactivate. } } } break; case "b": case "break": lock (this) { string BkptFile = ""; string sBkptLine; { int ilc = args.LastIndexOf(':'); if (ilc > 1) { BkptFile = args.Substring(0, ilc); sBkptLine = args.Substring(ilc + 1); } else { sBkptLine = args; } } int BkptLine; if (!int.TryParse(sBkptLine, out BkptLine) || BkptLine < 0) { dout.WriteLine("Error: breakpoint line number expected"); continue; } Guid CLSID_CorSymBinder = new Guid("0A29FF9E-7F9C-4437-8B11-F424491E3931"); ISymUnmanagedBinder binder = (ISymUnmanagedBinder)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_CorSymBinder)); for (int im = 0; im < imodules.Count; im++) { ICorDebugModule imod = imodules[im]; 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); } if (!assemblyname.EndsWith(".exe", true, null)) { continue; } /*IMetaDataImport importer; { object oimdi; Guid IMetaDataImportGUID = typeof(IMetaDataImport).GUID; imod.GetMetaDataInterface(ref IMetaDataImportGUID, out oimdi); importer = (IMetaDataImport)oimdi; }*/ 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) { int cDocs = 0; reader.GetDocuments(0, out cDocs, null); ISymUnmanagedDocument[] unmDocs = new ISymUnmanagedDocument[cDocs]; reader.GetDocuments(cDocs, out cDocs, unmDocs); for (int idoc = 0; idoc < cDocs; idoc++) { // See if current doc is the one I'm adding to.. via GetURL ISymUnmanagedDocument unmDoc = unmDocs[idoc]; //BkptFile if (null != BkptFile) { string docurl; { int urllen = 0; unmDoc.GetURL(0, out urllen, null); StringBuilder sburl = new StringBuilder(urllen); unmDoc.GetURL(urllen, out urllen, sburl); sburl.Length = urllen - 1; // Remove nul. docurl = sburl.ToString(); } if (!FileNamesMatch(docurl, BkptFile)) { continue; } } { int RealBkptLine = -1; try { unmDoc.FindClosestLine(BkptLine, out RealBkptLine); } catch { } if (RealBkptLine < 0) { continue; } BkptLine = RealBkptLine; } ISymUnmanagedMethod unmMethod; reader.GetMethodFromDocumentPosition(unmDoc, BkptLine, 0, out unmMethod); System.Diagnostics.SymbolStore.SymbolToken methodToken; unmMethod.GetToken(out methodToken); 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); int spoffset = -1; for (int isp = 0; isp < cPoints; isp++) { if (BkptLine == spstartlines[isp]) { spoffset = spoffsets[isp]; break; } } ICorDebugFunction idbgFunc; imod.GetFunctionFromToken((uint)methodToken.GetToken(), out idbgFunc); ICorDebugFunctionBreakpoint pBkpt; if (-1 != spoffset) { ICorDebugCode pCode; idbgFunc.GetILCode(out pCode); pCode.CreateBreakpoint((uint)spoffset, out pBkpt); } else { idbgFunc.CreateBreakpoint(out pBkpt); } pBkpt.Activate(1); ibreakpoints.Add(pBkpt); } } } finally { if (IntPtr.Zero != pimporter) { Marshal.Release(pimporter); pimporter = IntPtr.Zero; } } } } break; case "n": case "next": case "so": // Step over. Step(false); break; case "s": case "step": case "si": Step(true); break; case "out": case "o": StepOut(); break; case "where": case "w": lock (this) { List<WhereInfo> wheres = new List<WhereInfo>(); int CurrentFrameIndex = GetWhere(wheres, 50); for (int fi = 0; fi < wheres.Count; fi++) { WhereInfo wi = wheres[fi]; dout.Write("{0}){1} {2}", fi, (fi == CurrentFrameIndex) ? "*" : "", wi.Source); if (-1 != wi.FileLineNumber) { string slinenum; if (HIDDEN_LINE_NUMBER == wi.FileLineNumber) { slinenum = "?"; } else { slinenum = wi.FileLineNumber.ToString(); } dout.WriteLine(" in {0}:{1}", wi.FileName, slinenum); } else { dout.WriteLine(); } } } break; case "print": lock (this) { ICorDebugThread ithd; idbgproc.GetThread(ActiveThreadID, out ithd); ICorDebugFrame iframe; ithd.GetActiveFrame(out iframe); if (null == iframe) { dout.WriteLine("Error: No frame available"); } else { ICorDebugFunction ifunc; iframe.GetFunction(out ifunc); ICorDebugILFrame ilframe = iframe as ICorDebugILFrame; if (null == ilframe) { dout.WriteLine("Error: No IL frame"); } else { uint ftoken; ifunc.GetToken(out ftoken); ICorDebugModule imod; ifunc.GetModule(out imod); 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)); Guid CLSID_CorSymBinder = new Guid("0A29FF9E-7F9C-4437-8B11-F424491E3931"); ISymUnmanagedBinder binder = (ISymUnmanagedBinder)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_CorSymBinder)); ISymUnmanagedReader reader; int hrreader = binder.GetReaderForFile(pimporter, assemblyname, null, out reader); if (0 == hrreader) { ISymUnmanagedMethod unmMethod; reader.GetMethod(new System.Diagnostics.SymbolStore.SymbolToken((int)ftoken), out unmMethod); if (null != unmMethod) { IMetaDataImport importer; { object oimdi; Guid IMetaDataImportGUID = typeof(IMetaDataImport).GUID; imod.GetMetaDataInterface(ref IMetaDataImportGUID, out oimdi); importer = (IMetaDataImport)oimdi; } uint ip; CorDebugMappingResult mappingresults; ilframe.GetIP(out ip, out mappingresults); ISymUnmanagedScope unmScope; unmMethod.GetRootScope(out unmScope); _PrintLocals(ilframe, unmScope, ip, dout); _PrintArgs(ilframe, importer, dout); } } else { } } finally { if (IntPtr.Zero != pimporter) { Marshal.Release(pimporter); pimporter = IntPtr.Zero; } } } } } break; case "funceval": case "f": { bool needwait = false; ICorDebugEval peval; ICorDebugFunction ifunc; ICorDebugValue pvalue; lock (this) { string xxstart = "System.Object::ToString "; if (!args.StartsWith(xxstart)) { dout.WriteLine("funceval only supports " + xxstart); } string TypeName = "System.Object"; string FuncName = "ToString"; string fargs = args.Substring(xxstart.Length); ICorDebugValue fargvalue0 = MyFindLocalVarOrArg_unlocked(fargs); if (null == fargvalue0) { dout.WriteLine("Could not resolve argument {0} - funceval only supports one parameter that is a local", fargvalue0); } else { IMetaDataImport importerMscorlib; { object oimdi; Guid IMetaDataImportGUID = typeof(IMetaDataImport).GUID; imoduleMscorlib.GetMetaDataInterface(ref IMetaDataImportGUID, out oimdi); importerMscorlib = (IMetaDataImport)oimdi; } uint ctoken; if (0 != importerMscorlib.FindTypeDefByName(TypeName, 0, out ctoken)) { dout.WriteLine("Could not resolve {0}", TypeName); } else { List<uint> MethodTokens = new List<uint>(); { uint hEnum = 0; uint[] aMethodToken = new uint[1]; for (; ; ) { uint cTokens; importerMscorlib.EnumMethods(ref hEnum, ctoken, aMethodToken, 1, out cTokens); if (0 == cTokens) { break; } MethodTokens.Add(aMethodToken[0]); } } IMetaDataImport importer = importerMscorlib; uint ftoken = 0; for (int imt = 0; imt < MethodTokens.Count; imt++) { uint cmftoken = MethodTokens[imt]; uint cmftypedeftoken; string cmMethodName; { uint chMethod; uint dwAttr; IntPtr pvSigBlob; uint cbSigBlob; uint ulCodeRVA; uint dwImplFlags; int hrmethodprops = (int)importer.GetMethodProps(cmftoken, out cmftypedeftoken, null, 0, out chMethod, out dwAttr, out pvSigBlob, out cbSigBlob, out ulCodeRVA, out dwImplFlags); Marshal.ThrowExceptionForHR(hrmethodprops); char[] methodnamechars = new char[chMethod]; hrmethodprops = (int)importer.GetMethodProps(cmftoken, out cmftypedeftoken, methodnamechars, (uint)methodnamechars.Length, out chMethod, out dwAttr, out pvSigBlob, out cbSigBlob, out ulCodeRVA, out dwImplFlags); Marshal.ThrowExceptionForHR(hrmethodprops); chMethod--; // Remove nul. cmMethodName = new string(methodnamechars, 0, (int)chMethod); } if (cmMethodName == FuncName) { ftoken = cmftoken; break; } } if (0 == ftoken) { dout.WriteLine("Could not resolve {0}.{1}", TypeName, FuncName); } else { //ICorDebugEval peval; idbgthd.CreateEval(out peval); if (null == peval) { dout.WriteLine("Cannot evaluate at this time"); } else { //ICorDebugFunction ifunc; imoduleMscorlib.GetFunctionFromToken(ftoken, out ifunc); //ICorDebugValue pvalue; pvalue = fargvalue0; peval.CallFunction(ifunc, 1, ref pvalue); needwait = true; } } } } } if (needwait) { ContinueUntil("EvalComplete"); } } break; case "quit": case "exit": if (!ProcessExit) { lock (this) { idbgproc.Terminate(0); } Until("ExitProcess").WaitOne(); } else { System.Threading.Thread.Sleep(1000); } ProcessExit = true; break; default: dout.WriteLine("Error: Command '{0}' not found.", origcmd); break; } } } catch (Exception e) { #if DEBUG System.IO.File.WriteAllText(@"c:\mrdebug-errors.txt", DateTime.Now.ToString() + " - " + e.ToString()); #endif dout.WriteLine("Command exception: " + e.ToString()); System.Threading.Thread.Sleep(1000); } } }
internal SymbolDocument(ISymUnmanagedDocument document) { m_unmanagedDocument = document; }
public int GetMethodsInDocument(ISymUnmanagedDocument document, int bufferLength, out int count, ISymUnmanagedMethod[] methods) { throw new NotImplementedException(); }
/// <summary> /// Get a string representing the source location for the given IL offset and method /// </summary> /// <param name="method">The method of interest</param> /// <param name="ilOffset">The offset into the IL</param> /// <returns>A string of the format [filepath]:[line] (eg. "C:\temp\foo.cs:123"), or null /// if a matching PDB couldn't be found</returns> /// <remarks>Thows various COMExceptions (from DIA SDK error values) if a PDB couldn't be opened/read</remarks> public SourceLoc GetSourceLoc(MethodBase method, int ilOffset) { // Get the symbol reader corresponding to the module of the supplied method string modulePath = method.Module.FullyQualifiedName; ISymUnmanagedReader symReader = GetSymbolReaderForFile(modulePath); if (symReader == null) return null; // no PDBs ISymUnmanagedMethod symMethod = symReader.GetMethod(new SymbolToken(method.MetadataToken)); // Get all the sequence points for the method int count = symMethod.GetSequencePointCount(); ISymUnmanagedDocument[] docs = new ISymUnmanagedDocument[count]; int[] startLines = new int[count]; int[] ilOffsets = new int[count]; int[] endLines = new int[count]; int[] startCols = new int[count]; int[] endCols = new int[count]; int outPoints; symMethod.GetSequencePoints(count, out outPoints, ilOffsets, docs, startLines, startCols, endLines, endCols); // Find the closest sequence point to the requested offset // Sequence points are returned sorted by offset so we're looking for the last one with // an offset less than or equal to the requested offset. // Note that this won't necessarily match the real source location exactly if // the code was jit-compiled with optimizations. int i; for (i = 0; i < count; i++) { if (ilOffsets[i] > ilOffset) break; } // Found the first mismatch, back up if it wasn't the first if (i > 0) i--; // Now return the source file and line number for this sequence point StringBuilder url = new StringBuilder(512); int len; docs[i].GetURL(url.Capacity, out len, url); return new SourceLoc(url.ToString(), startLines[i], endLines[i], startCols[i], endCols[i]); }
public override IEnumerable<ILSequencePoint> GetSequencePointsForMethod(int methodToken) { ISymUnmanagedMethod symbolMethod; if (_symUnmanagedReader.GetMethod(methodToken, out symbolMethod) < 0) yield break; int count; ThrowExceptionForHR(symbolMethod.GetSequencePointCount(out count)); ISymUnmanagedDocument[] docs = new ISymUnmanagedDocument[count]; int[] lineNumbers = new int[count]; int[] ilOffsets = new int[count]; ThrowExceptionForHR(symbolMethod.GetSequencePoints(count, out count, ilOffsets, docs, lineNumbers, null, null, null)); for (int i = 0; i < count; i++) { if (lineNumbers[i] == 0xFEEFEE) continue; yield return new ILSequencePoint() { Document = GetUrl(docs[i]), LineNumber = lineNumbers[i], Offset = ilOffsets[i] }; } }
public int GetDocumentVersion(ISymUnmanagedDocument document, out int version, out bool isCurrent) { throw new NotImplementedException(); }
public bool GetSourceStartEnd(ISymbolDocument[] docs, int[] lines, int[] columns) { uint i; bool pRetVal = false; int spCount = 0; if (docs != null) spCount = docs.Length; else if (lines != null) spCount = lines.Length; else if (columns != null) spCount = columns.Length; // If we don't have at least 2 entries then return an error if (spCount < 2) throw new ArgumentException(); // Make sure all arrays are the same length. if ((docs != null) && (spCount != docs.Length)) throw new ArgumentException(); if ((lines != null) && (spCount != lines.Length)) throw new ArgumentException(); if ((columns != null) && (spCount != columns.Length)) throw new ArgumentException(); var unmanagedDocuments = new ISymUnmanagedDocument[docs.Length]; m_unmanagedMethod.GetSourceStartEnd(unmanagedDocuments, lines, columns, out pRetVal); if (pRetVal) { for (i = 0; i < docs.Length; i++) { docs[i] = new SymbolDocument(unmanagedDocuments[i]); } } return pRetVal; }
// Returns index in appendto of current, or -1 if current isn't contained in the list. int GetWhere(List<WhereInfo> appendto, int max) { if (max < 1) { return -1; } WhereInfo wi; ICorDebugThread ithd = idbgthd; ICorDebugChain ichain = null; try { ithd.GetActiveChain(out ichain); } catch (System.Runtime.InteropServices.COMException ce) { } if (null == ichain) { wi.Source = "Call stack not available at this time"; wi.FileName = null; wi.FileLineNumber = -1; appendto.Add(wi); return -1; } else { int CurrentFrameIndex = 0; ICorDebugFrame iframe; //ichain.GetActiveFrame(out iframe); idbgthd.GetActiveFrame(out iframe); for (int fi = 0; fi < max; fi++, iframe.GetCaller(out iframe)) { if (null == iframe) { break; } for (; ; ) { iframe.GetChain(out ichain); int xmanaged = 0; if (null != ichain) { ichain.IsManaged(out xmanaged); } if (0 == xmanaged) { iframe.GetCaller(out iframe); if (null == iframe) { break; } iframe.GetChain(out ichain); if (null == ichain) { continue; } } break; } if (null == iframe) { break; } { { { ICorDebugFunction ifunc; iframe.GetFunction(out ifunc); uint ftoken; ifunc.GetToken(out ftoken); ICorDebugModule imod; ifunc.GetModule(out imod); 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); } ICorDebugILFrame ilframe = iframe as ICorDebugILFrame; if (null != ilframe) { uint noffset; CorDebugMappingResult mapresult; ilframe.GetIP(out noffset, out mapresult); if (mapresult == CorDebugMappingResult.MAPPING_NO_INFO || mapresult == CorDebugMappingResult.MAPPING_UNMAPPED_ADDRESS) { wi.Source = "(source line information unavailable)"; wi.FileName = null; wi.FileLineNumber = -1; appendto.Add(wi); } else { 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)); Guid CLSID_CorSymBinder = new Guid("0A29FF9E-7F9C-4437-8B11-F424491E3931"); ISymUnmanagedBinder binder = (ISymUnmanagedBinder)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_CorSymBinder)); ISymUnmanagedReader reader; int hrreader = binder.GetReaderForFile(pimporter, assemblyname, null, out reader); if (0 == hrreader) { ISymUnmanagedMethod unmMethod; reader.GetMethod(new System.Diagnostics.SymbolStore.SymbolToken((int)ftoken), out unmMethod); if (null != 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); if (cPoints > 0 && spoffsets[0] <= noffset) { int ix; for (ix = 0; ix < cPoints; ix++) { if (spoffsets[ix] >= noffset) { break; } } if (ix == cPoints || spoffsets[ix] != noffset) { ix--; } int linnum = spstartlines[ix]; ISymUnmanagedDocument idoc = spdocs[ix]; string url; { int urllen = 0; idoc.GetURL(0, out urllen, null); StringBuilder sburl = new StringBuilder(urllen); idoc.GetURL(urllen, out urllen, sburl); sburl.Length = urllen - 1; // Remove nul. url = sburl.ToString(); } uint ftypedeftoken; string MethodName; { IMetaDataImport importer; { object oimdi; Guid IMetaDataImportGUID = typeof(IMetaDataImport).GUID; imod.GetMetaDataInterface(ref IMetaDataImportGUID, out oimdi); importer = (IMetaDataImport)oimdi; } uint chMethod; uint dwAttr; IntPtr pvSigBlob; uint cbSigBlob; uint ulCodeRVA; uint dwImplFlags; int hrmethodprops = (int)importer.GetMethodProps(ftoken, out ftypedeftoken, null, 0, out chMethod, out dwAttr, out pvSigBlob, out cbSigBlob, out ulCodeRVA, out dwImplFlags); Marshal.ThrowExceptionForHR(hrmethodprops); char[] methodnamechars = new char[chMethod]; hrmethodprops = (int)importer.GetMethodProps(ftoken, out ftypedeftoken, methodnamechars, (uint)methodnamechars.Length, out chMethod, out dwAttr, out pvSigBlob, out cbSigBlob, out ulCodeRVA, out dwImplFlags); Marshal.ThrowExceptionForHR(hrmethodprops); chMethod--; // Remove nul. MethodName = new string(methodnamechars, 0, (int)chMethod); } wi.Source = MethodName; wi.FileName = url; wi.FileLineNumber = linnum; appendto.Add(wi); } else { wi.Source = "(source line information unavailable) <cannot find in source>"; wi.FileName = null; wi.FileLineNumber = -1; appendto.Add(wi); } } else { wi.Source = "(source line information unavailable) <no information>"; wi.FileName = null; wi.FileLineNumber = -1; appendto.Add(wi); } } else { wi.Source = "(source line information unavailable) <no IL>"; wi.FileName = null; wi.FileLineNumber = -1; appendto.Add(wi); } } finally { if (IntPtr.Zero != pimporter) { Marshal.Release(pimporter); pimporter = IntPtr.Zero; } } } } else { wi.Source = "(source line information unavailable) <no IL frame>"; wi.FileName = null; wi.FileLineNumber = -1; appendto.Add(wi); } } } } } return CurrentFrameIndex; } return -1; }
public static int[] GetILOffsetForEachLine( ISymUnmanagedReader symReader, int methodToken, ISymUnmanagedDocument document, int minLine, int maxLine) { Assert.True(minLine >= 1); Assert.True(maxLine >= minLine); var result = new List<int>(); ISymUnmanagedMethod method; Assert.Equal(HResult.S_OK, symReader.GetMethod(methodToken, out method)); for (int line = minLine; line <= maxLine; line++) { int offset; int hr = method.GetOffset(document, line, 0, out offset); if (hr != HResult.S_OK) { Assert.Equal(HResult.E_FAIL, hr); offset = int.MaxValue; } result.Add(offset); } return result.ToArray(); }
public SymbolDocument(ISymUnmanagedDocument document) { this.document = document; }
public static int[][] GetILOffsetRangesForEachLine( ISymUnmanagedReader symReader, int methodToken, ISymUnmanagedDocument document, int minLine, int maxLine) { Assert.True(minLine >= 1); Assert.True(maxLine >= minLine); var result = new List<int[]>(); ISymUnmanagedMethod method; Assert.Equal(HResult.S_OK, symReader.GetMethod(methodToken, out method)); for (int line = minLine; line <= maxLine; line++) { int count; Assert.Equal(HResult.S_OK, method.GetRanges(document, line, 0, 0, out count, null)); int count2; int[] ranges = new int[count]; Assert.Equal(HResult.S_OK, method.GetRanges(document, line, 0, count, out count2, ranges)); Assert.Equal(count, count2); result.Add(ranges); } return result.ToArray(); }
public void GetSequencePoints(int[] offsets, ISymbolDocument[] documents, int[] lines, int[] columns, int[] endLines, int[] endColumns) { int spCount = 0; if (offsets != null) spCount = offsets.Length; else if (documents != null) spCount = documents.Length; else if (lines != null) spCount = lines.Length; else if (columns != null) spCount = columns.Length; else if (endLines != null) spCount = endLines.Length; else if (endColumns != null) spCount = endColumns.Length; // Don't do anything if they're not really asking for anything. if (spCount == 0) return; // Make sure all arrays are the same length. if ((offsets != null) && (spCount != offsets.Length)) throw new ArgumentException(); if ((lines != null) && (spCount != lines.Length)) throw new ArgumentException(); if ((columns != null) && (spCount != columns.Length)) throw new ArgumentException(); if ((endLines != null) && (spCount != endLines.Length)) throw new ArgumentException(); if ((endColumns != null) && (spCount != endColumns.Length)) throw new ArgumentException(); var unmanagedDocuments = new ISymUnmanagedDocument[documents.Length]; int cPoints = 0; uint i; m_unmanagedMethod.GetSequencePoints(documents.Length, out cPoints, offsets, unmanagedDocuments, lines, columns, endLines, endColumns); // Create the SymbolDocument form the IntPtr's for (i = 0; i < documents.Length; i++) { documents[i] = new SymbolDocument(unmanagedDocuments[i]); } return; }
public static int[] FindClosestLineForEachLine(ISymUnmanagedDocument document, int minLine, int maxLine) { Assert.True(minLine >= 1); Assert.True(maxLine >= minLine); var result = new List<int>(); for (int line = minLine; line <= maxLine; line++) { int closestLine; int hr = document.FindClosestLine(line, out closestLine); if (hr != HResult.S_OK) { Assert.Equal(HResult.E_FAIL, hr); closestLine = 0; } result.Add(closestLine); } return result.ToArray(); }
private string GetUrl(ISymUnmanagedDocument doc) { lock (this) { if (_urlCache == null) _urlCache = new Dictionary<ISymUnmanagedDocument, string>(); string url; if (_urlCache.TryGetValue(doc, out url)) return url; int urlLength; ThrowExceptionForHR(doc.GetUrl(0, out urlLength, null)); // urlLength includes terminating '\0' char[] urlBuffer = new char[urlLength]; ThrowExceptionForHR(doc.GetUrl(urlLength, out urlLength, urlBuffer)); url = new string(urlBuffer, 0, urlLength - 1); _urlCache.Add(doc, url); return url; } }
public int GetMethodsFromDocumentPosition(ISymUnmanagedDocument document, int line, int column, int bufferLength, out int count, ISymUnmanagedMethod[] methods) { throw new NotImplementedException(); }