From: Ulrich Weigand <uweigand@de.ibm.com>
To: gdb-patches@sources.redhat.com
Subject: [RFA] gdbserver fetch/store registers problem on s390x
Date: Tue, 10 May 2005 19:48:00 -0000 [thread overview]
Message-ID: <200505101654.j4AGsTCj028703@53v30g15.boeblingen.de.ibm.com> (raw)
Hello,
this patch fixes another problem with gdbserver on s390x occurring
on recent kernels. The problem is that some registers accessed by
ptrace (notably the access registers and the floating-point status
register) are still 32 bits wide, even though the PTRACE_PEEKUSER
and PTRACE_POKEUSER commands always transfer 64 bits.
This is a problem for two reasons: when fetching those registers,
a 4-byte buffer is allocated via alloca, but then 8 bytes are
written to that buffer (which just happens to work because alloca
rounds the size up to the next multiple of 8 anyway). The same
holds for storing the register; but in this case the second 4 bytes
have just random contents, and recent kernels won't allow the POKEUSER
command to succeed unless those extra bytes are zero.
The following patch fixes this problem by always allocating a buffer
that has multiple of sizeof (PTRACE_XFER_TYPE) as size, and by
zeroing out the excess bytes of the buffer when storing the register.
Tested on s390-ibm-linux and s390x-ibm-linux.
OK?
Bye,
Ulrich
ChangeLog:
* linux-low.c (fetch_register): Ensure buffer size is a multiple
of sizeof (PTRACE_XFER_TYPE).
(usr_store_inferior_registers): Likewise. Zero out excess bytes.
Index: gdb/gdbserver/linux-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-low.c,v
retrieving revision 1.34
diff -c -p -r1.34 linux-low.c
*** gdb/gdbserver/linux-low.c 3 Mar 2005 16:56:53 -0000 1.34
--- gdb/gdbserver/linux-low.c 10 May 2005 11:53:40 -0000
*************** static void
*** 1095,1101 ****
fetch_register (int regno)
{
CORE_ADDR regaddr;
! register int i;
char *buf;
if (regno >= the_low_target.num_regs)
--- 1095,1101 ----
fetch_register (int regno)
{
CORE_ADDR regaddr;
! int i, size;
char *buf;
if (regno >= the_low_target.num_regs)
*************** fetch_register (int regno)
*** 1106,1113 ****
regaddr = register_addr (regno);
if (regaddr == -1)
return;
! buf = alloca (register_size (regno));
! for (i = 0; i < register_size (regno); i += sizeof (PTRACE_XFER_TYPE))
{
errno = 0;
*(PTRACE_XFER_TYPE *) (buf + i) =
--- 1106,1115 ----
regaddr = register_addr (regno);
if (regaddr == -1)
return;
! size = (register_size (regno) + sizeof (PTRACE_XFER_TYPE) - 1)
! & - sizeof (PTRACE_XFER_TYPE);
! buf = alloca (size);
! for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE))
{
errno = 0;
*(PTRACE_XFER_TYPE *) (buf + i) =
*************** static void
*** 1147,1153 ****
usr_store_inferior_registers (int regno)
{
CORE_ADDR regaddr;
! int i;
char *buf;
if (regno >= 0)
--- 1149,1155 ----
usr_store_inferior_registers (int regno)
{
CORE_ADDR regaddr;
! int i, size;
char *buf;
if (regno >= 0)
*************** usr_store_inferior_registers (int regno)
*** 1162,1170 ****
if (regaddr == -1)
return;
errno = 0;
! buf = alloca (register_size (regno));
collect_register (regno, buf);
! for (i = 0; i < register_size (regno); i += sizeof (PTRACE_XFER_TYPE))
{
errno = 0;
ptrace (PTRACE_POKEUSER, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
--- 1164,1175 ----
if (regaddr == -1)
return;
errno = 0;
! size = (register_size (regno) + sizeof (PTRACE_XFER_TYPE) - 1)
! & - sizeof (PTRACE_XFER_TYPE);
! buf = alloca (size);
! memset (buf, 0, size);
collect_register (regno, buf);
! for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE))
{
errno = 0;
ptrace (PTRACE_POKEUSER, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
--
Dr. Ulrich Weigand
Linux on zSeries Development
Ulrich.Weigand@de.ibm.com
next reply other threads:[~2005-05-10 16:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-10 19:48 Ulrich Weigand [this message]
2005-05-15 19:39 ` Daniel Jacobowitz
2005-07-13 1:35 ` Daniel Jacobowitz
2005-07-13 12:03 ` Ulrich Weigand
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=200505101654.j4AGsTCj028703@53v30g15.boeblingen.de.ibm.com \
--to=uweigand@de.ibm.com \
--cc=gdb-patches@sources.redhat.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