Hard-to-find and Useful Information for gdb-oneapi
This page contains links to key pieces of information that are otherwise hard to find.
Useful debugging features
Here are four useful debugging features: live-attach, auto-attach, pretty-printing, and prettify-frames. The first two are used to attach the gdb-oneapi debugger to an application that is already running but is not being debugged. The second two provide ways to simplify the display of complex SYCL objects and templates.
Auto-Attach
The auto-attach feature enables listening to debug events from the GPU.
This feature allows the debugger to launch a gdbserver-ze process to listen to GPU debug events and connects the gdbserver-ze to the debugger. For each device on the system, an inferior is created on the gdbserver-ze connection. This feature is designed to improve your debugging experience and ensure that you can debug the kernel offloaded to GPU.
The auto-attach feature is enabled by default.
The feature does not affect the debugging capability on the CPU device. However, to eliminate the extra output this feature creates, you can turn it off with the INTELGT_AUTO_ATTACH_DISABLE environment variable. To do it, execute the following command on the shell before starting gdb-oneapi:
To enable the feature again:
Reducing Overhead
Executing the info threads command may take a noticeable amount of time to complete, because it needs to fetch the data of a large number of threads when debugging GPUs. To reduce the overhead, it is recommended to run the info threads command without printing the frame arguments. This can be achieved by changing the setting globally using
or by using
for a single command execution.
Pretty-Printing
The pretty-printing feature simplifies the display of complex objects. If a pretty-printer is registered for the type of value you are going to print, the debugger simplifies the output. Otherwise, the debugger prints the value normally.
Intel® Distribution for GDB* supports pretty-printing for the SYCL* types accessor, buffer, device, exception, handler, id, item, local_accessor, queue and range from the sycl namespace.
You can write your own pretty-printer for any type. Refer to Writing a Pretty Printer for more information.
To display the list of pretty-printers available, run the following command:
Example output:
- global pretty-printers:
-
- builtin
-
workitem
- libsycl
-
sycl::_V1::accessor sycl::_V1::buffer sycl::_V1::device sycl::_V1::exception sycl::_V1::handler sycl::_V1::id sycl::_V1::item sycl::_V1::local_accessor sycl::_V1::queue sycl::_V1::range
Pretty-printing is enabled by default. For example, when you print a value of the sycl::id<2> wiID variable:
The output is the following:
To disable pretty-printing and display raw content instead, use the /r flag:
Example output:
To disable all pretty-printers, use the following command:
To enable pretty-printers:
Prettify Frames
Some C++ templates/SYCL constructs make it difficult to view the output of info threads and backtrace given multi-line function names.
You can use the concept of frame filters to change the visibility of a printed frame with the ‘backtrace’ command. For details refer to the GDB Documentation Frame Filter API.
It is also possible to change the visibility of a printed frame globally. Consider the setting print frame-info:
Refer to the GDB documentation for more information.
Print settings for kernel data
Given the sample program array-transform.cpp:
Inside the kernel we need to use a sycl::accessor to access data in the host’s sycl::buffer. To review the contents of the sycl::buffer object buffer_in of length 64 from inside the kernel, one can simply print the sycl::accessor object in whose pretty-printer provides easy access to the data:
Use the print setting print elements to further configure number of printed elements:
Consider the print setting print repeats in case the output contains repeated elements: