Skip to content

gdb: extend maint print address-spaces to show all dbgapi available info - #218

Open
czidev-amd wants to merge 1 commit into
amd-stagingfrom
users/czissule/address-spaces
Open

gdb: extend maint print address-spaces to show all dbgapi available info#218
czidev-amd wants to merge 1 commit into
amd-stagingfrom
users/czissule/address-spaces

Conversation

@czidev-amd

@czidev-amd czidev-amd commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Motivation

The maint print address-spaces command previously printed only a flat list of address-space names. Rewrite address_spaces_dump to query dbgapi for five properties per address space and emit them as a structured ui_out table: name, DWARF number, address size in bits, null address, and access class.

Technical Details

A new helper, address_space_access_to_string, maps the amd_dbgapi_address_space_access_t enum to a human-readable string (all, program-constant, dispatch-constant). The command help text and the maint print address-spaces section in gdb.texinfo are updated to document the new columns.

Test Plan

A new test, gdb.rocm/maint-print-address-spaces.exp, runs the command, and checks that a header row and at least one data row are printed without error.

Submission Checklist

Comment thread gdb/doc/gdb.texinfo
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-spaces.exp Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-spaces.exp Outdated
Comment thread .gitignore Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
@aktemur aktemur removed their assignment Jul 17, 2026
@czidev-amd
czidev-amd force-pushed the users/czissule/address-spaces branch 2 times, most recently from 92c8d64 to 5158025 Compare July 20, 2026 12:09
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-spaces.exp Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
@czidev-amd
czidev-amd force-pushed the users/czissule/address-spaces branch 2 times, most recently from d609587 to 8c2130e Compare July 24, 2026 13:10
@czidev-amd

Copy link
Copy Markdown
Contributor Author

Pushed a new version with the next changes:

  • address_space_access_to_string: change return type to std::string and print the raw value in hex for the unknown case, e.g. "unknown (0x42)",to aid debugging.

  • address_spaces_dump: collect all dbgapi properties in a single pass into an aspace_info vector, so each property is queried exactly once. Width calculation and printing both iterate the cached vector. This eliminates the double-query-per-property pattern and the single-statement braced if blocks in the old first-pass loop.

  • Width sentinels: use strlen(("Name")) / strlen(("Access")) instead of the bare string literals so the gettext result is measured, not the key.

  • Numeric fields: switch dwarf and addr columns from field_fmt("%lu") to field_unsigned(), which is portable (no LLP64 truncation on Windows) and preserves correct right-alignment.

  • Test: anchor the header regex so -lbl matching fires on a full header line, not a substring buried elsewhere in the output.

Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
@czidev-amd
czidev-amd force-pushed the users/czissule/address-spaces branch from 8c2130e to d841773 Compare July 29, 2026 12:30
@czidev-amd

Copy link
Copy Markdown
Contributor Author

Thank you @amd-shahab for your input, I have fix that and each error message will contain the returned error status too (as Pedro requested in #225)

@czidev-amd
czidev-amd force-pushed the users/czissule/address-spaces branch from d841773 to 1934fd1 Compare July 29, 2026 13:39

@lumachad lumachad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nits. Take it or not, your choice.

Comment thread gdb/amd-dbgapi-target.c
Comment thread gdb/amd-dbgapi-target.c

# The actual output isn't very important, we want to verify that GDB
# doesn't have any latent error. Moreover, the number of address
# spaces can vary, if one is setting a different architecture.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "setting a different architecture" mean?

Did you mean "testing"?

We do "set architecture amdgcn:gfx90a" above, though, so the architecture is fixed. So how can the premise that the output varies be true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing message from previous refactoring, removing.

@palves palves Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that still leaves the whole premise that lead to not parsing actual specific address spaces incorrect -- if we're hard coding one specific architecture, then we could make the testcase look closer to the address spaces that came out. OTOH, maybe we want instead to loop over all architectures and issue the command, to confirm that we (gdb, dbgapi, etc.) don't do anything bad in any.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That (having a strict testcase for a specific architecture) was my initial draft, however, after speaking with Lancelot, I've simplified the test case to what we have right now. However, I can loop over a list of known architectures, and check if we crash or something of a sort.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with testing the values is: aperture configuration are not part of the ABI. Those are not expected to change often, but they could, and are different on Windows and Linux.

We could have "probe" kernels which we use to figure out the configuration and deduce valid conversions we want to test for if we really wanted to test conversion.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are thinking of the address alias PR instead? This PR is about listing this:

Name              DWARF  Addr Bits    Null Address  Access
global                0         64             0x0     all
generic               1         64             0x0     all
local                 3         32      0xffffffff     all
private_lane          5         32      0xffffffff     all
private_wave          6         32      0xffffffff     all

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, sorry for the confusion. Yes, I was thinking about the alias PR.

The list of address space supported is a per architecture, but we could teach GDB what to expect for here, and match the actual output.

@czidev-amd czidev-amd Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the test, now it loops over the gdb's known amdgpu arches and executes for each one the maintenance command. Please let me know if you want to strength more up the test. For example, null address can be either 0x0+ or 0xf+

@czidev-amd
czidev-amd force-pushed the users/czissule/address-spaces branch from 1934fd1 to 11e9b8d Compare July 31, 2026 12:57
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-spaces.exp Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-spaces.exp Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
Comment thread gdb/amd-dbgapi-target.c Outdated
The maint print address-spaces command previously printed only a flat
list of address-space names.  Rewrite address_spaces_dump to query
dbgapi for five properties per address space and emit them as a
structured ui_out table: name, DWARF number, address size in bits, null
address, and access class.

A new helper, address_space_access_to_string, maps the
amd_dbgapi_address_space_access_t enum to a human-readable string (all,
program-constant, dispatch-constant).  The command help text and the
maint print address-spaces section in gdb.texinfo are updated to
document the new columns.

A new test, gdb.rocm/maint-print-address-spaces.exp, runs the command,
and checks that a header row and at least one data row are printed
without error.
@czidev-amd
czidev-amd force-pushed the users/czissule/address-spaces branch from 11e9b8d to 722c868 Compare August 6, 2026 09:48

@lancesix lancesix left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this LGTM.

Maybe give some time to other people who contributed reviews before merging see if they are happy to.

Comment thread gdb/amd-dbgapi-target.c
Displays the address space names supported by the current architecture."),
Display address-space properties supported by the current architecture.\n\
For each address space, print its name, DWARF id, address size,\n\
null address, and access class."),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still has the same problem:

Display address-space properties supported by the current architecture.\n\

The set of properties is fixed! What varies is the address spaces.

For each address space, print its name, DWARF id, address size,\n
null address, and access class."),

So this would be more correct:

Display properties of address spaces supported by the current architecture.\n
For each address space, print its name, DWARF id, address size,\n
null address, and access class."),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants