Memory access violations occur when a kernel is reading or writing out of
bounds of an object or reading uninitialized memory. Violations can manifest in
multiple ways such as a simulator crash or hang. Violations can also cause simulator
results to be non-repeatable. You can use the x86simulator
--valgrind option to find memory access violations in kernel source
code.
This option allows detection of memory access violations in kernel source code during x86 simulation with Valgrind. The system can detect the following types of access violations:
- Out-of-bounds write
- Out-of-bounds read
- Read of uninitialized memory
You can use this option in the following two ways:
-
x86simulator --valgrind - This option runs the simulation with access violation detection turned on. At the end of the simulation, Valgrind prints a report on access violations. If there are none, the report ends with ERROR SUMMARY: 0 errors from 0 contexts. Otherwise, the report lists each access violation found. The report includes a stack trace, which highlights the line number in the kernel source code where the access violations occurred.
-
x86simulator --valgrind-gdb - This option runs the simulation with access violation detection turned on
and debug with GDB. The simulation comes up in GDB and is halted at
main(). At this point you can set additional breakpoints. After continuing, the simulation stops if it detects an access violation. At this point you can inspect local variables and the stack to diagnose the problem.
In either case, you can add arguments to the Valgrind command using flag --valgrind-args='list of arguments for
valgrind'.
The following example uses arguments to specify not to track memory leakage, and to display the overall stack when discovering an access violation. The example uses the following command:
--valgrind-args='-v --leak-check=no --track-origins=yes'
The snippet below shows the simulation running this command.