1

Based on the question "Step over" when debugging multithreaded programs in Visual Studio, consider the following scenario:

Thread A running some code starts Thread B and keep going until the point where Thread A needs the result of Thread B. For the sake of sanity, let's assume the following scheme:

Thread A
    line 1 // <---- Starts Thread B
    line 2
    line 3 // <---- Breakpoint
    line 4
    line 5 // <---- Wait for Thread B

Thread B
    line 1
    line 2 // <------ When the code breaks, stoped here
    line 3
    line 4

What happens when one click on the "step over" button?

I can think of three things:

  1. A go to line 4. B stays in line 2 until the "continue" button was pressed.
  2. A go to line 4. B go to line 3
  3. A go to line 4. While A don't stop at line 4, B keeps going indefinitely. As soon as A stop again, B stops. This means that B can be in line 4 or exited while A is going from line 3 to 4.

If I was asked to guess, I'd choose my option 3.

Following that line, there's a way to debug threads line by line like my option 2? I'm asking in terms of there is any C++ debugger able to halt all threads and step over line by line each one individually?

4
  • 1
    Yes I think your option 3. is right. You can "simulate" the options 1. and 2. by freezing threads via visual studio thread wind. But I suspect you already know that. Commented Apr 19, 2013 at 21:24
  • actually I didn't know, thanks for that =). I use mingw with gdb in my work so I was hoping for some free tool able to do the task. Unfortunately none seem to be practical. Commented Apr 19, 2013 at 21:29
  • 1
    Options for gdb stackoverflow.com/questions/2643884/gdb-multithreading Commented Apr 19, 2013 at 22:13
  • Do you know if there is a free IDE able to use the gdb thread commands? Commented Apr 20, 2013 at 12:56

1 Answer 1

0

Windbg's step command p allows you to specify which threads are to continue executing while all the others remain frozen. See http://msdn.microsoft.com/en-us/library/windows/hardware/ff553496(v=vs.85).aspx

Specifically look at the optional [~ Thread] at the beginning of the command.

Sign up to request clarification or add additional context in comments.

2 Comments

Windbg is specific for projects compiled with Visual Studio right?
Nope. It can attach to any process running on Windows (as long as you have adequate permissions). Not sure if you'll have symbols for your binary though since I'm guessing you're building with some gnu tools. So finding the place in your binary where you want to do this will be challenging but not impossible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.