Skip to content

Implements the "maintenance info amdgpu address-aliases" command - #225

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

Implements the "maintenance info amdgpu address-aliases" command#225
czidev-amd wants to merge 1 commit into
amd-stagingfrom
users/czissule/address-alias

Conversation

@czidev-amd

Copy link
Copy Markdown
Contributor

Motivation

Given an expression that evaluates to an address in some address space, show for each address space supported by the current AMDGPU architecture the aliasing address in that space, if any, along with the number of consecutive bytes for which the aliasing is valid.

This is purely a diagnostic aid: it queries amd_dbgapi_convert_address_space for every address space known to the architecture and reports "" for the ones the given address does not alias into.

Test Plan

New show_address_aliases.exp test added.

@czidev-amd
czidev-amd requested a review from a team as a code owner July 21, 2026 12:40
@czidev-amd
czidev-amd force-pushed the users/czissule/address-alias branch from 3d2d94b to d234a73 Compare July 21, 2026 12:45
@czidev-amd czidev-amd changed the title Implements the "maintenance info amdgpu address-aliases" comman Implements the "maintenance info amdgpu address-aliases" command Jul 21, 2026
Comment thread gdb/amdgpu-tdep.c
Comment thread gdb/amdgpu-tdep.c
Comment thread gdb/amdgpu-tdep.c
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.cpp Outdated
Comment thread gdb/amdgpu-tdep.c
Comment thread gdb/testsuite/gdb.rocm/show_address_aliases.exp Outdated
Comment thread gdb/amdgpu-tdep.c
Comment thread gdb/amdgpu-tdep.c
Comment thread gdb/amdgpu-tdep.c
Comment thread gdb/testsuite/gdb.rocm/show_address_aliases.exp Outdated
@lumachad lumachad assigned czidev-amd and unassigned lumachad Jul 22, 2026
@czidev-amd
czidev-amd marked this pull request as draft July 27, 2026 11:39
@czidev-amd
czidev-amd marked this pull request as draft July 27, 2026 11:39
@czidev-amd
czidev-amd force-pushed the users/czissule/address-alias branch 2 times, most recently from dbe0775 to 1432895 Compare July 27, 2026 15:08

@czidev-amd czidev-amd left a comment

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.

Thank you @lumachad for your review, I have reworked a bit this PR to include your comments. One observation is the renaming of the tests to match other "maint" tests naming pattern. Also, I have relaxed the test as I cannot really guarantee the same output across different architectures. Now, the tests is testing if gdb implementation is sane rather than gdbabi output sanity.

@czidev-amd
czidev-amd marked this pull request as ready for review July 27, 2026 15:14
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.cpp Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.cpp Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.exp Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.exp Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.exp Outdated
Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/doc/gdb.texinfo Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.cpp Outdated
@czidev-amd
czidev-amd force-pushed the users/czissule/address-alias branch from 1432895 to 2f1c254 Compare July 28, 2026 11:36
@czidev-amd

Copy link
Copy Markdown
Contributor Author

I have spined a new version including Pedro's and Lancelot's inputs.

Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.exp
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.exp
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.cpp Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.cpp
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.cpp Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.exp Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.exp
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.exp
Comment thread gdb/amdgpu-tdep.c
Comment thread gdb/amdgpu-tdep.c
/* Not a real alias, NULL just maps to NULL in every
space. */
if (src_is_null_address)
ui_out->field_string ("valid", "<null>");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMHO it wouldn't be wrong to print 0 here.

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 can do that, let's see if anyone else has a different idea.

Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.cpp Outdated
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.exp Outdated
Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/doc/gdb.texinfo Outdated
Comment thread gdb/doc/gdb.texinfo
Some address spaces are private to a wave or a lane of a wave, and
@value{GDBN} converts using whichever wave and lane are currently
selected. Not every address is reachable from every space: if it isn't,
the row for that space reads @samp{<not reachable>}.

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.

One nit, I think that we do an LDS -> global conversion, but this is only valid (ish) while the wave is stopped. As soon as we resume, this address is not valid anymore. Not sure if this should be described, or maybe this is just a dbgapi bug we should address.

Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/amdgpu-tdep.c
@czidev-amd
czidev-amd force-pushed the users/czissule/address-alias branch from 2f1c254 to 9b0c0d2 Compare August 4, 2026 13:39
Comment thread gdb/doc/gdb.texinfo
Comment thread gdb/testsuite/gdb.rocm/maint-print-address-aliases.exp Outdated
@czidev-amd
czidev-amd marked this pull request as draft August 17, 2026 11:10
@czidev-amd
czidev-amd force-pushed the users/czissule/address-alias branch from 9b0c0d2 to ec37ff2 Compare August 17, 2026 11:16
It can sometimes be useful to be able to convert address from an
address space to another one (if such conversion is possible).  This
patch proposes to add a maintenance command which shows for a given
address (in any address space) the aliasing addresses in other address
spaces.  It also shows the number of consecutive bytes this conversion
is valid for.

Here are example outputs on this new command:

    (gdb) maintenance info amdgpu address-aliases &idx
    Address space                      Address         Valid for
    global                      0x7ff7f4600c00               0x4
    generic            generic#0x2000000000030             0x3d0
    private_wave            private_wave#0xc00               0x4
    private_lane             private_lane#0x30             0x3d0
    local                      <not reachable>               0x0

    (gdb) maintenance info amdgpu address-aliases gidx_p
    Address space                      Address         Valid for
    global                     <not reachable>               0x0
    generic            generic#0x1000000000000             0x200
    private_wave               <not reachable>               0x0
    private_lane               <not reachable>               0x0
    local                            local#0x0       0x100000000

Tested on x86_64-linux + gfx942.

Change-Id: I9d118f208589c3db6a2ec966ac221b1a54d0ccb6

Co-authored-by: Claudiu Zissulescu-Ianculescu <claudiu.zissulescu-ianculescu@amd.com>
@czidev-amd
czidev-amd force-pushed the users/czissule/address-alias branch from ec37ff2 to 866d8c3 Compare August 17, 2026 13:14
@czidev-amd
czidev-amd marked this pull request as ready for review August 17, 2026 13:16

@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.

Some automated comments. Take it or leave it. They seem mostly nits to me.

Comment thread gdb/amdgpu-tdep.c
}

/* Implements the "maintenance info amdgpu address-aliases" command.

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.

GDB function comments should be written in third-person present tense describing what the function does, not "Implements the". Consider:

/* Show for each address space supported by the current AMDGPU
   architecture the aliases of a given ADDR, and the number of
   consecutive bytes for which each aliasing is valid.  */

"Implements the" reads more like a commit message than a source comment.

Comment thread gdb/amdgpu-tdep.c
error (_("amd_dbgapi_address_space_get_info (NULL_ADDRESS) failed (%s)"),
get_status_string (status));
bool src_is_null_address = (offset == src_null_address);

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 outer parentheses around the comparison are unnecessary in C++:

bool src_is_null_address = offset == src_null_address;

Comment thread gdb/amdgpu-tdep.c
ui_out->table_header (max_aspace_name_len, ui_left, "aspace",
_("Address space"));
/* Address form is: <Name>0xNN..NNN. */
ui_out->table_header (max_aspace_name_len + addr_width,

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 comment on the next line (/* Address form is: <Name>0xNN..NNN. */) is inaccurate. paspace() emits a # separator between the address-space name and the hex address (e.g., generic#0x2000000000030), and for the default space it emits nothing at all. Suggested wording:

/* Address form is: <name>#0xNN..NNN for a named space,
   or just 0xNN..NNN for the default (global) space.  */

Comment thread gdb/amdgpu-tdep.c

add_cmd ("address-aliases", class_maintenance,
amdgpu_info_address_aliases_command, _("\
Show ADDRESS aliases across AMDGPU address spaces.\n\

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 commit message headline says "maint amdgpu info address-alias" (singular, and with amdgpu before info), but the registered command is "maintenance info amdgpu address-aliases" (plural, correct order). Please update the commit headline to match, e.g.:

gdb: Add "maint info amdgpu address-aliases" command

@@ -0,0 +1,60 @@
/* Copyright (C) 2026 Free Software Foundation, Inc.
Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved.

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 filename says maint-print-address-aliases but the command under test is maint info amdgpu address-aliases (note info, not print). Consider renaming both test files to maint-info-amdgpu-address-aliases.{cpp,exp} so they are discoverable by command name.

# Count address spaces known to the architecture.
set aspaces 0
gdb_test_multiple "maint print address-spaces" "" -lbl {
-re "\r\n${asname}\[ \t\]+$::decimal\[ \t\]+" {

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 address-space count is obtained from maint print address-spaces and then cross-checked against the row count from maint info amdgpu address-aliases. If those two commands ever diverge (e.g. one filters address spaces the other doesn't), the assertion gives a confusing failure with no obvious cause. It would be more robust to count the rows produced by the address-aliases command itself.

}

-re "^\r\n${asname}\[ \t\]+${asname}#*$::hex\[ \t\]+($::hex|<null>)${trailer}" {
# Match address space.

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.

#* matches zero or more # characters, so this branch can fire even when there is no # in the address field, potentially stealing matches from the global branch above. The separator is always exactly # for named spaces, so use a literal #:

-re "^\r\n${asname}\[ \t\]+${asname}#$::hex\[ \t\]+($::hex|<null>)${trailer}" {

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.

5 participants