October 22, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Visual C++ Thread Debugging

  • August 6, 2008
  • By Nick Wienholt
  • Send Email »
  • More Articles »

In an application with a large number of threads, having an excessive number of breakpoints hit can be a real problem during a debugging session. To overcome this problem, breakpoints can be filtered so that they are only active on particular threads. To filter a breakpoint, right-click on either the breakpoint icon in the code margin or the Breakpoint window and select Filter from the context menu. The dialog shown in Figure 5 will be displayed, and threads can be filtered based on either ID or name. Because the ID of a thread will change for each debug session, it will be more time efficient to include some debug-build only code that names the threads of interest so that a new filter condition does not need to be setup every time the debugged process is restarted.

Figure 5: Filter Breakpoint for Threads and Processes

Multi-threading debugging is one of the most challenging debugging experiences that a developer can undertake. Although nothing will replace experience and skill in working out why threads are interacting with each other in strange and unexpected ways, the Visual Studio 2008 debugger provides excellent support in controlling thread execution and inspecting what each thread in an application is doing. The new Show Threads in Source option is particularly useful for understanding the current execution paths of a source code file.

Conclusion

Multi-threading debugging is one of the most challenging debugging experiences that a developer can undertake. Even though nothing will replace experience and skill in working out why threads are interacting with each other in strange and unexpected ways, the Visual Studio 2008 debugger provides excellent support in controlling thread execution and inspecting what each thread in an application is doing. The new Show Threads in Source option is particularly useful for understanding the current execution paths of a source code file, and developers should ensure that it is enabled for all debugging sessions.

As with previous versions of Visual Studio, the Thread Window is the main focus of any multi-threading debugging session, allowing the active thread to be set, threads to be paused and thawed, and threads to be flagged for more detailed attention. New in Visual Studio 2008 is the call stack tooltip; it allows the tasks that each thread is performing to be quickly examined without changing the active thread.

About the Author

Nick Wienholt is an independent Windows and .NET consultant based in Sydney. He is the author of Maximizing .NET Performance and co-author of A Programmers Introduction to C# 2.0 from Apress, and specialises in system-level software architecture and development, with a particular focus of performance, security, interoperability, and debugging.

Nick is a keen and active participant in the .NET community. He is the co-founder of the Sydney Deep .NET User group and writes technical articles for Australian Developer Journal, ZDNet, Pinnacle Publishing, CodeGuru, MSDN Magazine (Australia and New Zealand Edition) and the Microsoft Developer Network. An archive of Nick's SDNUG presentations, articles, and .NET blog is available at www.dotnetperformance.com.

In recognition of his work in the .NET area, he was awarded the Microsoft Most Valued Professional Award from 2002 through 2007.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel