예제 #1
0
        // Create an IL snippet that matches the given range (startLine to endLine, inclusive) in the
        // given source file.
        // Although we could compute the lines collection from the other 3 parameters, we pass it in for perf reasons
        // since we already have it available.
        public InlineILSnippet(string pathSourceFile, int idxStartLine, int idxEndLine, StringCollection lines)
        {
            Sourcefile = pathSourceFile;
            StartLine  = idxStartLine;
            EndLine    = idxEndLine;

            // This assert would be false if the incoming lines collection has been preprocessed (Eg, if the caller
            // already inject .line directives to map back to the source).
            Debug.Assert(idxEndLine - idxStartLine + 1 == lines.Count);

            // Marshal into an array. Since we're already copying, we'll also inject the sequence point info.
            Lines    = new string[(lines.Count * 2) + 1];
            Lines[0] = string.Format("// Snippet from {0}:{1}", pathSourceFile, idxStartLine);


            for (var i = 0; i < lines.Count; i++)
            {
                var idxSourceLine = idxStartLine + i;

                // ILAsm only lets us add sequence points to statements.
                var sequenceMarker = ILDocument.IsStatement(lines[i]) ?
                                     ILDocument.CreateILSequenceMarker(pathSourceFile, idxSourceLine, idxSourceLine, 1, lines[i].Length + 1) :
                                     "// skip sequence marker";

                Lines[2 * i + 1] = sequenceMarker;
                Lines[2 * i + 2] = lines[i];
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: zzyyll2/JitHook
        // Create an IL snippet that matches the given range (startLine to endLine, inclusive) in the
        // given source file.
        // Although we could compute the lines collection from the other 3 parameters, we pass it in for perf reasons
        // since we already have it available.
        public InlineILSnippet(string pathSourceFile, int idxStartLine, int idxEndLine, StringCollection lines)
        {
            m_pathSourcefile = pathSourceFile;
            m_idxStartLine   = idxStartLine;
            m_idxEndLine     = idxEndLine;

            // This assert would be false if the incoming lines collection has been preprocessed (Eg, if the caller
            // already inject .line directives to map back to the source).
            Debug.Assert(idxEndLine - idxStartLine + 1 == lines.Count);

            // Marshal into an array. Since we're already copying, we'll also inject the sequence point info.
            m_lines = new string[lines.Count * 2];

            for (int i = 0; i < lines.Count; i++)
            {
                int    idxSourceLine = idxStartLine + i;
                string sequenceMarker;

                // ILAsm only lets us add sequence points to statements.
                if (ILDocument.IsStatement(lines[i]))
                {
                    sequenceMarker = ILDocument.GetILSequenceMarker(
                        pathSourceFile, idxSourceLine, idxSourceLine, 1, lines[i].Length + 1);
                }
                else
                {
                    sequenceMarker = "// skip sequence marker";
                }

                m_lines[2 * i]     = sequenceMarker;
                m_lines[2 * i + 1] = lines[i];
            }
        }