Tutorial: Debugging with Intel® Distribution for GDB*

Single Stepping

A common debugging activity is single-stepping in the source. To check the current thread data, run the following command:

thread

You should get the following output:

[Current thread is 3 (Thread 0x7fffdba79700 (LWP 21605))]

To check the data of a particular thread, run:

info thread 3

Example output:

  Id  Target Id   Frame
* 3   Thread [...]   main::$_1::operator()[...] at array-transform.cpp:56

To make Thread 3 move forward by one source line, run:

next

You should see the following output:

[Switching to Thread 0x7fffdb277700 (LWP 21607)]

Thread 5 "array-transform" hit Breakpoint 1, main::$_1::operator()[...]
    at array-transform.cpp:56
56        int element = in[index];  // breakpoint-here

Stepping has not occurred. Instead, a breakpoint event from Thread 5 is received and the debugger switched the context to that thread. This happens because you are debugging a multi-threaded program and multiple events may be received from different threads. This is the default behavior, but you can configure it for more efficient debugging. To ensure the current thread executes a single line without interference, set the scheduler-locking setting to on or step:

set scheduler-locking step

Important

The default value of scheduler-locking is replay. If you set it to on and you want to resume your DPC++ program with the continue command, do not forget to set scheduler-locking back to replay or off. Otherwise, only the current thread is resumed. Hence, the recommended value for scheduler-locking is step.

Continue executing the next command:

next

You should see the following outputs:

  1. 57        int result = element + 50;
  2. 58        if (id0 % 2 == 0) {

To see the value of index variable, run:

print index

You should see the following output:

$6 = cl::sycl::id<1> = {16}

Run:

print in[index]

The expected output looks as follows:

$7 = 116

Finally, run:

print result

You should see the following output:

$8 = 166