Preparations for debugging
To prepare the conditions for debugging with the GDB server of QEMU, you must complete the following steps:
- Disable ASLR support and define the memory addresses for loading the
.text
sections of executable files.To do so, you need to use the following
CMake
command:set_target_properties(<program name> PROPERTIES LINK_FLAGS "-no-pie -Ttext <address>")The GDB debugger needs the memory address used to load the ELF image to map the debug symbols to the ELF image. When ASLR is supported by default, this address is defined by a random value that is unknown to the GDB debugger, which complicates debugging. To disable ASLR support, indicate the
-no-pie
flag.The GDB server of QEMU views all running processes managed by KasperskyOS as one process. If ASLR is not supported, by default the linker causes the executable files to be loaded at the same memory address of processes. As a result, the loaded segments of executable files overlap in memory from the perspective of the GDB debugger, and debugging is carried out incorrectly (for example, incorrect values of variables are displayed, or breakpoints set for another program are triggered). To prevent overlapping of loaded segments corresponding to different programs, use the
-Ttext
<address
> parameter that defines the load address of the.text
section. The offset between the load addresses of the.text
section in different processes can be a value that is 1 MB larger than the largest executable file in the solution image. For example, the value0x06000000
can be specified as the loading address of the.text
section for theClient
program in the ping example, and the value0x06200000
can be specified for theServer
program in this example.The offset between addresses of
.text
sections cannot guarantee that there will be no overlaps of loaded segments if pre-built executable files used in the solution (for example, from KasperskyOS Community Edition) were linked for ASLR support. (You can disable ASLR and define the addresses for loading.text
sections only for the executable files that are built during creation of the solution. This cannot be done for pre-built executable files.) The.text
sections of these executable files are loaded to random addresses, which could cause overlaps with loaded segments corresponding to the program that you need to debug. - [Optional] Define the settings for running QEMU.
To change the initial settings and/or add new settings for running QEMU, you need to use the
QEMU_FLAGS
parameter of theCMake
commandbuild_kos_qemu_image()
.Example:
set(QEMU_FLAGS "-m 2048 -machine vexpress-a15,secure=on \ -cpu cortex-a72 -nographic -monitor none -smp 4") build_kos_qemu_image(kos-qemu-image ... QEMU_FLAGS "${QEMU_FLAGS}")