Esempio n. 1
0
        private static string[] ExecuteScript(string code, params string[] arguments)
        {
            TextWriter output = Console.Out;
            TextWriter error  = Console.Error;

            try
            {
                using (StringWriter writer = new StringWriter())
                {
                    Console.SetError(writer);
                    Console.SetOut(writer);
                    ExecuteScript((fileName, args) => ScriptExecution.Execute(fileName, args), code, arguments);
                    writer.Flush();

                    string text = writer.GetStringBuilder().ToString();

                    return(text.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                }
            }
            finally
            {
                Console.SetOut(output);
                Console.SetError(error);
            }
        }
Esempio n. 2
0
        public static int Execute(IntPtr client, [MarshalAs(UnmanagedType.LPStr)] string args)
        {
            string[] arguments = args.Split(" ".ToCharArray());

            return(ExecuteAction(client, () =>
            {
                ScriptExecution.Execute(arguments[0], arguments.Skip(1).ToArray());
            }));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Options options = null;

            Parser.Default.ParseArguments <Options>(args)
            .WithParsed(o => options = o);

            if (options == null)
            {
                return;
            }

            DebuggerInitialization.OpenDump(options.DumpPath, options.SymbolPath);
            Console.WriteLine("Threads: {0}", Thread.All.Length);
            Console.WriteLine("Current thread: {0}", Thread.Current.Id);
            var frames = Thread.Current.StackTrace.Frames;

            Console.WriteLine("Call stack:");
            foreach (var frame in frames)
            {
                try
                {
                    Console.WriteLine("  {0,3:x} {1}+0x{2:x}   ({3}:{4})", frame.FrameNumber, frame.FunctionName, frame.FunctionDisplacement, frame.SourceFileName, frame.SourceFileLine);
                }
                catch (Exception)
                {
                    Console.WriteLine("  {0,3:x} {1}+0x{2:x}", frame.FrameNumber, frame.FunctionName, frame.FunctionDisplacement);
                }
            }

            // In order to use console output and error in scripts, we must set it to debug client
            DebugOutput captureFlags = DebugOutput.Normal | DebugOutput.Error | DebugOutput.Warning | DebugOutput.Verbose
                                       | DebugOutput.Prompt | DebugOutput.PromptRegisters | DebugOutput.ExtensionWarning | DebugOutput.Debuggee
                                       | DebugOutput.DebuggeePrompt | DebugOutput.Symbols | DebugOutput.Status;
            var callbacks = DebuggerOutputToTextWriter.Create(Console.Out, captureFlags);

            using (OutputCallbacksSwitcher switcher = OutputCallbacksSwitcher.Create(callbacks))
            {
                Action action = () =>
                {
                    ScriptExecution.Execute(@"..\..\samples\script.csx", args);
                };
                DbgEngDll dbgEngDll = Context.Debugger as DbgEngDll;

                if (dbgEngDll != null)
                {
                    dbgEngDll.ExecuteAction(action);
                }
                else
                {
                    action();
                }
            }
        }