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:
- Put a sleep function (e.g., sleeping 10 seconds) in the main function of
consumerbefore doing any job such as reading fromstdin. - Invoke
producer | consumerfrom the console. Then,consumeris started with a 10-second-sleep. - Attach
consumerprocess by VC++ and gdb in 10 seconds. - Okay, after the sleep, I can now debug the consumer.
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.