Debugging the Samples in Visual Studio Code

Ahead of debugging, open the workspace project related to the sample and convert the applet by following the steps mentioned in the previous section Running the Samples in Visual Studio Code).

Run the Simulator Device in Debug Mode

One of the available launch configurations within the applet is “Start Java Card Simulator Debug Mode” which runs the simulator in debug mode, launches the debug proxy and attaches the debugger to the proxy.

Go to the Run and Debug section, select from the dropdown with the available configurations “Start Java Card Simulator Debug Mode” and launch the configuration from Run > Start Debugging (F5). Two terminals will open, one with the simulator instance and one with the debug proxy.

Add breakpoints as needed in the applet(s).

Run the Client

After adding any breakpoints, select “Run Java Card Client” from the dropdown and launch the configuration from Run > Start Debugging (F5). A new debug session will start and the client will run until a breakpoint is hit.

The “Variables”, “Watch” and “Call Stack” tabs are available on the left section of the window. You can use them to analyze the available variables, add new expressions for the debugger to evaluate and keep track of the call stack. You can also navigate through the code by using the debug bar’s buttons.

At the end, you can click “Continue” from the debug bar to finish the client’s execution. The output of the client will be available in the Debug Console, by selecting the console “Run Java Card Client” from the dropdown menu.

Note:

When running the client, the Simulator will attempt to make two connections, one for port checking, the other one being the actual client execution. The first one will display the error "client address rejected" in the Simulator logs. Without the port check, the client will not start properly.