gdb/amdgcn: Dynamically select which bits to use to hold CORE_ADDR#56
Merged
amd-shahab merged 2 commits intoamd-stagingfrom Apr 16, 2026
Merged
Conversation
ed82c64 to
187e19d
Compare
187e19d to
0f7b779
Compare
Contributor
Author
|
0f7b779 to
c635173
Compare
palves
reviewed
Apr 16, 2026
palves
reviewed
Apr 16, 2026
| (address_space_id) & 1) << shift)); | ||
| shift++; | ||
| address_space_id >>= 1; | ||
| } |
Collaborator
There was a problem hiding this comment.
I think this be equivalent to the above. It'd be more efficient, for not having a nested loop, and you wouldn't need ctz:
uint64_t mask = aspace_id_mask;
uint64_t id = address_space_id;
uint64_t result = 0;
for (; id != 0 && mask != 0; id >>= 1)
{
/* Isolate the lowest set bit in the mask. */
uint64_t lowbit = mask & ~(mask - 1);
if (id & 1)
result |= lowbit;
/* Clear bit from mask. */
mask ^= lowbit;
}
address |= result;
(disclaimer: completely untested, written in github comment directly.)
palves
reviewed
Apr 16, 2026
| << aspace_id_shift++); | ||
| shift++; | ||
| } | ||
|
|
Collaborator
There was a problem hiding this comment.
Here, I think we can do the same as in amdgpu_segment_address_to_core_address:
arch_addr_space_id aspace_id = 0;
uint64_t dest_bit = 1; /* bit position in resulting ID */
uint64_t mask = aspace_id_mask;
/* Iterate for as many bits as are set in the mask. */
while (mask != 0)
{
/* Isolate lowest set bit in mask. */
uint64_t lowbit = mask & ~(mask - 1);
if (addr & lowbit)
aspace_id |= dest_bit;
dest_bit <<= 1;
/* Clear bit from mask. *
mask ^= lowbit;
}
return aspace_id;
To support the various address-spaces from AMDGPU, amdgpu-tdep implements gdbarch hooks to encode the address-space ID in the top bits of a CORE_ADDR. Exactly which bits to use out of the CORE_ADDR is currently statically built into GDB. However, for AMDGPU, the "flat" address-space (also known as generic) is configured by the driver, and it is not part of the ABI which bits out of the top byte are used or not to carry meaning. To address this, librocm-dbgapi >= 0.80 provides a mask of bits which carry information for the current process. GDB can use this mask to deduce which bits out of a CORE_ADDR can safely be used to encode address space IDs. This patch provides an implementation for GDB to encode the address-space ID into the top bits reported as unused by dbgapi. Note that dbgapi reports which bits can be used by any address space, including "global". This means that the unused bits must be the top ones, and we should account for the fact that "normalized" addresses are sign extended in the top bits. This means that the top bits of a valid address can be either all 0s or all 1s. For this reason, we do not support encoding an address space ID whose binary representation on the available bits of a CORE_ADDR is all 1s, so the all 1s case can be reserved for sign-extended addresses. Bug: AIROCGDB-26 Co-Authored-By: Pedro Palves <pedro@palves.net> Change-Id: I4cbb41a922443d64003ebc6415547c02ab43afcf
Now that in its configure script, rocgdb requires dbgapi 0.80, for querying significant address bits, remove the codes that try to stay compatible with dbgapi versions lower than 0.79. Change-Id: I675aaac0fdf3fa3a5e73ee71a79606e08d878754
c635173 to
e7d1a38
Compare
Contributor
Author
|
palves
approved these changes
Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relies on dbgapi's PR: Add AMD_DBGAPI_PROCESS_INFO_SIGNIFICANT_ADDRESS_BITS
To support the various address-spaces from AMDGPU, amdgpu-tdep implements gdbarch hooks to encode the address-space ID in the top bits of a CORE_ADDR. Exactly which bits to use out of the CORE_ADDR is currently statically built into GDB. However, for AMDGPU, the "flat" address-space (also known as generic) is configured by the driver, and it is not part of the ABI which bits out of the top byte are used or not to carry meaning.
To address this, librocm-dbgapi >= 0.80 provides a mask of bits which carry information for the current process. GDB can use this mask to deduce which bits out of a CORE_ADDR can safely be used to encode address space IDs.
This patch provides an implementation for GDB to encode the address-space ID into the top bits reported as unused by dbgapi. Note that dbgapi reports which bits can be used by any address space, including "global". This means that the unused bits must be the top ones, and we should account for the fact that "normalized" addresses are sign extended in the top bits. This means that the top bits of a valid address can be either all 0s or all 1s. For this reason, we do not support encoding an address space ID whose binary representation on the available bits of a CORE_ADDR is all 1s, so the all 1s case can be reserved for sign-extended addresses.
Bug: AIROCGDB-26
Change-Id: I4cbb41a922443d64003ebc6415547c02ab43afcf