Example #1
0
        // Public build function.
        // Fails to build (and returns null) if it can't load the file.
        static public SourceViewerForm Build(MainForm parent,string path)
        {
            ArrayList lines = LoadLinesFromFile(path);
            if (lines == null) { return null; }

            return new SourceViewerForm(parent, path, lines);
        }
Example #2
0
        // parent - main containing window that this source window lives inside of.
        // path - unique string identifier for source window (full pathname)
        // lines - content
        SourceViewerForm(MainForm parent,string path,ArrayList lines)
        {
            m_lines = lines;
            BeginInit(parent);

            InitLines("{0,4}:", lines, null);

            EndInit(path);
        }
Example #3
0
        public static void Gui(string args)
        {
            // just do the check that gui is not already loaded,
            // strange things are happening else:
            ArgParser ap = new ArgParser(args);
            if( ap.Exists(0) )
            {
                if( ap.AsString(0) == "close" )
                {
                    if( m_mainForm!=null )
                    {
                        m_mainForm.CloseGui();
                        Application.Exit(); // this line will cause the message pump on other thread to quit.
                        return;
                    }
                    else
                        throw new MDbgShellException("GUI not started.");
                }
                else
                    throw new MDbgShellException("invalid argument");
            }
            
            if(Shell.IO == m_mainForm)
            {
                WriteOutput("GUI already started. Cannot start second instance.");
                return;
            }

            WriteOutput("starting gui");

            m_mainForm = new MainForm(Shell);

            Thread t = new Thread(new ThreadStart(RunMessageLoop));

            // Only MTA Threads can access CorDebug interfaces because mscordbi doesn't provide marshalling to make them accessable from STA Threads
            t.SetApartmentState(ApartmentState.MTA);
            t.IsBackground = true;

            t.Start();
            m_mainForm.InitComplete.WaitOne(); // wait till form is fully displayed.
            
            WriteOutput("GUI: Simple Extension for Managed debugger (Mdbg) started");
            WriteOutput("\nfor information on how to use the extension select in menu bar help->Info\n");
        }
            public SequencePointIterator(RawWriter w,MainForm parent,
                    int[] seqIlOffsets,
                    string[] seqPaths,
                    int[] seqStartLines, 
                    int[] seqStartColumns,
                    int[] seqEndLines,
                    int [] seqEndColumns)
            {
                m_writer = w;
                m_parent = parent;

                this.m_seqIlOffsets    = seqIlOffsets;
                this.m_seqPaths        = seqPaths;
                this.m_seqStartLines   = seqStartLines;
                this.m_seqStartColumns = seqStartColumns;
                this.m_seqEndLines     = seqEndLines;
                this.m_seqEndColumns   = seqEndColumns;

                Debug.Assert(m_seqCount == 0);
                if (m_seqIlOffsets != null)
                {
                    m_seqCount = m_seqIlOffsets.Length;

                    // All arrays should be same length.
                    Debug.Assert(seqIlOffsets.Length == m_seqCount);
                    Debug.Assert(seqPaths.Length == m_seqCount);
                    Debug.Assert(seqStartLines.Length == m_seqCount);
                    Debug.Assert(seqStartColumns.Length == m_seqCount);
                    Debug.Assert(seqEndLines.Length == m_seqCount);
                    Debug.Assert(seqEndColumns.Length == m_seqCount);
                }
            }
        // parent - main containing window that this source window lives inside of.
        // function - function for which we're building virtual source around.
        // Get the IL from the given frame.
        // Called on UI thread.
        internal VirtualSourceViewerForm(MainForm parent, MDbgFunction function)
        {
            m_function = function;
            Debug.Assert(function != null);

            // Now actually right in text. do this first so that we can get the current font.
            BeginInit(parent);

            // Get fonts
            FontCache cache;
            {
                Font fontCurrent = this.richText.Font;
                Font emphasis = new Font(
                                   fontCurrent.FontFamily,
                                   fontCurrent.Size,
                                   FontStyle.Bold
                                );

                cache = new FontCache(emphasis);
            }

            // Underlying writer to the window.
            RawWriter rawWriter = new RawWriter(cache);

            // Il2Native mapping can be used to find out what IL offsets we can actually stop on.
            Il2NativeIterator il2nativeIterator = null;

            // Actual IL disassembly in string form.
            ILDasmIterator ilDasm = null;

            // Iterator through sequence points and source files.
            SequencePointIterator seqIterator = null;

            string fullName = "?";
            int token = 0;

            ulong nativeStartAddress = 0;
            CorDebugJITCompilerFlags codeFlags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DEFAULT;

            // Make cross-thread call to worker thread to collect raw information.
            // This needs to access MDbg and so can't be done on our UI thread.
            parent.ExecuteOnWorkerThreadIfStoppedAndBlock(delegate(MDbgProcess proc)
            {
                Debug.Assert(proc != null);
                Debug.Assert(!proc.IsRunning);
                Debug.Assert(function.Module.Process == proc);

                // Get some properties about this function to display.
                token = function.CorFunction.Token;
                nativeStartAddress = function.CorFunction.NativeCode.Address;
                codeFlags = function.CorFunction.NativeCode.CompilerFlags;

                CorCode ilCode = function.CorFunction.ILCode;
                Debug.Assert(true == ilCode.IsIL);
                byte[] code = ilCode.GetCode();
                fullName = function.FullName;

                // This does the real disassembly work.
                string[] lines = null; // strings of IL.
                ILDisassembler.Disassemble(code, function.Module.Importer, out lines, out m_il2RowMapping);

                ilDasm = new ILDasmIterator(rawWriter, m_il2RowMapping, lines);

                IL2NativeMap[] il2nativeMapping = function.CorFunction.NativeCode.GetILToNativeMapping();
                il2nativeIterator = new Il2NativeIterator(rawWriter, il2nativeMapping, code);

                // Get sequence points
                ISymbolMethod symMethod = function.SymMethod;

                // Sequence point information
                int[] seqIlOffsets = null;
                string[] seqPaths = null;
                int[] seqStartLines = null, seqEndLines = null, seqStartColumns = null, seqEndColumns = null;
                int seqCount = 0;

                if (symMethod != null)
                {
                    seqCount = symMethod.SequencePointCount;
                    seqIlOffsets = new int[seqCount];
                    ISymbolDocument[] seqDocuments = new ISymbolDocument[seqCount];
                    seqPaths = new string[seqCount];
                    seqStartLines = new int[seqCount];
                    seqEndLines = new int[seqCount];
                    seqStartColumns = new int[seqCount];
                    seqEndColumns = new int[seqCount];

                    symMethod.GetSequencePoints(seqIlOffsets, seqDocuments, seqStartLines, seqStartColumns, seqEndLines, seqEndColumns);

                    for (int i = 0; i < seqCount; i++)
                    {
                        seqPaths[i] = seqDocuments[i].URL;
                    }
                }
                seqIterator = new SequencePointIterator(rawWriter, parent, seqIlOffsets, seqPaths, seqStartLines, seqStartColumns, seqEndLines, seqEndColumns);
            }
            ); // end worker call

            // We assume sequence points are sorted by IL offset. We assert that in the iterators below.
            // Now we need to go through and stitch the IL + Source together.
            // This also works even if we have no source (since that's just the degenerate case of 0 sequence points)

            // Print out header information
            Debug.Assert(token != 0);
            rawWriter.WriteLine(String.Format(CultureInfo.InvariantCulture,
                "> Function name:{0} (token={1:x})", fullName, token));
            rawWriter.WriteLine(String.Format(CultureInfo.InvariantCulture,
                "> Native Code Address =0x{0:x}, flags={1}", nativeStartAddress, codeFlags));

            // Walk through the IL in order and write out interleaved IL and Sequence Points.
            while (!seqIterator.IsDone)
            {
                // Add IL snippets that occur before this sequence point.
                WriteIlAndNative(ilDasm, il2nativeIterator, seqIterator.IlOffset);

                seqIterator.WriteSource();
                seqIterator.Next();
            }
            // Write the IL that's after the last sequence point
            WriteIlAndNative(ilDasm, il2nativeIterator, ilDasm.IlLength);

            // Set the text.
            InitLines(null, rawWriter.Lines, rawWriter.FormatList);

            EndInit(fullName);
        }
 public SyncWriter(MainForm form, string txt)
 {
     Debug.Assert(txt != null && form != null);
     m_txt = txt;
     m_form = form;
 }
            // We pass in a type of the form to create rather than encode it as a generic parameter
            // so that we can have an array of the HelperWindowMenuItem.
            public HelperWindowMenuItem(MainForm mainForm, string name, System.Type tForm)
            {
                Debug.Assert(tForm.IsSubclassOf(typeof(gui.DebuggerToolWindow)));
                this.m_mainForm = mainForm;
                this.m_typeHelperForm = tForm;

                EventHandler handler = new EventHandler(this.OnClick);
                MenuItem item = new MenuItem(name, handler);
                this.m_mainForm.AddToViewMenu(item);
            }
Example #8
0
            public SyncWriter(MainForm form, string outputType, string txt, int highlightStart, int highlightLen)
            {
                Debug.Assert(txt != null && form != null);

                if (highlightLen == Int32.MaxValue)
                {
                    highlightLen = txt.Length;
                }

                m_txt = txt;
                m_form = form;
                m_type = outputType;
                m_highlightStart = highlightStart;
                m_highlightLen = highlightLen;
            }
Example #9
0
 // There's one SourceViewerForm instance for each source-file
 // Get the instance for the new source file.
 // Called on UI thread.
 public static SourceViewerBaseForm GetSourceFile(MainForm parent, MDbgFunction function)
 {            
     SourceViewerBaseForm source = (SourceViewerBaseForm)m_sourceList[function];
     if (source == null)
     {
         source = new VirtualSourceViewerForm(parent, function);
         AddSourceViewer(source);
     }
     m_ActiveSourceFile = source;
     return source;
 }
Example #10
0
 // There's one SourceViewerForm instance for each source-file
 // Get the instance for the new source file.
 // Called on UI thread.
 public static SourceViewerForm GetSourceFile(MainForm parent,string path)
 {
     path = CommandBase.Shell.FileLocator.GetFileLocation(path);
     SourceViewerForm source = (SourceViewerForm)m_sourceList[path];
     if(source==null)
     {
         source = SourceViewerForm.Build(parent, path);
         if (source != null)
         {
             AddSourceViewer(source);
         }
     }
     m_ActiveSourceFile = source;
     return source;
 }
Example #11
0
        // Initialization function. called by derived ctor.

        // parent - main containing window that this source window lives inside of.
        // path - unique string identifier for source window (full pathname)
        // lines - content
        protected void BeginInit(MainForm parent)
        {
            if (m_glyphs == null)
            {
                m_glyphs = new Glyphs();
            }

            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // Set window properties
            MdiParent = parent;
            Debug.Assert(parent == MainForm);

            // Still not visisible. We return from here, and then caller will initialize content
            // and then call EndInit().
        }