Debugging Windows Programs: Strategies, Tools, and Techniques for Visual C++ Programmers

Overview

For professional software developers, debugging is a way of life. This book is the definitive guide to Windows debugging, providing developers with the strategies and techniques they need to fulfill one of their most important responsibilities efficiently and effectively.

Debugging Windows Programs shows readers how to prevent bugs by taking full advantage of the Visual C++ development tools and writing code in a way that makes certain types of bugs impossible. They also will ...

See more details below
Other sellers (Paperback)
  • All (18) from $1.99   
  • New (7) from $29.99   
  • Used (11) from $1.99   
Sending request ...

Overview

For professional software developers, debugging is a way of life. This book is the definitive guide to Windows debugging, providing developers with the strategies and techniques they need to fulfill one of their most important responsibilities efficiently and effectively.

Debugging Windows Programs shows readers how to prevent bugs by taking full advantage of the Visual C++ development tools and writing code in a way that makes certain types of bugs impossible. They also will learn how to reveal bugs with debugging statements that force bugs to expose themselves when the program is executed, and how to make the most of debugging tools and features available in Windows, Visual C++, MFC, and ATL. The authors provide specific solutions to the most common debugging problems, including memory corruption, resource leaks, stack problems, release build problems, finding crash locations, and multithreading problems.

These essential topics are covered:

  • The debugging process
  • Writing C++ code for debugging
  • Strategically using assertions, trace statements, and exceptions
  • Windows postmortem debugging using Dr. Watson and MAP files
  • Using the Visual C++ debugger
  • Debugging memory
  • Debugging multithreaded programs
  • Debugging COM

Each chapter provides developers with exactly what they need to master the subject and improve development productivity and software quality.

Comprehensive, current, and practical, Debugging Windows Programs helps developers understand the debugging process and make the most of the Visual C++ debugging tools.

020170238XB04062001

Read More Show Less

Editorial Reviews

Booknews
Shows how to prevent bugs by taking advantage of the Visual C++ development tools and writing code in a way that makes certain types of bugs impossible. The authors recommend the use of debugging statements that force bugs to expose themselves when the program is executed, and provide specific solutions to the most common debugging problems, including memory corruption, resource leaks, stack problems, release build problems, and finding crash locations. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9780201702385
  • Publisher: Addison-Wesley
  • Publication date: 8/18/2000
  • Series: Developmentor Series
  • Pages: 592
  • Product dimensions: 7.30 (w) x 9.00 (h) x 1.40 (d)

Meet the Author

Everett N. McKay has been honing his debugging skills "the hard way" since 1975. He has been developing Windows programs since 1990, specializing in user interface design. He now works as a user interface program manager for a large, well-known software company based in Redmond, Washington. Everett is also the author of Developing User Interfaces for Microsoft Windows.

Mike Woodring is an independent consultant specializing in system software development and an instructor for DevelopMentor, a premier research and training company that specializes in object technologies. Previously, he was a senior software systems engineer at Intel. He is co-author of Win32 Multithreaded Programming.

020170238XAB04062001

Read More Show Less

Read an Excerpt

Debugging Windows programs is a large, complex subject. A book that covered all possible aspects of Windows debugging could easily be twice the size of this book. The problem with such a comprehensive approach to the subject is that the results would be so large and intimidating that few people would want to read it. Consequently, we had to draw the line somewhere and focus on some aspects of Windows debugging at the exclusion of others. Let's start by explaining how we chose to draw that line.

The fundamental motivation behind this book is the belief that programmers' debugging skills could be much improved if they had access to better debugging information. Although plenty of debugging information is available, it is not currently in a form that a programmer can read and then have mastery of the subject. Too often the information is vague and incomplete, or the focus is on debugging tools instead of debugging concepts. The ultimate debugging tool is the programmer's mind, and too often that tool has been neglected. Mastering fundamental Windows debugging concepts will help you prevent many bugs and find the remaining bugs more efficiently, even if you are the most gung ho tool user.

This book identifies the fundamental debugging skills required for effective Windows debugging. Once you have read a chapter, you should have that chapter's subject wired. Part I of the book focuses on debugging strategies to help you understand the debugging process and how to use the C++ language, assertions, trace statements, and exceptions to prevent, reveal, diagnose, and remove bugs. Part II focuses on debugging tools included in Visual C++ as well as Windows. Part III focuses on debugging techniques to help you get the most out of Visual C++ debugging tools, with special attention to debugging memory-related problems, multithreaded programs, and COM.

Some subjects addressed here straddle the border between programming skills and debugging skills. However, since bug prevention is very much a part of debugging, you need to know the common programming mistakes in order to avoid making them. Most programming texts avoid the subjects of debugging and bug prevention, so these subjects need to be addressed.

What's missing in the presentation is also notable. We have largely avoided discussing third-party debugging tools or any Microsoft debugging tools that are not part of Visual C++ (such as WinDbg) or Windows. There are several motivations for this decision. The obvious motivation is to stay focused on debugging concepts and not get side tracked by documenting tools. Another strong motivation is that Visual C++ programmers need better information on how to use the tools they already have. Finally, we doubt that we could say anything about these other tools that would be more helpful than the information provided by the tool vendors themselves.

But I Use BoundsChecker . . .

Some readers are now thinking, "But I use BoundsChecker, so why should I read this book?" Excellent question. Debugging tools, such as Compuware NuMega's BoundsChecker and Rationale Software's Purify, do an excellent job of finding many types of runtime errors—bad pointers and handles, memory corruption and leaks, bad Windows API parameters, and so on. What they don't do is help you understand the debugging process, including how to use the C++ language, assertions, trace statements, and exceptions to prevent and remove bugs, how to take full advantage of the debugging tools that are part of Visual C++ Windows, or how to debug multithreaded programs and COM—all of which this book does.

Furthermore, these tools certainly do not detect all bugs, and they do nothing to help you prevent bugs. If you are totally dependent on debugging tools, you will be helpless when presented with bugs these tools don't find. In addition, using these tools requires you to perform an extra development step, and they can have a significant impact on runtime performance, whereas many of the bug-detection techniques described in this book happen automatically whenever you run the debug build and have a minimal impact on performance. Debugging is a complex puzzle, but these debugging tools will help you with only one piece.

How to Read This Book

Although our hope is that you will read this book from cover to cover, we realize that many readers are in a hurry and won't have the time to read a whole book in order to track down a bug. Consequently, each chapter is largely self-contained so you should be able to read only the chapters you need in the order you want. This self-containment approach means there are some bits of redundant material that apply to more than one chapter, although we tried to keep such redundancy to a minimum. We hope you will agree that this approach makes the book a much more useful reference.

After the Contents, there is a list of answers to frequently asked questions, which can quickly guide you to solutions to many common debugging problems. Chapter 8 is also organized in this way, and either the FAQ list or the chapter can help you quickly find an answer to a specific debugging question.

There are many different types of Windows programs, so there are many different types of debugging techniques. Debugging is presented from the point of view of the Windows API, as well as the MFC and ATL application frameworks. We have clearly identified the material that is specific to MFC and ATL; so if you're not using these frameworks, feel free to skip over those sections if you are in a hurry. If you're not in a hurry, you might want to read them because it is often useful to look at debugging from other points of view.

Finally, each chapter contains key points of advice about debugging, which are presented in a special format as shown here.

These tips highlight the most useful debugging ideas, make the text easier to scan, and will help you locate important debugging topics quickly.

Windows Versions and Hardware

To simplify the presentation, we refer primarily to the current versions of Windows, which at the time of this writing are Windows 2000 and Windows 98. Almost everything said here about Windows 2000 applies to Windows NT 4.0, and nearly everything said about Windows 98 also applies to Windows 95. We mention Windows NT 4.0 and Windows 95 only when referring to those specific versions of Windows.

To further simplify the presentation, we assume you are using Windows on an Intel x86 central processing unit (CPU). Although most of this book is CPU independent, the specific CPU becomes a factor when you are reading hex dumps or debugging at the assembly-language level. For those of you doing assembly-level debugging on a non-Intel platform, you have our sympathy, but not much else.

Who Is "I"?

Although there are two names on the cover, we wrote this book using the first person. Each chapter tells its story from the point of view of a single author. Mike Woodring wrote Chapter 10, Debugging Multithreaded Programs, and Chapter 11, COM Debugging, whereas Everett McKay wrote the remainder. Consequently, the "I" in Chapters 10 and 11 refers to Mike Woodring, whereas the "I" in the other chapters refers to Everett McKay.

For Updated Information

The information in this book is based on Microsoft Visual C++ version 6.0. If you are using a later version of Visual C++, chances are the majority of this book is still accurate but a few details related to the compiler or debugger have changed. To help keep this book's information fresh, we will post any updates or corrections at http://www.windebug.com, along with selected debugging tools. Should you find any errors or out-of-date information, please let us know by sending an e-mail message to corrections@windebug.com.

Read More Show Less

Table of Contents

(Each Chapter concludes with "Recommended Reading")

Answers to Frequently Asked Questions.

Preface.

Introduction.

I. DEBUGGING STRATEGIES.

1. The Debugging Process.

The Five (Wrong) Stages of Debugging.

The Five Stages of Debugging.

Determining That a Bug Exists.

Gathering Bug Information.

Analyzing the Bug Information.

Removing the Bug.

Verifying the Change.

Debug Smarter, Not Harder.

2. Writing C++ Code for Debugging.

Design.

C++ Programming Style.

The C++ Language.

The Visual C++ Compiler.

3. Using Assertions.

The Limitations of Assertions.

Types of Assertions.

More MFC Assertion Macros.

Custom Assertions.

Portable Assertions.

Assertion Strategy.

Invariants.

Assertion Patterns.

Document Your Assertions.

Implementing AssertValid.

Defensive Programming.

Error Handling.

Miscellaneous Tips.

4. Using Trace Statements.

Types of Trace Statements.

Custom Trace Statements.

Trace Statement Strategies.

Miscellaneous Tips.

5. Using Exceptions and Return Values.

Incorrect Error Handling Results in Bugs.

The Need for a Strategy.

Using Exceptions.

Using Return Values.

Exceptions and Bugs.

C++ Exceptions versus Windows Structured Exception Handling.

Translating Structured Exceptions to C++ Exceptions.

Exception Performance.

Exception Strategy.

Defensive Programming with Exceptions.

Debugging Exceptions.

Miscellaneous Tips.

II. DEBUGGING TOOLS.

6. Debugging with Windows.

Postmortem Debugging.

Windows API Error Codes.

Windows Exception Basics.

Portable Executable Basics.

Rebasing DLLs.

Assembly Language Basics.

Debugging with MAP Files.

Debugging with PDB Files.

Debugging Using a Windows 98 Crash Dialog Box.

Debugging Using Dr. Watson.

Miscellaneous Tips.

7. Debugging with the Visual C++ Debugger.

Compiler and Linker Options.

Debug versus Release Builds.

Debugging Release Builds.

The Test Build.

Debugging Symbols.

The Debug Windows.

Watch Expressions.

Datatip Expressions.

Registers and Pseudo-registers.

Watch Window Formatting Symbols.

Using Autoexp.dat.

Debugging with Breakpoints.

Just-in-time Debugging.

Remote Debugging.

Debugging with Edit and Continue.

III. DEBUGGING TECHNIQUES.

8. Basic Debugging Techniques.

General Debugging Techniques.

Visual C++ Debugger Techniques.

Windows Debugging Techniques.

MFC Debugging Techniques.

9. Debugging Memory.

Why Memory Leaks Aren't Acceptable.

Types of Memory Debugging.

Using the Debug Heap.

How the Debug Heap Works.

Reading Windows Memory Addresses.

Debugging Memory Corruption.

Debugging Memory Leaks.

Debugging Windows Resource Leaks.

Debugging Windows Thread Stacks.

Miscellaneous Tips.

10. Debugging Multithreaded Programs.

What Is Multithreading?

Issues in Multithreaded Programs.

Writing Thread-safe Code.

Thread Creation and Termination.

Understanding the Debugger.

Debugging Techniques.

11. COM Debugging.

Chapter Basics.

Defensive COM Programming Practices.

Debugging Base COM DLLs.

Debugging Base COM EXEs.

Debugging Configured Components.

Debugging Base COM DLLs That Are Called From ASPs.

12. Desperate Measures.

Checking the Easy Stuff.

Using Your Head.

Rechecking Your Assumptions.

Checking the Obvious.

Checking the Code.

Checking the System.

Double-Checking the Documentation.

Using Other People.

Using Newsgroups.

Stop Living Dangerously.

Bibliography.

Index. 020170238XT04062001

Read More Show Less

Preface

Debugging Windows programs is a large, complex subject. A book that covered all possible aspects of Windows debugging could easily be twice the size of this book. The problem with such a comprehensive approach to the subject is that the results would be so large and intimidating that few people would want to read it. Consequently, we had to draw the line somewhere and focus on some aspects of Windows debugging at the exclusion of others. Let's start by explaining how we chose to draw that line.

The fundamental motivation behind this book is the belief that programmers' debugging skills could be much improved if they had access to better debugging information. Although plenty of debugging information is available, it is not currently in a form that a programmer can read and then have mastery of the subject. Too often the information is vague and incomplete, or the focus is on debugging tools instead of debugging concepts. The ultimate debugging tool is the programmer's mind, and too often that tool has been neglected. Mastering fundamental Windows debugging concepts will help you prevent many bugs and find the remaining bugs more efficiently, even if you are the most gung ho tool user.

This book identifies the fundamental debugging skills required for effective Windows debugging. Once you have read a chapter, you should have that chapter's subject wired. Part I of the book focuses on debugging strategies to help you understand the debugging process and how to use the C++ language, assertions, trace statements, and exceptions to prevent, reveal, diagnose, and remove bugs. Part II focuses on debugging tools included in Visual C++ as well as Windows. Part III focuses on debugging techniques to help you get the most out of Visual C++ debugging tools, with special attention to debugging memory-related problems, multithreaded programs, and COM.

Some subjects addressed here straddle the border between programming skills and debugging skills. However, since bug prevention is very much a part of debugging, you need to know the common programming mistakes in order to avoid making them. Most programming texts avoid the subjects of debugging and bug prevention, so these subjects need to be addressed.

What's missing in the presentation is also notable. We have largely avoided discussing third-party debugging tools or any Microsoft debugging tools that are not part of Visual C++ (such as WinDbg) or Windows. There are several motivations for this decision. The obvious motivation is to stay focused on debugging concepts and not get side tracked by documenting tools. Another strong motivation is that Visual C++ programmers need better information on how to use the tools they already have. Finally, we doubt that we could say anything about these other tools that would be more helpful than the information provided by the tool vendors themselves.

But I Use BoundsChecker . . .

Some readers are now thinking, "But I use BoundsChecker, so why should I read this book?" Excellent question. Debugging tools, such as Compuware NuMega's BoundsChecker and Rationale Software's Purify, do an excellent job of finding many types of runtime errors--bad pointers and handles, memory corruption and leaks, bad Windows API parameters, and so on. What they don't do is help you understand the debugging process, including how to use the C++ language, assertions, trace statements, and exceptions to prevent and remove bugs, how to take full advantage of the debugging tools that are part of Visual C++ Windows, or how to debug multithreaded programs and COM--all of which this book does.

Furthermore, these tools certainly do not detect all bugs, and they do nothing to help you prevent bugs. If you are totally dependent on debugging tools, you will be helpless when presented with bugs these tools don't find. In addition, using these tools requires you to perform an extra development step, and they can have a significant impact on runtime performance, whereas many of the bug-detection techniques described in this book happen automatically whenever you run the debug build and have a minimal impact on performance. Debugging is a complex puzzle, but these debugging tools will help you with only one piece.

How to Read This Book

Although our hope is that you will read this book from cover to cover, we realize that many readers are in a hurry and won't have the time to read a whole book in order to track down a bug. Consequently, each chapter is largely self-contained so you should be able to read only the chapters you need in the order you want. This self-containment approach means there are some bits of redundant material that apply to more than one chapter, although we tried to keep such redundancy to a minimum. We hope you will agree that this approach makes the book a much more useful reference.

After the Contents, there is a list of answers to frequently asked questions, which can quickly guide you to solutions to many common debugging problems. Chapter 8 is also organized in this way, and either the FAQ list or the chapter can help you quickly find an answer to a specific debugging question.

There are many different types of Windows programs, so there are many different types of debugging techniques. Debugging is presented from the point of view of the Windows API, as well as the MFC and ATL application frameworks. We have clearly identified the material that is specific to MFC and ATL; so if you're not using these frameworks, feel free to skip over those sections if you are in a hurry. If you're not in a hurry, you might want to read them because it is often useful to look at debugging from other points of view.

Finally, each chapter contains key points of advice about debugging, which are presented in a special format as shown here.

These tips highlight the most useful debugging ideas, make the text easier
to scan, and will help you locate important debugging topics quickly.

Windows Versions and Hardware

To simplify the presentation, we refer primarily to the current versions of Windows, which at the time of this writing are Windows 2000 and Windows 98. Almost everything said here about Windows 2000 applies to Windows NT 4.0, and nearly everything said about Windows 98 also applies to Windows 95. We mention Windows NT 4.0 and Windows 95 only when referring to those specific versions of Windows.

To further simplify the presentation, we assume you are using Windows on an Intel x86 central processing unit (CPU). Although most of this book is CPU independent, the specific CPU becomes a factor when you are reading hex dumps or debugging at the assembly-language level. For those of you doing assembly-level debugging on a non-Intel platform, you have our sympathy, but not much else.

Who Is "I"?

Although there are two names on the cover, we wrote this book using the first person. Each chapter tells its story from the point of view of a single author. Mike Woodring wrote Chapter 10, Debugging Multithreaded Programs, and Chapter 11, COM Debugging, whereas Everett McKay wrote the remainder. Consequently, the "I" in Chapters 10 and 11 refers to Mike Woodring, whereas the "I" in the other chapters refers to Everett McKay.

For Updated Information

The information in this book is based on Microsoft Visual C++ version 6.0. If you are using a later version of Visual C++, chances are the majority of this book is still accurate but a few details related to the compiler or debugger have changed. To help keep this book's information fresh, we will post any updates or corrections at http://www.windebug.com, along with selected debugging tools. Should you find any errors or out-of-date information, please let us know by sending an e-mail message to corrections@windebug.com.

020170238XP04062001

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Anonymous

    Posted May 8, 2003

    Debugging Windows 101

    You can't get simpler than this book.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)