Debugging MtxVec Applications

Debugging tools and techniques for MtxVec applications.

Debugger Visualizer (Delphi IDE):

  • Install the MtxVec debugger visualizer package into the IDE
  • CTRL+F6: View values in a table (works for Vector, TVec, Matrix, TMtx, etc.)
  • CTRL+ALT+F6: Draw values on a chart
  • Supports: Vector, TVec, VectorInt, TVecInt, Matrix, TMtx, MatrixInt, TMtxInt, clVector, clMatrix, 1D static/dynamic arrays, TSignal
  • Visualizer windows support docking and persist between debug sessions
  • Expressions are auto-updated on each step-over/step-into

Debugger Visualizer (Visual Studio):

Dew Math ships debugger visualizers for Visual Studio: the dialog in Dew.Math.Visualizer.UI, and one object source per runtime — Dew.Math.Visualizer.Windows, .Core and .Linux, matching Dew.Math, Dew.Math.Core and Dew.Math.Linux. Place them in the Visual Studio Visualizers folder; the debugger then offers them on any value of a supported type.

  • Registered for Vector, Matrix, VectorInt, MatrixInt, and any object deriving from TMtxVecBase, each under its own name ("Vector Visualizer", "Matrix Visualizer", "Dew Math Visualizer", …)
  • Open it from the magnifying-glass icon on a DataTip, or on an entry in the Watch, Locals or Autos window, and pick the visualizer by name

The window ("MtxVec Array Visualizer") offers:

  • View table — the values in a grid, with row and column indices, scientific or custom numeric formatting, automatic or fixed column width, and complex numbers optionally split into separate real and imaginary columns
  • View chart — the same values drawn on a chart
  • Math Expression — evaluate an expression over the data (y = x) and see the result without leaving the debugger
  • File > Open / Save, and Copy / Paste including Copy As Real and Paste As Complex, with a configurable text delimiter, for moving data in and out of other tools
  • Layout and formatting choices persist between debugging sessions

The object is copied out of the debugged process to be displayed. Turning on View > Editable makes the grid editable, but the edits stay in that copy — nothing is written back into the running program.

C++ edition: no debugger visualizer is included for the native C++ edition. In the debugger, Vector and Matrix show the public FData pointer to the wrapped TVec / TMtx object.

Manual watch expressions:

In Delphi IDE, use these watch expressions to inspect vector/matrix data:

In C# / Visual Studio, inspect the internal data arrays:

In C++ there is no Assertions switch: MTXVEC_RANGE_CHECKING adds the element accessor checks (topic range-checking), and SetVecCacheSize(0, 0) / SetMtxCacheSize(0, 0) (below) make CreateIt allocate a new object on the heap instead of taking one from the pool.

  1. Enable Assertions in compiler options (disables object cache)
  2. Use FastMM4 debugging features (or similar memory manager)
  3. After all MtxVec operations complete, check:
// Should be 0 — if not, you have a CreateIt without matching FreeIt
TMtxVecPoolItem* pool = Controller->Pool[Controller->GetPoolIndex()];
int vecLeaks = pool->Vec->GetCacheUsedCount();
int mtxLeaks = pool->Mtx->GetCacheUsedCount();
  1. On application exit, MtxVec raises an exception if any TVec/TMtx objects were not freed

Detecting memory overwrites:

  1. Enable Assertions → disables object cache, enables explicit range checks
  2. Enable Delphi range checking ({$R+}) for your own code
  3. Use FastMM debug mode for buffer overrun detection
  4. Disable memory pre-allocation for debugging:
Controller->SetVecCacheSize(0, 0);
Controller->SetMtxCacheSize(0, 0);

This makes access violations appear closer to the actual cause.

SSE/AVX alignment issues:

  • All MtxVec-allocated memory is properly aligned for SIMD
  • Problems occur when passing external (non-MtxVec) arrays to vectorized routines
  • Symptoms: access violations or subtle memory corruption
  • Debug: progressively comment out code blocks until the problem disappears

Release build checklist:

  • Assertions OFF (enables object cache, disables range checks)
  • Delphi range checking OFF for MtxVec-intensive code
  • FastMM in release mode (not debug mode)