From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31379 invoked by alias); 25 Aug 2004 20:40:28 -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 31369 invoked from network); 25 Aug 2004 20:40:26 -0000 Received: from unknown (HELO biscayne-one-station.mit.edu) (18.7.7.80) by sourceware.org with SMTP; 25 Aug 2004 20:40:26 -0000 Received: from melbourne-city-street.mit.edu (MELBOURNE-CITY-STREET.MIT.EDU [18.7.21.86]) by biscayne-one-station.mit.edu (8.12.4/8.9.2) with ESMTP id i7PKePGV003463 for ; Wed, 25 Aug 2004 16:40:25 -0400 (EDT) Received: from contents-vnder-pressvre.mit.edu (CONTENTS-VNDER-PRESSVRE.MIT.EDU [18.7.16.67]) (authenticated bits=56) (User authenticated as nathanw@ATHENA.MIT.EDU) by melbourne-city-street.mit.edu (8.12.4/8.12.4) with ESMTP id i7PKePuv007804 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 25 Aug 2004 16:40:25 -0400 (EDT) Received: (from nathanw@localhost) by contents-vnder-pressvre.mit.edu (8.12.9) id i7PKeP9Y026628; Wed, 25 Aug 2004 16:40:25 -0400 (EDT) To: gdb-patches@sources.redhat.com Subject: [RFC/RFA] target.c: Check current_target in target_resize_to_sections From: "Nathan J. Williams" Organization: Wasabi Systems, Inc. Date: Wed, 25 Aug 2004 20:40:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2004-08/txt/msg00702.txt.bz2 I recently came across an internal error/malloc failure while running the gdb.threads/print-threads.exp test with gdbserver. The problem is related to the target stack and to_sections being copied as part of the stack. In brief, the sequence of commands that reproduces the problem is: $ gdb print-threads (gdb) set solib-absolute-prefix ... (gdb) b main (gdb) target remote remotehost:1234 (gdb) c (gdb) target remote remotehost:1235 (gdb) c (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. 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;