[uClinux-dev] gdb code review, pointer madness

NZG ngustavson at emacinc.com
Mon Jan 23 15:38:25 EST 2006


I'm trying to get gdb 6.1's machine interface to work correctly with the m68k 
arch, and I'm having some weird results.

I've noticed that if I do a (frame -1) command on gdb after connecting to 
remote gdb server, but before breaking in the main program, gdb goes crazy 
and starts requesting random memory locations from gdbserver until something 
crashes.

Sooo... I'm using regular gdb to debug the m68k-elf-gdb connection, and I'm 
seeing a problem "extract_unsigned_integer" (pasted below).

Specifically this loop doesn't seem to be executing correctly

 for (p = startaddr; p < endaddr; ++p)
	retval = (retval << 8) | *p;

In the function call I'm watching, 
endaddr = startaddr+4, 
yet, when I step through the function the loop executes 8 times and overshoots 
the array.

I don't see anything wrong with the code.
Can anyone else see anything weird in the pointer math below?

thx,
NZG



ULONGEST
extract_unsigned_integer (const void *addr, int len)
{
  ULONGEST retval;
  const unsigned char *p;
  const unsigned char *startaddr = addr;
  const unsigned char *endaddr = startaddr + len;

  if (len > (int) sizeof (ULONGEST))
    error ("\
That operation is not available on integers of more than %d bytes.",
	   (int) sizeof (ULONGEST));

  /* Start at the most significant end of the integer, and work towards
     the least significant.  */
  retval = 0;
  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
    {
      for (p = startaddr; p < endaddr; ++p)
	retval = (retval << 8) | *p;
    }
  else
    {
      for (p = endaddr - 1; p >= startaddr; --p)
	retval = (retval << 8) | *p;
    }
  return retval;
}



More information about the uClinux-dev mailing list