From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32271 invoked by alias); 26 Aug 2004 21:25:59 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 32224 invoked from network); 26 Aug 2004 21:25:55 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 26 Aug 2004 21:25:55 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.10/8.12.10) with ESMTP id i7QLPsS2016339 for ; Thu, 26 Aug 2004 17:25:55 -0400 Received: from localhost.redhat.com (porkchop.devel.redhat.com [172.16.58.2]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id i7QLPl322846; Thu, 26 Aug 2004 17:25:52 -0400 Received: from gnu.org (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id DED122B9D; Thu, 26 Aug 2004 17:24:38 -0400 (EDT) Message-ID: <412E5516.6050209@gnu.org> Date: Thu, 26 Aug 2004 21:25:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-GB; rv:1.4.1) Gecko/20040801 MIME-Version: 1.0 To: "Nathan J. Williams" Cc: gdb-patches@sources.redhat.com Subject: Re: [RFC/RFA] target.c: Check current_target in target_resize_to_sections References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-08/txt/msg00717.txt.bz2 > (with instances of gdbserver running on both ports on the remotehost). > > The errors I see are: > gdb in realloc(): warning: modified (page-) pointer > ../../../gdb-w/gdb/utils.c:994: internal-error: virtual memory exhausted: can't allocate 2032 bytes > > (the former error is from the NetBSD realloc call) > > The problem is that update_current_inferior() will copy a valid > to_sections value out of one of the targets in the stack into > current_target, but that pointer may become invalid later when > target_resize_to_sections() is called again on any target using the > same pointer. Finally, when handle_inferior_event() calls > SOLIB_ADD(.., ¤t_target, ...), target_resize_to_sections() calls > realloc() again on a pointer that's already been realloc'd. "Boom." > > My fix is to make target_resize_to_sections update current_target as > well as all of the targets in target_structs. Seems to do the job, > though I can't say it thrills me. > > Comments? Suggestions for better approaches? It definitely fixes the > problem, and doesn't seem any messier than the rest of the target > stack stuff. It might be better to not use current_target with > anything that looks at to_sections, but I've no idea how difficult it > might be to do that. > > - Nathan > > 2004-08-25 Nathan J. Williams > > * target.c (target_resize_to_sections): Check > current_target.to_sections for an old value when updating. Can you just add some sort of brief comment noting why current_target also needs to be checked. With that it's ok (but post the revised patch when committing). Long term `current_target', along with this problem, will go away. Andrew > Index: target.c > =================================================================== > RCS file: /cvs/src/src/gdb/target.c,v > retrieving revision 1.78 > diff -u -r1.78 target.c > --- target.c 3 Aug 2004 00:57:26 -0000 1.78 > +++ target.c 25 Aug 2004 20:35:37 -0000 > @@ -1415,6 +1415,11 @@ > (*t)->to_sections_end = target->to_sections_end; > } > } > + if (current_target.to_sections == old_value) > + { > + current_target.to_sections = target->to_sections; > + current_target.to_sections_end = target->to_sections_end; > + } > } > > return old_count; > >