Main Content

Debugging Strategies

Before you perform code verification, choose a debugging strategy for detecting and correcting noncompliant code in your MATLAB® applications, especially if they consist of many MATLAB files that call each other's functions. The following table describes two general strategies, each of which has advantages and disadvantages.

Debugging StrategyWhat to DoProsCons

Bottom-up verification

  1. Verify that your lowest-level (leaf) functions are compliant.

  2. Work your way up the function hierarchy incrementally to compile and verify each function, ending with the top-level function.

  • Efficient

  • Unlikely to cause errors

  • Easy to isolate code generation syntax violations

Requires application tests that work from the bottom up

Top-down verification

  1. Declare functions called by the top-level function to be extrinsic so that MATLAB Coder™ does not compile them. See Declaring MATLAB Functions as Extrinsic Functions.

  2. Verify that your top-level function is compliant.

  3. Work your way down the function hierarchy incrementally by removing extrinsic declarations one by one to compile and verify each function, ending with the leaf functions.

You retain your top-level tests

Introduces extraneous code that you must remove after code verification, including:

  • Extrinsic declarations

  • Additional assignment statements as required to convert opaque values returned by extrinsic functions to nonopaque values (see Working with mxArrays).