From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22646 invoked by alias); 11 Apr 2009 10:22:03 -0000 Received: (qmail 22637 invoked by uid 22791); 11 Apr 2009 10:22:02 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 11 Apr 2009 10:21:57 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n3BALu7O002237 for ; Sat, 11 Apr 2009 06:21:56 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n3BALvPg014061 for ; Sat, 11 Apr 2009 06:21:57 -0400 Received: from host0.dyn.jankratochvil.net (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n3BALtr8011786 for ; Sat, 11 Apr 2009 06:21:55 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id n3BALqWf000487 for ; Sat, 11 Apr 2009 12:21:53 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.2/Submit) id n3BALqj7000486 for gdb-patches@sourceware.org; Sat, 11 Apr 2009 12:21:52 +0200 Date: Sat, 11 Apr 2009 10:22:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] [3/5] Types reference counting [make_function_type-objfile] Message-ID: <20090411102152.GD32624@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-IsSubscribed: yes 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/msg00202.txt.bz2 Hi, make_function_type was sometimes being called with permanent target type which would now also create a permanent function type while it should be objfile-associated function type instead. This patch only fixes a small leak. Thanks, Jan gdb/ 2009-04-11 Jan Kratochvil Make specifiable the make_function_type type memory ownership. * gdbtypes.c (make_function_type): New parameter `objfile', use it explicitely instead of TYPE-initialized removed local variable `objfile'. Describe `objfile' it in the function comment. (lookup_function_type): Update make_function_type callers. * gdbtypes.h (make_function_type): Update the prototype. * jv-lang.c (java_link_class_type): Update make_function_type callers. * dwarf2read.c (read_subroutine_type): Likewise. * stabsread.c (read_type): Likewise. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index c3f3838..bcf7bb8 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -5011,7 +5011,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) struct attribute *attr; type = die_type (die, cu); - ftype = make_function_type (type, (struct type **) 0); + ftype = make_function_type (type, (struct type **) 0, cu->objfile); /* All functions in C++, Pascal and Java have prototypes. */ attr = dwarf2_attr (die, DW_AT_prototyped, cu); diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index fb52e1a..f415773 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -378,24 +378,24 @@ lookup_reference_type (struct type *type) /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points to a pointer to memory where the function type should be stored. If *TYPEPTR is zero, update it to point to the - function type we return. We allocate new memory if needed. */ + function type we return. We allocate new memory from OBJFILE if needed; use + NULL for permanent types. */ struct type * -make_function_type (struct type *type, struct type **typeptr) +make_function_type (struct type *type, struct type **typeptr, + struct objfile *objfile) { struct type *ntype; /* New type */ - struct objfile *objfile; if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ { - ntype = alloc_type (TYPE_OBJFILE (type)); + ntype = alloc_type (objfile); if (typeptr) *typeptr = ntype; } else /* We have storage, but need to reset it. */ { ntype = *typeptr; - objfile = TYPE_OBJFILE (ntype); smash_type (ntype); TYPE_OBJFILE (ntype) = objfile; } @@ -415,7 +415,7 @@ make_function_type (struct type *type, struct type **typeptr) struct type * lookup_function_type (struct type *type) { - return make_function_type (type, (struct type **) 0); + return make_function_type (type, (struct type **) 0, TYPE_OBJFILE (type)); } /* Identify address space identifier by name -- diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 3c4e948..fc54acc 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1165,7 +1165,8 @@ extern struct type *make_pointer_type (struct type *, struct type **); extern struct type *lookup_pointer_type (struct type *); -extern struct type *make_function_type (struct type *, struct type **); +extern struct type *make_function_type (struct type *, struct type **, + struct objfile *); extern struct type *lookup_function_type (struct type *); diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c index 0d0f4bc..ce17a28 100644 --- a/gdb/jv-lang.c +++ b/gdb/jv-lang.c @@ -557,7 +557,8 @@ java_link_class_type (struct type *type, struct value *clas) } fn_fields[k].physname = ""; fn_fields[k].is_stub = 1; - fn_fields[k].type = make_function_type (java_void_type, NULL); /* FIXME */ + /* FIXME */ + fn_fields[k].type = make_function_type (java_void_type, NULL, objfile); TYPE_CODE (fn_fields[k].type) = TYPE_CODE_METHOD; } diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 5ce53e3..20bc4f5 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -1685,7 +1685,7 @@ again: case 'f': /* Function returning another type */ type1 = read_type (pp, objfile); - type = make_function_type (type1, dbx_lookup_type (typenums)); + type = make_function_type (type1, dbx_lookup_type (typenums), objfile); break; case 'g': /* Prototyped function. (Sun) */ @@ -1708,7 +1708,8 @@ again: const char *type_start = (*pp) - 1; struct type *return_type = read_type (pp, objfile); struct type *func_type - = make_function_type (return_type, dbx_lookup_type (typenums)); + = make_function_type (return_type, dbx_lookup_type (typenums), + objfile); struct type_list { struct type *type; struct type_list *next;