]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/solib-rocm: add support for file URI on Windows
authorLancelot Six <lancelot.six@amd.com>
Wed, 20 May 2026 17:22:56 +0000 (18:22 +0100)
committerLancelot SIX <lancelot.six@amd.com>
Wed, 27 May 2026 10:27:02 +0000 (11:27 +0100)
commitd623dadc2c4ecd509359015ae5a1ac856ba89b05
treea3f79f45a9a6b0f362b4c35491fc475218cfa024
parentb27279c5ac9290f7fd1d765a9bea64c0b91b9c78
gdb/solib-rocm: add support for file URI on Windows

For processes using the ROCm runtime, GPU code objects are reported to
the debugger in the form of a URI (those are available to GDB using the
amd_dbgapi_process_code_object_list function and query the
AMD_DBGAPI_CODE_OBJECT_INFO_URI_NAME property).  Each URI can be of 2
forms:
  - "memory://$PID/mem#offset=$ADDR&size=$SIZE"
  - "file://$PATH#offset=$OFFSET&size=$SIZE"

On the Windows platform, only the "memory" URI form is used at the
moment, but future runtime changes might make it report code objects
using the "file" form.  When using the "file" form, when the runtime
reports an absolute path, the URI will look something like this:

    file:///C:/foo/bar/file.exe#offset=0x123&size=0x321

The decoding scheme currently implemented in
gdb/solib-rocm:rocm_bfd_iovec_open would extract the file path as
"/C:/foo/bar/file.exe", and will eventually hand this path to
solib_open.

Surprisingly enough, solib_open still manages to locate the file
properly.  This is due to the following of code which effectively drops
the leading "/" turning the path into a valid absolute path which can
eventually be opened.

    /* If the search in gdb_sysroot failed, and the path name is
       absolute at this point, make it relative.  (openp will try and open the
       file according to its absolute path otherwise, which is not what we want.)
       Affects subsequent searches for this solib.  */
    if (found_file < 0 && IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname))
      {
        /* First, get rid of any drive letters etc.  */
        while (!IS_TARGET_DIR_SEPARATOR (fskind, *in_pathname))
          in_pathname++;

        /* Next, get rid of all leading dir separators.  */
        while (IS_TARGET_DIR_SEPARATOR (fskind, *in_pathname))
          in_pathname++;
      }

This patch proposes to fix rocm_solib so we properly decode the file
path and give a valid path to solib_open to properly support this
scheme.

Note that this patch only looks for forward slashes "/" in the pattern
matching and not the traditional backslashes (as IS_TARGET_DIR_SEPARATOR
would) as URIs use forward slashes, not backslashes.

Current GDB does not really AMDGPU debugging on Windows (there are still
a couple of missing necessary pieces), but this patch can still be
applied upstream and will eventually be needed.  I have tested this
patch on top of the downstream ROCgdb windows branch[1].  I have also
tested this patch on Linux + gfx1031 on top of master to ensure this
causes no regression.

[1] https://github.com/ROCm/ROCgdb/tree/amd-temp-windows

Approved-By: Pedro Alves <pedro@palves.net>
Change-Id: I10a1a32167007d5613e5a8696918bad5438285f3
gdb/solib-rocm.c