您的位置:首页 > 运维架构 > Linux

Vs2013在Linux开发中的应用(31):内存块显示

2015-01-07 18:29 525 查看
快乐虾http://blog.csdn.net/lights_joy/欢迎转载,但请保留作者信息

要实现内存块的显示,需要实现IDebugMemoryBytes2接口,类似这样的:

class AD7MemoryBytes : IDebugMemoryBytes2
    {
        private AD7Engine _engine;
        public AD7Engine Engine { get { return _engine; } }

        public AD7MemoryBytes(AD7Engine engine)
        {
            _engine = engine;
        }
        public int GetSize(out ulong pqwSize)
        {
            throw new NotImplementedException();
        }

        public int ReadAt(IDebugMemoryContext2 pStartContext, uint dwCount, byte[] rgbMemory, out uint pdwRead, ref uint pdwUnreadable)
        {
            AD7MemoryAddress addr = pStartContext as AD7MemoryAddress;
            pdwRead = dwCount;
            pdwUnreadable = 0;
            return Constants.S_OK;
        }

        public int WriteAt(IDebugMemoryContext2 pStartContext, uint dwCount, byte[] rgbMemory)
        {
            throw new NotImplementedException();
        }

当VS显示内存窗口时,会调用:
// The memory bytes as represented by the IDebugMemoryBytes2 object is for the program's image in memory and not any memory 
        // that was allocated when the program was executed.
        public int GetMemoryBytes(out IDebugMemoryBytes2 ppMemoryBytes)
        {
            ppMemoryBytes = new AD7MemoryBytes(this);
            return Constants.S_OK;
        }

这里仅仅实现了一个空接口,并没有实现内存实际值的刷新,但此时已经可以在IDE中看到这样的效果了:


在读取数据的接口中使用gdb的-data-read-memory实际读取数据并填充后就成了这样:


搞定!


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: