Example #1
0
        /// <summary>
        /// Gets the source position from a given Instruction Pointer
        /// </summary>
        /// <param name="ip">The Instruction Pointer.</param>
        /// <returns>The Source Position.</returns>
        private SourcePosition GetSourcePositionFromIP(int ip)
        {
            //EnsureIsUpToDate();
            //if (!m_haveSymbols)
            //return null;
            const int SpecialSequencePoint = 0xfeefee;
            int       seqCount             = offsets.Length;

            if ((seqCount > 0) && (offsets[0] <= ip))
            {
                int i;
                for (i = 0; i < seqCount; ++i)
                {
                    if (offsets[i] >= ip)
                    {
                        break;
                    }
                }
                if (i == seqCount || offsets[i] != ip)
                {
                    --i;
                }

                SourcePosition sp = null;

                if (startLines[i] == SpecialSequencePoint)
                {
                    int j = i;
                    // let's try to find a sequence point that is not special somewhere earlier in the code
                    // stream.
                    while (j > 0)
                    {
                        --j;
                        if (startLines[j] != SpecialSequencePoint)
                        {
                            sp = new SourcePosition(false, symDocs[j].URL, startLines[j],
                                                    endLines[j], startColumns[j], endColumns[j]);
                            break;
                        }
                    }

                    if (sp == null)
                    {
                        // we didn't find any non-special seqeunce point before current one, let's try to search
                        // after.
                        j = i;
                        while (++j < seqCount)
                        {
                            if (startLines[j] != SpecialSequencePoint)
                            {
                                sp = new SourcePosition(false, symDocs[j].URL, startLines[j],
                                                        endLines[j], startColumns[j], endColumns[j]);
                                break;
                            }
                        }
                    }
                    // The following Assert somewhow is not always true for w3wp.exe (ASP.Net) process
                    // Debug.Assert(sp != null, "Only SpecialSequence point detected");
                }
                else
                {
                    sp = new SourcePosition(false, symDocs[i].URL, startLines[i],
                                            endLines[i], startColumns[i], endColumns[i]);
                }

                //<strip>@TODO ENC HACK diasymreader</strip>
                //if (CorFunction.Version != 1) // function has been edited
                //sp.m_fixedFile = Module.GetEditsSourceFile(CorFunction.Version - 1);

                return(sp);
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Gets the source position from a given Instruction Pointer
        /// </summary>
        /// <param name="ip">The Instruction Pointer.</param>
        /// <returns>The Source Position.</returns>
        private SourcePosition GetSourcePositionFromIP(int ip)
        {
            //EnsureIsUpToDate();
            //if (!m_haveSymbols)
            //return null;
            const int SpecialSequencePoint = 0xfeefee;
            int seqCount = offsets.Length;
            if ((seqCount > 0) && (offsets[0] <= ip))
            {
                int i;
                for (i = 0; i < seqCount; ++i)
                {
                    if (offsets[i] >= ip)
                    {
                        break;
                    }
                }
                if (i == seqCount || offsets[i] != ip)
                {
                    --i;
                }

                SourcePosition sp = null;

                if (startLines[i] == SpecialSequencePoint)
                {
                    int j = i;
                    // let's try to find a sequence point that is not special somewhere earlier in the code
                    // stream.
                    while (j > 0)
                    {
                        --j;
                        if (startLines[j] != SpecialSequencePoint)
                        {
                            sp = new SourcePosition(false, symDocs[j].URL, startLines[j],
                                endLines[j], startColumns[j], endColumns[j]);
                            break;
                        }
                    }

                    if (sp == null)
                    {
                        // we didn't find any non-special seqeunce point before current one, let's try to search
                        // after.
                        j = i;
                        while (++j < seqCount)
                        {
                            if (startLines[j] != SpecialSequencePoint)
                            {
                                sp = new SourcePosition(false, symDocs[j].URL, startLines[j],
                                    endLines[j], startColumns[j], endColumns[j]);
                                break;
                            }
                        }
                    }
                    // The following Assert somewhow is not always true for w3wp.exe (ASP.Net) process
                    // Debug.Assert(sp != null, "Only SpecialSequence point detected");
                }
                else
                {
                    sp = new SourcePosition(false, symDocs[i].URL, startLines[i],
                        endLines[i], startColumns[i], endColumns[i]);

                }

                //<strip>@TODO ENC HACK diasymreader</strip>
                //if (CorFunction.Version != 1) // function has been edited
                //sp.m_fixedFile = Module.GetEditsSourceFile(CorFunction.Version - 1);

                return sp;
            }
            return null;
        }
Example #3
0
        /// <summary>
        /// Read the pdb file for this module and frame
        /// Retrieve infomation about the function
        /// </summary>
        /// <remarks>
        /// When an unmanaged app like reflector loads CLR, "Function.Module.Name"
        /// doesn't return a valid value and so this function returns null.
        /// </remarks>
        /// <returns>SourcePosition of the function</returns>
        private SourcePosition GetMetaDataInfo(CorMetadataImport importer)
        {
            SourcePosition functionPos = null;             //position in this function where we are

            try
            {
                moduleFullName  = thisFrame.Function.Module.Name;
                moduleShortName = System.IO.Path.GetFileName(moduleFullName);
            }
            catch (ArgumentException)
            {
                moduleFullName  = "";
                moduleShortName = "";
                return(null);
            }


            //TODO: Implement a better method to determine the symbol path than just assuming it's in the same
            //      directory
            string sympath = ".";

            //dealing with readinf the source in the module
            ISymbolReader  metaReader   = null;
            ISymbolBinder1 symbolBinder = new SymbolBinder();

            try
            {
                if (moduleFullName.Length > 0)
                {
                    metaReader = (symbolBinder as ISymbolBinder2).
                                 GetReaderForFile(importer.RawCOMObject, moduleFullName, sympath);
                }
            }
            catch (COMException)
            {
                //Debug.WriteLine(ed.ToString(CultureInfo.CurrentCulture.NumberFormat));
                //will get here for any function which we cant read the .pdb file for
                //its not a big deal we just wont have source and line info
            }

            if (metaReader != null)
            {
                ISymbolMethod symMethod = null;
                try
                {
                    symMethod = metaReader.GetMethod(new SymbolToken((int)thisFrame.Function.Token), thisFrame.Function.Version);
                    int sequenceCount = symMethod.SequencePointCount;
                    symDocs      = new ISymbolDocument[sequenceCount];
                    offsets      = new int[sequenceCount];
                    startLines   = new int[sequenceCount];
                    startColumns = new int[sequenceCount];
                    endLines     = new int[sequenceCount];
                    endColumns   = new int[sequenceCount];

                    //Get the sequence points and store them in the apporpriate arrays. Seqeunce points
                    //represent the different points in the files which correlate to il instruction and lines
                    symMethod.GetSequencePoints(offsets, symDocs, startLines, startColumns, endLines, endColumns);

                    functionPos = GetSourcePositionFromFrame();
                }
                catch (COMException)
                {
                    functionPos = null;
                }
                finally
                {
                    symDocs   = null;
                    symMethod = null;
                }
            }


            CorType ctype = GetClassType();

            if (ctype != null)
            {
                StringBuilder sb = new StringBuilder();
                GetFunctionClassPath(sb, ctype);
                functionFullName = sb.ToString();
            }
            else
            {
                functionFullName = "";
            }

            MethodInfo methIn = importer.GetMethodInfo(thisFrame.Function.Token);

            functionFullName += "." + methIn.Name;
            functionShortName = methIn.Name;
            return(functionPos);
        }