public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* [bug] fetch_register_using_p() is not endian-ness safe
@ 2004-10-20  5:12 Theodore A. Roth
  2004-10-26 13:29 ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Theodore A. Roth @ 2004-10-20  5:12 UTC (permalink / raw)
  To: gdb; +Cc: Paul Schlie

Hi,

Just got bit by this one.

The recent changes to remote.c to implement 'p' packets using
fetch_register_using_p() is broken.

It is padding out the hex-ified regnum with zeros, but the resulting
endian-ness is tied to the gdb host. For example, on my x86 linux box,
fetching the PC, gdb sends this packet:

	"$p22000000#f4"

while on Paul's powerpc system, he sees this packet:

	"$p00000022#f4"

This poses a problem for the remote target when the stub needs to parse
this packet since the byte ordering is not well defined.

The problem code is this line in remote.c:

  bin2hex((char *) &regnum, &buf[1], sizeof(regnum));

What's the proper way to handle this? Seems to me that bin2hex() is not
even needed in this case, wouldn't a simple snprintf() be a bit more
sane? Something like this maybe:

  snprintf (buf+1, rs->remote_packet_size-1, "%X", regnum);

---
Ted Roth
PGP Key ID: 0x18F846E9
Jabber ID: troth@jabber.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug] fetch_register_using_p() is not endian-ness safe
  2004-10-20  5:12 [bug] fetch_register_using_p() is not endian-ness safe Theodore A. Roth
@ 2004-10-26 13:29 ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2004-10-26 13:29 UTC (permalink / raw)
  To: Theodore A. Roth; +Cc: gdb, Paul Schlie

On Tue, Oct 19, 2004 at 06:18:46PM -0700, Theodore A. Roth wrote:
> Hi,
> 
> Just got bit by this one.
> 
> The recent changes to remote.c to implement 'p' packets using
> fetch_register_using_p() is broken.
> 
> It is padding out the hex-ified regnum with zeros, but the resulting
> endian-ness is tied to the gdb host. For example, on my x86 linux box,
> fetching the PC, gdb sends this packet:
> 
> 	"$p22000000#f4"
> 
> while on Paul's powerpc system, he sees this packet:
> 
> 	"$p00000022#f4"
> 
> This poses a problem for the remote target when the stub needs to parse
> this packet since the byte ordering is not well defined.

FYI, Jim Blandy noticed this a little earlier - and his patch for the
problem was just approved.

-- 
Daniel Jacobowitz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-10-25 23:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-20  5:12 [bug] fetch_register_using_p() is not endian-ness safe Theodore A. Roth
2004-10-26 13:29 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).