IEnumerator IEnumerable.GetEnumerator()
        {
            var ret = new MDbgThread[m_items.Count];

            m_items.Values.CopyTo(ret, 0);
            Array.Sort(ret);
            return(ret.GetEnumerator());
        }
Esempio n. 2
0
 public void loadCurrentLocationFromMDbgThread(MDbgThread mdbgThread)
 {
      
     functionName = (mdbgThread.CurrentFrame != null && mdbgThread.CurrentFrame.Function != null)
                        ? mdbgThread.CurrentFrame.Function.FullName
                        : "";
     //mdbgsourcePosition = mdbgThread.BottomFrame.SourcePosition;
     loadDataFromMDbgSourcePosition(mdbgThread.BottomFrame.SourcePosition);            
 }
 internal void UnRegister(CorDebug.CorThread t)
 {
     m_items.Remove(t.Id);
     if (m_active != null &&
         m_active.CorThread.Id == t.Id)
     {
         m_active = null;
     }
 }
 internal void SetActiveThread(CorDebug.CorThread thread)
 {
     if (thread == null)
     {
         m_active = null;
     }
     else
     {
         m_active = GetThreadFromThreadId(thread.Id);
     }
     lock (m_process)
     {
         m_frameFactory.InvalidateStackWalkers(); // @TODO can this line be removed???
     }
 }
Esempio n. 5
0
        public O2MDbgThread(MDbgThread mdbgThread) : this()
        {
            MdbgThread = mdbgThread;            
            Id = mdbgThread.Id;
            Number = mdbgThread.Number;
            HaveCurrentFrame = mdbgThread.HaveCurrentFrame;            
            currentLocation = new O2MDbgCurrentLocation(mdbgThread.CurrentSourcePosition);
            if (mdbgThread.CurrentException != null && mdbgThread.CurrentException.IsNull == false)
            {
                currentException = mdbgThread.CurrentException.GetStringValue(false);
                currentException_expandedView = mdbgThread.CurrentException.GetStringValue(true);
            }
            calculateStackTrace();

            o2MDbgvariables = DI.o2MDbg.sessionData.getCurrentFrameVariables(0 /*expandDepth*/, false /*canDoFunceval*/);
        }
Esempio n. 6
0
 internal void UnRegister(CorDebug.CorThread t)
 {
     m_items.Remove(t.Id);
     if (m_active != null &&
         m_active.CorThread.Id == t.Id)
     {
         m_active = null;
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Creates a new stack walker object.
 /// </summary>
 /// <param name="factory">FrameFactory owning this walker</param>
 /// <param name="thread">Thread associated with the stackwalker</param>
 public MDbgV2StackWalker(MDbgFrameFactoryBase factory, MDbgThread thread)
     : base(factory, thread)
 {
 }
Esempio n. 8
0
 /// <summary>
 /// Creates a stack walker and associates the walker with the frame factory and a thread.
 /// </summary>
 /// <param name="factory">FrameFactory that created the stackwalker</param>
 /// <param name="thread">Thread associated the the stack walker</param>
 protected MDbgStackWalkerBase(MDbgFrameFactoryBase factory, MDbgThread thread)
 {
     m_thread = thread;
     m_factory = factory;
     m_logicalStopClock = factory.m_logicalStopClock;
 }
Esempio n. 9
0
 public O2MDbgCurrentLocation(MDbgThread mdbgThread) : this()
 {
     loadCurrentLocationFromMDbgThread(mdbgThread);
     raiseOnBreakEvent();
 }
Esempio n. 10
0
 /// <summary>
 /// Creates an instance of class MDbgFramebase.
 /// </summary>
 /// <param name="thread"></param>
 protected MDbgFrameBase(MDbgThread thread)
 {
     Debug.Assert(thread != null);
     m_thread = thread;
 }
 /// <summary>
 /// Creates a stack walker and associates the walker with the frame factory and a thread.
 /// </summary>
 /// <param name="factory">FrameFactory that created the stackwalker</param>
 /// <param name="thread">Thread associated the the stack walker</param>
 protected MDbgStackWalkerBase(MDbgFrameFactoryBase factory, MDbgThread thread)
 {
     m_thread           = thread;
     m_factory          = factory;
     m_logicalStopClock = factory.m_logicalStopClock;
 }
Esempio n. 12
0
 // Helper to set the debug state and ignore certain errors. 
 // Throws on error.
 private static void SetDebugStateWrapper(MDbgThread t, CorDebugThreadState newState)
 {
     try
     {
         t.CorThread.DebugState = newState;
     }
     catch (COMException e)
     {
         if (e.ErrorCode == (int) HResult.CORDBG_E_BAD_THREAD_STATE) // CORDBG_E_BAD_THREAD_STATE
         {
             WriteOutput(MDbgOutputConstants.Ignore, "Warning: Thread " + t.Id + " can't be set to " + newState);
             return; // thread is unavailable, ignore it
         }
         throw; // let error propogate up.
     }
 }
Esempio n. 13
0
        private static string GetThreadStateDescriptionString(MDbgThread thread)
        {
            CorThread t = thread.CorThread;
            var debuggerState = new StringBuilder();
            var clientState = new StringBuilder();

            if (t.DebugState == CorDebugThreadState.THREAD_SUSPEND)
                debuggerState.Append("(SUSPENDED)");

            try
            {
                CorDebugUserState userState = t.UserState;

                if ((userState & CorDebugUserState.USER_SUSPENDED) != 0)
                    clientState.Append("user suspended");

                if ((userState & CorDebugUserState.USER_WAIT_SLEEP_JOIN) != 0)
                {
                    if (clientState.Length > 0)
                        clientState.Append(", ");
                    clientState.Append("waiting");
                }
            }
            catch (COMException e)
            {
                if (e.ErrorCode != (int) HResult.CORDBG_E_BAD_THREAD_STATE)
                    throw;

                clientState.Append("in bad thread state");
            }

            StringBuilder result = debuggerState;
            if (clientState.Length > 0)
            {
                if (result.Length > 0)
                    result.Append(" ");
                result.Append("[").Append(clientState.ToString()).Append("]");
            }
            return result.ToString();
        }
Esempio n. 14
0
            public void SetThreadNickName(string nickName, MDbgThread thread)
            {
                Debug.Assert(thread != null);
                if (thread == null) throw new ArgumentException();
                {
                    NickNamesHash.Remove(GetNickNameFromThreadNumber(thread.Number)); // remove old nick-name, if any
                }
                if (nickName == null || nickName.Length == 0)
                {
                    return; // we just want to remove nickname
                }

                if (IsNumber(nickName))
                {
                    throw new MDbgShellException("invalid nickname");
                }

                if (NickNamesHash.ContainsKey(nickName))
                {
                    throw new MDbgShellException("nickname already exists");
                }
                NickNamesHash.Add(nickName, Debugger.Processes.Active.Threads.Active.Number);
            }
Esempio n. 15
0
 public string GetThreadName(MDbgThread thread)
 {
     Debug.Assert(thread != null);
     if (thread == null)
     {
         throw new ArgumentException();
     }
     string nick = GetNickNameFromThreadNumber(thread.Number);
     if (nick.Length == 0)
     {
         // no nick name
         return thread.Number.ToString(CultureInfo.InvariantCulture);
     }
     else
     {
         return nick;
     }
 }
 internal MDbgILFrame(MDbgThread thread, CorFrame frame)
     : base(thread)
 {
     Debug.Assert(frame != null);
     m_frame = frame;
 }
 /// <summary>
 /// Creates an instance of class MDbgFramebase.
 /// </summary>
 /// <param name="thread"></param>
 protected MDbgFrameBase(MDbgThread thread)
 {
     Debug.Assert(thread != null);
     m_thread = thread;
 }
Esempio n. 18
0
 internal void Clear()
 {
     m_items.Clear();
     m_active = null;
     m_freeThreadNumber = 0;
 }
Esempio n. 19
0
 internal void SetActiveThread(CorDebug.CorThread thread)
 {
     if (thread == null)
     {
         m_active = null;
     }
     else
     {
         m_active = GetThreadFromThreadId(thread.Id);
     }
     lock (m_process)
     {
         m_frameFactory.InvalidateStackWalkers(); // @TODO can this line be removed???
     }
 }
 /// <summary>
 /// Creates a new V2 StackWalker.
 /// </summary>
 /// <param name="thread">a thread object associated with the stackwalker</param>
 /// <returns>object implementing MDbgStackWalker interface</returns>
 public override IMDbgStackWalker CreateStackWalker(MDbgThread thread)
 {
     return(new MDbgV2StackWalker(this, thread));
 }
Esempio n. 21
0
 internal MDbgILFrame(MDbgThread thread, CorFrame frame)
     : base(thread)
 {
     Debug.Assert(frame != null);
     m_frame = frame;
 }
Esempio n. 22
0
 /// <summary>
 /// Create a new instance of the ThreadCreatedStopReason class.
 /// </summary>
 /// <param name="thread">The thread that has been created.</param>
 public ThreadCreatedStopReason(MDbgThread thread)
 {
     Debug.Assert(thread != null);
     m_thread = thread;
 }
 /// <summary>
 /// Creates a new stack walker object.
 /// </summary>
 /// <param name="factory">FrameFactory owning this walker</param>
 /// <param name="thread">Thread associated with the stackwalker</param>
 public MDbgV2StackWalker(MDbgFrameFactoryBase factory, MDbgThread thread)
     : base(factory, thread)
 {
 }
 internal void Clear()
 {
     m_items.Clear();
     m_active           = null;
     m_freeThreadNumber = 0;
 }
        private string PrintObject(int indentLevel, CorDebug.CorObjectValue ov, int expandDepth, bool canDoFunceval)
        {
            Debug.Assert(expandDepth >= 0);

            // Print generics-aware type.
            string name = InternalUtil.PrintCorType(m_process, ov.ExactType);

            var txt = new StringBuilder();

            txt.Append(name);

            if (expandDepth > 0)
            {
                // we gather the field info of the class before we do
                // funceval since funceval requires running the debugger process
                // and this in turn can cause GC and invalidate our references.
                var expandedDescription = new StringBuilder();
                if (IsComplexType)
                {
                    foreach (MDbgValue v in GetFields())
                    {
                        expandedDescription.Append("\n").Append(IndentedString(indentLevel + 1, v.Name)).
                        Append("=").Append(IndentedBlock(indentLevel + 2,
                                                         v.GetStringValue(expandDepth - 1, false)));
                    }
                }

                if (ov.IsValueClass && canDoFunceval)
                // we could display even values for real Objects, but we will just show
                // "description" for valueclasses.
                {
                    CorDebug.CorClass cls      = ov.ExactType.Class;
                    CorMetadataImport importer = m_process.Modules.Lookup(cls.Module).Importer;
                    var mdType = importer.GetType(cls.Token) as MetadataType;

                    if (mdType.ReallyIsEnum)
                    {
                        txt.AppendFormat(" <{0}>", InternalGetEnumString(ov, mdType));
                    }
                    else if (m_process.IsRunning)
                    {
                        txt.Append(" <N/A during run>");
                    }
                    else
                    {
                        MDbgThread activeThread = m_process.Threads.Active;

                        CorDebug.CorValue     thisValue;
                        CorDebug.CorHeapValue hv = ov.CastToHeapValue();
                        if (hv != null)
                        {
                            // we need to pass reference value.
                            CorDebug.CorHandleValue handle = hv.CreateHandle(CorDebugHandleType.HANDLE_WEAK_TRACK_RESURRECTION);
                            thisValue = handle;
                        }
                        else
                        {
                            thisValue = ov;
                        }

                        try
                        {
                            CorDebug.CorEval eval = m_process.Threads.Active.CorThread.CreateEval();
                            m_process.CorProcess.SetAllThreadsDebugState(CorDebugThreadState.THREAD_SUSPEND,
                                                                         activeThread.CorThread);

                            MDbgFunction toStringFunc =
                                m_process.ResolveFunctionName(null, "System.Object", "ToString"
                                                              , thisValue.ExactType.Class.Module.Assembly.AppDomain);
                            Debug.Assert(toStringFunc != null);
                            // we should be always able to resolve ToString function.

                            eval.CallFunction(toStringFunc.CorFunction, new[] { thisValue });
                            m_process.Go();
                            do
                            {
                                m_process.StopEvent.WaitOne();
                                if (m_process.StopReason is EvalCompleteStopReason)
                                {
                                    CorDebug.CorValue cv = eval.Result;
                                    Debug.Assert(cv != null);
                                    var    mv      = new MDbgValue(m_process, cv);
                                    string valName = mv.GetStringValue(0);

                                    // just purely for esthetical reasons we 'discard' "
                                    if (valName.StartsWith("\"") && valName.EndsWith("\""))
                                    {
                                        valName = valName.Substring(1, valName.Length - 2);
                                    }

                                    txt.Append(" <").Append(valName).Append(">");
                                    break;
                                }
                                if ((m_process.StopReason is ProcessExitedStopReason) ||
                                    (m_process.StopReason is EvalExceptionStopReason))
                                {
                                    txt.Append(" <N/A cannot evaluate>");
                                    break;
                                }
                                // hitting bp or whatever should not matter -- we need to ignore it
                                m_process.Go();
                            } while (true);
                        }
                        catch (COMException e)
                        {
                            // Ignore canot copy a VC class error - Can't copy a VC with object refs in it.
                            if (e.ErrorCode != (int)CorDebug.HResult.CORDBG_E_OBJECT_IS_NOT_COPYABLE_VALUE_CLASS)
                            {
                                throw;
                            }
                        }
                        finally
                        {
                            // we need to resume all the threads that we have suspended no matter what.
                            m_process.CorProcess.SetAllThreadsDebugState(CorDebugThreadState.THREAD_RUN,
                                                                         activeThread.CorThread);
                        }
                    }
                }
                txt.Append(expandedDescription.ToString());
            }
            return(txt.ToString());
        }
 /// <summary>
 /// Creates a new StackWalker.
 /// </summary>
 /// <param name="thread">a thread object associated with the stackwalker</param>
 /// <returns>object implementing MDbgStackWalker interface</returns>
 public abstract IMDbgStackWalker CreateStackWalker(MDbgThread thread);
        // Update list w/ current callstack. Return an array of FramePair representing the callstack.
        // Run on worker thread.
        private static FramePair[] GetFrameList(MDbgThread thread)
        {
            // Populate listbox with frames.
            MDbgFrame f = thread.BottomFrame;
            MDbgFrame af = thread.HaveCurrentFrame ? thread.CurrentFrame : null;

            var l = new ArrayList();

            int i = 0;
            int depth = 20;
            bool verboseOutput = true;

            while (f != null && (depth == 0 || i < depth))
            {
                string line;
                if (f.IsInfoOnly)
                {
                    line = string.Format(CultureInfo.InvariantCulture, "[{0}]", f);
                }
                else
                {
                    string frameDescription = "<unknown>";
                    try
                    {
                        // Get IP info.
                        uint ipNative;
                        uint ipIL;
                        CorDebugMappingResult result;
                        f.CorFrame.GetNativeIP(out ipNative);
                        f.CorFrame.GetIP(out ipIL, out result);
                        string frameLocation = String.Format(CultureInfo.InvariantCulture,
                                                             " N=0x{0:x}, IL=0x{1:x} ({2})",
                                                             ipNative, ipIL, result);


                        // This may actually do a ton of work, including evaluating parameters.
                        frameDescription = f.ToString(verboseOutput ? "v" : null) + frameLocation;
                    }
                    catch (COMException)
                    {
                        if (f.Function != null)
                        {
                            frameDescription = f.Function.FullName;
                        }
                    }

                    line = string.Format(CultureInfo.InvariantCulture, "{0}{1}. {2}", f.Equals(af) ? "*" : " ", i,
                                         frameDescription);
                    ++i;
                }
                l.Add(new FramePair(f, line));
                f = f.NextUp;
            }
            if (f != null && depth != 0) // means we still have some frames to show....
            {
                l.Add(new FramePair(null,
                                    string.Format(CultureInfo.InvariantCulture,
                                                  "displayed only first {0} frames. For more frames use -c switch",
                                                  depth)
                          ));
            }

            return (FramePair[]) l.ToArray(typeof (FramePair));
        }
Esempio n. 28
0
 /// <summary>
 /// Create a new instance of the ThreadCreatedStopReason class.
 /// </summary>
 /// <param name="thread">The thread that has been created.</param>
 public ThreadCreatedStopReason(MDbgThread thread)
 {
     Debug.Assert(thread != null);
     m_thread = thread;
 }
Esempio n. 29
0
 /// <summary>
 /// Creates a new V2 StackWalker.
 /// </summary>
 /// <param name="thread">a thread object associated with the stackwalker</param>
 /// <returns>object implementing MDbgStackWalker interface</returns>
 public override IMDbgStackWalker CreateStackWalker(MDbgThread thread)
 {
     return new MDbgV2StackWalker(this, thread);
 }
        public static void InternalWhereCommand(MDbgThread thread, int depth, bool verboseOutput)
        {
            if (thread != null)
            {                

                CommandBase.WriteOutput("Thread [#:" + MdbgCommands.g_threadNickNames.GetThreadName(thread) + "]");

                MDbgFrame af = thread.HaveCurrentFrame ? thread.CurrentFrame : null;
                MDbgFrame f = thread.BottomFrame;
                int i = 0;
                while (f != null && (depth == 0 || i < depth))
                {
                    string line;
                    if (f.IsInfoOnly)
                    {
                        if (!CommandBase.ShowInternalFrames)
                        {
                            // in cases when we don't want to show internal frames, we'll skip them
                            f = f.NextUp;
                            continue;
                        }
                        line = String.Format(CultureInfo.InvariantCulture, "    {0}", f);
                    }
                    else
                    {
                        string frameDescription = f.ToString(verboseOutput ? "v" : null);
                        line = String.Format(CultureInfo.InvariantCulture, "{0}{1}. {2}", f.Equals(af) ? "*" : " ", i,
                                             frameDescription);
                        ++i;
                    }
                    CommandBase.WriteOutput(line);
                    f = f.NextUp;
                }
                if (f != null && depth != 0) // means we still have some frames to show....
                {
                    CommandBase.WriteOutput(String.Format(CultureInfo.InvariantCulture,
                                                          "displayed only first {0} frames. For more frames use -c switch",
                                                          depth));
                }
            }
        }
Esempio n. 31
0
 /// <summary>
 /// Creates a new StackWalker.
 /// </summary>
 /// <param name="thread">a thread object associated with the stackwalker</param>
 /// <returns>object implementing MDbgStackWalker interface</returns>
 public abstract IMDbgStackWalker CreateStackWalker(MDbgThread thread);
Esempio n. 32
0
 IEnumerator IEnumerable.GetEnumerator()
 {
     var ret = new MDbgThread[m_items.Count];
     m_items.Values.CopyTo(ret, 0);
     Array.Sort(ret);
     return ret.GetEnumerator();
 }