Beispiel #1
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();
                }
            }
        }
Beispiel #2
0
        private static int ExecuteAction(IntPtr client, Action action)
        {
            try
            {
                IDebugClient debugClient = (IDebugClient)Marshal.GetUniqueObjectForIUnknown(client);

                DbgEngDll.InitializeContext(debugClient);
                Context.ClrProvider = new CLR.ClrMdProvider();
                DbgEngDll dbgEngDll = Context.Debugger as DbgEngDll;

                dbgEngDll.ExecuteAction(action);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(ex.HResult);
            }
            finally
            {
                DbgEngDll.InitializeContext(null);
            }

            return(0);
        }
        private void InterpretInteractive(string code)
        {
            DbgEngDll dbgEngDll = Context.Debugger as DbgEngDll;

            dbgEngDll.ExecuteAction(() => DumpInitialization.InteractiveExecution.Interpret(code));
        }