Debugging

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

Trackback URL for this entry: http://www.tbayne.net/trackback.php?id=20070531085048509

No trackback comments for this entry.

41 comments

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. newyearquoteswishes.com www.bigboxofficecollection.com Best Happy New Year Wishes Messages
Authored by: Anonymous User on Thursday, January 14 2016 @ 04:55 PM EST Debugging
http://www.freeforums.com/member.php?145212-Heidelberger
http://www.unsigned.com/fans/derikosamerstwo
http://www.chordie.com/forum/profile.php?id=809184
http://www.finehomebuilding.com/profile/JohnDewis
http://www.autismuk.com/forum/index.php?action=profile;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 grammar.new 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: http://www.bayperfect.com/product/fabulous-paris-kim-kardashian-leather-jacket
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="http://www.ssc10thresults2017.in/">ap 10th Class Result 2017</a>
ap ssc results 2017 name wise,
[url="http://www.ssc10thresults2017.in/"]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
Authored by: 192.168.1.1 admin on Friday, June 09 2017 @ 12:32 AM EDT 192.168.1.1 admin
Authored by: showbox on macbook on Thursday, June 15 2017 @ 03:18 AM EDT showbox on macbook
Authored by: facetime video call app on Friday, June 16 2017 @ 05:56 AM EDT facetime video call app
Authored by: game of thrones season 7 online on Tuesday, June 20 2017 @ 01:27 AM EDT game of thrones season 7 online
Authored by: VivaVideo for PC on Wednesday, June 21 2017 @ 03:29 AM EDT VivaVideo for PC
Authored by: www.appsinsider.org on Friday, June 23 2017 @ 02:09 AM EDT www.appsinsider.org
Authored by: 192.168.1.254 router default log on Tuesday, June 27 2017 @ 02:05 AM EDT 192.168.1.254 router default login
Authored by: aptoide apk on Friday, June 30 2017 @ 06:44 AM EDT aptoide apk
aptoide apk aptoide for android Aptoide For Android: After the evolution of Android device, Google Play store is only the app that is serving us till this day
Authored by: Linkerseo on Friday, July 07 2017 @ 09:08 AM EDT Masters Degree
Students Are Developing Community Ties at Online Universities Masters Degree
Authored by: Anonymous User on Sunday, July 09 2017 @ 05:26 PM EDT good post
Online Leadership Training is Paying Dividends for Employers Course of Study
Authored by: Odin with ROM Flashing Tool on Thursday, July 13 2017 @ 12:13 AM EDT Odin with ROM Flashing Tool
Authored by: Luke Randall on Saturday, July 15 2017 @ 11:54 AM EDT Debugging
Make an arrangement of multi-level logging schedules that give follow yield from your program. Outline your program with the goal that an order line contention, condition variable, or menu alternative will empower follow yield. The alternative to spare follow yield to a record gives you an approach to get program follows from your clients. Appoint predictable levels to different capacities. The higher the follows level the more data that gets dumped. For instance: www.mycourseworkhelp.co.uk
Authored by: hack for Pokemon go on Monday, July 17 2017 @ 02:45 AM EDT hack for Pokemon go
Authored by: WadeZack on Wednesday, July 19 2017 @ 08:51 AM EDT Debugging
Recently I got a draft of my research project to demonstrate it to my educator. All is well! My own essayist is making a decent showing with regards to. Incidentally, I like the capacity to speak with essayist. Revealing can realize Academic Editing to all the more effective making and thusly more fruitful records. I will illuminate you in regards to article making since it is the demand of current world.
Authored by: Anonymous User on Friday, July 21 2017 @ 01:23 AM EDT Debugging
Uncovering can understand to all the more powerful making and accordingly more productive records. I will light up you as to article making since it is the request of current world. As of late I got a draft of my examination Homework Writing venture to show it to my instructor. All is well! My own writer is making a nice appearing with respect to. By chance, I like the ability to talk with writer.

My Account





Sign up as a New User
Lost your password?

Events

There are no upcoming events