Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Debugging techniques and approches

Debugging techniques and approches

Basic Debugging techniques and approaches while development.

Kunal Kushwaha

May 10, 2013

Transcript

9 slides
  1.  Debugging is a methodical process of finding and reducing

    the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected
  2.  Writing new code / functions  Modifying existing code.

     What we do in our code? ◦ Essentially it will do following  Some mathematical calculation based on data we have.  Data manipulation/ memory manipulation.  On Stack  On Heap.  Conditions  Execution path
  3.  Calculation logic in code is as per desired logic.

    ◦ Output of such logic must me tested w.r.t. all possible conditions (best case, worst cases and boundary cases)  Data Manipulation ◦ On Stack  Correct usage of stack  Conditions of stack overflow.  Passing address of stack allocated memory to such function, which are out of scope of functions stack.
  4. ◦ On Heap.  Free all allocated memory.  Memory

    under-run/over-run issues.  Uninitialized memory access/manipulation.  Execution paths ◦ A function can have various execution paths depending on if-else, switch, goto usage in code. ◦ All execution paths must be executed at-least once with all possible conditions. ◦ Terminating condition for loops.
  5.  Methods to catch the bug at earliest. ◦ Usage

    of prints ◦ Usage of Asserts – defensing programming.  Methods to debug newly added function(s). ◦ In, Out parameters and return values. ◦ ASSERT for mandatory parameters for expected value or range. (used for debug version only) ◦ Handle the graceful exit from function with proper error return value (wherever applicable) ◦ Defined return path and value.
  6. ◦ Can test computation's in code with helps of prints.

    ◦ If coping data to some memory location, check for size of copy and start address of storage. ( Buffer over-run / under-run conditions). ◦ Global structure management - use of reference count. ◦ Memory corruptions  Padding – add some signature at start and end of memory allocated while allocation, and check while freeing it.
  7.  Functions / Macros ◦ Test for best case, worst

    case and boundary cases. ◦ Invoke functions/Macros from test code and verify if it works as expected in all scenarios.  Modification in current code. ◦ Verify for all modifications, if they are not breaking or introducing new bug to existing function.

More Decks by Kunal Kushwaha

Other Decks in Programming