From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2058 invoked by alias); 7 Nov 2010 03:50:51 -0000 Received: (qmail 2050 invoked by uid 22791); 7 Nov 2010 03:50:49 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 07 Nov 2010 03:50:44 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oA73oge0008661 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 6 Nov 2010 23:50:42 -0400 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oA73ocKR001996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 6 Nov 2010 23:50:41 -0400 Received: from host0.dyn.jankratochvil.net (localhost.localdomain [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.4/8.14.4) with ESMTP id oA73oZRu029967 for ; Sun, 7 Nov 2010 04:50:36 +0100 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.4/8.14.4/Submit) id oA73oXLh029966 for gdb-patches@sourceware.org; Sun, 7 Nov 2010 04:50:33 +0100 Date: Sun, 07 Nov 2010 03:50:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch 1/2] Code cleanup: New init_one_comp_unit Message-ID: <20101107035032.GA8598@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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: 2010-11/txt/msg00107.txt.bz2 Hi, unify some code into a function, to be extended in the next patch. Thanks, Jan gdb/ 2010-11-06 Jan Kratochvil Code cleanup. * dwarf2read.c (alloc_one_comp_unit): Rename prototype to ... (init_one_comp_unit): ... this one. (prepare_one_comp_unit): New prototype. (dw2_require_line_header, process_psymtab_comp_unit): Use init_one_comp_unit. (process_psymtab_comp_unit): Use prepare_one_comp_unit. (load_partial_comp_unit): Remove variable attr. Use init_one_comp_unit with xmalloc. Use prepare_one_comp_unit. (load_full_comp_unit): Use init_one_comp_unit with xmalloc. Use prepare_one_comp_unit. (read_signatured_type): Remove variable attr. Use init_one_comp_unit. Use prepare_one_comp_unit. (alloc_one_comp_unit): Rename to ... (init_one_comp_unit): ... here and remove there calloc, new parameter cu. (prepare_one_comp_unit): New function. --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1241,7 +1241,11 @@ static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit static struct dwarf2_per_cu_data *dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile); -static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile); +static void init_one_comp_unit (struct dwarf2_cu *cu, + struct objfile *objfile); + +static void prepare_one_comp_unit (struct dwarf2_cu *cu, + struct die_info *comp_unit_die); static void free_one_comp_unit (void *); @@ -2018,10 +2022,7 @@ dw2_require_line_header (struct objfile *objfile, return; this_cu->v.quick->read_lines = 1; - memset (&cu, 0, sizeof (cu)); - cu.objfile = objfile; - obstack_init (&cu.comp_unit_obstack); - + init_one_comp_unit (&cu, objfile); cleanups = make_cleanup (free_stack_comp_unit, &cu); if (this_cu->from_debug_types) @@ -3024,10 +3025,7 @@ process_psymtab_comp_unit (struct objfile *objfile, CORE_ADDR best_lowpc = 0, best_highpc = 0; struct die_reader_specs reader_specs; - memset (&cu, 0, sizeof (cu)); - cu.objfile = objfile; - obstack_init (&cu.comp_unit_obstack); - + init_one_comp_unit (&cu, objfile); back_to_inner = make_cleanup (free_stack_comp_unit, &cu); info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, @@ -3081,12 +3079,7 @@ process_psymtab_comp_unit (struct objfile *objfile, return info_ptr; } - /* Set the language we're debugging. */ - attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu); - if (attr) - set_cu_language (DW_UNSND (attr), &cu); - else - set_cu_language (language_minimal, &cu); + prepare_one_comp_unit (&cu, comp_unit_die); /* Allocate a new partial symbol table structure. */ attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); @@ -3301,7 +3294,6 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, struct die_info *comp_unit_die; struct dwarf2_cu *cu; struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; - struct attribute *attr; int has_children; struct die_reader_specs reader_specs; int read_cu = 0; @@ -3314,7 +3306,8 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, if (this_cu->cu == NULL) { - cu = alloc_one_comp_unit (objfile); + cu = xmalloc (sizeof (*cu)); + init_one_comp_unit (cu, objfile); read_cu = 1; @@ -3354,12 +3347,7 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, &has_children); - /* Set the language we're debugging. */ - attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); - if (attr) - set_cu_language (DW_UNSND (attr), cu); - else - set_cu_language (language_minimal, cu); + prepare_one_comp_unit (cu, comp_unit_die); /* Check if comp unit has_children. If so, read the rest of the partial symbols from this comp unit. @@ -4314,7 +4302,8 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) if (per_cu->cu == NULL) { - cu = alloc_one_comp_unit (objfile); + cu = xmalloc (sizeof (*cu)); + init_one_comp_unit (cu, objfile); read_cu = 1; @@ -4352,11 +4341,7 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) all objfiles needed for references have been loaded yet, and symbol table processing isn't initialized. But we have to set the CU language, or we won't be able to build types correctly. */ - attr = dwarf2_attr (cu->dies, DW_AT_language, cu); - if (attr) - set_cu_language (DW_UNSND (attr), cu); - else - set_cu_language (language_minimal, cu); + prepare_one_comp_unit (cu, cu->dies); /* Similarly, if we do not read the producer, we can not apply producer-specific interpretation. */ @@ -13220,17 +13205,15 @@ read_signatured_type (struct objfile *objfile, struct dwarf2_cu *cu; ULONGEST signature; struct cleanup *back_to, *free_cu_cleanup; - struct attribute *attr; dwarf2_read_section (objfile, &dwarf2_per_objfile->types); types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; gdb_assert (type_sig->per_cu.cu == NULL); - cu = xmalloc (sizeof (struct dwarf2_cu)); - memset (cu, 0, sizeof (struct dwarf2_cu)); - obstack_init (&cu->comp_unit_obstack); - cu->objfile = objfile; + cu = xmalloc (sizeof (*cu)); + init_one_comp_unit (cu, objfile); + type_sig->per_cu.cu = cu; cu->per_cu = &type_sig->per_cu; @@ -13262,11 +13245,7 @@ read_signatured_type (struct objfile *objfile, all objfiles needed for references have been loaded yet, and symbol table processing isn't initialized. But we have to set the CU language, or we won't be able to build types correctly. */ - attr = dwarf2_attr (cu->dies, DW_AT_language, cu); - if (attr) - set_cu_language (DW_UNSND (attr), cu); - else - set_cu_language (language_minimal, cu); + prepare_one_comp_unit (cu, cu->dies); do_cleanups (back_to); @@ -14314,15 +14293,29 @@ dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) return this_cu; } -/* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */ +/* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */ -static struct dwarf2_cu * -alloc_one_comp_unit (struct objfile *objfile) +static void +init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile) { - struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu)); + memset (cu, 0, sizeof (*cu)); cu->objfile = objfile; obstack_init (&cu->comp_unit_obstack); - return cu; +} + +/* Initiailize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ + +static void +prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) +{ + struct attribute *attr; + + /* Set the language we're debugging. */ + attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); + if (attr) + set_cu_language (DW_UNSND (attr), cu); + else + set_cu_language (language_minimal, cu); } /* Release one cached compilation unit, CU. We unlink it from the tree