From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15185 invoked by alias); 8 Apr 2009 18:27:05 -0000 Received: (qmail 15163 invoked by uid 22791); 8 Apr 2009 18:27:03 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 08 Apr 2009 18:26:58 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 3EFB02BAB42 for ; Wed, 8 Apr 2009 14:26:56 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id dv+xiFHVREdk for ; Wed, 8 Apr 2009 14:26:56 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 089992BAAF1 for ; Wed, 8 Apr 2009 14:26:56 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 4A563F5A13; Wed, 8 Apr 2009 11:26:51 -0700 (PDT) Date: Wed, 08 Apr 2009 18:27:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFC] problem with read_memory_string (reads 8 bytes at a time) Message-ID: <20090408182650.GE7535@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-04/txt/msg00154.txt.bz2 Hello, I did what I thought would be a nice cleanup in ada-lang.c last weekend, by deleting a local function (extract_string), and replacing it by a call to read_memory_string instead. This works fine most of the time, but nightly testing did reveal a problem with that function on powerpc-elf. (gdb) start Cannot access memory at address 0x1002e8 Here is what happens: 1. The "start" commands needs to know that the name of the "main" program is. As a result, we call ada_main_name, which finds the symbol that points us to the string containing that main name. 2. To read that name, we call read_memory_string now, and this routine performs strings reads 8 bytes at a time. The problem is that our string is at the end of our .rodata section. The string is 8 bytes long, and sits at 0x1002e0. The .rodata section ends at 0x001102ec. So here's what we end up doing: a. Read 8 bytes from 0x1002e0 - no problem. But we haven't read the \0 yet, so we keep going. b. Read 8 bytes from 0x1002e0 + 8 = 0x1002e8: i. The section ends at 0x001102ec, so bfd returns only 4 bytes read. ii. We find out that only 4 bytes were read, so we still need to read another 4 bytes for the 8byte read to be complete iii. the next 4byte read doesn't find a section from which to read the 4bytes, and so returns 0 signifying an error. I don't really know how to fix this issue except by reading the string one byte at a time :-(. Any suggestion? Thanks, -- Joel