Thread View: gnu.gdb.bug
1 messages
1 total messages
Started by Frederick Herrmann
Wed, 07 Oct 1992 20:04
Unaligned access on suns
Author: 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;
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads