From patchwork Thu Feb 22 15:36:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 26002 Received: (qmail 31154 invoked by alias); 22 Feb 2018 15:36:49 -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 31042 invoked by uid 89); 22 Feb 2018 15:36:48 -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=*linkage_name, sk:DW_AT_s, sk:dw_at_s X-HELO: mail-wm0-f67.google.com Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Feb 2018 15:36:46 +0000 Received: by mail-wm0-f67.google.com with SMTP id t82so4363833wmt.5 for ; Thu, 22 Feb 2018 07:36:46 -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=h90vCpDkqiWh3ArHVQlr0LArhfpIIdiETvncWxFJUvM=; b=pNZ0F5igRgdrWiBINrVX4HSvtTLNCq1St9ddOvK0r5qVTyWTsa1MSfRWDd/tBvm7RF c+VJKsm9peClZT/bi9rC8uWNXjhViWFhG9cJYn/+2wXAnmUcNnCzcV7J6+UYKJGeGBc7 GlzyGBbB67ishf8QhT2DxWhtDogRuvj9brogDh7Fo4KcLAavrOwVt2SA58U2ISe5IjEr AxyEd3e7GQ6+ygIR8NF28vQvxzYFZix/b/bGQeEkVpzayreKKfZ9W3cBv+5eredbFvC7 ZHQm9J2l3lz+rBAQ4PI/hy/LFKWEm71l+JzGWNYZ3b3yBNwcGaSh1RrJA7ujCgcjpHP/ FkRg== X-Gm-Message-State: APf1xPCKIsy5teQny1Db8I7VDFjZRG+vw1JQcRt8CF2hDD4n/ssCmvu5 Mt0SMBnVdACvTKndBg2BVN35tGr4 X-Google-Smtp-Source: AH8x2274M0rEdb2oeDCwmP3GwtwTxRnCPVVVdLHL8N/A7X1MQTUPqLwRXck8JsXwLBVxZ3gYuYrt/Q== X-Received: by 10.28.51.6 with SMTP id z6mr5169783wmz.26.1519313804172; Thu, 22 Feb 2018 07:36:44 -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 a67sm538325wrc.13.2018.02.22.07.36.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Feb 2018 07:36:43 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 4/7] Class-fy partial_die_info Date: Thu, 22 Feb 2018 15:36:33 +0000 Message-Id: <1519313796-2397-5-git-send-email-yao.qi@linaro.org> In-Reply-To: <1519313796-2397-1-git-send-email-yao.qi@linaro.org> References: <1519313796-2397-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes This patch is to class-fy partial_die_info. Two things special here, - disable assignment operator, but keep copy ctor, which is used in load_partial_dies, - have a private ctor which is only used by dwarf2_cu::find_partial_die, I don't want other code use it, so make it private, gdb: 2018-01-11 Yao Qi * dwarf2read.c (struct partial_die_info): Add ctor, delete assignment operator. (load_partial_dies): Use ctor and copy ctor. (read_partial_die): Update. (dwarf2_cu::find_partial_die): Use ctor. --- gdb/dwarf2read.c | 88 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 26 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index f386873..b01d9f3 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1402,16 +1402,23 @@ file_entry::include_dir (const line_header *lh) const /* When we construct a partial symbol table entry we only need this much information. */ -struct partial_die_info +struct partial_die_info : public allocate_on_obstack { + partial_die_info (sect_offset sect_off, struct abbrev_info *abbrev); + + /* Disable assign but still keep copy ctor, which is needed + load_partial_dies. */ + partial_die_info& operator=(const partial_die_info& rhs) = delete; + /* Offset of this DIE. */ - sect_offset sect_off; + const sect_offset sect_off; /* DWARF-2 tag for this DIE. */ - ENUM_BITFIELD(dwarf_tag) tag : 16; + const ENUM_BITFIELD(dwarf_tag) tag : 16; /* Assorted flags describing the data found in this DIE. */ - unsigned int has_children : 1; + const unsigned int has_children : 1; + unsigned int is_external : 1; unsigned int is_declaration : 1; unsigned int has_type : 1; @@ -1446,15 +1453,15 @@ struct partial_die_info /* The name of this DIE. Normally the value of DW_AT_name, but sometimes a default name for unnamed DIEs. */ - const char *name; + const char *name = nullptr; /* The linkage name, if present. */ - const char *linkage_name; + const char *linkage_name = nullptr; /* The scope to prepend to our children. This is generally allocated on the comp_unit_obstack, so will disappear when this compilation unit leaves the cache. */ - const char *scope; + const char *scope = nullptr; /* Some data associated with the partial DIE. The tag determines which field is live. */ @@ -1464,26 +1471,58 @@ struct partial_die_info struct dwarf_block *locdesc; /* The offset of an import, for DW_TAG_imported_unit. */ sect_offset sect_off; - } d; + } d {}; /* If HAS_PC_INFO, the PC range associated with this DIE. */ - CORE_ADDR lowpc; - CORE_ADDR highpc; + CORE_ADDR lowpc = 0; + CORE_ADDR highpc = 0; /* Pointer into the info_buffer (or types_buffer) pointing at the target of DW_AT_sibling, if any. */ /* NOTE: This member isn't strictly necessary, read_partial_die could return DW_AT_sibling values to its caller load_partial_dies. */ - const gdb_byte *sibling; + const gdb_byte *sibling = nullptr; /* If HAS_SPECIFICATION, the offset of the DIE referred to by DW_AT_specification (or DW_AT_abstract_origin or DW_AT_extension). */ - sect_offset spec_offset; + sect_offset spec_offset {}; /* Pointers to this DIE's parent, first child, and next sibling, if any. */ - struct partial_die_info *die_parent, *die_child, *die_sibling; + struct partial_die_info *die_parent = nullptr; + struct partial_die_info *die_child = nullptr; + struct partial_die_info *die_sibling = nullptr; + + friend struct partial_die_info * + dwarf2_cu::find_partial_die (sect_offset sect_off); + + private: + /* Only need to do look up in dwarf2_cu::find_partial_die. */ + partial_die_info (sect_offset sect_off) + : partial_die_info (sect_off, DW_TAG_padding, 0) + { + } + + partial_die_info (sect_offset sect_off_, enum dwarf_tag tag_, + int has_children_) + : sect_off (sect_off_), tag (tag_), has_children (has_children_) + { + is_external = 0; + is_declaration = 0; + has_type = 0; + has_specification = 0; + has_pc_info = 0; + may_be_inlined = 0; + main_subprogram = 0; + scope_set = 0; + has_byte_size = 0; + has_const_value = 0; + has_template_arguments = 0; + fixup_called = 0; + is_dwz = 0; + spec_is_dwz = 0; + } }; /* This data structure holds the information of an abbrev. */ @@ -18306,9 +18345,9 @@ load_partial_dies (const struct die_reader_specs *reader, continue; } - struct partial_die_info pdi; + struct partial_die_info pdi ((sect_offset) (info_ptr - reader->buffer), + abbrev); - memset (&pdi, 0, sizeof (pdi)); info_ptr = read_partial_die (reader, &pdi, abbrev, bytes_read, info_ptr); @@ -18384,9 +18423,8 @@ load_partial_dies (const struct die_reader_specs *reader, } struct partial_die_info *part_die - = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info); + = new (&cu->comp_unit_obstack) partial_die_info (pdi); - 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; @@ -18480,6 +18518,12 @@ load_partial_dies (const struct die_reader_specs *reader, } } +partial_die_info::partial_die_info (sect_offset sect_off_, + struct abbrev_info *abbrev) + : partial_die_info (sect_off_, abbrev->tag, abbrev->has_children) +{ +} + /* Read a minimal amount of information into the minimal die structure. */ static const gdb_byte * @@ -18499,15 +18543,8 @@ read_partial_die (const struct die_reader_specs *reader, int has_high_pc_attr = 0; int high_pc_relative = 0; - memset (part_die, 0, sizeof (struct partial_die_info)); - - part_die->sect_off = (sect_offset) (info_ptr - buffer); - info_ptr += abbrev_len; - part_die->tag = abbrev->tag; - part_die->has_children = abbrev->has_children; - for (i = 0; i < abbrev->num_attrs; ++i) { info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); @@ -18707,9 +18744,8 @@ struct partial_die_info * dwarf2_cu::find_partial_die (sect_offset sect_off) { struct partial_die_info *lookup_die = NULL; - struct partial_die_info part_die; + struct partial_die_info part_die (sect_off); - part_die.sect_off = sect_off; lookup_die = ((struct partial_die_info *) htab_find_with_hash (partial_dies, &part_die, to_underlying (sect_off)));