From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Jacobowitz To: Eli Zaretskii Cc: gdb-patches@sources.redhat.com Subject: Re: [RFA] mips: Fix "info registers" output Date: Thu, 21 Jun 2001 13:12:00 -0000 Message-id: <20010621131219.A21039@nevyn.them.org> References: <20010621083624.A9719@nevyn.them.org> <20010621094418.A30641@nevyn.them.org> <1438-Thu21Jun2001215717+0300-eliz@is.elta.co.il> X-SW-Source: 2001-06/msg00371.html On Thu, Jun 21, 2001 at 09:57:18PM +0300, Eli Zaretskii wrote: > > There was indeed a bug on that path of the code, but it doesn't > > actually affect the output. We have this: > > > > raw_buffer[0] = (char *) alloca (REGISTER_RAW_SIZE (FP0_REGNUM)); > > raw_buffer[1] = (char *) alloca (REGISTER_RAW_SIZE (FP0_REGNUM)); > > dbl_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM)); > > > > /* Get the data in raw format. */ > > if (read_relative_register_raw_bytes (regnum, raw_buffer[HI])) > > error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum)); > > > > [snip] > > > > memcpy (dbl_buffer, raw_buffer[HI], 2 * REGISTER_RAW_SIZE (FP0_REGNUM)); > > flt1 = unpack_double (builtin_type_float, > > &raw_buffer[HI][offset], &inv1); > > doub = unpack_double (builtin_type_double, dbl_buffer, &inv3); > > > > So we're copying 2 * 8 bytes out of an 8 byte buffer. > > I don't think so. The memcpy part uses raw_buffer[HI] as its address, > but the two buffers whose addresses are in raw_buffer[0] and > raw_buffer[1] are layed out on the stack one after the other. So you > have enough space there, and memcpy can copy up to 2*8 bytes without > fear. It's nasty code, but it works. (No, I didn't write that code ;-) Well, there's still issues. We only initialized one register's worth of data, for one thing. And we only need one register's worth. > > The real killer is on the other branch, size == 4: > > memcpy (dbl_buffer, raw_buffer, 2 * REGISTER_RAW_SIZE (FP0_REGNUM)); > > > > raw_buffer points to 8 bytes, sure enough - but they're both pointers > > to four byte buffers before my patch. That won't decode. > > So why replacing raw_buffer with raw_buffer[HI] in the call to memcpy > isn't all that is needed to fix this? HI could be 0 or 1. It's not clear what order we want to end up with, or when we want to byteswap. There's slightly less invasive corrections for this, but we have the handy REGISTER_CONVERT_TO_TYPE macro. We use it in the code for 'info register f0', so I made us use the same code in 'info registers'. -- Daniel Jacobowitz Carnegie Mellon University MontaVista Software Debian GNU/Linux Developer