Debugging Features

twinBASIC includes several features to help with debugging. Breakpoints, stepping through code, and what the IDE shows when a run-time error stops a program are on the Debug menu page.

Debug Trace Logger

New to the debugging experience is a trace logging feature that automatically creates detailed logs to either the debug console or a file. Messages can be output with Debug.TracePrint. The logger works both when running from the IDE and in compiled executables.

The Project Settings page showing the Compilation: Trace Flags and Compilation: Trace Output options

Public Sub ProcessOrder(ByVal orderId As Long)
    Debug.TracePrint "ProcessOrder called, orderId=" & CStr(orderId)
    ' ... processing ...
End Sub

Clearing the Debug Console

Debug.Cls empties the Debug Console from code, the same as its Clear Debug Console button. Calling it as a run begins separates that run’s output from the previous one, which is the difference between reading a log and scrolling for where it started:

Private Sub Form_Load()
    Debug.Cls
    Debug.Print "--- run starting ---"
End Sub

Stale/Dangling Pointer Detection

Bugs result from using Strings and Variants after they have been freed. It may not be noticed immediately if the memory has not been overwritten, but it’s sometimes hard to detect and can cause issues like a String displaying it’s previous value or garbage. This debugging option detects use-after-free, and replaces the data with a special symbol indicating the problem.

Below shows an example where the ListView ColumnHeader text had been set by previously-freed string and detected by this feature:

A ListView whose column header text has been replaced by rows of warning symbols, marking the use of a freed string

Previously, it had shown the same text for every column– but only under certain circumstances, leading to the issue being overlooked for a long time.