To begin debugging using the GDB server of QEMU, you must complete the following steps:
To do so, call the cmake
shell commands, and specify the -D CMAKE_BUILD_TYPE:STRING=Debug
and --target gdbsim
parameters.
Example:
#!/bin/bash
...
cmake -G "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 gdbsim
Instead of the gdbsim
target, you can specify the gdbsim/fast
target to avoid rebuilding.
QEMU starts but does not execute the solution code while it waits for a call of the GDB command continue
.
To do so, you must call the shell command make gdb
in the build
directory.
During step 1, the build/einit/.gdbinit
file automatically records the path where the GDB debugger will search for dynamic libraries containing debug symbols from KasperskyOS Community Edition (as a parameter of the GDB command set sysroot
). To define additional paths to search for dynamic libraries, call the following GDB command:
set solib-search-path <path to directory>...
If .text
section loading addresses are defined for executable files with static linking (using the CMake
command set_target_properties()
), the GDB command for loading debug symbols for each of these files is automatically added to the build/einit/.gdbinit
file at step 1.
If a .text
section loading address is defined for one executable file with dynamic linking, the GDB command for loading debug symbols for this file is automatically added to the build/einit/.gdbinit
file at step 1. If .text
section loading addresses are defined for multiple executable files with dynamic linking, the GDB command for loading debug symbols is not automatically added to the build/einit/.gdbinit
file for any of these executable files at step 1.
To manually load debug symbols, 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 command add-symbol-file
for the GDB debugger to load the debug symbols only for an executable file with dynamic linking.
The GDB command file
can be used only for one executable file. In other words, the GDB debugger cannot load debug symbols of dynamic libraries for multiple executable files at the same time.
After the GDB command file
is called, the following message can be displayed:
warning: Unable to find dynamic linker breakpoint function.GDB will be unable to debug shared library initializers and track explicitly loaded dynamic code.
This message should be ignored.
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
or file
is called, you can specify the executable file or the file containing debug symbols.
When performing a repeat build (step 1), you do not have to terminate the debug session (i.e. exit the debugger). (This means that you can avoid repeating operations such as loading debug symbols and defining additional paths to search for dynamic libraries.) To avoid terminating the debug session, you must run the GDB command detach
before running the repeat build, then you must run the GDB command target remote localhost:1234
after starting QEMU.
GDB commands (for example, to load debug symbols or define additional paths to search for dynamic libraries) can be written to a file and then called by using the GDB command source
<path to file
>.