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

Vs2013在Linux开发中的应用(27):线程列表

2015-01-02 12:09 543 查看
快乐虾http://blog.csdn.net/lights_joy/欢迎转载,但请保留作者信息

在gdb加载应用程序并运行时,可以检测到线程的创建,我们将此消息以事件的形式通知了SDM。因此当中断发生时,对于每一个线程,VS的SDM将调用我们的回调:
// Retrieves a list of the stack frames for this thread.
        // We currently call into the process and get the frames.  We might want to cache the frame info.
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 enumObject) {
            if(_debuggedThread.Id == -1)
            {
                enumObject = null;
                return VSConstants.E_FAIL;
            }

            IList<PythonStackFrame> stackFrames = new List<PythonStackFrame>();
            string info = _debuggedThread.Process.ExecCommand("-thread-select " + _debuggedThread.Id.ToString());
            int depth = GetStackInfoDepth();
            for (int i = 0; i < depth; i++ )
            {
                PythonStackFrame frm = GetStackInfo(i);
                stackFrames.Add(frm);
            }

            _debuggedThread.Frames = stackFrames;

            int numStackFrames = stackFrames.Count;
            FRAMEINFO[] frameInfoArray;

            frameInfoArray = new FRAMEINFO[numStackFrames];

            for (int i = 0; i < numStackFrames; i++) {
                AD7StackFrame frame = new AD7StackFrame(_engine, this, stackFrames[i]);
                frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
            }

            enumObject = new AD7FrameInfoEnum(frameInfoArray);
            return VSConstants.S_OK;
        }
在此我们填上了此线程中的栈信息,而后SDM还将针对栈的每一层调用查询更进一步的信息,如局部变量、函数参数等,按照接口的要求返回之后就可以在VS下看到线程列表的信息了:



双击可以查看线程的栈列表:


这里存在的一个问题是速度,当线程比较多的时候(44个),刷新一次居然要将近5秒,看来需要改进gdb命令调用的方式。


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