[PATCH v4 00/44] A new target to debug Intel GPUs

Markus Metzger <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
Intel would like to submit patches to enable fundamental debug support for
Intel GPU devices.  In the future, we plan to add more patches that
improve the performance and the user experience.  Those patches are
already available in the downstream "Intel Distribution for GDB" debugger
at

  https://github.com/intel/gdb

Previous revisions of the submission:

  v1: https://sourceware.org/pipermail/gdb-patches/2024-July/210264.html
  v2: https://sourceware.org/pipermail/gdb-patches/2024-December/214029.html
  v3: https://sourceware.org/pipermail/gdb-patches/2025-August/219593.html

This revision (v4) makes the following changes:

  - The comments received from Simon have been addressed.
  - The UNAVAILABLE thread state has been removed.
  - The vAck packet has been removed.
  - Add basic support for allowing processes without threads.
  - Add %Library notifications to RSP.
  - Patches are rebased on the master branch, addressing pre-commit
    findings.

GPU threads operate in a SIMD/SIMT (single instruction multiple data,
single instruction multiple thread) manner: they are vectorized, where
each lane (also known as "execution channel") executes the same
instruction but using different data values.  Lanes of the same thread
execute in a lock-step movement.  Displaying the value of a source
program variable therefore requires not only a thread context but also
a lane context.  GDB currently does not have this knowledge built-in.
Furthermore, some DWARF extensions are necessary to express data
locations in a lane-relative way, which are currently under discussion
of or to be submitted to the DWARF committee.  Hence, with this
submission, variables may appear with an error like "<error reading
variable: Unhandled dwarf expression opcode 0xed>".  Similar
restrictions apply also to the AMD ROCm (AMDGPU) target in the
upstream GDB for the same reasons.  The downstream "Intel Distribution
for GDB" debugger implements lane support as well as DWARF extensions
and hence is able to print lane-relative values properly.  Lane
support is a future GDB topic; see the presentation hosted by Intel
and AMD in GNU Tools Cauldron 2025 for more details if interested.

We provide a gdbserver low target definition.  The target uses the
Level-Zero debug API:

  https://oneapi-src.github.io/level-zero-spec/level-zero/latest/tools/PROG.html#program-debug
  https://oneapi-src.github.io/level-zero-spec/level-zero/latest/tools/api.html#debug

The user-space implementation of the Level-Zero Debug API comes from
"Intel(R) Graphics Compute Runtime for oneAPI Level Zero and OpenCL(TM)
Driver":

  https://github.com/intel/compute-runtime

The kernel-space implementation of the Level-Zero Debug API, i.e.  the
'eudebug' feature of the "Xe Intel graphics driver", is under submission.
See the discussions at

  https://lists.freedesktop.org/archives/intel-xe/

E.g. Submission v9:

  https://lists.freedesktop.org/archives/intel-xe/2026-June/128834.html

For Level-Zero based devices, we show threads that are active when GDB
obtains the thread list, e.g. on an event from the target.  This is
consistent with remote debugging on other architectures.  GPU threads are
typically short-lived, so as long as threads get dispatched and exit
without creating an event, they will not be visible to GDB.

This patch series implements support for a non-stop extended remote target
with explicit attach.  Start gdbserver with --multi, then attach to the
host process PID.

The Intel GPU target can be used in combination with a native target,
relying on GDB's multi-target feature, to debug the GPU and the host
application in the same debug session.  For this, bring the native app
(e.g.  a SYCL [https://www.khronos.org/sycl/] program) to a state
where the Level-Zero backend for the GPU has been initialized (e.g.
after the first queue has been created in SYCL), then create a
gdbserver instance and connect to it from a second inferior.
At GNU Tools Cauldron 2024, we gave a talk presenting the approach.
We invite interested parties to watch the recording.

  https://www.youtube.com/watch?v=sYep57kjvHM

Below is a sample session that shows how to set up inferiors and
targets manually.  In the downstream debugger, a Python script is used
to take these steps in an automated manner for better user experience.

  $ gdb demo
  ...
  (gdb) maintenance set target-non-stop on
  (gdb) tbreak 60
  Temporary breakpoint 1 at 0x4049c8: file demo.cpp, line 60.
  (gdb) run
  ...
  [SYCL] Using device: [Intel(R) Graphics ...] from [Intel(R) oneAPI Unified Runtime over Level-Zero]

  Thread 1 "demo" hit Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd9b8) at demo.cpp:60
  60          range data_range{length};
  (gdb)

Connect the Intel GT gdbserver by specifying the host inferior PID.

  (gdb) add-inferior -no-connection
  [New inferior 2]
  Added inferior 2
  (gdb) inferior 2
  [Switching to inferior 2 [<null>] (<noexec>)]
  (gdb) info inferiors
    Num  Description       Connection           Executable
    1    process 16458     1 (native)           /temp/demo
  * 2    <null>
  (gdb) target extended-remote | gdbserver-intelgt --multi -
  Remote debugging using | gdbserver-intelgt --multi -
  Remote debugging using stdio
  (gdb) attach 16458
  Attaching to process 16458
  Attached; given pid = 16458, updated to 1
  (gdb)

We also include patches for the testsuite, where we introduce the
infrastructure and a number of test cases using SYCL.

For convenience, the patches in this series are available at

  https://github.com/intel/gdb/tree/upstream/intelgt-mvp

To those who may want to try the debugger, we also provide

  https://github.com/intel/gdb/tree/upstream/intelgt-mvp-plus

with a number of additional patches (not yet submitted) that bring (1)
lane support, (2) ability to make GPU threads do inferior calls for
expression evaluation, (3) a minimal Python script that starts and
connects gdbserver-intelgt automatically for more convenience.  Submission
of these additional features (and more) is planned for future after the
fundamental debug support is accepted and after aligning with the upstream
community on GPU support (e.g. lanes) in GDB.


Albertano Caruso (2):
  gdb, intelgt: add disassemble feature for the Intel GT architecture.
  testsuite, arch, intelgt: add a disassembly test

Markus Metzger (24):
  config.sub: recognize level-zero as "ze"
  gdb, arch, intelgt: add intelgt arch definitions
  gdbserver: move dlls_changed initialization on attach into targets
  gdbserver: check process when we need a process
  gdb: use process in xfer_partial if inferior_ptid is null_ptid
  gdb: allow inferiors without threads in all_matching_threads_iterator
  gdbserver: improve threads debug output for process general thread
  gdb, gdbserver: allow setting null_ptid as general thread
  gdbserver: allow inferiors without threads
  gdb: allow creating and attaching to inferiors without threads
  gdb, remote: don't create an inferior on attach
  gdb: allow switching to an inferior without threads
  gdb: allow resuming an inferior with no threads
  gdb: allow continuing an inferior without threads
  gdb: partially fix C-c not working
  gdb, linux-nat: use current_inferior()->pid in mourn_inferior()
  gdb: inferior events
  gdb, remote: allow deleting the last thread in inferior in
    update_thread_list()
  gdb: keep target registered in inferior_event_handler()
  gdb, dwarf, ze: add DW_OP_INTEL_regval_bits
  gdb, gdbserver, ze: in-memory libraries
  gdb, gdbserver: library notifications
  gdbserver, ze, intelgt: introduce ze-low and intelgt-ze-low targets
  testsuite, intelgt: add a test for interrupting an exited thread

Natalia Saiapova (1):
  bfd: add intelgt target to BFD

Nils-Christian Kempke (1):
  gdb, gdbserver, gdbsupport: add 'device' tag to XML target description

Tankut Baris Aktemur (16):
  opcodes: add intelgt as a configuration
  gdbserver: allow configuring for a heterogeneous target
  gdbserver: import AC_LIB_HAVE_LINKFLAGS macro into the autoconf script
  gdb: add a new extract_integer variant that takes two array_views
  gdb, intelgt: add the target-dependent definitions for the Intel GT
    architecture
  gdb: revise the pid_to_exec_file target op
  gdb, remote: do 'remote_add_inferior' in 'remote_notice_new_inferior'
    earlier
  gdbserver: adjust pid after the target attaches
  gdbserver: add a pointer to the owner thread in regcache
  testsuite, sycl: add SYCL support
  testsuite, sycl: add test for backtracing inside a kernel
  testsuite, sycl: add test for 'info locals' and 'info args'
  testsuite, sycl: add tests for stepping
  testsuite, sycl: add test for 1-D and 2-D parallel_for kernels
  testsuite, sycl: add test for scheduler-locking
  testsuite, arch, intelgt: add intelgt-program-bp.exp

 bfd/Makefile.am                               |    2 +
 bfd/Makefile.in                               |    4 +
 bfd/archures.c                                |    4 +
 bfd/bfd-in2.h                                 |    2 +
 bfd/config.bfd                                |    5 +
 bfd/configure                                 |    1 +
 bfd/configure.ac                              |    1 +
 bfd/cpu-intelgt.c                             |   41 +
 bfd/elf64-intelgt.c                           |   48 +
 bfd/targets.c                                 |    2 +
 binutils/dwarf.c                              |    6 +
 binutils/readelf.c                            |    5 +
 config.sub                                    |    3 +-
 gdb/Makefile.in                               |    8 +-
 gdb/NEWS                                      |   19 +
 gdb/README                                    |    8 +
 gdb/arch/intelgt.c                            |  191 ++
 gdb/arch/intelgt.h                            |  185 ++
 gdb/config.in                                 |    3 +
 gdb/configure                                 |  565 +++-
 gdb/configure.ac                              |   47 +
 gdb/configure.tgt                             |    5 +
 gdb/disasm-selftests.c                        |   12 +
 gdb/doc/gdb.texinfo                           |   69 +-
 gdb/dwarf2/expr.c                             |   37 +
 gdb/dwarf2/expr.h                             |    5 +
 gdb/dwarf2/loc.c                              |    2 +
 gdb/exec.c                                    |    6 +
 gdb/extract-store-integer.c                   |   53 +-
 gdb/extract-store-integer.h                   |    8 +
 gdb/features/gdb-target.dtd                   |   11 +-
 gdb/features/library-list.dtd                 |    6 +-
 gdb/inf-loop.c                                |   11 +-
 gdb/infcmd.c                                  |   70 +-
 gdb/inferior.c                                |   39 +-
 gdb/inferior.h                                |   15 +
 gdb/infrun.c                                  |  426 ++-
 gdb/intelgt-tdep.c                            | 1010 ++++++
 gdb/linux-nat.c                               |    8 +-
 gdb/remote-notif.c                            |    1 +
 gdb/remote-notif.h                            |    2 +
 gdb/remote.c                                  |  228 +-
 gdb/selftest-arch.c                           |    3 +-
 gdb/solib-target.c                            |   66 +-
 gdb/solib.c                                   |   80 +-
 gdb/solib.h                                   |   23 +-
 gdb/target-descriptions.c                     |   19 +
 gdb/target.c                                  |   15 +-
 gdb/target.h                                  |    3 +
 gdb/testsuite/README                          |    9 +
 gdb/testsuite/boards/intel-offload.exp        |   36 +
 .../gdb.arch/intelgt-disassemble.exp          |   82 +
 .../intelgt-interrupt-exited-thread.exp       |   85 +
 gdb/testsuite/gdb.arch/intelgt-program-bp.exp |   83 +
 gdb/testsuite/gdb.arch/sycl-hello.cpp         |   33 +
 .../gdb.base/annota-input-while-running.exp   |    2 +-
 gdb/testsuite/gdb.base/annota1.exp            |    4 +-
 .../gdb.base/breakpoint-in-ro-region.exp      |    4 +-
 gdb/testsuite/gdb.base/multi-forks.exp        |   12 +-
 .../premature-dummy-frame-removal.exp         |   16 +-
 .../gdb.base/sss-bp-on-user-bp-2.exp          |    4 +-
 gdb/testsuite/gdb.base/ui-redirect.exp        |    2 +-
 gdb/testsuite/gdb.cp/annota2.exp              |    2 +-
 gdb/testsuite/gdb.replay/missing-thread.exp   |   28 +-
 gdb/testsuite/gdb.sycl/break.cpp              |  127 +
 gdb/testsuite/gdb.sycl/break.exp              |  246 ++
 gdb/testsuite/gdb.sycl/call-stack.cpp         |   92 +
 gdb/testsuite/gdb.sycl/call-stack.exp         |  176 +
 .../gdb.sycl/info-locals-and-args.exp         |   78 +
 gdb/testsuite/gdb.sycl/parallel-for-1D.cpp    |   72 +
 gdb/testsuite/gdb.sycl/parallel-for-1D.exp    |   57 +
 gdb/testsuite/gdb.sycl/parallel-for-2D.cpp    |   73 +
 gdb/testsuite/gdb.sycl/parallel-for-2D.exp    |   57 +
 gdb/testsuite/gdb.sycl/scheduler-locking.exp  |   63 +
 gdb/testsuite/gdb.sycl/step.exp               |   48 +
 gdb/testsuite/gdb.threads/ia64-sigill.exp     |    8 +-
 .../process-dies-while-detaching.exp          |    5 +-
 ...al-while-stepping-over-bp-other-thread.exp |    2 +-
 .../gdb.threads/stepi-random-signal.exp       |    4 +-
 .../gdb.threads/watchthreads-reorder.exp      |    4 +-
 gdb/testsuite/lib/gdb.exp                     |   17 +-
 gdb/testsuite/lib/intelgt-utils.exp           |   43 +
 gdb/testsuite/lib/sycl-devices.cpp            |  106 +
 gdb/testsuite/lib/sycl-hello.cpp              |   33 +
 gdb/testsuite/lib/sycl-util.cpp               |  135 +
 gdb/testsuite/lib/sycl.exp                    |  399 +++
 gdb/thread-iter.c                             |    2 +-
 gdb/top.c                                     |   10 +
 gdb/xml-tdesc.c                               |   36 +
 gdbserver/Makefile.in                         |    4 +-
 gdbserver/acinclude.m4                        |    5 +
 gdbserver/config.in                           |    3 +
 gdbserver/configure                           |  500 +++
 gdbserver/configure.ac                        |   18 +
 gdbserver/configure.srv                       |   15 +-
 gdbserver/dll.cc                              |  147 +-
 gdbserver/dll.h                               |   51 +-
 gdbserver/gdbthread.h                         |    2 +-
 gdbserver/intelgt-ze-low.cc                   | 1002 ++++++
 gdbserver/linux-low.cc                        |   11 +-
 gdbserver/linux-low.h                         |    2 +-
 gdbserver/netbsd-low.cc                       |    2 +-
 gdbserver/netbsd-low.h                        |    2 +-
 gdbserver/notif.cc                            |    4 +
 gdbserver/notif.h                             |    4 +
 gdbserver/regcache.cc                         |    1 +
 gdbserver/regcache.h                          |    3 +
 gdbserver/remote-utils.cc                     |    3 +-
 gdbserver/server.cc                           |  150 +-
 gdbserver/server.h                            |    3 +
 gdbserver/target.cc                           |   38 +-
 gdbserver/target.h                            |   45 +-
 gdbserver/tdesc.cc                            |   21 +-
 gdbserver/tdesc.h                             |    3 +
 gdbserver/win32-low.cc                        |   11 +-
 gdbserver/win32-low.h                         |    2 +-
 gdbserver/ze-low.cc                           | 2846 +++++++++++++++++
 gdbserver/ze-low.h                            |  465 +++
 gdbsupport/tdesc.cc                           |   24 +
 gdbsupport/tdesc.h                            |   54 +
 include/dwarf2.def                            |    4 +
 include/elf/intelgt.h                         |   45 +
 opcodes/configure                             |    1 +
 opcodes/configure.ac                          |    1 +
 124 files changed, 10699 insertions(+), 471 deletions(-)
 create mode 100644 bfd/cpu-intelgt.c
 create mode 100644 bfd/elf64-intelgt.c
 create mode 100644 gdb/arch/intelgt.c
 create mode 100644 gdb/arch/intelgt.h
 create mode 100644 gdb/intelgt-tdep.c
 create mode 100644 gdb/testsuite/boards/intel-offload.exp
 create mode 100644 gdb/testsuite/gdb.arch/intelgt-disassemble.exp
 create mode 100644 gdb/testsuite/gdb.arch/intelgt-interrupt-exited-thread.exp
 create mode 100644 gdb/testsuite/gdb.arch/intelgt-program-bp.exp
 create mode 100644 gdb/testsuite/gdb.arch/sycl-hello.cpp
 create mode 100644 gdb/testsuite/gdb.sycl/break.cpp
 create mode 100644 gdb/testsuite/gdb.sycl/break.exp
 create mode 100644 gdb/testsuite/gdb.sycl/call-stack.cpp
 create mode 100644 gdb/testsuite/gdb.sycl/call-stack.exp
 create mode 100644 gdb/testsuite/gdb.sycl/info-locals-and-args.exp
 create mode 100644 gdb/testsuite/gdb.sycl/parallel-for-1D.cpp
 create mode 100644 gdb/testsuite/gdb.sycl/parallel-for-1D.exp
 create mode 100644 gdb/testsuite/gdb.sycl/parallel-for-2D.cpp
 create mode 100644 gdb/testsuite/gdb.sycl/parallel-for-2D.exp
 create mode 100644 gdb/testsuite/gdb.sycl/scheduler-locking.exp
 create mode 100644 gdb/testsuite/gdb.sycl/step.exp
 create mode 100644 gdb/testsuite/lib/intelgt-utils.exp
 create mode 100644 gdb/testsuite/lib/sycl-devices.cpp
 create mode 100644 gdb/testsuite/lib/sycl-hello.cpp
 create mode 100644 gdb/testsuite/lib/sycl-util.cpp
 create mode 100644 gdb/testsuite/lib/sycl.exp
 create mode 100644 gdbserver/intelgt-ze-low.cc
 create mode 100644 gdbserver/ze-low.cc
 create mode 100644 gdbserver/ze-low.h
 create mode 100644 include/elf/intelgt.h

-- 
2.43.0


--- b4-submit-tracking ---
{
  "series": {
    "revision": 4,
    "change-id": "20241213-upstream-intelgt-mvp-684d5f2f6730",
    "prefixes": []
  }
}
________________________________________
Intel Deutschland GmbH 

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany 

Tel: +49 (89) 99143-0 

www.intel.de 

Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman

Chairperson of the Supervisory Board: Sonja Pierer

Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.