Example #1
0
 private void LoadCommandList(IMDbgShell shell)
 {
     foreach (IMDbgCommand command in shell.Commands)
     {
         _CmdList.Add(command.CommandName);
     }
 }
Example #2
0
 public Screen(IMDbgShell shell)
 {
     Console.WindowWidth = 100;
     _Shell        = shell;
     _OldIo        = _Shell.IO;
     _CurrentMenu  = _MainMenu;
     _FileList     = new FileList(shell, Console.WindowHeight - 7);
     _VariableView = new VariableViewer(_Shell, "#vars#");
     _Buffers.Add(_CommandView);
 }
Example #3
0
 public Screen(IMDbgShell shell)
 {
     Console.WindowWidth = 100;
     _Shell = shell;
     _OldIo = _Shell.IO;
     _CurrentMenu = _MainMenu;
     _FileList = new FileList(shell, Console.WindowHeight - 7);
     _VariableView = new VariableViewer(_Shell, "#vars#");
     _Buffers.Add(_CommandView);
 }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <b>CommandExecutedEventArgs</b> class.
        /// </summary>
        /// <param name="sender">The sender for this event</param>
        /// <param name="command">The command that is getting executed</param>
        /// <param name="arguments">The arguments for the command</param>
        /// <param name="movementCommand">Is this a movement command.</param>
        public CommandExecutedEventArgs(IMDbgShell sender, IMDbgCommand command, string arguments,
                                        bool movementCommand)
        {
            Debug.Assert(sender != null);
            Debug.Assert((command == null) == (arguments == null));

            m_sender = sender;
            m_command = command;
            m_arguments = arguments;
            m_movementCommand = movementCommand;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <b>CommandExecutedEventArgs</b> class.
        /// </summary>
        /// <param name="sender">The sender for this event</param>
        /// <param name="command">The command that is getting executed</param>
        /// <param name="arguments">The arguments for the command</param>
        /// <param name="movementCommand">Is this a movement command.</param>
        public CommandExecutedEventArgs(IMDbgShell sender, IMDbgCommand command, string arguments,
                                        bool movementCommand)
        {
            Debug.Assert(sender != null);
            Debug.Assert((command == null) == (arguments == null));

            m_sender          = sender;
            m_command         = command;
            m_arguments       = arguments;
            m_movementCommand = movementCommand;
        }
        public MainForm(IMDbgShell ui)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            Debug.Assert(ui!=null);
            m_ui = ui;
            
            cmdHistory.Text=" ";
            SourceViewerForm.ClearSourceFiles();
        }
Example #7
0
        public DebuggerClient(IMDbgShell shell)
        {
            //Debug.Assert(false);
            //Environment.SetEnvironmentVariable("CSSNPP_DBG_AGENTASSEMBLY", Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "dbgagent.dll"));
            css.RemoteInspector.AssemblyFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "dbgagent.dll");

            this.shell = shell;
            this.shell.Debugger.ParseExpression = new DefaultExpressionParser(shell.Debugger).ParseExpression2;
            this.shell.OnCommandError          += shell_OnCommandError;
            channel.Trace = message => Console.WriteLine(message);
            channel.Start();

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    string command = MessageQueue.WaitForCommand();
                    ExecuteCommand(command);
                }
            });
        }
Example #8
0
 public VariableViewer(IMDbgShell shell, string name)
     : base(name)
 {
     _Shell = shell;
 }
Example #9
0
 public ExecuteCmdAction(IMDbgShell mdbg,
                         string actionString,
                         Type stopReasonType)
 {
     Debug.Assert(mdbg != null);
     Debug.Assert(actionString != null);
     Debug.Assert(stopReasonType != null);
     m_mdbg = mdbg;
     m_actionString = actionString;
     m_stopReasonType = stopReasonType;
     m_id = g_id++;
 }
Example #10
0
 public FileList(IMDbgShell shell, int maxHeight)
 {
     _Shell = shell;
     _MaxHeight = maxHeight;
     LoadCommandList(shell);
 }
Example #11
0
 private void LoadCommandList(IMDbgShell shell)
 {
     foreach (IMDbgCommand command in shell.Commands)
     {
         _CmdList.Add(command.CommandName);
     }
 }
        public static void FuncEvalCmd(string arguments, IMDbgShell Shell, O2Thread.FuncVoidT1<string> execOnEval)
        {
            try
            {

                var activeProcess = DI.o2MDbg.ActiveProcess; //Debugger.Processes.Active
                const string appDomainOption = "ad";
                var ap = new ArgParser(arguments, appDomainOption + ":1");
                if (!(ap.Count >= 1))
                {
                    throw new MDbgShellException("Not Enough arguments");
                }


                // Currently debugger picks first function -- we have not implementing resolving overloaded functions.
                // Good example is Console.WriteLine -- there is 18 different types:
                // 1) [06000575] Void WriteLine()
                // 2) [06000576] Void WriteLine(Boolean)
                // 3) [06000577] Void WriteLine(Char)
                // 4) [06000578] Void WriteLine(Char[])
                // 5) [06000579] Void WriteLine(Char[], Int32, Int32)
                // 6) [0600057a] Void WriteLine(Decimal)
                // 7) [0600057b] Void WriteLine(Double)
                // 8) [0600057c] Void WriteLine(Single)
                // 9) [0600057d] Void WriteLine(Int32)
                // 10) [0600057e] Void WriteLine(UInt32)
                // 11) [0600057f] Void WriteLine(Int64)
                // 12) [06000580] Void WriteLine(UInt64)
                // 13) [06000581] Void WriteLine(Object)
                // 14) [06000582] Void WriteLine(String)
                // 15) [06000583] Void WriteLine(String, Object)
                // 16) [06000584] Void WriteLine(String, Object, Object)
                // 17) [06000585] Void WriteLine(String, Object, Object, Object)
                // 18) [06000586] Void WriteLine(String, Object, Object, Object, Object, ...)
                // 19) [06000587] Void WriteLine(String, Object[])
                //
                CorAppDomain appDomain;
                if (ap.OptionPassed(appDomainOption))
                {
                    MDbgAppDomain ad = activeProcess.AppDomains[ap.GetOption(appDomainOption).AsInt];
                    if (ad == null)
                    {
                        throw new ArgumentException("Invalid Appdomain Number");
                    }
                    appDomain = ad.CorAppDomain;
                }
                else
                {
                    appDomain = activeProcess.Threads.Active.CorThread.AppDomain;
                }

                MDbgFunction func = activeProcess.ResolveFunctionNameFromScope(ap.AsString(0), appDomain);
                if (null == func)
                {
                    throw new MDbgShellException(String.Format(CultureInfo.InvariantCulture, "Could not resolve {0}",
                                                               new Object[] {ap.AsString(0)}));
                }

                CorEval eval = activeProcess.Threads.Active.CorThread.CreateEval();

                // Get Variables
                var vars = new ArrayList();
                String arg;
                for (int i = 1; i < ap.Count; i++)
                {
                    arg = ap.AsString(i);

                    CorValue v = Shell.ExpressionParser.ParseExpression2(arg, activeProcess,
                                                                         activeProcess.Threads.Active.
                                                                             CurrentFrame);

                    if (v == null)
                    {
                        throw new MDbgShellException("Cannot resolve expression or variable " + ap.AsString(i));
                    }

                    if (v is CorGenericValue)
                    {
                        vars.Add(v);
                    }

                    else
                    {
                        CorHeapValue hv = v.CastToHeapValue();
                        if (hv != null)
                        {
                            // we cannot pass directly heap values, we need to pass reference to heap valus
                            CorReferenceValue myref =
                                eval.CreateValue(CorElementType.ELEMENT_TYPE_CLASS, null).CastToReferenceValue();
                            myref.Value = hv.Address;
                            vars.Add(myref);
                        }
                        else
                        {
                            vars.Add(v);
                        }
                    }
                }

                eval.CallFunction(func.CorFunction, (CorValue[]) vars.ToArray(typeof (CorValue)));
                activeProcess.Go().WaitOne();

                // now display result of the funceval
                if (!(activeProcess.StopReason is EvalCompleteStopReason))
                {
                    // we could have received also EvalExceptionStopReason but it's derived from EvalCompleteStopReason
                    Shell.IO.WriteOutput(MDbgOutputConstants.StdOutput,
                                         "Func-eval not fully completed and debuggee has stopped");
                    Shell.IO.WriteOutput(MDbgOutputConstants.StdOutput,
                                         "Result of funceval won't be printed when finished.");
                }
                else
                {
                    eval = (activeProcess.StopReason as EvalCompleteStopReason).Eval;
                    Debug.Assert(eval != null);

                    CorValue cv = eval.Result;
                    if (cv != null)
                    {
                        var mv = new MDbgValue(activeProcess, cv);
                        if (execOnEval != null) // if this callback is set then execute 
                        {
                            execOnEval(mv.GetStringValue(1));                         
                            return;
                        }
                        Shell.IO.WriteOutput(MDbgOutputConstants.StdOutput, "result = " + mv.GetStringValue(1));
                        if (cv.CastToReferenceValue() != null)
                            if (activeProcess.DebuggerVars.SetEvalResult(cv))
                                Shell.IO.WriteOutput(MDbgOutputConstants.StdOutput, "results saved to $result");

                    }
                }               
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in FuncEvalCmd");
            }
            if (execOnEval != null)                         // need to call this here so that the sync AutoResetEvent is set
                execOnEval(null);
        }
Example #13
0
 public VariableViewer(IMDbgShell shell, string name)
     : base(name)
 {
     _Shell = shell;
 }
Example #14
0
        public static void FuncEvalCmd(string arguments, IMDbgShell Shell, O2Thread.FuncVoidT1 <string> execOnEval)
        {
            try
            {
                var          activeProcess   = DI.o2MDbg.ActiveProcess; //Debugger.Processes.Active
                const string appDomainOption = "ad";
                var          ap = new ArgParser(arguments, appDomainOption + ":1");
                if (!(ap.Count >= 1))
                {
                    throw new MDbgShellException("Not Enough arguments");
                }


                // Currently debugger picks first function -- we have not implementing resolving overloaded functions.
                // Good example is Console.WriteLine -- there is 18 different types:
                // 1) [06000575] Void WriteLine()
                // 2) [06000576] Void WriteLine(Boolean)
                // 3) [06000577] Void WriteLine(Char)
                // 4) [06000578] Void WriteLine(Char[])
                // 5) [06000579] Void WriteLine(Char[], Int32, Int32)
                // 6) [0600057a] Void WriteLine(Decimal)
                // 7) [0600057b] Void WriteLine(Double)
                // 8) [0600057c] Void WriteLine(Single)
                // 9) [0600057d] Void WriteLine(Int32)
                // 10) [0600057e] Void WriteLine(UInt32)
                // 11) [0600057f] Void WriteLine(Int64)
                // 12) [06000580] Void WriteLine(UInt64)
                // 13) [06000581] Void WriteLine(Object)
                // 14) [06000582] Void WriteLine(String)
                // 15) [06000583] Void WriteLine(String, Object)
                // 16) [06000584] Void WriteLine(String, Object, Object)
                // 17) [06000585] Void WriteLine(String, Object, Object, Object)
                // 18) [06000586] Void WriteLine(String, Object, Object, Object, Object, ...)
                // 19) [06000587] Void WriteLine(String, Object[])
                //
                CorAppDomain appDomain;
                if (ap.OptionPassed(appDomainOption))
                {
                    MDbgAppDomain ad = activeProcess.AppDomains[ap.GetOption(appDomainOption).AsInt];
                    if (ad == null)
                    {
                        throw new ArgumentException("Invalid Appdomain Number");
                    }
                    appDomain = ad.CorAppDomain;
                }
                else
                {
                    appDomain = activeProcess.Threads.Active.CorThread.AppDomain;
                }

                MDbgFunction func = activeProcess.ResolveFunctionNameFromScope(ap.AsString(0), appDomain);
                if (null == func)
                {
                    throw new MDbgShellException(String.Format(CultureInfo.InvariantCulture, "Could not resolve {0}",
                                                               new Object[] { ap.AsString(0) }));
                }

                CorEval eval = activeProcess.Threads.Active.CorThread.CreateEval();

                // Get Variables
                var    vars = new ArrayList();
                String arg;
                for (int i = 1; i < ap.Count; i++)
                {
                    arg = ap.AsString(i);

                    CorValue v = Shell.ExpressionParser.ParseExpression2(arg, activeProcess,
                                                                         activeProcess.Threads.Active.
                                                                         CurrentFrame);

                    if (v == null)
                    {
                        throw new MDbgShellException("Cannot resolve expression or variable " + ap.AsString(i));
                    }

                    if (v is CorGenericValue)
                    {
                        vars.Add(v);
                    }

                    else
                    {
                        CorHeapValue hv = v.CastToHeapValue();
                        if (hv != null)
                        {
                            // we cannot pass directly heap values, we need to pass reference to heap valus
                            CorReferenceValue myref =
                                eval.CreateValue(CorElementType.ELEMENT_TYPE_CLASS, null).CastToReferenceValue();
                            myref.Value = hv.Address;
                            vars.Add(myref);
                        }
                        else
                        {
                            vars.Add(v);
                        }
                    }
                }

                eval.CallFunction(func.CorFunction, (CorValue[])vars.ToArray(typeof(CorValue)));
                activeProcess.Go().WaitOne();

                // now display result of the funceval
                if (!(activeProcess.StopReason is EvalCompleteStopReason))
                {
                    // we could have received also EvalExceptionStopReason but it's derived from EvalCompleteStopReason
                    Shell.IO.WriteOutput(MDbgOutputConstants.StdOutput,
                                         "Func-eval not fully completed and debuggee has stopped");
                    Shell.IO.WriteOutput(MDbgOutputConstants.StdOutput,
                                         "Result of funceval won't be printed when finished.");
                }
                else
                {
                    eval = (activeProcess.StopReason as EvalCompleteStopReason).Eval;
                    Debug.Assert(eval != null);

                    CorValue cv = eval.Result;
                    if (cv != null)
                    {
                        var mv = new MDbgValue(activeProcess, cv);
                        if (execOnEval != null) // if this callback is set then execute
                        {
                            execOnEval(mv.GetStringValue(1));
                            return;
                        }
                        Shell.IO.WriteOutput(MDbgOutputConstants.StdOutput, "result = " + mv.GetStringValue(1));
                        if (cv.CastToReferenceValue() != null)
                        {
                            if (activeProcess.DebuggerVars.SetEvalResult(cv))
                            {
                                Shell.IO.WriteOutput(MDbgOutputConstants.StdOutput, "results saved to $result");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in FuncEvalCmd");
            }
            if (execOnEval != null)                         // need to call this here so that the sync AutoResetEvent is set
            {
                execOnEval(null);
            }
        }
Example #15
0
 public FileList(IMDbgShell shell, int maxHeight)
 {
     _Shell     = shell;
     _MaxHeight = maxHeight;
     LoadCommandList(shell);
 }