Reputation: 9050
I'm running a typical producer and consumer process, but they are executed by using pipe in the command line like the following:
c:\>producer | consumer
producer
is just printing out data to stdout
, and consumer
reads from stdin
.
My problem is that I want to debug consumer
process. What is the best way to do it in both VC++ and gdb?
One solution is dumping out into a file and reading the file:
c:\>producer > temp.data
c:\>consumer < temp.data
However, the amount of data communicated by the two is extremely large. temp.data
would be more than 1TB! I may use compression, but it takes huge amount of time for just compressing/uncompressing. So, I want to do it online.
Current my workaround is:
consumer
before doing any job such as reading from stdin
.producer | consumer
from the console. Then, consumer
is started with a 10-second-sleep.consumer
process by VC++ and gdb in 10 seconds.Yes, this workaround is working. But, it's pretty annoying. I guess there is a better way to debug in this situation. I appreciate any idea for it.
Upvotes: 1
Views: 418
Reputation: 1754
Two solutions come to mind
Change your sleep to be
// this waits indefinitely without killing the CPU
while(true) {SleepEx(100, FALSE);}
Once you attach the debugee manually you just put a break point on the sleep and then you can jump out of the loop manually.
or better yet (unless its a service/process with no UI access) add a DebugBreak statement where the Sleep is instead. This will cause the an exception to be thrown and you will be prompted to kill the process or debug launching your default debugger on the system..
DebugBreak();
Upvotes: 2