Contents
Initial steps of debugging in QEMU
To begin debugging using the GDB server of the KasperskyOS kernel in QEMU, you must complete the following steps:
- Build debug versions of executable files and libraries, create a solution image for QEMU, and run QEMU.
To do so, call the
cmake
shell commands, and specify the-D CMAKE_BUILD_TYPE:STRING=Debug
and--target sim
parameters.Example:
"Unix Makefiles" \ -D CMAKE_BUILD_TYPE:STRING=Debug \ -D CMAKE_TOOLCHAIN_FILE=$SDK_PREFIX/toolchain/share/toolchain-$TARGET.cmake \ -B build \ && cmake --build build --target sim... cmake -GInstead of the
sim
target, you can specify thesim/fast
target to avoid rebuilding.QEMU starts and executes the solution code. Execution of the solution code stops when the GDB debugger connects.
- Run the GDB debugger and connect to the GDB server of the kernel.
To do so, run the executable file
toolchain/bin/aarch64-kos-gdb
from KasperskyOS Community Edition. It must be run in the directory where the manually created.gdbinit
file was saved. - Create inferiors, attach them to processes, and load debug symbols.
To load debug symbols, you need to switch to the inferior associated with the process and use the following GDB commands:
add-symbol-file
<path to file
> — for executable files with static or dynamic linking.file
<path to file
> – for executable files with dynamic linking.
The GDB command
file
must be used so that the GDB debugger can load debug symbols of an executable file and the dynamic libraries required by this executable file. Use the GDB commandadd-symbol-file
for the GDB debugger to load the debug symbols only for an executable file with dynamic linking.If debug symbols are saved in separate files instead of in the executable files, links to the files containing the debug symbols are added to the executable files. When the GDB command
add-symbol-file
orfile
is called, you can specify the executable file or the file containing debug symbols.
When performing a repeat build (step 1), you need to terminate the debug session (exit the GDB debugger) and repeat steps 2 and 3.