public CounterSourceInfo GetSource(string cs) { if (SourceInfos.ContainsKey(cs)) { return(SourceInfos[cs]); } lock (SourceInfos) { Reload(); if (SourceInfos.ContainsKey(cs)) { return(SourceInfos[cs]); } CreateNewCounterSourceInfo(cs); return(SourceInfos[cs]); } }
public SourceInfos GetSourceInfos(UInt32 aAddress) { var xResult = new SourceInfos(); try { var xMethod = GetMethod(aAddress); if (xMethod != null) { var xSymbols = GetSymbols(xMethod); var xAssemblyFile = mConnection.Get <AssemblyFile>(xMethod.AssemblyFileID); var xSymbolReader = SymbolAccess.GetReaderForFile(xAssemblyFile.Pathname); var xMethodSymbol = xSymbolReader.GetMethod(new SymbolToken(xMethod.MethodToken)); int xSeqCount = xMethodSymbol.SequencePointCount; var xCodeOffsets = new int[xSeqCount]; var xCodeDocuments = new ISymbolDocument[xSeqCount]; var xCodeLines = new int[xSeqCount]; var xCodeColumns = new int[xSeqCount]; var xCodeEndLines = new int[xSeqCount]; var xCodeEndColumns = new int[xSeqCount]; xMethodSymbol.GetSequencePoints(xCodeOffsets, xCodeDocuments, xCodeLines, xCodeColumns, xCodeEndLines, xCodeEndColumns); if (xSymbols.Length == 0 && xSeqCount > 0) { var xSourceInfo = new SourceInfo() { SourceFile = xCodeDocuments[0].URL, Line = xCodeLines[0], LineEnd = xCodeEndLines[0], Column = xCodeColumns[0], ColumnEnd = xCodeEndColumns[0], MethodName = xMethod.LabelCall }; xResult.Add(aAddress, xSourceInfo); } else { foreach (var xSymbol in xSymbols) { var xRow = mConnection.Query <Label>(new SQLinq <Label>().Where(i => i.Name == xSymbol.LabelName)).FirstOrDefault(); if (xRow != null) { UInt32 xAddress = (UInt32)xRow.Address; // Each address could have mult labels, but this wont matter for SourceInfo, its not tied to label. // So we just ignore duplicate addresses. if (!xResult.ContainsKey(xAddress)) { int xIdx = SourceInfo.GetIndexClosestSmallerMatch(xCodeOffsets, xSymbol.IlOffset); var xSourceInfo = new SourceInfo() { SourceFile = xCodeDocuments[xIdx].URL, Line = xCodeLines[xIdx], LineEnd = xCodeEndLines[xIdx], Column = xCodeColumns[xIdx], ColumnEnd = xCodeEndColumns[xIdx], MethodName = xMethod.LabelCall }; xResult.Add(xAddress, xSourceInfo); } } } } } } catch (Exception) { } return(xResult); }
private SourceInfos DoGetSourceInfos(uint aAddress) { var xResult = new SourceInfos(); try { var xMethod = GetMethod(aAddress); if (xMethod != null) { var xSymbols = GetSymbols(xMethod); var xAssemblyFile = mConnection.Get <AssemblyFile>(xMethod.AssemblyFileID); var xSeqPoints = GetSequencePoints(xAssemblyFile.Pathname, xMethod.MethodToken).ToList(); int xSeqCount = xSeqPoints.Count; var xCodeOffsets = new int[xSeqCount]; var xCodeDocuments = new string[xSeqCount]; var xCodeStartLines = new int[xSeqCount]; var xCodeStartColumns = new int[xSeqCount]; var xCodeEndLines = new int[xSeqCount]; var xCodeEndColumns = new int[xSeqCount]; for (int i = 0; i < xSeqPoints.Count; i++) { xCodeOffsets[i] = xSeqPoints[i].Offset; xCodeDocuments[i] = xSeqPoints[i].Document; xCodeStartLines[i] = xSeqPoints[i].LineStart; xCodeStartColumns[i] = xSeqPoints[i].ColStart; xCodeEndLines[i] = xSeqPoints[i].LineEnd; xCodeEndColumns[i] = xSeqPoints[i].ColEnd; } if (xSymbols.Length == 0 && xSeqCount > 0) { var xSourceInfo = new SourceInfo() { SourceFile = xCodeDocuments[0], LineStart = xCodeStartLines[0], LineEnd = xCodeEndLines[0], ColumnStart = xCodeStartColumns[0], ColumnEnd = xCodeEndColumns[0], MethodName = xMethod.LabelCall }; xResult.Add(aAddress, xSourceInfo); } else { foreach (var xSymbol in xSymbols) { var xRow = mConnection.GetList <Label>(Predicates.Field <Label>(q => q.Name, Operator.Eq, xSymbol.LabelName)).FirstOrDefault(); if (xRow != null) { uint xAddress = (uint)xRow.Address; // Each address could have mult labels, but this wont matter for SourceInfo, its not tied to label. // So we just ignore duplicate addresses. if (!xResult.ContainsKey(xAddress)) { int xIdx = SourceInfo.GetIndexClosestSmallerMatch(xCodeOffsets, xSymbol.IlOffset); var xSourceInfo = new SourceInfo() { SourceFile = xCodeDocuments[xIdx], LineStart = xCodeStartLines[xIdx], LineEnd = xCodeEndLines[xIdx], ColumnStart = xCodeStartColumns[xIdx], ColumnEnd = xCodeEndColumns[xIdx], MethodName = xMethod.LabelCall }; xResult.Add(xAddress, xSourceInfo); } } } } } } catch (Exception) { } return(xResult); }