Chapter 11. Debugging Techniques

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • How to run your program under the control of the Visual C++ 2010 debugger

  • How to step through your program a statement at a time

  • How to monitor or change the values of variables in your programs

  • How to monitor the value of an expression in your program

  • The call stack

  • Assertions and how to use them to check your code

  • How to add debugging specific code to a program

  • How to detect memory leaks in a native C++ program

  • How to use the execution tracing facilities and generate debugging output in C++/CLI programs

If you have been doing the exercises in the previous chapters, you have most likely been battling with bugs in your code. In this chapter you will explore how the basic debugging capabilities built into Visual C++ 2010 can help with this. You will also investigate some additional tools that you can use to find and eliminate errors from your programs, and see some of the ways in which you can equip your programs with specific code to check for errors.

UNDERSTANDING DEBUGGING

Bugs are errors in your program, and debugging is the process of finding and eliminating them. You are undoubtedly aware by now that debugging is an integral part of the programming process — it goes with the territory, as they say. The facts about bugs in your programs are rather depressing:

  • Every program you write that is more than trivial will contain bugs that you need to try to expose, find, and eliminate if your program is to be reliable and effective. ...

Get Ivor Horton's Beginning Visual C++® 2010 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.