我可以在Visual Studio(c ++)中设置断点以在线程上下文切换时中断吗? [英] Can I set a breakpoint in Visual Studio (c++) to break on a thread context switch?

查看:180
本文介绍了我可以在Visual Studio(c ++)中设置断点以在线程上下文切换时中断吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们只想打断某个线程.任何想法如何做到这一点?我似乎找不到解决这种情况的方法.

We want to only break in a certain thread. Any idea how to do that? I can't seem to find a way to break on that condition.

我应该在文本中更具体地说明.顾名思义,我想将上下文切换中断到线程中.

I should have been more specific in the text. As the title suggests, I would like to break on the context switch into the thread.

推荐答案

如果有一种在用户模式调试器中执行此操作的方法,我会感到惊讶.

I'd be surprised if there were a way to do this in a user-mode debugger.

想象:您为线程42接通时设置了一个断点.该断点命中.调试器已激活.现在激活了另一个线程,并且线程42不再处于活动状态!

Imagine: you set a breakpoint for when thread 42 gets switched in. The breakpoint hits. The debugger is activated. Now a different thread is activated, and thread 42 is no longer active!

我建议您尝试从 Sysinternals (现已成为Microsoft的一部分).您可以将其限制为仅捕获线程和进程事件,从而产生如下内容:

I suggest you try Process Monitor from Sysinternals (now part of Microsoft). You can limit it to only capture thread and process events, producing something like the following:

20:43:51.9162409    lsass.exe   440 Thread Create       SUCCESS Thread ID: 5420
20:43:51.9166730    lsass.exe   440 Thread Create       SUCCESS Thread ID: 7916
20:43:53.2990544    svchost.exe 736 Thread Create       SUCCESS Thread ID: 5540
20:43:53.7664146    svchost.exe 736 Thread Create       SUCCESS Thread ID: 7384
20:43:53.7985662    svchost.exe 736 Thread Create       SUCCESS Thread ID: 1888
20:43:54.2444922    wmiprvse.exe    3144    Thread Create       SUCCESS Thread ID: 6300
20:43:54.2466447    svchost.exe 736 Thread Create       SUCCESS Thread ID: 5636
20:43:54.2480367    wmiprvse.exe    3144    Thread Create       SUCCESS Thread ID: 6624
20:43:54.2515443    svchost.exe 736 Thread Create       SUCCESS Thread ID: 7392
20:43:55.5332047    devenv.exe  4640    Thread Exit     SUCCESS Thread ID: 4696, User Time: 0.0000000, Kernel Time: 0.0000000
20:43:55.9179052    Explorer.EXE    3176    Process Create  C:\WINDOWS\system32\verclsid.exe    SUCCESS PID: 3356, Command line: /S /C {2559A1F4-21D7-11D4-BDAF-00C04F60B9F0} /I {000214E6-0000-0000-C000-000000000046} /X 0x401
20:43:55.9179079    verclsid.exe    3356    Process Start       SUCCESS Parent PID: 3176
20:43:55.9179101    verclsid.exe    3356    Thread Create       SUCCESS Thread ID: 7108
20:43:55.9354621    verclsid.exe    3356    Thread Create       SUCCESS Thread ID: 940
20:43:55.9521113    verclsid.exe    3356    Thread Create       SUCCESS Thread ID: 2704
20:43:56.5259637    verclsid.exe    3356    Thread Exit     SUCCESS Thread ID: 2704, User Time: 0.0000000, Kernel Time: 0.0000000

您还可以进行其他各种过滤,这应该使您能够在发现问题之前甚至在生产中都保持实用程序的运行.

You can do all sorts of other filtering as well, which should allow you to keep the utility running until the problem occurs, even in production.

这篇关于我可以在Visual Studio(c ++)中设置断点以在线程上下文切换时中断吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆