Home > front end >  Debuging multithread app, how to glue the debugger step by step process to a particular thread?
Debuging multithread app, how to glue the debugger step by step process to a particular thread?

Time:03-08

When debugging multithread app, Is it possible to glue the debugger to a particular thread? because when I do step by step (F7) debugging often I jump in another thread and that is a little awful for debugging :(

CodePudding user response:

If I interpret your question as:

"When debugging is it possible to only allow execution of the thread I am debugging"

Then the answer is yes.

  • Set your breakpoint.
  • When the debugger hits your breakpoint, go to the threads view. The current thread will be marked with a 'running' icon (it has a green 'play' arrowhead on it in recent versions of RAD Studio).
  • Right click on that thread and choose Freeze all other threads.

The debugger will now allow you to single step through the current thread without allowing the other threads to be scheduled.

When you have finished you can right click on any of the threads and choose Thaw all threads

Of course this will affect the behaviour of the system as the other threads will not be running.

If I interpret your question as:

"Is it possible to ensure that a breakpoint only fires for a particular thread"

Then the answer is yes.

  • Set your breakpoint.
  • Right click on the breakpoint and choose "Breakpoint Properties".
  • Select a thread from the dropdown list and only this thread will break into the debugger at the breakpoint.

If I interpret your question as:

"Is it possible to have all threads running, but only single step through a single thread in the debugger (while other threads run)"

Then practically I think the answer is no. You could set a break point on each successive line and set the properties for the breakpoint to the current thread, but that's not really practical for most single-stepping.

Remember that when debugging any enabled breakpoint (hit by any thread) will be evaluated and will cause a break into the debugger unless the properties of the breakpoint prevent that. When single stepping the debugger is effectively inserting a breakpoint at the next line, so any thread hitting that line will cause a break to the debugger.

If all of your threads are executing different code this will not be a problem, but if they are executing common code (including library routines and object methods) then any thread hitting that next step will break.

Another thing that may help you with single-stepping a multi-threaded application when you have a number of breakpoints set is to disable them in the breakpoints window (normally a tab in the bottom part of the debugger view) when single stepping so that hitting one of them in another thread does not cause a break to the debugger.

  • Related