DefaultDebugThread.cs :  » Script » IronRuby » Microsoft » Scripting » Debugging » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Script » IronRuby 
IronRuby » Microsoft » Scripting » Debugging » DefaultDebugThread.cs
/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 *
 * ***************************************************************************/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Microsoft.Scripting.Debugging.CompilerServices;

namespace Microsoft.Scripting.Debugging{
    /// <summary>
    /// Default implementation of BaseDebugThread, which uses DLR's RuntimeVariablesExpression for lifting locals.
    /// </summary>
    internal sealed class DefaultDebugThread : DebugThread {
        private readonly List<FrameRuntimeVariablesPair> _frames;

        internal DefaultDebugThread(DebugContext debugContext)
            : base(debugContext) {
            _frames = new List<FrameRuntimeVariablesPair>();
        }

        #region Internal Members

        internal void LiftVariables(IRuntimeVariables runtimeVariables) {
            // Don't create the frame object right away.  Create it when it's actually needed for debugging.
            _frames.Add(new FrameRuntimeVariablesPair(new DebugRuntimeVariables(runtimeVariables), null));
        }

        #endregion

        #region BaseDebugThread overrides

        internal override IEnumerable<DebugFrame> Frames {
            get {
                for (int i = _frames.Count - 1; i >= 0; i--) {
                    yield return GetFrame(i);
                }
            }
        }

        internal override DebugFrame GetLeafFrame() {
            return GetFrame(_frames.Count - 1);
        }

        internal override bool TryGetLeafFrame(ref DebugFrame frame) {
            if (_frames.Count > 0) {
                frame = _frames[_frames.Count - 1].Frame;
                return frame != null;
            } else {
                frame = null;
                return false;
            }
        }

        internal override int FrameCount {
            get { return _frames.Count; }
        }

        internal override void PushExistingFrame(DebugFrame frame) {
            _frames.Add(new FrameRuntimeVariablesPair(null, frame));
        }

        internal override bool PopFrame() {
            Debug.Assert(_frames.Count > 0);
            _frames.RemoveAt(_frames.Count - 1);
            return _frames.Count == 0;
        }

        internal override FunctionInfo GetLeafFrameFunctionInfo(out int stackDepth) {
            int leafIndex = _frames.Count - 1;
            if (leafIndex >= 0) {
                stackDepth = leafIndex;
                DebugFrame leafFrame = _frames[leafIndex].Frame;
                if (leafFrame != null) {
                    Debug.Assert(leafIndex == leafFrame.StackDepth);
                    return leafFrame.FunctionInfo;
                } else {
                    Debug.Assert(_frames[leafIndex].RuntimeVariables is IDebugRuntimeVariables);
                    return ((IDebugRuntimeVariables)_frames[leafIndex].RuntimeVariables).FunctionInfo;
                }
            }

            stackDepth = Int32.MaxValue;
            return null;
        }

        #endregion

        private DebugFrame GetFrame(int index) {
            DebugFrame frame = null;
            if (index >= 0) {
                frame = _frames[index].Frame;
                if (frame == null) {
                    IDebugRuntimeVariables runtimeVariables = _frames[index].RuntimeVariables as IDebugRuntimeVariables;
                    Debug.Assert(runtimeVariables != null);
                    frame = new DebugFrame(this, runtimeVariables.FunctionInfo, runtimeVariables, index);
                    _frames[index] = new FrameRuntimeVariablesPair(null, frame);
                }
            }

            if (index == _frames.Count - 1) {
                frame.IsInTraceback = IsInTraceback;
                frame.ThrownException = ThrownException;
            }

            return frame;
        }

        private struct FrameRuntimeVariablesPair {
            public IRuntimeVariables RuntimeVariables;
            public DebugFrame Frame;

            public FrameRuntimeVariablesPair(IRuntimeVariables runtimeVariables, DebugFrame frame) {
                RuntimeVariables = runtimeVariables;
                Frame = frame;
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.