public void Return_The_Correct_StackTrace()
        {
            // arrange
            var dumpThread = new DumpThread();
            var items      = new[]
            {
                new DumpStackFrame
                {
                    DisplayString = "Foo()"
                },
                new DumpStackFrame
                {
                    DisplayString = "Bar()"
                }
            };

            foreach (var dumpStackFrame in items)
            {
                dumpThread.ManagedStackFramesInternal.Add(dumpStackFrame);
            }

            // act
            // assert
            dumpThread.StackTrace.Should().Be("Foo()\nBar()");
            dumpThread.StackTrace.Should().Be("Foo()\nBar()");
        }
Example #2
0
        public ulong GetThreadTeb(uint id)
        {
            DumpThread thread = _dumpReader.GetThread((int)id);

            if (thread == null)
            {
                return(0);
            }

            return(thread.Teb);
        }
Example #3
0
        public bool GetThreadContext(uint id, uint contextFlags, uint contextSize, IntPtr context)
        {
            DumpThread thread = _dumpReader.GetThread((int)id);

            if (thread == null)
            {
                return(false);
            }

            thread.GetThreadContext(context, (int)contextSize);
            return(true);
        }
        public void Add_A_Root_Only_Once()
        {
            // arrange
            var dumpThread = new DumpThread();
            var root       = new DumpObjectRoot();

            // act
            dumpThread.AddRoot(root);
            dumpThread.AddRoot(root);

            // assert
            dumpThread.Roots.Should().HaveCount(1);
        }
        public void Add_A_Blocking_Object_Only_Once()
        {
            // arrange
            var dumpThread     = new DumpThread();
            var blockingObject = new DumpBlockingObject();

            // act
            dumpThread.AddBlockingObject(blockingObject);
            dumpThread.AddBlockingObject(blockingObject);

            // assert
            dumpThread.BlockingObjects.Should().HaveCount(1);
        }
Example #6
0
        public void Add_A_Thread_Only_Once()
        {
            // arrange
            var sut    = new DumpObject();
            var thread = new DumpThread();

            // act
            sut.AddThread(thread);
            sut.AddThread(thread);

            // assert
            sut.Threads.Should().HaveCount(1);
        }
        public void Exhibit_Entity_Equality()
        {
            // arrange
            var a = new DumpThread()
            {
                OsId = 0
            };
            var b = new DumpThread
            {
                OsId = 0
            };
            var c = new DumpThread
            {
                OsId = 1
            };

            // act
            // assert
            a.GetHashCode().Should().Be(b.GetHashCode());
            a.GetHashCode().Should().NotBe(c.GetHashCode());

            a.Equals(a).Should().BeTrue();
            a.Equals(b).Should().BeTrue();
            a.Equals(c).Should().BeFalse();
            a.Equals(null).Should().BeFalse();
            a.Equals("").Should().BeFalse();
            a.CompareTo(a).Should().Be(0);
            a.CompareTo(b).Should().Be(0);
            a.CompareTo(c).Should().Be(-1);
            a.CompareTo(null).Should().Be(1);
            a.Equals((object)a).Should().BeTrue();
            a.Equals((object)b).Should().BeTrue();
            a.Equals((object)c).Should().BeFalse();
            a.Equals((object)null).Should().BeFalse();
            a.CompareTo((object)a).Should().Be(0);
            a.CompareTo((object)b).Should().Be(0);
            a.CompareTo((object)c).Should().Be(-1);
            a.CompareTo((object)null).Should().Be(1);
            (a < b).Should().BeFalse();
            (a <= b).Should().BeTrue();
            (c > a).Should().BeTrue();
            (c >= a).Should().BeTrue();
            Action throws = () => a.CompareTo("");

            throws.Should().Throw <ArgumentException>();
        }
Example #8
0
        public void Add_A_Thread_Only_Once()
        {
            // arrange
            var sut = new DumpObjectRoot
            {
                Address = 0x4000
            };
            var thread = new DumpThread
            {
                OsId = 0x40
            };

            // act
            sut.AddThread(thread);
            sut.AddThread(thread);

            // assert
            sut.Threads.Should().HaveCount(1);
        }
        /// <summary>
        ///     Creates the threads.
        /// </summary>
        public void CreateThreads()
        {
            Threads = new Dictionary <uint, DumpThread>();
            ThreadToExceptionMapping = new Dictionary <uint, ulong>();
            ThreadToRootMapping      = new Dictionary <uint, IList <ulong> >();
            ThreadToObjectMapping    = new Dictionary <uint, IList <ulong> >();
            foreach (var thread in Runtime.Threads)
            {
                var newThread = new DumpThread
                {
                    Address                = thread.Address,
                    AppDomainAddress       = thread.AppDomain,
                    GcMode                 = thread.GcMode,
                    IsAborted              = thread.IsAborted,
                    IsAbortRequested       = thread.IsAbortRequested,
                    IsAlive                = thread.IsAlive,
                    IsBackground           = thread.IsBackground,
                    IsCoinitialized        = thread.IsCoInitialized,
                    IsCreatedButNotStarted = thread.IsUnstarted,
                    IsDebuggerHelper       = thread.IsDebuggerHelper,
                    IsDebugSuspended       = thread.IsDebugSuspended,
                    IsFinalizer            = thread.IsFinalizer,
                    IsGc = thread.IsGC,
                    IsGcSuspendPending = thread.IsGCSuspendPending,
                    IsMta                      = thread.IsMTA,
                    IsShutdownHelper           = thread.IsShutdownHelper,
                    IsSta                      = thread.IsSTA,
                    IsSuspendingEe             = thread.IsSuspendingEE,
                    IsThreadpoolCompletionPort = thread.IsThreadpoolCompletionPort,
                    IsThreadpoolGate           = thread.IsThreadpoolGate,
                    IsThreadpoolTimer          = thread.IsThreadpoolTimer,
                    IsThreadpoolWait           = thread.IsThreadpoolWait,
                    IsThreadpoolWorker         = thread.IsThreadpoolWorker,
                    IsUserSuspended            = thread.IsUserSuspended,
                    LockCount                  = thread.LockCount,
                    StackLimit                 = thread.StackLimit,
                    Teb  = thread.Teb,
                    OsId = thread.OSThreadId
                };
                newThread.ManagedStackFramesInternal = thread.StackTrace.Select(x => new DumpStackFrame
                {
                    InstructionPointer = x.InstructionPointer,
                    Kind          = x.Kind,
                    ModuleName    = x.ModuleName,
                    StackPointer  = x.StackPointer,
                    Thread        = newThread,
                    DisplayString = x.DisplayString
                }).ToList();

                if (!Threads.ContainsKey(newThread.OsId))
                {
                    Threads.Add(newThread.OsId, newThread);
                }

                if (thread.CurrentException != null && !ThreadToExceptionMapping.ContainsKey(newThread.OsId))
                {
                    ThreadToExceptionMapping.Add(newThread.OsId, thread.CurrentException.Address);
                }

                if (!ThreadToObjectMapping.ContainsKey(newThread.OsId))
                {
                    var objects = thread.EnumerateStackObjects().Select(x => x.Address).ToList();
                    ThreadToObjectMapping.Add(newThread.OsId, objects);
                }
            }
        }