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 ?
Yes, set a breakpoint in the function
_RtlExitUserThread@4, and add a condition of*(int*)(ESP+4) == 42to test if the exit status is a particular value (42, in this example); for 64-bit programs, useESP+8instead ofESP+4.However, if the thread exited by returning from its main thread procedure (the usual case) instead of directly calling
ExitThreador 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@4is an implementation detail that might change in future versions of Windows;_RtlExitUserThread@4is the name on Windows 7. To find out what the actual is on your system, rundumpbin /exports C:\Windows\system32\kernel32.dlland look for the name thatExitThreadmaps to.