Re: Misaligned read/write of memory by GDB

Dave Brolley <[email protected]>
Newsgroups gmane.comp.emulators.sid.devel
Organization Red Hat Canada, Ltd
Message-ID <[email protected]>
Ooops, sent the wrong patch......

Dave Brolley wrote:

> Hi,
>
> Some sid components don't support misaligned reads/writes. The current 
> cache components are the example which caused my particular problem. 
> They punt on misaligned reads/writes, presumably so that they don't 
> have to worry about accesses which cross cache line boundaries. This 
> causes a problem when GDB attempts to read memory at unaligned addresses.
>
> This patch to gdb::process_get_mem and gdb::process_set_mem forces any 
> unaligned requests to use the existing byte-at-a-time method.
>
> I've committed this patch. Let me know if there are any problems.
>
> Dave
>
sid-gdb-align.patch.txt (text/plain, 4.8 KB)
Index: sid/component/gdb/gdb.cxx
===================================================================
RCS file: /cvs/src/src/sid/component/gdb/gdb.cxx,v
retrieving revision 1.11
diff -c -p -r1.11 gdb.cxx
*** sid/component/gdb/gdb.cxx	22 Mar 2004 21:27:23 -0000	1.11
--- sid/component/gdb/gdb.cxx	28 Jun 2004 21:10:43 -0000
*************** gdb::process_get_mem (struct gdbserv_reg
*** 620,642 ****
      }
    host_int_4 addr = addr8; // truncate
  
!   if (len==1 && e==endian_big) 
!     read_bus_word (gdbserv, memory, addr, big_int_1());
!   else if (len==1 && e==endian_little)
!     read_bus_word (gdbserv, memory, addr, little_int_1());
!   else if (len==2 && e==endian_big) 
!     read_bus_word (gdbserv, memory, addr, big_int_2());
!   else if (len==2 && e==endian_little)
!     read_bus_word (gdbserv, memory, addr, little_int_2());
!   else if (len==4 && e==endian_big) 
!     read_bus_word (gdbserv, memory, addr, big_int_4());
!   else if (len==4 && e==endian_little)
!     read_bus_word (gdbserv, memory, addr, little_int_4());
!   else if (len==8 && e==endian_big) 
!     read_bus_word (gdbserv, memory, addr, big_int_8());
!   else if (len==8 && e==endian_little)
!     read_bus_word (gdbserv, memory, addr, little_int_8());
!   else if (e==endian_little)
      {
        for (unsigned long i=0; i<len; i++)
  	read_bus_word (gdbserv, memory, addr + i, little_int_1());
--- 620,647 ----
      }
    host_int_4 addr = addr8; // truncate
  
!   if (addr % len == 0)
!     {
!       if (len==1 && e==endian_big) 
! 	{ read_bus_word (gdbserv, memory, addr, big_int_1()); return; }
!       if (len==1 && e==endian_little)
! 	{ read_bus_word (gdbserv, memory, addr, little_int_1()); return; }
!       if (len==2 && e==endian_big) 
! 	{ read_bus_word (gdbserv, memory, addr, big_int_2()); return; }
!       if (len==2 && e==endian_little)
! 	{ read_bus_word (gdbserv, memory, addr, little_int_2()); return; }
!       if (len==4 && e==endian_big) 
! 	{ read_bus_word (gdbserv, memory, addr, big_int_4()); return; }
!       if (len==4 && e==endian_little)
! 	{ read_bus_word (gdbserv, memory, addr, little_int_4()); return; }
!       if (len==8 && e==endian_big) 
! 	{ read_bus_word (gdbserv, memory, addr, big_int_8()); return; }
!       if (len==8 && e==endian_little)
! 	{ read_bus_word (gdbserv, memory, addr, little_int_8()); return; }
!     }
! 
!   // Unaligned access or unsupported size.
!   if (e==endian_little)
      {
        for (unsigned long i=0; i<len; i++)
  	read_bus_word (gdbserv, memory, addr + i, little_int_1());
*************** gdb::process_set_mem (struct gdbserv_reg
*** 700,722 ****
      }
    host_int_4 addr = addr8; // truncate
  
!   if (len==1 && e==endian_big) 
!     write_bus_word (gdbserv, binary, memory, addr, big_int_1());
!   else if (len==1 && e==endian_little)
!     write_bus_word (gdbserv, binary, memory, addr, little_int_1());
!   else if (len==2 && e==endian_big) 
!     write_bus_word (gdbserv, binary, memory, addr, big_int_2());
!   else if (len==2 && e==endian_little)
!     write_bus_word (gdbserv, binary, memory, addr, little_int_2());
!   else if (len==4 && e==endian_big) 
!     write_bus_word (gdbserv, binary, memory, addr, big_int_4());
!   else if (len==4 && e==endian_little)
!     write_bus_word (gdbserv, binary, memory, addr, little_int_4());
!   else if (len==8 && e==endian_big) 
!     write_bus_word (gdbserv, binary, memory, addr, big_int_8());
!   else if (len==8 && e==endian_little)
!     write_bus_word (gdbserv, binary, memory, addr, little_int_8());
!   else if (e==endian_little)
      {
        for (unsigned long i=0; i<len; i++)
  	write_bus_word (gdbserv, binary, memory, addr + i, little_int_1());
--- 705,732 ----
      }
    host_int_4 addr = addr8; // truncate
  
!   if (addr % len == 0)
!     {
!       if (len==1 && e==endian_big) 
! 	{ write_bus_word (gdbserv, binary, memory, addr, big_int_1()); return; }
!       if (len==1 && e==endian_little)
! 	{ write_bus_word (gdbserv, binary, memory, addr, little_int_1()); return; }
!       if (len==2 && e==endian_big) 
! 	{ write_bus_word (gdbserv, binary, memory, addr, big_int_2()); return; }
!       if (len==2 && e==endian_little)
! 	{ write_bus_word (gdbserv, binary, memory, addr, little_int_2()); return; }
!       if (len==4 && e==endian_big) 
! 	{ write_bus_word (gdbserv, binary, memory, addr, big_int_4()); return; }
!       if (len==4 && e==endian_little)
! 	{ write_bus_word (gdbserv, binary, memory, addr, little_int_4()); return; }
!       if (len==8 && e==endian_big) 
! 	{ write_bus_word (gdbserv, binary, memory, addr, big_int_8()); return; }
!       if (len==8 && e==endian_little)
! 	{ write_bus_word (gdbserv, binary, memory, addr, little_int_8()); return; }
!     }
! 
!   // Unaligned access or unsupported size.
!   if (e==endian_little)
      {
        for (unsigned long i=0; i<len; i++)
  	write_bus_word (gdbserv, binary, memory, addr + i, little_int_1());
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.