Article View: gnu.gdb.bug
Article #452Unaligned access on suns
From: Frederick Herrmann
Date: Wed, 07 Oct 1992 20:04
Date: Wed, 07 Oct 1992 20:04
64 lines
2109 bytes
2109 bytes
I hesitate to report this as a bug, because some might well consider
it a feature...
The problem occurs with gdb 4.6, compiled with gcc 2.2.2 on a sun4
host.
It seems the sun requires doubles to be aligned to 8-byte boundaries,
violations result in bus errors. That's fine, except that gdb allows
me to do unaligned accesses with the p command. I was porting some
code from a decstation to a sun, and got very confused when I could
write to pointers from within gdb, but my program couldn't.
It would be nice if gdb warned me when it did an unaligned access.
I've appended a simple example program below.
- Fritz
/* Illustrate funny byte alignment problem with gdb
*
* F. Herrmann fritz@mtl.mit.edu
*
*/
int main( int argc, char **argv)
{
double dblarray[2];
double *goodptr, *badptr;
/* Start with a good pointer to a double */
goodptr = dblarray;
/* Create an unaligned bad pointer */
badptr = (double *) ( 1 + (int *) goodptr);
/* Put a break point here.
*
* The unaligned assignment below will cause a bus error on a sun.
* But GDB is perfectly happy to let you do:
*
* (gdb) p *badptr
*
* or even:
*
* (gdb) p *badptr = 2.718
*
* I guess it's nice that gdb can do something the hardware can't, but
* I would have appreciated a warning that the operation was illegal.
* I was porting some code from a decstation to a sun and got stuck on
* this for some time.
*/
/* Try to store a double */
*badptr = 3.14159;
/* Don't expect to get here */
printf( "%f\n", *badptr);
return 0;
}
Technical Details
Message-ID:
<9210080404.AA12055@mtl.mit.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mtl.mit.edu!fritzShow Full Headers
Complete Article Headers
Newsgroups: gnu.gdb.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mtl.mit.edu!fritz From: fritz@mtl.mit.edu (Frederick Herrmann) Subject: Unaligned access on suns Message-ID: <9210080404.AA12055@mtl.mit.edu> Sender: gnulists@ai.mit.edu Reply-To: fritz@mtl.mit.edu Organization: MIT Microsystems Technology Laboratories Distribution: gnu Date: Wed, 7 Oct 1992 20:04:05 GMT Approved: bug-gdb@prep.ai.mit.edu Lines: 65