Breakpoint a multi thread application

2019-04-06 18:31发布

问题:

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 ?

回答1:

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.



回答2:

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)



回答3:

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.