Пример #1
0
        ///////////////////////////////////////////////////////////////////////

        private static void AddInfo(
            AppDomainSetup appDomainSetup,
            StringPairList list,
            DetailFlags detailFlags
            )
        {
            if (list == null)
            {
                return;
            }

            if (appDomainSetup != null)
            {
                bool empty = HostOps.HasEmptyContent(detailFlags);

                if (empty || (appDomainSetup.ApplicationBase != null))
                {
                    list.Add("ApplicationBase",
                             appDomainSetup.ApplicationBase);
                }

                if (empty || (appDomainSetup.PrivateBinPath != null))
                {
                    list.Add("PrivateBinPath",
                             appDomainSetup.PrivateBinPath);
                }
            }
            else
            {
                list.Add(FormatOps.DisplayNull);
            }
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////

        public static void WriteCore(
            string value
            )
        {
            ConsoleColor savedForegroundColor;

            savedForegroundColor = Console.ForegroundColor; /* throw */

            //
            // TODO: Maybe change the background color here as well?
            //
            Console.ForegroundColor = HostOps.GetHighContrastColor(
                Console.BackgroundColor); /* throw */

            try
            {
                Console.WriteLine(value); /* throw */
            }
            finally
            {
                Console.ForegroundColor = savedForegroundColor; /* throw */
            }
        }
Пример #3
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode Wait(
            Interpreter interpreter,
            long microseconds,
            bool timeout,
            bool strict,
            ref Result error
            ) /* THREAD-SAFE */
        {
            ReturnCode code = ReturnCode.Ok;

            if (interpreter != null)
            {
                int waitCount;

                if ((waitCount = interpreter.EnterWait()) > 0)
                {
                    if (microseconds == 0)
                    {
#if WINFORMS
                        //
                        // NOTE: If necessary, process all Windows messages
                        //       from the queue.
                        //
                        if (!strict)
                        {
                            code = WindowOps.ProcessEvents(
                                interpreter, ref error);
                        }

                        if (code == ReturnCode.Ok)
#endif
                        {
                            //
                            // NOTE: Yield to other running threads.  This
                            //       also gives them an opportunity to cancel
                            //       the script in progress on this thread.
                            //
                            HostOps.Yield();
                        }
                    }
                    else
                    {
                        //
                        // NOTE: Keep track of how many iterations through
                        //       the loop we take.
                        //
                        int iterations = 0;

                        //
                        // HACK: Account for our processing overhead; use half
                        //       of the requested delay.
                        //
                        int milliseconds = ConversionOps.ToInt(
                            PerformanceOps.GetMilliseconds(microseconds) /
                            WaitDivisor);

                        if (milliseconds < 0)
                        {
                            milliseconds = 0;
                        }

                        if (milliseconds > WaitMaximumSleepTime)
                        {
                            milliseconds = WaitMaximumSleepTime;
                        }

                        //
                        // NOTE: For more precise timing, use the high-resolution
                        //       CPU performance counter.
                        //
                        long startCount = PerformanceOps.GetCount();

                        //
                        // BUGFIX: Make sure the slop time does not exceed the
                        //         actual wait.
                        //
                        long slopMicroseconds = Math.Min(
                            microseconds / WaitSlopDivisor, WaitSlopMinimumTime);

                        //
                        // NOTE: Delay for approximately the specified number of
                        //       microseconds, optionally timing out if we cannot
                        //       obtain the interpreter lock before the time period
                        //       elapses.
                        //
                        while (((code = Interpreter.EventReady(interpreter,
                                                               timeout ? milliseconds : _Timeout.Infinite,
                                                               ref error)) == ReturnCode.Ok) &&
                               !PerformanceOps.HasElapsed(startCount,
                                                          microseconds, slopMicroseconds))
                        {
#if WINFORMS
                            if (!strict)
                            {
                                code = WindowOps.ProcessEvents(interpreter, ref error);

                                if (code != ReturnCode.Ok)
                                {
                                    break;
                                }
                            }
#endif

                            HostOps.SleepOrMaybeComplain(interpreter, milliseconds); iterations++;
                        }

                        long stopCount = PerformanceOps.GetCount();

                        double elapsedMicroseconds = PerformanceOps.GetMicroseconds(
                            startCount, stopCount, 1);

                        TraceOps.DebugTrace(String.Format(
                                                "Wait: code = {0}, iterations = {1}, microseconds = {2}, " +
                                                "elapsedMicroseconds = {3}, sleepMilliseconds = {4}, " +
                                                "slopMicroseconds = {5}, differenceMicroseconds = {6}, " +
                                                "waitCount = {7}, error = {8}",
                                                code, iterations, microseconds, elapsedMicroseconds, milliseconds,
                                                slopMicroseconds, elapsedMicroseconds - (double)microseconds,
                                                waitCount, FormatOps.WrapOrNull(true, true, error)),
                                            typeof(EventOps).Name, TracePriority.EventDebug);
                    }

                    /* IGNORED */
                    interpreter.ExitWait();
                }
                else
                {
                    error = "wait subsystem locked";
                    code  = ReturnCode.Error;
                }
            }
            else
            {
                error = "invalid interpreter";
                code  = ReturnCode.Error;
            }

            return(code);
        }
Пример #4
0
        ///////////////////////////////////////////////////////////////////////

        #region Internal State Introspection Methods
        //
        // NOTE: Used by the _Hosts.Default.BuildEngineInfoList method.
        //
        public static void AddInfo(
            StringPairList list,
            DetailFlags detailFlags
            )
        {
            if (list == null)
            {
                return;
            }

            lock (syncRoot) /* TRANSACTIONAL */
            {
                bool           empty     = HostOps.HasEmptyContent(detailFlags);
                StringPairList localList = new StringPairList();

                if (empty || isTracePossible)
                {
                    localList.Add("IsTracePossible",
                                  isTracePossible.ToString());
                }

                if (empty || (tracePriorities != TracePriority.None))
                {
                    localList.Add("TracePriorities",
                                  tracePriorities.ToString());
                }

                if (empty || (defaultTracePriority != TracePriority.None))
                {
                    localList.Add("DefaultTracePriority",
                                  defaultTracePriority.ToString());
                }

                if (empty || isTraceEnabledByDefault)
                {
                    localList.Add("IsTraceEnabledByDefault",
                                  isTraceEnabledByDefault.ToString());
                }

                if (empty || (isTraceEnabled != null))
                {
                    localList.Add("IsTraceEnabled", (isTraceEnabled != null) ?
                                  isTraceEnabled.ToString() : FormatOps.DisplayNull);
                }

                if (empty || (traceFormat != null))
                {
                    localList.Add("TraceFormat",
                                  FormatOps.DisplayString(traceFormat));
                }

                if (empty || traceDateTime)
                {
                    localList.Add("TraceDateTime",
                                  traceDateTime.ToString());
                }

                if (empty || tracePriority)
                {
                    localList.Add("TracePriority",
                                  tracePriority.ToString());
                }

                if (empty || traceAppDomain)
                {
                    localList.Add("TraceAppDomain",
                                  traceAppDomain.ToString());
                }

                if (empty || traceInterpreter)
                {
                    localList.Add("TraceInterpreter",
                                  traceInterpreter.ToString());
                }

                if (empty || traceThreadId)
                {
                    localList.Add("TraceThreadId",
                                  traceThreadId.ToString());
                }

                if (empty || traceMethod)
                {
                    localList.Add("TraceMethod",
                                  traceMethod.ToString());
                }

                if (empty || (traceCategories != null))
                {
                    localList.Add("TraceCategories", (traceCategories != null) ?
                                  traceCategories.KeysAndValuesToString(null, false) :
                                  FormatOps.DisplayNull);
                }

                if (localList.Count > 0)
                {
                    list.Add((IPair <string>)null);
                    list.Add("Trace Information");
                    list.Add((IPair <string>)null);
                    list.Add(localList);
                }
            }
        }
Пример #5
0
        ///////////////////////////////////////////////////////////////////////

        //
        // BUGFIX: *DEADLOCK* Prevent deadlocks here by using the TryLock
        //         pattern.
        //
        // NOTE: Used by the _Hosts.Default.WriteEngineInfo method.
        //
        public static void AddInfo(
            StringPairList list,
            DetailFlags detailFlags
            )
        {
            if (list == null)
            {
                return;
            }

            bool locked = false;

            try
            {
                TryLock(ref locked); /* TRANSACTIONAL */

                if (locked)
                {
                    bool           empty     = HostOps.HasEmptyContent(detailFlags);
                    StringPairList localList = new StringPairList();

                    if (empty || (isAvailable != null))
                    {
                        localList.Add("IsAvailable", (isAvailable != null) ?
                                      isAvailable.ToString() : FormatOps.DisplayNull);
                    }

                    if (empty || locked)
                    {
                        localList.Add("Locked", locked.ToString());
                    }

                    if (empty || disabled)
                    {
                        localList.Add("Disabled", disabled.ToString());
                    }

                    if (empty || strictPath)
                    {
                        localList.Add("StrictPath", strictPath.ToString());
                    }

                    if (empty || noReflection)
                    {
                        localList.Add("NoReflection", noReflection.ToString());
                    }

                    if (empty || (nativeModule != IntPtr.Zero))
                    {
                        localList.Add("NativeModule", nativeModule.ToString());
                    }

                    if (empty || (nativeFileName != null))
                    {
                        localList.Add("NativeFileName", (nativeFileName != null) ?
                                      nativeFileName : FormatOps.DisplayNull);
                    }

                    if (empty || ((nativeDelegates != null) && (nativeDelegates.Count > 0)))
                    {
                        localList.Add("NativeDelegates", (nativeDelegates != null) ?
                                      nativeDelegates.Count.ToString() : FormatOps.DisplayNull);
                    }

                    if (empty || (nativeGetVersion != null))
                    {
                        localList.Add("NativeGetVersion", (nativeGetVersion != null) ?
                                      nativeGetVersion.ToString() : FormatOps.DisplayNull);
                    }

                    if (empty || (nativeAllocateMemory != null))
                    {
                        localList.Add("NativeAllocateMemory", (nativeAllocateMemory != null) ?
                                      nativeAllocateMemory.ToString() : FormatOps.DisplayNull);
                    }

                    if (empty || (nativeFreeMemory != null))
                    {
                        localList.Add("NativeFreeMemory", (nativeFreeMemory != null) ?
                                      nativeFreeMemory.ToString() : FormatOps.DisplayNull);
                    }

                    if (empty || (nativeFreeElements != null))
                    {
                        localList.Add("NativeFreeElements", (nativeFreeElements != null) ?
                                      nativeFreeElements.ToString() : FormatOps.DisplayNull);
                    }

                    if (empty || (nativeSplitList != null))
                    {
                        localList.Add("NativeSplitList", (nativeSplitList != null) ?
                                      nativeSplitList.ToString() : FormatOps.DisplayNull);
                    }

                    if (empty || (nativeJoinList != null))
                    {
                        localList.Add("NativeJoinList", (nativeJoinList != null) ?
                                      nativeJoinList.ToString() : FormatOps.DisplayNull);
                    }

                    if (empty || (version != null))
                    {
                        localList.Add("Version", (version != null) ?
                                      version : FormatOps.DisplayNull);
                    }

                    if (empty || (itemsFieldInfo != null))
                    {
                        localList.Add("ItemsFieldInfo", (itemsFieldInfo != null) ?
                                      itemsFieldInfo.ToString() : FormatOps.DisplayNull);
                    }

                    if (empty || Parser.UseNativeSplitList)
                    {
                        localList.Add("UseNativeSplitList",
                                      Parser.UseNativeSplitList.ToString());
                    }

                    if (empty || GenericOps <string> .UseNativeJoinList)
                    {
                        localList.Add("UseNativeJoinList",
                                      GenericOps <string> .UseNativeJoinList.ToString());
                    }

                    if (localList.Count > 0)
                    {
                        list.Add((IPair <string>)null);
                        list.Add("Native Utility");
                        list.Add((IPair <string>)null);
                        list.Add(localList);
                    }
                }
                else
                {
                    StringPairList localList = new StringPairList();

                    localList.Add(FormatOps.DisplayBusy);

                    if (localList.Count > 0)
                    {
                        list.Add((IPair <string>)null);
                        list.Add("Native Utility");
                        list.Add((IPair <string>)null);
                        list.Add(localList);
                    }
                }
            }
            finally
            {
                ExitLock(ref locked); /* TRANSACTIONAL */
            }
        }
Пример #6
0
        ///////////////////////////////////////////////////////////////////////

        #region IDebugger Members
        public void AddInfo(
            StringPairList list,
            DetailFlags detailFlags
            )
        {
            CheckDisposed();

            bool empty = HostOps.HasEmptyContent(detailFlags);

            if (empty || (suspendCount > 0))
            {
                list.Add("SuspendCount", suspendCount.ToString());
            }

            if (empty || Enabled)
            {
                list.Add("Enabled", Enabled.ToString());
            }

            if (empty || (Loops > 0))
            {
                list.Add("Loops", Loops.ToString());
            }

            if (empty || (Active > 0))
            {
                list.Add("Active", Active.ToString());
            }

            if (empty || SingleStep)
            {
                list.Add("SingleStep", SingleStep.ToString());
            }

#if BREAKPOINTS
            if (empty || BreakOnToken)
            {
                list.Add("BreakOnToken", BreakOnToken.ToString());
            }
#endif

            if (empty || BreakOnExecute)
            {
                list.Add("BreakOnExecute", BreakOnExecute.ToString());
            }

            if (empty || BreakOnCancel)
            {
                list.Add("BreakOnCancel", BreakOnCancel.ToString());
            }

            if (empty || BreakOnError)
            {
                list.Add("BreakOnError", BreakOnError.ToString());
            }

            if (empty || BreakOnReturn)
            {
                list.Add("BreakOnReturn", BreakOnReturn.ToString());
            }

            if (empty || BreakOnTest)
            {
                list.Add("BreakOnTest", BreakOnTest.ToString());
            }

            if (empty || BreakOnExit)
            {
                list.Add("BreakOnExit", BreakOnExit.ToString());
            }

            if (empty || (Steps > 0))
            {
                list.Add("Steps", Steps.ToString());
            }

            if (empty || (Types != BreakpointType.None))
            {
                list.Add("Types", Types.ToString());
            }

#if BREAKPOINTS
            BreakpointDictionary breakpoints = Breakpoints;

            if (empty || ((breakpoints != null) && (breakpoints.Count > 0)))
            {
                list.Add("Breakpoints", (breakpoints != null) ?
                         breakpoints.Count.ToString() : FormatOps.DisplayNull);
            }
#endif

#if DEBUGGER_ARGUMENTS
            ArgumentList executeArguments = ExecuteArguments;

            if (empty || (executeArguments != null))
            {
                list.Add("ExecuteArguments", (executeArguments != null) ?
                         executeArguments.ToString(ToStringFlags.NameAndValue,
                                                   null, false) : FormatOps.DisplayNull);
            }
#endif

            if (empty || !String.IsNullOrEmpty(Command))
            {
                list.Add("Command", FormatOps.DisplayString(
                             FormatOps.ReplaceNewLines(FormatOps.NormalizeNewLines(
                                                           Command))));
            }

            if (empty || !String.IsNullOrEmpty(Result))
            {
                list.Add("Result", FormatOps.DisplayString(
                             FormatOps.ReplaceNewLines(FormatOps.NormalizeNewLines(
                                                           Result))));
            }

            QueueList <string, string> queue = Queue;

            if (empty || ((queue != null) && (queue.Count > 0)))
            {
                list.Add("Queue", (queue != null) ?
                         queue.Count.ToString() : FormatOps.DisplayNull);
            }

            StringList callbackArguments = CallbackArguments;

            if (empty || ((callbackArguments != null) &&
                          (callbackArguments.Count > 0)))
            {
                list.Add("CallbackArguments", (callbackArguments != null) ?
                         callbackArguments.ToString() : FormatOps.DisplayNull);
            }

            if (interpreter != null)
            {
                interpreter.GetHostDebuggerInfo(ref list, detailFlags);
            }
            else if (empty)
            {
                list.Add((IPair <string>)null);
                list.Add("Interpreter");
                list.Add((IPair <string>)null);
                list.Add("Id", FormatOps.DisplayNull);
            }
        }
Пример #7
0
        ///////////////////////////////////////////////////////////////////////

        public static HeaderFlags GetHeaderFlags(
            IInteractiveHost interactiveHost,
            HeaderFlags headerFlags,
            bool debug,
            bool show,
            bool empty,
            bool @default
            )
        {
            //
            // NOTE: If we are in debug mode and no header display flags have
            //       been explicitly set for the interpreter, initialize them
            //       to the default value.
            //
            if (@default && FlagOps.HasFlags(
                    headerFlags, HeaderFlags.Invalid, true))
            {
                //
                // NOTE: Remove the "these flags have not been setup before"
                //       indicator flag.
                //
                headerFlags &= ~HeaderFlags.Invalid;

                //
                // NOTE: Add the default header flags for the interactive
                //       host.  If the interactive host is not available,
                //       fallback on the system default header flags.
                //
                HeaderFlags defaultHeaderFlags = HeaderFlags.Default;

                if (interactiveHost != null)
                {
                    headerFlags |= HostOps.GetHeaderFlags(
                        interactiveHost, defaultHeaderFlags);
                }
                else
                {
                    headerFlags |= defaultHeaderFlags;
                }
            }

            //
            // NOTE: Only modify (set or unset) the active debugger flag if we
            //       have been told to do so; otherwise, the active debugger
            //       flag may have been manually changed and should be left
            //       alone.
            //
            if (show)
            {
                //
                // NOTE: Is there an active debugger?
                //
                if (debug)
                {
                    //
                    // NOTE: Set the active debugger flag.
                    //
                    headerFlags |= HeaderFlags.Debug;
                }
                else
                {
                    //
                    // NOTE: Unset the active debugger flag.
                    //
                    headerFlags &= ~HeaderFlags.Debug;
                }
            }

            //
            // NOTE: Show empty content?
            //
            if (empty)
            {
                headerFlags |= HeaderFlags.EmptyContent;
            }

            return(headerFlags);
        }