From: Aditya Vidyadhar Kamath <akamath996@gmail.com>
To: ulrich.weigand@de.ibm.com, simon.marchi@polymtl.ca, tom@tromey.com
Cc: gdb-patches@sourceware.org, Aditya.Kamath1@ibm.com,
sangamesh.swamy@in.ibm.com,
Aditya Vidyadhar Kamath <aditya.kamath1@ibm.com>
Subject: [PATCH v4 5/5] Fix 32-bit GPR and SPR register reads/writes in pthdb callbacks.
Date: Mon, 5 Oct 2026 19:06:39 +0530 [thread overview]
Message-ID: <20261005133638.32325-2-akamath996@gmail.com> (raw)
From: Aditya Vidyadhar Kamath <aditya.kamath1@ibm.com>
This patch does two simple changes mentioned in each paragraph below:
When a 32-bit thread's GPRs are read via pdc_read_regs, a raw memcpy
from a uint32_t[32] array into pthdb_context_t::gpr which holds
uint64_t elements was silently truncating or misinterpreting data.
Replace the memcpy with an element-wise assignment so each 32-bit
value is correctly zero-extended into the 64-bit context field.
Similarly, the SPRS read for 32-bit threads was copying the entire
struct ptsprs over &context->msr, clobbering adjacent context fields.
Replace the memcpy with explicit field-by-field assignments.
For writes in pdc_write_regs, restore the arch64 branch distinction:
1: 64-bit: pass context->gpr / &context->msr directly as before.
2: 32-bit GPRs: truncate each context->gpr[i] (uint64_t) into a local
uint32_t gprs32[] array before calling ptrace64aix.
3: 32-bit SPRs: pack a local struct ptsprs from the individual context
fields before calling ptrace64aix.
---
gdb/aix-thread.c | 42 ++++++++++++++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 4 deletions(-)
diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index 4826e33265c..f4693702804 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -411,7 +411,8 @@ pdc_read_regs (pthdb_user_t user_current_pid,
{
if (!ptrace64aix (PTT_READ_GPRS, tid, (long long) gprs32, 0, NULL))
memset (gprs32, 0, sizeof (gprs32));
- memcpy (context->gpr, gprs32, sizeof (gprs32));
+ for (int i = 0; i < ppc_num_gprs; i++)
+ context->gpr[i] = gprs32[i];
}
}
@@ -436,7 +437,14 @@ pdc_read_regs (pthdb_user_t user_current_pid,
{
if (!ptrace64aix (PTT_READ_SPRS, tid, (long long) &sprs32, 0, NULL))
memset (&sprs32, 0, sizeof (sprs32));
- memcpy (&context->msr, &sprs32, sizeof (sprs32));
+ context->iar = sprs32.pt_iar;
+ context->msr = sprs32.pt_msr;
+ context->cr = sprs32.pt_cr;
+ context->lr = sprs32.pt_lr;
+ context->ctr = sprs32.pt_ctr;
+ context->xer = sprs32.pt_xer;
+ context->fpscr = sprs32.pt_fpscr;
+ context->mq = sprs32.pt_mq;
}
}
@@ -486,7 +494,17 @@ pdc_write_regs (pthdb_user_t user_current_pid,
/* General-purpose registers. */
if (flags & PTHDB_FLAG_GPRS)
- ptrace64aix (PTT_WRITE_GPRS, tid, (long long) context->gpr, 0, NULL);
+ {
+ if (data->arch64)
+ ptrace64aix (PTT_WRITE_GPRS, tid, (long long) context->gpr, 0, NULL);
+ else
+ {
+ uint32_t gprs32[ppc_num_gprs];
+ for (int i = 0; i < ppc_num_gprs; i++)
+ gprs32[i] = context->gpr[i];
+ ptrace64aix (PTT_WRITE_GPRS, tid, (long long) gprs32, 0, NULL);
+ }
+ }
/* Floating-point registers. */
if (flags & PTHDB_FLAG_FPRS)
@@ -494,7 +512,23 @@ pdc_write_regs (pthdb_user_t user_current_pid,
/* Special-purpose registers. */
if (flags & PTHDB_FLAG_SPRS)
- ptrace64aix (PTT_WRITE_SPRS, tid, (long long) &context->msr, 0, NULL);
+ {
+ if (data->arch64)
+ ptrace64aix (PTT_WRITE_SPRS, tid, (long long) &context->msr, 0, NULL);
+ else
+ {
+ struct ptsprs sprs32;
+ sprs32.pt_iar = context->iar;
+ sprs32.pt_msr = context->msr;
+ sprs32.pt_cr = context->cr;
+ sprs32.pt_lr = context->lr;
+ sprs32.pt_ctr = context->ctr;
+ sprs32.pt_xer = context->xer;
+ sprs32.pt_fpscr = context->fpscr;
+ sprs32.pt_mq = context->mq;
+ ptrace64aix (PTT_WRITE_SPRS, tid, (long long) &sprs32, 0, NULL);
+ }
+ }
/* vector registers. */
if (__power_vmx () && (flags & PTHDB_FLAG_REGS))
--
2.51.2
reply other threads:[~2026-10-05 13:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261005133638.32325-2-akamath996@gmail.com \
--to=akamath996@gmail.com \
--cc=Aditya.Kamath1@ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=sangamesh.swamy@in.ibm.com \
--cc=simon.marchi@polymtl.ca \
--cc=tom@tromey.com \
--cc=ulrich.weigand@de.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox