From patchwork Thu Jan 25 09:38:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 25534 Received: (qmail 110528 invoked by alias); 25 Jan 2018 09:38:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 110384 invoked by uid 89); 25 Jan 2018 09:38:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:6337, H*r:sk:static. X-HELO: mail-wr0-f194.google.com Received: from mail-wr0-f194.google.com (HELO mail-wr0-f194.google.com) (209.85.128.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 25 Jan 2018 09:38:44 +0000 Received: by mail-wr0-f194.google.com with SMTP id a1so2228612wri.5 for ; Thu, 25 Jan 2018 01:38:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Q6ZGNKSLoHACWbY4xVmpJF/SCTgTeV2fWd4m0jBSSCw=; b=S3iLbM20vvefiGIx9YXmIdScc8nqH26ZrGTSuGJhaJwvH9ibcqF4WSYr+mHxkEnxuU S29SH9K5fU3l1d1GI8vqP5n1J3lpMJqWcHdJ88rkxmQpUnMKLYiaYqwOIXtU9oWl8Dt6 UdjvE/Rnpna18XLATO84i/qOIPQGKW5tgmpobt/c+Sdhx5p/uOwz4wGuvcc29SIc0P+Z nkPv5tHUinjWlaQp+TRZDb2WxtzeRnGyIuDAPRZYRvufcfFSCM1HWDH/EUfTFgUzQEEK JW9IK75LvbqJ/rHWh4O9YCahAHU19plLWMYHSk7iTfJBtlrRlm9iNDQ0j/a4KftkU3mu SVvA== X-Gm-Message-State: AKwxytcTHdQIe98eroRfsrxInrMEmItKuTzteDp7R01P11ji8s0hWaxt xZDujMd7tH1pgQgd0FlwyW03tw== X-Google-Smtp-Source: AH8x227jlSaLQRu6SIEo7ANzIc8DqePHXEYZEZOn8ChMsSg/jVFqa1l79hjRBMii1FYf9U9KqI/Sbw== X-Received: by 10.223.141.139 with SMTP id o11mr1705207wrb.0.1516873121873; Thu, 25 Jan 2018 01:38:41 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id p15sm3767493wre.47.2018.01.25.01.38.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Jan 2018 01:38:41 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 1/7] Re-write partial_die_info allocation in load_partial_dies Date: Thu, 25 Jan 2018 09:38:28 +0000 Message-Id: <1516873114-7449-2-git-send-email-yao.qi@linaro.org> In-Reply-To: <1516873114-7449-1-git-send-email-yao.qi@linaro.org> References: <1516873114-7449-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes load_partial_dies has a "while (1)" loop to visit each die, and create partial_die_info if needed in each iteration, like this, part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info); while (1) { if (foo1) continue; if (foo2) continue; read_partial_die (, , part_die, ,); .... part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info); }; the code was written in a way that spaces are allocated on necessary on cu->comp_unit_obstack. I want to class-fy partial_die_info, but partial_die_info ctor can't follow XOBNEW immediately, so this patch rewrite this loop to: while (1) { if (foo1) continue; if (foo2) continue; struct partial_die_info pdi; read_partial_die (, , &pdi, ,); part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info); memcpy (part_die, &pdi, sizeof (pdi)); }; we create a local variable pdi, if we need it, call XOBNEW, and copy. This also reduce one XOBNEW call. I measured the number of XOBNEW call in load_partial_dies when gdb reads dwarf2read.o, without this patch, it is 18827, and with this patch, it is 18826. gdb: 2018-01-18 Yao Qi * dwarf2read.c (load_partial_dies): Move the location of XOBNEW. --- gdb/dwarf2read.c | 55 +++++++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 96026a8..4d8958a 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -18183,7 +18183,6 @@ load_partial_dies (const struct die_reader_specs *reader, { struct dwarf2_cu *cu = reader->cu; struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile; - struct partial_die_info *part_die; struct partial_die_info *parent_die, *last_die, *first_die = NULL; unsigned int bytes_read; unsigned int load_all = 0; @@ -18205,8 +18204,6 @@ load_partial_dies (const struct die_reader_specs *reader, hashtab_obstack_allocate, dummy_obstack_deallocate); - part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info); - while (1) { abbrev_info *abbrev = peek_die_abbrev (*reader, info_ptr, &bytes_read); @@ -18215,15 +18212,8 @@ load_partial_dies (const struct die_reader_specs *reader, if (abbrev == NULL) { if (--nesting_level == 0) - { - /* PART_DIE was probably the last thing allocated on the - comp_unit_obstack, so we could call obstack_free - here. We don't do that because the waste is small, - and will be cleaned up when we're done with this - compilation unit. This way, we're also more robust - against other users of the comp_unit_obstack. */ - return first_die; - } + return first_die; + info_ptr += bytes_read; last_die = parent_die; parent_die = parent_die->die_parent; @@ -18281,7 +18271,10 @@ load_partial_dies (const struct die_reader_specs *reader, continue; } - info_ptr = read_partial_die (reader, part_die, abbrev, bytes_read, + struct partial_die_info pdi; + + memset (&pdi, 0, sizeof (pdi)); + info_ptr = read_partial_die (reader, &pdi, abbrev, bytes_read, info_ptr); /* This two-pass algorithm for processing partial symbols has a @@ -18301,18 +18294,18 @@ load_partial_dies (const struct die_reader_specs *reader, of them, for a language without namespaces), can be processed directly. */ if (parent_die == NULL - && part_die->has_specification == 0 - && part_die->is_declaration == 0 - && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) - || part_die->tag == DW_TAG_base_type - || part_die->tag == DW_TAG_subrange_type)) - { - if (building_psymtab && part_die->name != NULL) - add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, + && pdi.has_specification == 0 + && pdi.is_declaration == 0 + && ((pdi.tag == DW_TAG_typedef && !pdi.has_children) + || pdi.tag == DW_TAG_base_type + || pdi.tag == DW_TAG_subrange_type)) + { + if (building_psymtab && pdi.name != NULL) + add_psymbol_to_list (pdi.name, strlen (pdi.name), 0, VAR_DOMAIN, LOC_TYPEDEF, &objfile->static_psymbols, 0, cu->language, objfile); - info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); + info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr); continue; } @@ -18324,37 +18317,41 @@ load_partial_dies (const struct die_reader_specs *reader, it could not find the child DIEs referenced later, this is checked above. In correct DWARF DW_TAG_typedef should have no children. */ - if (part_die->tag == DW_TAG_typedef && part_die->has_children) + if (pdi.tag == DW_TAG_typedef && pdi.has_children) complaint (&symfile_complaints, _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " "- DIE at 0x%x [in module %s]"), - to_underlying (part_die->sect_off), objfile_name (objfile)); + to_underlying (pdi.sect_off), objfile_name (objfile)); /* If we're at the second level, and we're an enumerator, and our parent has no specification (meaning possibly lives in a namespace elsewhere), then we can add the partial symbol now instead of queueing it. */ - if (part_die->tag == DW_TAG_enumerator + if (pdi.tag == DW_TAG_enumerator && parent_die != NULL && parent_die->die_parent == NULL && parent_die->tag == DW_TAG_enumeration_type && parent_die->has_specification == 0) { - if (part_die->name == NULL) + if (pdi.name == NULL) complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); else if (building_psymtab) - add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, + add_psymbol_to_list (pdi.name, strlen (pdi.name), 0, VAR_DOMAIN, LOC_CONST, cu->language == language_cplus ? &objfile->global_psymbols : &objfile->static_psymbols, 0, cu->language, objfile); - info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); + info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr); continue; } + struct partial_die_info *part_die + = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info); + + memcpy (part_die, &pdi, sizeof (pdi)); /* We'll save this DIE so link it in. */ part_die->die_parent = parent_die; part_die->die_sibling = NULL; @@ -18406,8 +18403,6 @@ load_partial_dies (const struct die_reader_specs *reader, *slot = part_die; } - part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info); - /* For some DIEs we want to follow their children (if any). For C we have no reason to follow the children of structures; for other languages we have to, so that we can get at method physnames