Is it possible to break on thread exit with specific error code?

谁都会走 提交于 2019-12-09 09:33:53

问题


I was wondering if it was possible to configure visual studio 2008 debugger to stop execution when a thread exits with a precise error code (or at least any non-zero value). My app use a tremendous number of threads, so it's impossible to track them all manually.

Is there a way to tell VS2008 to break when ANY thread in the program hits "exit(X);" (X being different from 0) and display source ?


回答1:


Yes, set a breakpoint in the function _RtlExitUserThread@4, and add a condition of *(int*)(ESP+4) == 42 to test if the exit status is a particular value (42, in this example); for 64-bit programs, use ESP+8 instead of ESP+4.

However, if the thread exited by returning from its main thread procedure (the usual case) instead of directly calling ExitThread or one of its wrappers, then you won't have any information about what thread it was or what caused it to exit other than the exit status and the thread ID.

Note: The function name _RtlExitUserThread@4 is an implementation detail that might change in future versions of Windows; _RtlExitUserThread@4 is the name on Windows 7. To find out what the actual is on your system, run dumpbin /exports C:\Windows\system32\kernel32.dll and look for the name that ExitThread maps to.



来源:https://stackoverflow.com/questions/13163785/is-it-possible-to-break-on-thread-exit-with-specific-error-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!