From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2786 invoked by alias); 23 Jan 2006 20:39:42 -0000 Received: (qmail 2775 invoked by uid 22791); 23 Jan 2006 20:39:42 -0000 X-Spam-Check-By: sourceware.org Received: from mail.emacinc.com (HELO mail.emacinc.com) (208.248.202.76) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 23 Jan 2006 20:39:40 +0000 Received: from emac77.emacinc.com ([208.248.202.77] helo=eng011.emacinc.com) by mail.emacinc.com with esmtp (Exim 4.50) id 1F18TJ-0000zI-6d; Mon, 23 Jan 2006 14:39:35 -0600 From: NZG To: gdb-patches@sourceware.org, uClinux development list Date: Mon, 23 Jan 2006 20:39:00 -0000 User-Agent: KMail/1.8.2 MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200601231438.26040.ngustavson@emacinc.com> X-SA-Exim-Connect-IP: 208.248.202.77 X-SA-Exim-Mail-From: ngustavson@emacinc.com Subject: gdb code review, pointer madness Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Relay: X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-01/txt/msg00337.txt.bz2 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; }