Exemplo n.º 1
0
        /// <summary>
        /// Gets the timestamp and size of the module.
        /// </summary>
        /// <param name="module">The module.</param>
        public Tuple<DateTime, ulong> GetModuleTimestampAndSize(Module module)
        {
            ulong baseAddress = module.Address;

            using (var moduleParameters = new RegularMarshalArrayReader<DEBUG_MODULE_PARAMETERS>(1))
            {
                DateTime timestamp;
                ulong size;

                Symbols.GetModuleParameters(1, ref baseAddress, 0, moduleParameters.Pointer);
                var mp = moduleParameters.Elements.First();
                size = mp.Size;
                timestamp = new DateTime(1970, 1, 1) + TimeSpan.FromSeconds(mp.TimeDateStamp);
                return Tuple.Create(timestamp, size);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the stack trace from the specified context.
        /// </summary>
        /// <param name="thread">The thread.</param>
        /// <param name="contextAddress">The context address.</param>
        /// <param name="contextSize">Size of the context.</param>
        /// <returns></returns>
        private StackTrace GetStackTraceFromContext(Thread thread, IntPtr contextAddress, uint contextSize)
        {
            #if false
            if (thread.Process.DumpFileMemoryReader != null)
            {
                if (contextAddress == IntPtr.Zero)
                {
                    using (ThreadSwitcher switcher = new ThreadSwitcher(StateCache, thread))
                    using (MarshalArrayReader<ThreadContext> threadContextBuffer = ThreadContext.CreateArrayMarshaler(thread.Process, 1))
                    {
                        Advanced.GetThreadContext(threadContextBuffer.Pointer, (uint)(threadContextBuffer.Count * threadContextBuffer.Size));
                        return ReadStackTraceFromContext(thread, threadContextBuffer.Pointer);
                    }
                }
                else
                {
                    return ReadStackTraceFromContext(thread, contextAddress);
                }
            }
            #endif

            const int MaxCallStack = 10240;
            using (ThreadSwitcher switcher = new ThreadSwitcher(StateCache, thread))
            using (MarshalArrayReader<_DEBUG_STACK_FRAME_EX> frameBuffer = new RegularMarshalArrayReader<_DEBUG_STACK_FRAME_EX>(MaxCallStack))
            using (MarshalArrayReader<ThreadContext> threadContextBuffer = ThreadContext.CreateArrayMarshaler(thread.Process, MaxCallStack))
            {
                uint framesCount;

                Control.GetContextStackTraceEx(contextAddress, contextSize, frameBuffer.Pointer, (uint)frameBuffer.Count, threadContextBuffer.Pointer, (uint)(threadContextBuffer.Size * threadContextBuffer.Count), (uint)threadContextBuffer.Size, out framesCount);
                return new StackTrace(thread, frameBuffer.Elements.Take((int)framesCount).ToArray(), threadContextBuffer.Elements.Take((int)framesCount).ToArray());
            }
        }