KasperskyOS Community Edition 1.3

Debugging a program that is part of a KPA package

Unlike debugging programs in a KasperskyOS-based solution, debugging a program in a KPA package means you don’t have to rebuild the entire KasperskyOS-based solution after updating the application code.

The scenario for debugging a program that is part of a KPA package looks as follows:

  1. Install the KasperskyOS SDK Extension.
  2. Build an application and package it into a KPA package. You must use the CMake commands of the kpa library to pack a program into a KPA package.
  3. Run a basic KasperskyOS image from KasperskyOS Community Edition with a GDB server built into the kernel.
  4. Connect the debugger to the GDB server of the kernel. The debugger can be connected at program startup or while the program is running. Details:
  5. Debugging a program using the Visual Studio Code graphical user interface. For more details, refer to the Visual Studio Code documentation: https://code.visualstudio.com/docs/editor/debugging .
Page top
[Topic kpa_debug]

Connecting a debugger when starting a program in a basic image

To connect a debugger to the GDB server of the kernel while starting a program in QEMU using the Visual Studio Code extension:

  1. Set a breakpoint in the program source code before the fragment to be debugged.
  2. Build the program. You must use the CMake commands of the kpa library to pack a program into a KPA package.
  3. Run a basic KasperskyOS image from KasperskyOS Community Edition.
  4. Wait for the basic image to finish loading and install the program by running the command KOS: Install package.
  5. On the side bar of Visual Studio Code, click Run and debug > create a launch.json file and then select KasperskyOS Debugger.

    This will create a debug configuration file named launch.json.

  6. In the launch.json file, in the field of the configuration named (kos/gdb) Launch & debug application, specify the path to the binary file of your program resulting from the build, and the program name. In the eiid field, you need to specify the kl.Kds value.
  7. Start debugging by clicking the (kos/gdb) Launch & debug application button on the lower pane.
  8. In the drop-down list, select the configuration named (kos/gdb) Launch & debug application.
  9. The debug console will show a message stating that the program is ready for debugging. Click Continue, and program execution will be stopped at the breakpoint that you selected at step 1.
Page top
[Topic kpa_debug_start]

Connecting a debugger while a program is running from a basic image

To connect a debugger to the GDB server of the kernel while the program is running in QEMU using the Visual Studio Code extension:

  1. Add an infinite loop to the main function of the program. This enables the debugger to connect to the running program.
  2. Set a breakpoint in the program source code before the fragment to be debugged.
  3. Build the program. You must use the CMake commands of the kpa library to pack a program into a KPA package.
  4. Run a basic KasperskyOS image from KasperskyOS Community Edition.
  5. On the side bar of Visual Studio Code, click Run and debug > create a launch.json file and then select KasperskyOS Debugger.

    This will create a debug configuration file named launch.json.

  6. In the launch.json file, in the field of the configuration named (kos/gdb) Attach to process, specify the path to the binary file of your program resulting from the build.
  7. Start the program in the basic image.
  8. Start debugging by clicking the (kos/gdb) Attach to process button on the lower pane.
  9. In the drop-down list, select the configuration named (kos/gdb) Attach to process and select the name of the program to debug.
  10. The debug console will show a message stating that the program is ready for debugging. Click Continue, and program execution will be stopped at the breakpoint that you selected at step 2.
Page top
[Topic kpa_debug_attach]