Developer Guide

Intel® oneAPI DPC++/C++ Compiler Handbook for FPGAs

ID 785441
Date 10/24/2024
Public
Document Table of Contents

Debugging Your Kernel in Visual Studio* Code with a Native Debugger

Before debugging in Visual Studio* Code (VS Code*) with a native debugger on, ensure that you have completed the initial configuration as described in Configure Running and Debugging in a Visual Studio* Code Project.

The instructions that follow assume that you have followed the steps in Set the Environment Variables and Launch Visual Studio* Code to launch VS Code* with the required oneAPI environment and have opened the project that you want to debug.

(Linux) Debugging in VS Code* with GDB

To debug in VS Code* with GDB:

  1. If you have not yet compiled your project for debugging, compile your source code for emulation. Ensure that you include the -g and -O0 compiler command options. The -g option enables debugging and the -O0 option disables code optimizations.
    icpx -fintelfpga -g -O0 <kernel code.cpp> -o fpga_emu

    IMPORTANT:
    Disable code optimizations with the -O0 option only for emulation. Do not disable code optimizations for simulation or hardware compilation.
    If you are compiling a code sample, CMake generates the debug flags for you:
    mkdir build
    cd build
    cmake ..  -DCMAKE_BUILD_TYPE=Debug
    make fpga_emu

  2. If necessary, update the "program": "", pair in your launch.json file to point at the executable file that you want to debug.
  3. Click the Run and Debug icon in the Activity Bar (or press Ctrl+Shift+D).
  4. At the top of the Run and Debug Side Bar, ensure that the correct debugger is selected:

  5. Press F5 (or click the arrow on the left of the selected debugger) to start debugging.

    The debugger automatically stops at any breakpoints that you have set in your code. You can inspect your variables and step through the code as you would with any GUI-based debugger.



(Windows) Debugging in VS Code* with the Visual Studio* Windows Debugger

To debug in VS Code* with the Visual Studio* Windows Debugger:

  1. If you have not yet compiled your project for debugging, compile your source code for emulation. Ensure that you include the /DEBUG and /Od compiler command options. The /DEBUG option enables debugging and the /Od0 option disables code optimizations.
    icx-cl -fintelfpga /DEBUG /Od /EHsc <kernel code.cpp> -o fpga_emu.exe

    IMPORTANT:
    Disable code optimizations with the /Od option only for emulation. Do not disable code optimizations for simulation or hardware compilation.

    If you are compiling a code sample, CMake generates the debug flags for you:

    mkdir build
    cd build
    cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug
    nmake fpga_emu

  2. If necessary, update the "program": "", pair in your launch.json file to point at the executable file that you want to debug.
  3. Click the Run and Debug icon in the Activity Bar (or press Ctrl+Shift+D).
  4. At the top of the Run and Debug Side Bar, ensure that the correct debugger is selected:

  5. Press F5 (or click the arrow on the left of the selected debugger) to start debugging.

    The debugger automatically stops at any breakpoints that you have set in your code. You can inspect your variables and step through the code as you would with any GUI-based debugger.