How to switch to the next thread in VS2010 - multithreading

When I step over (F10) in the debugger, I am staying on the thread I am currently in.
Therefore, when I step over a line of code, and the process crash in an over thread, I am not able to see in which thread it went.
As I don't know in which thread the crash is happening, I can not simply click on it in the thread window.
Do you know how to switch to "guilty" thread ?
Thanks

You can go into Debug >> Windows >> threads to see all your threads. You can also right lick on thread and select 'switch thread'.

Related

Get and suspend threads of process in CMD

I want to suspend a thread in a process and also I want to get all of the threads.
But I googled and didn't find a method to list or change it.
Example, what I mean:
dwm.exe has these threads inside: http://prntscr.com/hru52n (Opened with process explorer).
But I want to make it on cmd (.bat). I really do not know what I should do.
I would be happy if someone helps me.
Thank you!
I want to suspend a thread in a process
Why? It is not advised to do this as there is a good chance you will deadlock the process:
Q: What is the result of suspending a thread in the middle of a
threadsafe operation?
[The] Critical section never gets unlocked if you’re inside it.
Q: What happens if – subsequently – you try to access that same object
(in this case, the console) from another thread?
Deadlock…
Source Why you should never suspend a thread

Breakpoint a multi thread application

What happens if I breakpoint a multi thread application.
does it stop all the threads, just the one that is break pointed or does the whole program just crash ?
If it is possible would I want to stop just one thread or would this mess up my application ?
If I cannot break point a multi tread application what are the debug techniques available to me ?
JAVA: As far as personal experience goes, you can debug multi-threaded applications by stopping all threads or individual threads. It would most likely depend on what IDE you are using, and what application you are connecting to, but for me its:
Eclipse connecting in debug mode to a Tomcat server running in jpda
Place a breakpoint in the code, go to Eclipse's debug perspective (sometimes it pauses but doesn't switch perspective)
In the breakpoints window, you will see a list of breakpoints. Each one you can right-click and set properties on... if you want to stop all threads on one breakpoint, hit the Suspend VM radio button. If you only want to stop a single thread, click suspend thread.
I'm not sure you're able at this point to select which thread you want to pause if using the single thread stop option. In Suspend VM, you can look at the Debug pane and see your thread... scroll down and you can jump between the threads (Daemon thread 10 vs Daemon thread 9, something like that)
It stops all threads.
It is not normally possible to just stop one thread. For more information on debugging threads with GDB see this part of the manual.
Since you didn't tag your question with a specific language/platform, I'll give a Java-related answer.
In most IDEs you can set properties on your breakpoints, specifically conditional properties. So, if you know the name of your thread, you can do something like this:
"ThreadName".equals(Thread.currentThread().getName())
...and all other threads utilising the same class (where you set the breakpoint) will carry on unhindered.

Display Thread name when debugging - delphi

I've found some good questions and with good answers for naming threads in Delphi.
Like this one Named threads in Delphi - what is that for?.
But how, while debugging, I get to see the name of the thread?
And also, even with that, I cannot see the thread name in utilities like Process Explorer right?
When the execution is paused (because you trigger the pause by clicking the "pause" icon or selecting menu Run, Program Pause; or because the breakpoint is hit), the thread names are visible in the Threads window (View, Debug Windows, Threads; or Ctrl-Alt-T).
No, Process Explorer cannot show thread names.

IntelliJ - pause a thread while debugging

Can I pause a thread while debugging on intellij? What I want to have is something similiar to other ID - right click on a thread and pause it.
You either use a standard breakpoint which will pause all threads when hit or you can use a breakpoint with the suspend policy = thread.

How do I get Visual Studio to stay on one thread when debugging?

When I am debugging within Visual Studio, for some reason when debugging a certain thread, Visual Studio will just jump around to different threads.
How do I change to behavior so it sits on the same thread?
When you say, "when debugging a certain thread, visual studio will just jump around randomly to different threads", do you mean that as you step through code on a particular thread you may hit a breakpoint on a different thread?
If so, you can use the Thread window to 'freeze' threads other than the one you're interested in debugging:
From http://msdn.microsoft.com/en-us/library/w15yf86f.aspx:
From the Threads window, you can set
the active thread. In addition, you
can freeze or thaw the execution of
each individual thread. Freezing
prevents the execution of a thread.
Thawing enables it to continue. Two
vertical blue bars identify a frozen
thread.
Support for this may depend on the version of Visual Studio you have (for example, I don't think the Express versions support the Thread window).
All the answers here talk about freezing the threads, but it gets cumbersome when there're lots of them, and you don't know which one to freeze. I found an easier trick.
When a breakpoint is hit by a thread i, and say j, k, etc. are going to hit the same in some time, then disable the breakpoint temporarily and start debugging thread i. I see that the debugger doesn't jump on to the other threads since for those threads there's no breakpoint to break into. Enable the breakpoint when you're done debugging.
It is the default because running the program in the debugger shouldn't change the results of the program, I assume.
When the program is running "live", it is constantly switching between threads, so if the debugger didn't do the same, the program would be behaving differently.
In any case, the only way I know of to prevent it is to open the Threads window, right click on all other threads than the current one, and select freeze. (Remember to thaw them again afterwards)
Generally, I freeze the other threads by right-click in the threads panel. I don't know if this is sane or not though.

Resources