Memory Access Violations and Valgrind - 2022.1 English

Versal ACAP AI Engine Programming Environment User Guide (UG1076)

Document ID
UG1076
Release Date
2022-05-25
Version
2022.1 English

Memory access violations occur when a kernel is reading or writing out of bounds of an object or reading uninitialized memory. This can manifest itself in multiple ways like a simulator crash or hang. It can also cause simulator results to be non-repeatable. The x86simulator --valgrind option will find memory access violations in kernel source code.

Note: Valgrind needs to be installed for this feature to work. Xilinx recommends using Valgrind version 3.16.1.

This option allows detection of memory access violations in kernel source code during x86 simulation with Valgrind. The following kinds of access violations can be detected.

  • Out-of-bounds write
  • Out-of-bounds read
  • Read of uninitialized memory

There are two ways to use this option:

x86simulator --valgrind
This 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. This includes a stack trace, which highlights the line number in the kernel source code where the access violations occurred.
x86simulator --valgrind-gdb
This 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 will stop if an access violation is detected. At this point you can inspect local variables and the stack to diagnose the problem.

In either case, some arguments can be added to the Valgrind command using flag --valgrind-args='list of arguments for valgrind'. For example:

--valgrind-args='-v --leak-check=no --track-origins=yes'

This will not track memory leakage and would display the overall stack when discovering an access violation.

Note: Running the x86simulator with the Valgrind option will increase the simulation run time.