4.5 Code Debug Tips

  • Problem handling stages (gather statistics, guess the potential causes, sort by priority, check each cause)
  • Find the changes from previous version
  • Review the code.
  • Read error description in the manual
  • Add an error to the code when checking compilation problem.
  • Fix compilation errors by the order they appear
  • Use assertions.
  • Write validity checks of parameters.
  • Check if the problem occurs with previous versions
  • Check the platform. (check hardware/OS/compiler/libraries/drivers/power is on)
  • Check if the problem occurs with similar platforms.
  • Check if the problem is consistent or random.
  • Remark suspected parts of the code and see if problem disappeared.
  • Use debugger.
  • Set debug mode build.
  • Undo recent changes until problem disappears.
  • Use binary search to find the problem. (lion in the desert).
  • Trial and error. (try several ways and choose the one that works the best)
  • Use scope to probe output signal (embedded).
  • Consult customer support (I).
  • Search internet forums and resources
  • Use debug variables.
  • Use debug prints. (printf/MessageBox).
  • Check that the source/object/executable files are updated. (open windows explorer and sort by date).
  • Check the version number. (that you are working with the right version)
  • Check that the problem really exist. (bad testing method)
  • Use conditional compilation of debug code. (#ifdef DEBUG #endif)
  • Rewrite the code (last option - get previous version and write)
  • Common bug: array index / pointer overflow. (Check memory corruption (of stack/pointers).
  • Common bug: casting error in calculation ((float)(a+0.5) - when a int)
  • Common bug: if( a=b ) ... (overwrite a)
  • Common bug: for(i=0; i<10; j++)     (endless loop)
  • Common bug: use of local variable instead of dynamic allocation

    When using variables and objects, be aware of variable scope.

    When using local variables that are allocated on the stack, the allocation is released when the function ends.

  • Common bug: cyclic include dependencies.

    This is a common compilation bug.

    A includes B and B includes A.

  • Check the compiled asm file (advanced programming)
  • Check the map file - to determine code and data size
  • Check memory leaks
  • Find a workaround the problem.
  • Compare memory section images (good operation vs bad - file compare diff)
  • Add conditional breakpoints and prints (if( xxx ) a=a messagebox() )
  • Rebuild all
  • Fix bugs immediately (stable system / might be related to the bug)
  • When problem is not consistent, try to make the problem happen more frequently (increase the suspected problem factors)
  • Link error: missing library / missing file in project

    unresolved external symbol "myfunc()"

 

 

 

Write how to improve this page

PROGRAMMING TIPS
RAPID TABLES