コード例 #1
0
        private static string GetDocumentUrl(ISymUnmanagedDocument document)
        {
            int cchUrl;

            document.GetURL(0, out cchUrl, null);
            StringBuilder result = new StringBuilder(cchUrl);

            document.GetURL(cchUrl, out cchUrl, result);
            return(result.ToString());
        }
コード例 #2
0
 static string GetFilenameFromSymDocument(Module module, ISymUnmanagedDocument symDoc)
 {
     foreach (string filename in RelocateSymURL(module, symDoc.GetURL()))
     {
         if (File.Exists(filename))
         {
             return(filename);
         }
     }
     return(symDoc.GetURL());
 }
コード例 #3
0
ファイル: SymbolWriter.cs プロジェクト: maresja1/SDenc
        /// <summary>
        /// Defines copy of <c>document</c> in new symbols file.
        /// </summary>
        /// <param name="document">Document to be copied</param>
        /// <returns>Instance of <c>ISymUnmanagedDocumentWriter</c>, which is used to write <c>document</c> in symbole file.</returns>
        public ISymUnmanagedDocumentWriter DefineDocument(ISymUnmanagedDocument document)
        {
            if (State != WriterState.Building)
            {
                throw new TranslatingException("ISym* interfaces were not initializde. (EnC)");
            }
            string url        = document.GetURL();
            Guid   type       = document.GetDocumentType();
            Guid   language   = document.GetLanguage();
            Guid   langVendor = document.GetLanguageVendor();
            IntPtr pUrl       = Marshal.StringToCoTaskMemUni(url);

            try{
                return(mWriter.__DefineDocument(pUrl, ref language, ref langVendor, ref type));
            } finally {
                Marshal.FreeCoTaskMem(pUrl);
            }
        }
コード例 #4
0
		static string GetFilenameFromSymDocument(Module module, ISymUnmanagedDocument symDoc)
		{
			foreach (string filename in RelocateSymURL(module, symDoc.GetURL())) {
				if (File.Exists(filename))
					return filename;
			}
			return symDoc.GetURL();
		}
コード例 #5
0
        public static SourcecodeSegment Resolve(Module module, string fileName, byte[] checkSum, int line, int column)
        {
            // Do not use ISymUnmanagedReader.GetDocument!  It is broken if two files have the same name
            // Do not use ISymUnmanagedMethod.GetOffset!  It sometimes returns negative offset

            ISymUnmanagedReader symReader = module.SymReader;

            if (symReader == null)
            {
                return(null);                               // No symbols
            }
            ISymUnmanagedDocument symDoc = GetSymDocumentFromFilename(module, fileName, checkSum);

            if (symDoc == null)
            {
                return(null);                            // Document not found
            }
            ISymUnmanagedMethod symMethod;

            try {
                uint validLine = symDoc.FindClosestLine((uint)line);
                symMethod = symReader.GetMethodFromDocumentPosition(symDoc, (uint)validLine, (uint)column);
            } catch {
                return(null);                //Not found
            }

            SequencePoint[] seqPoints = symMethod.GetSequencePoints();
            Array.Sort(seqPoints);
            if (seqPoints.Length == 0)
            {
                return(null);
            }
            if (line < seqPoints[0].Line)
            {
                return(null);
            }
            foreach (SequencePoint sqPoint in seqPoints)
            {
                if (sqPoint.Line == 0xFEEFEE)
                {
                    continue;
                }
                // If the desired breakpoint position is before the end of the sequence point
                if (line < sqPoint.EndLine || (line == sqPoint.EndLine && column < sqPoint.EndColumn))
                {
                    SourcecodeSegment segment = new SourcecodeSegment();
                    segment.module      = module;
                    segment.filename    = symDoc.GetURL();
                    segment.checkSum    = symDoc.GetCheckSum();
                    segment.startLine   = (int)sqPoint.Line;
                    segment.startColumn = (int)sqPoint.Column;
                    segment.endLine     = (int)sqPoint.EndLine;
                    segment.endColumn   = (int)sqPoint.EndColumn;
                    segment.corFunction = module.CorModule.GetFunctionFromToken(symMethod.GetToken());
                    segment.ilStart     = (int)sqPoint.Offset;
                    segment.ilEnd       = (int)sqPoint.Offset;
                    segment.stepRanges  = null;
                    return(segment);
                }
            }
            return(null);
        }
コード例 #6
0
ファイル: SymbolWriter.cs プロジェクト: maresja1/SDenc
 /// <summary>
 /// Defines copy of <c>document</c> in new symbols file.
 /// </summary>
 /// <param name="document">Document to be copied</param>
 /// <returns>Instance of <c>ISymUnmanagedDocumentWriter</c>, which is used to write <c>document</c> in symbole file.</returns>
 public ISymUnmanagedDocumentWriter DefineDocument(ISymUnmanagedDocument document)
 {
     if(State != WriterState.Building){
         throw new TranslatingException("ISym* interfaces were not initializde. (EnC)");
     }
     string url = document.GetURL();
     Guid type = document.GetDocumentType();
     Guid language = document.GetLanguage();
     Guid langVendor = document.GetLanguageVendor();
     IntPtr pUrl = Marshal.StringToCoTaskMemUni(url);
     try{
         return mWriter.__DefineDocument(pUrl,ref language,ref langVendor,ref type);
     } finally {
         Marshal.FreeCoTaskMem(pUrl);
     }
 }
コード例 #7
0
 private static string GetDocumentUrl(ISymUnmanagedDocument document)
 {
     int cchUrl;
     document.GetURL(0, out cchUrl, null);
     StringBuilder result = new StringBuilder(cchUrl);
     document.GetURL(cchUrl, out cchUrl, result);
     return result.ToString();
 }
コード例 #8
0
        public void GetSourceLocationForOffset(uint methodDef, uint offset, out string fileLocation, out uint line, out uint column)
        {
            fileLocation = null;
            line         = 0;
            column       = 0;

            ISymUnmanagedMethod symMethod = null;

            ISymUnmanagedDocument[] documents = null;
            uint sequencePointCount           = 0;

            try
            {
                symMethod          = this.symReader.GetMethod(methodDef);
                sequencePointCount = symMethod.GetSequencePointCount();

                documents = new ISymUnmanagedDocument[sequencePointCount];
                uint[] offsets    = new uint[sequencePointCount];
                uint[] lines      = new uint[sequencePointCount];
                uint[] columns    = new uint[sequencePointCount];
                uint[] endLines   = new uint[sequencePointCount];
                uint[] endColumns = new uint[sequencePointCount];

                symMethod.GetSequencePoints(sequencePointCount, out sequencePointCount, offsets, documents, lines, columns, endLines, endColumns);

                uint index = 1;
                for (; index < sequencePointCount; index++)
                {
                    if (offsets[index] > offset)
                    {
                        break;
                    }
                }

                index = index - 1;

                // Work Around: AkashS - The SymReader returns bad line-column data for unconditional branch
                // instructions. The line number is whacky and the column number is 0. Need to verify why this is so.
                // We just look for a good sequence point data, it should be close enough in the source code.
                while (columns[index] == 0 && index > 0)
                {
                    index--;
                }

                while (index < sequencePointCount && columns[index] == 0)
                {
                    index++;
                }

                // What more can we do?
                if (index >= sequencePointCount || columns[index] == 0)
                {
                    index = 0;
                }

                // End Work around


                line   = lines[index];
                column = columns[index];

                ISymUnmanagedDocument document = documents[index];
                uint   urlLength = 261;
                string url       = new string('\0', (int)urlLength);

                document.GetURL(urlLength, out urlLength, url);
                fileLocation = url.Substring(0, (int)urlLength - 1);
            }
            finally
            {
                // Release COM objects so that files don't remain locked.
                for (uint i = 0; i < sequencePointCount; i++)
                {
                    if (documents[i] != null)
                    {
                        Marshal.ReleaseComObject(documents[i]);
                    }
                }

                if (symMethod != null)
                {
                    Marshal.ReleaseComObject(symMethod);
                }
            }
        }
コード例 #9
0
        public void GetSourceLocationForOffset(uint methodDef, uint offset, out string fileLocation, out uint line, out uint column)
        {
            fileLocation = null;
            line         = 0;
            column       = 0;
            ISymUnmanagedMethod o = null;

            ISymUnmanagedDocument[] documents = null;
            uint pointsCount = 0;

            try
            {
                o           = this.symReader.GetMethod(methodDef);
                pointsCount = o.GetSequencePointCount();
                documents   = new ISymUnmanagedDocument[pointsCount];
                uint[] offsets    = new uint[pointsCount];
                uint[] lines      = new uint[pointsCount];
                uint[] columns    = new uint[pointsCount];
                uint[] endLines   = new uint[pointsCount];
                uint[] endColumns = new uint[pointsCount];
                o.GetSequencePoints(pointsCount, out pointsCount, offsets, documents, lines, columns, endLines, endColumns);
                uint index = 1;
                while (index < pointsCount)
                {
                    if (offsets[index] > offset)
                    {
                        break;
                    }
                    index++;
                }
                index--;
                while ((columns[index] == 0) && (index > 0))
                {
                    index--;
                }
                while ((index < pointsCount) && (columns[index] == 0))
                {
                    index++;
                }
                if ((index >= pointsCount) || (columns[index] == 0))
                {
                    index = 0;
                }
                line   = lines[index];
                column = columns[index];
                ISymUnmanagedDocument document = documents[index];
                uint   urlLength = 0x105;
                string url       = new string('\0', (int)urlLength);
                document.GetURL(urlLength, out urlLength, url);
                fileLocation = url.Substring(0, ((int)urlLength) - 1);
            }
            finally
            {
                for (uint i = 0; i < pointsCount; i++)
                {
                    if (documents[i] != null)
                    {
                        Marshal.ReleaseComObject(documents[i]);
                    }
                }
                if (o != null)
                {
                    Marshal.ReleaseComObject(o);
                }
            }
        }