private void RunSession(string sessionId, NetworkStream stream)
        {
            DebugSession debugSession = null;

            lock (m_Lock)
            {
                if (m_Current != null)
                {
                    debugSession = new MoonSharpDebugSession(this, m_Current);
                }
                else
                {
                    debugSession = new EmptyDebugSession(this);
                }
            }

            debugSession.ProcessLoop(stream, stream);
        }
Exemple #2
0
        /// <summary>
        /// Replaces the script a debugger is debugging.
        /// </summary>
        /// <param name="previousScript">A script already attached for debugging.</param>
        /// <param name="newScript">A replacement script.</param>
        /// <exception cref="ArgumentException">If the script has not been attached to this debugger.</exception>
        public void ReplaceAttachedScript(Script previousScript, Script newScript, string name = null, Func <SourceCode, string> sourceFinder = null)
        {
            lock (m_Lock)
            {
                if (newScript == null)
                {
                    Detach(previousScript);
                }
                else if (m_PortSessionDictionary.Count > 0)
                {
                    MoonSharpDebugSession session = m_PortSessionDictionary.Values.FirstOrDefault(p => p.Session.Debugger?.Script == previousScript).Session;

                    if (session == null)
                    {
                        throw new ArgumentException("Cannot replace script that is not attached to this debug server.");
                    }

                    AsyncDebugger newDebugger = new AsyncDebugger(newScript, sourceFinder ?? session.Debugger.SourceFinder, name ?? session.Debugger.Name);
                    ReplaceListenerDebugger(session.Port, newDebugger);
                }
                else
                {
                    int index = m_PendingDebuggerList.FindIndex(d => d.Script == previousScript);

                    if (index < 0)
                    {
                        throw new ArgumentException("Cannot replace script that is not attached to this debug server.");
                    }

                    previousScript.DetachDebugger();

                    AsyncDebugger previousDebugger = m_PendingDebuggerList[index];
                    AsyncDebugger newDebugger      = new AsyncDebugger(newScript, sourceFinder ?? previousDebugger.SourceFinder, name ?? previousDebugger.Name);

                    m_PendingDebuggerList[index] = newDebugger;
                }
            }
        }