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?

Community
  • 1
  • 1
McLeary
  • 1,231
  • 2
  • 13
  • 21
  • 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. – hr_117 Apr 19 '13 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. – McLeary Apr 19 '13 at 21:29
  • 1
    Options for gdb http://stackoverflow.com/questions/2643884/gdb-multithreading – user1827356 Apr 19 '13 at 22:13
  • Do you know if there is a free IDE able to use the gdb thread commands? – McLeary Apr 20 '13 at 12:56

1 Answers1

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.

Marc Sherman
  • 2,303
  • 14
  • 22
  • Windbg is specific for projects compiled with Visual Studio right? – McLeary Apr 26 '13 at 16:07
  • 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. – Marc Sherman Apr 26 '13 at 20:26