ProgrammingDebugging techniques

There are a thousand different debugging techniques. The following are those that I have gotten the most mileage out of over the years:
Dump Routines

When you are defining a data structure, take a few minutes to create a routine that dumps the contents of the structure, in human readable form, to stdout or stderr (or if debugging Windows® software - use OutputDebugString() as mentioned below). This may seem like a waste of time, but it makes tracking down dynamic structure allocation problems much easier.

Logging Tools

Once your program is released, you will inevitably find that your users report bugs. Unless you can visit each user's site you need some way to get debugging output from your program, while it is running on the user's system.

This is where logging/tracing earn their keep. Build your program from the ground up with a trace/logging facility. Design your program so that a command line argument, environment variable, or menu option will the enable trace output.

Create a set of multi-level logging routines that provide trace output from your program. Design your program so that a command line argument, environment variable, or menu option will enable trace output. The option to save trace output to a file gives you a way to get program traces from your users. Assign consistent levels to various functions. The higher the traces level the more information that gets dumped. For example:

  • Level 1 - Function Entrance and Exits
  • Level 2 - Function Return Values
  • Level 3 - Function Parameters
  • Level 4 - Intermediate results
Feel free to assign your own scheme, but do it consistently, across all modules.

Windows® Debugging

Make use of OutputDebugString() to output debug messages. When used in combination with a multi-level logging capability, you have a powerful tool for tracking down software weirdness. Several third party tools are available which allow you to tap into the output of this routine, and most of these tools allow you to save the output to a file.

When attempting to debug multi-threaded programs, the trace output can be very helpful when trying to resolve thread synchronization issues.

Memory Allocation

Look at your malloc(), calloc(), realloc(), and free() calls. Look at each and every malloc() or calloc() call, can you easily point to its matching free() call? If not, get suspicious quick! Avoid calls to realloc() unless you really understand it (and how it behaves on your given operating system). When possible use calloc() instead of malloc(), calloc by default initializes all allocated bytes to a value of 0x0.

Further Reading

No Bugs!, by David Thielen, published by Addison-Wesley, ISBN 0-201-60890-1

Code Complete, by Steve McConnell, published by Microsoft Press, ISBN 1-55615-484-4

Windows is a registered trademark of Microsoft Corporation.

Note: I originally wrote this article on Everything2 it is duplicated here so I will always have a copy of it.


Trackback URL for this entry:

No trackback comments for this entry.


The following comments are owned by whomever posted them. This site is not responsible for what they say.
Authored by: Rivera on Tuesday, March 18 2014 @ 01:22 PM EDT Essay
Writing an review can seem conventional but it is essential first stage in the composing process. Explaining can cause to more essay service effective composing and thus more effective records.
Authored by: Anonymous User on Monday, August 18 2014 @ 05:16 PM EDT Debugging
Affordable college essays help for students!
Authored by: Anonymous User on Monday, March 30 2015 @ 04:14 PM EDT Debugging
I am going to tell you about article writing because it is the demand of modern world. If you look at college essay writing service reviews on our forum website which will help you to earn the confidence of modern writing.
Authored by: Anonymous User on Tuesday, May 26 2015 @ 06:54 AM EDT Debugging
A week ago I placed an essay writing order. Yesterday I received a draft of my term paper to show it to my professor. Everything is fine! My personal writer is doing a good job. By the way, I like the ability to communicate with writer. It is really convenient.
Authored by: Anonymous User on Friday, July 03 2015 @ 04:27 AM EDT Debugging
Do not know what to say, I liked your article and I hope you will have many entries or more. pacman unblocked happy wheels games unblockedgames hulk game mickey mouse game super adventure pals madness project nexus hacked
Authored by: Anonymous User on Thursday, July 23 2015 @ 03:40 AM EDT Debugging
Thank you! I have to thank you for the efforts you’ve put in penning this site.I really hope to check out the same high-grade blog posts by you later on as well. In truth, your creative writing abilities has motivated me to get my own website now ! barbie games| barbiegames| barbie| shooting games| shootinggames| shooting| dora games| doragames| dora fighting games| fightinggames| fighting| kissing games| kissinggames| kissing| christmas games| christmasgames| christmas
Authored by: Anonymous User on Thursday, August 13 2015 @ 11:13 AM EDT Debugging
Oh, man I wish that I learned about trace/logging facility earlier. Before I started building my program. I have had more success with a writing service website, those guys helped me a ton.
Authored by: Anonymous User on Tuesday, October 06 2015 @ 04:59 AM EDT Debugging
Authored by: Anonymous User on Tuesday, November 10 2015 @ 09:58 AM EST Debugging
It is a nice reminder that we do it because we love it. Those nice reviews make it all worth it. Thank you for helping me make my dream come true bythis awesome articles for me and for writing books I enjoy reading. Best Happy New Year Wishes Messages
Authored by: Anonymous User on Thursday, January 14 2016 @ 04:55 PM EST Debugging;u=429813
You always can publish something absorbing that does not waste minutes of your life like what you see on countless other sites. This is very interesting and I will be back for more.
Authored by: Anonymous User on Tuesday, April 19 2016 @ 06:55 AM EDT Debugging
Uniqueness and deadlines are one of the main requirements. Every time we click here for produce a new paper.
Authored by: vivavideo on Wednesday, October 12 2016 @ 03:25 AM EDT vivavideo app download
Viva Video App For Mac OS X, iPhone and iPad Download: Viva Video App For Mac OS X Download: vivavideo for android
Authored by: cartoon hd apk download on Wednesday, October 12 2016 @ 07:33 AM EDT cartoon hd apk for android
Steps to Download Cartoon HD Apk file on Android: Key Features of Cartoon HD App: Cartoon HD Apk for Android and Windows PC: Steps to Download Cartoon HD Apk file in your PC: cartoon hd apk for android
Authored by: WatsonZion on Saturday, November 26 2016 @ 02:29 AM EST Debugging
Composing a survey can appear to be traditional however it is basic first stage in the making procedure. Disclosing can bring about to more powerful making and along these lines more successful records. I will inform you regarding article composing since it is the request of current world. On the off chance that you take a gander at How Can I Write My Research Paper on our website which will help you to procure the certainty of cutting edge composing.
Authored by: happy new year funny resolutions on Thursday, December 08 2016 @ 07:30 AM EST happy new year 2017 resolutions
Fοr my New Υear’s resolution, Ι promise tο stop correcting yοur terrible spelling Αnd focus more οn your hοrrific year resolutions
Authored by: Paris Kim Kardashian Jacket on Friday, December 23 2016 @ 03:05 PM EST Debugging
Touches of intrigue like an etched bodice bound up lapels and crude edges put a fun loving completion on generally super moderate Paris Kim Kardashian Jacket
coats. Please Visit Our Website:
Authored by: game hacker latest version on Thursday, December 29 2016 @ 07:09 AM EST install game hacker
Important Features of SB Game Hacker APK: Why you should download the SB Game Hacker APK for Android: Download and Install SB Game Hacker APK for Android: game hacker latest version
Authored by: WagnerZack on Friday, December 30 2016 @ 06:10 AM EST Debugging
In case you look at on our site which will help you to secure the conviction of forefront making. I will advise you in regards to article forming since it is the demand of current world. Creating an overview can give off an impression of Chauffeur Hire London being conventional anyway it is fundamental first stage really taking shape system. Unveiling can achieve to all the more capable making and thusly more effective records.
Authored by: Anonymous User on Wednesday, February 22 2017 @ 01:37 PM EST Debugging
great post shawwebmail | webmail shaw
Authored by: Anonymous User on Thursday, March 30 2017 @ 02:50 AM EDT install norton security with product key
I like this site and the article as well Download install norton security with product key
Authored by: Anonymous User on Saturday, April 22 2017 @ 03:22 AM EDT best laptop brands
TOP 6 BEST LAPTOPS UNDER $500 DOLLARS IN 2017! BEST GUIDE best laptop brands
Authored by: Anonymous User on Saturday, April 22 2017 @ 05:43 AM EDT Happy New Year 2018 Greetings
Happy New Year 2018 Greetings is soon going to knock our doors. It is one of the best occasion and celebration of life
Authored by: Anonymous User on Wednesday, April 26 2017 @ 03:07 AM EDT Best Gaming Mouse
Authored by: manabadi ssc results 2017 on Friday, April 28 2017 @ 08:46 AM EDT Debugging
10th ssc results 2017 ap,
<a href="">ap 10th Class Result 2017</a>
ap ssc results 2017 name wise,
[url=""]ssc results 2017 telangana grade wise[/url]
ssc results 2017 telangana grade wise,
ap ssc results 2017,
ap ssc 2017 results

AP SSC/10th Class Results 2017: The Andhra Pradesh Board of Secondary Education (BSEAP) is likely to declare the SSC/10th Class results of the year 2017.
Authored by: Anonymous User on Saturday, April 29 2017 @ 05:22 AM EDT tubemate for ios
everything you share with us is current and very informative checkout tubemate for ios

My Account

Sign up as a New User
Lost your password?


There are no upcoming events