Exemple #1
0
        private MemSnapshot BuildSnapshotForFrame(int frame)
        {
            MemSnapshot snapshot      = new MemSnapshot();
            int         numOperations = m_memOperations.Count;
            int         frames        = 0;

            for (int i = 0; i < numOperations; ++i)
            {
                MemOperation op = m_memOperations[i];
                if (op.OpType == MemOperation.Type.Alloc)
                {
                    snapshot.AddBlock(op.UserData as MemBlock);
                }
                else if (op.OpType == MemOperation.Type.Free)
                {
                    snapshot.RemoveBlock((ulong)op.UserData);
                }
                else if (op.OpType == MemOperation.Type.FrameEnd)
                {
                    ++frames;
                }

                if (frames > frame)
                {
                    break;
                }
            }
            m_lastSnapshotViewFrame = frame;
            return(snapshot);
        }
Exemple #2
0
        private void HandleAlloc(byte[] msgData)
        {
            MemBlock memBlock    = new MemBlock();
            int      addressSize = 4;

            if (m_64bit)
            {
                addressSize = 8;
            }

            memBlock.m_address = GetAddress(msgData, 1);
            memBlock.m_size    = GetInt(msgData, 1 + addressSize);
            memBlock.m_tag     = GetInt(msgData, 1 + addressSize + 4);
            int stackDepth = (int)msgData[1 + addressSize + 8];

            System.Diagnostics.Debug.Assert(stackDepth > 0 && stackDepth < 100);
            ulong[] callStack      = new ulong[stackDepth];
            int     callstackStart = 1 + addressSize + 9;

            for (int i = 0; i < stackDepth; ++i)
            {
                callStack[i] = GetAddress(msgData, callstackStart + i * addressSize);
            }
            memBlock.m_callStackCRC = CallstackTab.CalcCRC(callStack);
            CallstackTab.AddCallStack(memBlock.m_callStackCRC, callStack);

            if (m_initialized)
            {
                MemOperation op = new MemOperation(MemOperation.Type.Alloc);
                op.UserData = memBlock;
                m_memOperations.Add(op);
                m_globalSnapshot.AddBlock(memBlock);
                if (memBlock.m_size < 65536)
                {
                    ++m_mostAllocatedBlocks[memBlock.m_size];
                }
            }
            m_dirty = true;
        }
Exemple #3
0
        MemSnapshot BuildSnapshotFromDesc(SnapshotDesc desc)
        {
            MemSnapshot snapshot      = new MemSnapshot();
            int         numOperations = desc.memOperationNr;

            if (numOperations > m_memOperations.Count)
            {
                numOperations = m_memOperations.Count;
            }
            for (int i = 0; i < numOperations; ++i)
            {
                MemOperation op = m_memOperations[i];
                if (op.OpType == MemOperation.Type.Alloc)
                {
                    snapshot.AddBlock(op.UserData as MemBlock);
                }
                else if (op.OpType == MemOperation.Type.Free)
                {
                    snapshot.RemoveBlock((ulong)op.UserData);
                }
            }

            return(snapshot);
        }
Exemple #4
0
        private void HandleMessage(byte[] msgData)
        {
            SocketPacket.CommandID commandId = (SocketPacket.CommandID)(msgData[0]);
            switch (commandId)
            {
            case SocketPacket.CommandID.INITIAL_SETTINGS:
            {
                ClientPlatform.Platform platform = (ClientPlatform.Platform)msgData[1];

                //if (platform == 2)
                //{
                //    PS3StackTracer ps3tracer = new PS3StackTracer(m_config.PS3BinPath,
                //                                    m_config.Verbose, m_config.UseCr,
                //                                    m_config.UseError);
                //    StackTracer = ps3tracer;
                //}

                m_64bit = (platform == ClientPlatform.Platform.WINDOWS_64);
                if (m_64bit)
                {
                    m_addressSize = 8;
                }

                m_maxTagLen           = (int)msgData[2];
                m_maxSnapshotNameLen  = (int)msgData[3];
                m_maxTracedVarNameLen = (int)msgData[4];
                System.Diagnostics.Debug.Assert(m_maxTagLen > 0);
                System.Diagnostics.Debug.Assert(m_maxSnapshotNameLen > 0);
                System.Diagnostics.Debug.Assert(m_maxTracedVarNameLen > 0);
                break;
            }

            case SocketPacket.CommandID.MODULE_INFO:
            {
                ulong modBase = GetAddress(msgData, 1);
                int   offset  = 1 + m_addressSize;

                ulong modSize = GetInt(msgData, offset);
                offset += 4;

                string debugFileName = GetStringFromBuffer(msgData, offset, 128);
                Invoke(m_delegateAddModuleInfo, new Object[] { debugFileName, modBase, modSize });
                m_initialized = true;
                break;
            }

            case SocketPacket.CommandID.ALLOC:
            {
                HandleAlloc(msgData);
                break;
            }

            case SocketPacket.CommandID.FREE:
            {
                ulong        addr = GetAddress(msgData, 1);
                MemOperation op   = new MemOperation(MemOperation.Type.Free);
                op.UserData = addr;
                m_memOperations.Add(op);
                m_globalSnapshot.RemoveBlock(addr);
                m_dirty = true;

//                        System.Console.Out.WriteLine("Free " + addr.ToString("X") + " " + (m_memOperations.Count - 1));

                break;
            }

            case SocketPacket.CommandID.TAG_BLOCK:
            {
                ulong  addr = GetInt(msgData, 1);
                string tag  = GetStringFromBuffer(msgData, (1 + m_addressSize), m_maxTagLen);
                ulong  crc  = TagDict.AddTag(tag);
                m_globalSnapshot.TagBlock(addr, crc);
                break;
            }

            case SocketPacket.CommandID.FRAME_END:
            {
                // Only add frame end marker if something interesting happened in this frame.
                // Otherwise we'd be just wasting memory.
                if (m_numMemOpsPrevFrame < m_memOperations.Count)
                {
                    MemOperation op = new MemOperation(MemOperation.Type.FrameEnd);
                    m_memOperations.Add(op);
                    ++m_frame;
                    ++m_numFrames;
                }
                m_numMemOpsPrevFrame = m_memOperations.Count;
                break;
            }

            case SocketPacket.CommandID.ADD_SNAPSHOT:
            {
                string snapshotName = GetStringFromBuffer(msgData, 1, m_maxSnapshotNameLen);

                //System.Console.Out.WriteLine("Snapshot " + snapshotName);

                SnapshotDesc desc = CreateSnapshotDesc(snapshotName);
                Invoke(m_delegateAddSnapshot, desc);

                break;
            }

            case SocketPacket.CommandID.TRACED_VAR:
            {
                int    tracedVarValue = (int)GetInt(msgData, 1);
                string tracedVarName  = GetStringFromBuffer(msgData, 5, m_maxTracedVarNameLen);

                SetTracedVar(tracedVarName, tracedVarValue);

                break;
            }

            default:
            {
                System.Diagnostics.Debug.Fail("Unknown command ID: " + commandId);
                break;
            }
            }
        }