Ejemplo n.º 1
0
        //////////////////////////////////////////////////////////////////////////////////
        //
        // Private implementation
        //
        //////////////////////////////////////////////////////////////////////////////////

        /* // NOT USED by O2MDbg
         * private int RunInputLoop()
         * {
         *  // Run the event loop
         *  string input;
         *  IMDbgCommand cmd = null;
         *  string cmdArgs = null;
         *
         *  int stopCount = -1;
         *
         *  while (true)
         *  {
         *      Thread.Sleep(1000);
         *      Debug.WriteLine("MSdn Shell, waiting for commands");
         *  }
         *
         *  while (m_run && IO.ReadCommand(out input))
         *  {
         *      try
         *      {
         *          if (Debugger.Processes.HaveActive)
         *          {
         *              stopCount = Debugger.Processes.Active.StopCounter;
         *          }
         *
         *          if (input.Length == 0)
         *          {
         *              if (cmd == null || !cmd.IsRepeatable)
         *              {
         *                  continue;
         *              }
         *          }
         *          else
         *          {
         *              Commands.ParseCommand(input, out cmd, out cmdArgs);
         *          }
         *          cmd.Execute(cmdArgs);
         *
         *          int newStopCount = Debugger.Processes.HaveActive
         *                                 ? Debugger.Processes.Active.StopCounter
         *                                 : Int32.MaxValue;
         *          bool movementCommand = newStopCount > stopCount;
         *          stopCount = newStopCount;
         *
         *          if (OnCommandExecuted != null)
         *          {
         *              OnCommandExecuted(this, new CommandExecutedEventArgs(this, cmd, cmdArgs, movementCommand));
         *          }
         *
         *          newStopCount = Debugger.Processes.HaveActive
         *                             ? Debugger.Processes.Active.StopCounter
         *                             : Int32.MaxValue;
         *          movementCommand = newStopCount > stopCount;
         *
         *          while (newStopCount > stopCount)
         *          {
         *              stopCount = newStopCount;
         *
         *              if (OnCommandExecuted != null)
         *              {
         *                  OnCommandExecuted(this, new CommandExecutedEventArgs(this, null, null, movementCommand));
         *              }
         *
         *              newStopCount = Debugger.Processes.HaveActive
         *                                 ? Debugger.Processes.Active.StopCounter
         *                                 : Int32.MaxValue;
         *              movementCommand = newStopCount > stopCount;
         *          }
         *          stopCount = newStopCount;
         *      }
         *      catch (Exception e)
         *      {
         *          ReportException(e);
         *      }
         *  } // end while
         *  return m_exitCode;
         * }
         */


        private void PrintCurrentException()
        {
            MDbgValue ex = Debugger.Processes.Active.Threads.Active.CurrentException;

            CommandBase.WriteOutput("Exception=" + ex.GetStringValue(0));
            foreach (MDbgValue f in ex.GetFields())
            {
                string outputType;
                string outputValue;

                if (f.Name == "_xptrs" || f.Name == "_xcode" || f.Name == "_stackTrace" ||
                    f.Name == "_remoteStackTraceString" || f.Name == "_remoteStackIndex" ||
                    f.Name == "_exceptionMethodString")
                {
                    outputType = MDbgOutputConstants.Ignore;
                }
                else
                {
                    outputType = MDbgOutputConstants.StdOutput;
                }

                outputValue = f.GetStringValue(0);
                // remove new line characters in string
                if (outputValue != null && (f.Name == "_exceptionMethodString" || f.Name == "_remoteStackTraceString"))
                {
                    outputValue = outputValue.Replace('\n', '#');
                }

                CommandBase.WriteOutput(outputType, "\t" + f.Name + "=" + outputValue);
            }
        }
Ejemplo n.º 2
0
        string SerializeException(CorValue exception)
        {
            var       result = new StringBuilder();
            MDbgValue ex     = new MDbgValue(shell.Debugger.Processes.Active, exception);

            result.Append(ex.GetStringValue(0) + ": ");
            foreach (MDbgValue f in ex.GetFields())
            {
                string outputValue = f.GetStringValue(0);

                if (f.Name == "_message")
                {
                    result.AppendLine(outputValue);
                    break;
                }

                //if (f.Name == "_xptrs" || f.Name == "_xcode" || f.Name == "_stackTrace" ||
                //    f.Name == "_remoteStackTraceString" || f.Name == "_remoteStackIndex" ||
                //    f.Name == "_exceptionMethodString")
                //{
                //    continue;
                //}

                //// remove new line characters in string
                //if (outputValue != "<null>" && outputValue != null && (f.Name == "_exceptionMethodString" || f.Name == "_remoteStackTraceString"))
                //{
                //    outputValue = outputValue.Replace('\n', '#');
                //}

                //string name = f.Name.Substring(1,1).ToUpper()+f.Name.Substring(2);
                //result.AppendLine("\t" + name + "=" + outputValue);
            }
            return(result.ToString());
        }
Ejemplo n.º 3
0
        internal List <O2MDbgVariable> getCurrentFrameVariable(O2MDbgVariable o2MDbgVariable)
        {
            var o2MDbgVariables = new List <O2MDbgVariable>();

            try
            {
                MDbgFrame frame     = DI.o2MDbg.ActiveProcess.Threads.Active.CurrentFrame;
                MDbgValue mbbgValue = DI.o2MDbg.ActiveProcess.ResolveVariable(o2MDbgVariable.fullName, frame);
                if (mbbgValue != null && mbbgValue.IsComplexType)
                {
                    try
                    {
                        // add properties
                        var valueType     = mbbgValue.TypeName;
                        var valueAssembly = mbbgValue.CorValue.ExactType.Class.Module.Assembly.Name;
                        //var properties2 = DI.reflection.getProperties(DI.reflection.getType(valueAssembly,valueType));
                        var properties = DI.reflection.getProperties(DI.reflection.getType(valueAssembly, valueType));
                        foreach (var property in properties)
                        {
                            o2MDbgVariables.Add(new O2MDbgVariable(property, o2MDbgVariable));
                        }
                    }
                    catch (Exception ex)
                    {
                        DI.log.ex(ex, "in getCurrentFrameVariable , add properties");
                    }
                    // add values
                    try
                    {
                        foreach (MDbgValue mdbgValue in mbbgValue.GetFields())
                        {
                            if (mdbgValue != null)
                            {
                                o2MDbgVariables.Add(new O2MDbgVariable(mdbgValue, o2MDbgVariable));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        DI.log.ex(ex, "in getCurrentFrameVariable , add values");
                    }
                }
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in getCurrentFrameVariable");
            }
            return(o2MDbgVariables);
        }
        /// <summary>
        /// Initialize a ManagedProcessUnhandledExceptionOccurredEventArgs object and raise the
        /// UnhandledExceptionOccurred event.
        /// </summary>
        private void HandleException()
        {
            CancelEventArgs e = new CancelEventArgs();

            this.OnStartHandleException(e);
            if (e.Cancel)
            {
                return;
            }

            MDbgValue ex = this.MDbgProcess.Threads.Active.CurrentException;

            if (ex.IsNull)
            {
                // No current exception is available.  Perhaps the user switched to a different
                // thread which was not throwing an exception.
                return;
            }

            IntPtr exceptionPointers = IntPtr.Zero;

            foreach (MDbgValue f in ex.GetFields())
            {
                if (f.Name == "_xptrs")
                {
                    string outputValue = f.GetStringValue(0);
                    exceptionPointers = (IntPtr)int.Parse(outputValue);
                }
            }

            if (exceptionPointers == IntPtr.Zero)
            {
                // Get the Exception Pointer in the target process
                MDbgValue value = FunctionEval(
                    "System.Runtime.InteropServices.Marshal.GetExceptionPointers");
                if (value != null)
                {
                    exceptionPointers = (IntPtr)int.Parse(value.GetStringValue(1));
                }
            }

            this.OnUnhandledExceptionOccurred(
                new ManagedProcessUnhandledExceptionOccurredEventArgs
            {
                ProcessID         = this.MDbgProcess.CorProcess.Id,
                ThreadID          = this.MDbgProcess.Threads.Active.Id,
                ExceptionPointers = exceptionPointers
            });
        }
Ejemplo n.º 5
0
        // Tries to lazily add the immediate children for a given node.
        // called on UI thread.
        static public void TryExpandNode(MainForm parent, TreeNode node)
        {
            MDbgValue val = (MDbgValue)node.Tag;
            if (val == null)
            {
                return;
            }
            node.Tag = null; // only expand it once. Else we'll keep readding the children on each select.

            MDbgValue[] items = null;

            
            parent.ExecuteOnWorkerThreadIfStoppedAndBlock(delegate(MDbgProcess proc)
            {
                Debug.Assert(proc != null);
                Debug.Assert(!proc.IsRunning);
                Debug.Assert(val.Process == proc);

                if (val.IsArrayType)
                {
                    items = val.GetArrayItems();
                }
                else if (val.IsComplexType)
                {
                    items = val.GetFields().Concat(
                            val.GetProperties()).ToArray(); 
                }
            });
            
            // Nothing to expand.
            if (items == null)
            {
                return;
            }

            // This node had a dummy sub-node so that it's marked as expandable. When we get the
            // BeforeExpand event, then we kill the dummy node and replace with real nodes.
            // We use a dummy node instead of real nodes because it lets us avoid having to add all the real nodes
            // (which may be a lot of work).
            node.Nodes.Clear(); // delete dummy node.

            foreach (MDbgValue field in items)
            {
                PrintInternal(parent, field, node.Nodes);
            }
        }
Ejemplo n.º 6
0
        private void PrintCurrentException()
        {
            MDbgValue ex = Debugger.Processes.Active.Threads.Active.CurrentException;

            if (ex.IsNull)
            {
                // No current exception is available.  Perhaps the user switched to a different
                // thread which was not throwing an exception.
                return;
            }

            CommandBase.WriteOutput("Exception=" + ex.GetStringValue(0));
            foreach (MDbgValue f in ex.GetFields())
            {
                string outputType;
                string outputValue;

                if (f.Name == "_xptrs" || f.Name == "_xcode" || f.Name == "_stackTrace" ||
                    f.Name == "_remoteStackTraceString" || f.Name == "_remoteStackIndex" ||
                    f.Name == "_exceptionMethodString")
                {
                    outputType = MDbgOutputConstants.Ignore;
                }
                else
                {
                    outputType = MDbgOutputConstants.StdOutput;
                }

                outputValue = f.GetStringValue(0);
                // remove new line characters in string
                if (outputValue != null && (f.Name == "_exceptionMethodString" || f.Name == "_remoteStackTraceString"))
                {
                    outputValue = outputValue.Replace('\n', '#');
                }

                CommandBase.WriteOutput(outputType, "\t" + f.Name + "=" + outputValue);
            }
        }
Ejemplo n.º 7
0
        string SerializeValue(MDbgValue value, bool itemsOnly, int itemsMaxCount)
        {
            string result = "";

            MDbgValue[] items        = null;
            MDbgValue[] diaplayItems = null; //decorated (fake) display items

            int tempMaxCount = itemsMaxCount;

            tempMaxCount++;

            if (value.IsArrayType)
            {
                items = value.GetArrayItems(tempMaxCount);
            }
            else if (value.IsListType)
            {
                diaplayItems = value.GenerateListItems(tempMaxCount);
            }
            else if (value.IsDictionaryType)
            {
                diaplayItems = value.GenerateDictionaryItems(tempMaxCount);
            }

            if (!itemsOnly && value.IsComplexType)
            {
                if (!IsPrimitiveType(value)) //boxed primitive type have their MDbgValue set to ComplexType
                {
                    items = value.GetFields().ToArray();
                    try
                    {
                        items = items.Concat(value.GetProperties()).ToArray();
                    }
                    catch { }
                }
            }

            if (items != null || itemsOnly)
            {
                string logicalItems = "";

                if (diaplayItems != null)
                {
                    MDbgValue truncatedValue = null;

                    if (diaplayItems.Count() > itemsMaxCount)
                    {
                        truncatedValue = diaplayItems.Last();
                    }

                    logicalItems = diaplayItems.Select(x =>
                    {
                        x.IsFake = true;
                        if (truncatedValue != null && x == truncatedValue)
                        {
                            return(Serialize(x, "...", "..."));
                        }
                        else
                        {
                            return(Serialize(x));
                        }
                    }).Join();
                }

                string rawItems = "";
                if (items != null)
                {
                    bool hasIndexer = value.IsListType || value.IsDictionaryType;

                    MDbgValue truncatedValue = null;

                    if (items.Count() > itemsMaxCount)
                    {
                        truncatedValue = items.Last();
                    }

                    rawItems = items.Where(x => !x.Name.Contains("$")) //ignore any internal vars
                               .Where(x => !hasIndexer || x.Name != "Item")
                               .Select(x =>
                    {
                        if (truncatedValue != null && x == truncatedValue)
                        {
                            return(Serialize(x, "...", "..."));
                        }
                        else
                        {
                            return(Serialize(x));
                        }
                    })
                               .Join();
                }

                result = "<items>" + logicalItems + rawItems + "</items>";
            }

            return(result);
        }