From patchwork Thu Jan 25 09:38:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 25535 Received: (qmail 110961 invoked by alias); 25 Jan 2018 09:38: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 110785 invoked by uid 89); 25 Jan 2018 09:38: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, dw_at_sibling, DW_AT_sibling, DWARF2 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:46 +0000 Received: by mail-wr0-f194.google.com with SMTP id v31so1559149wrc.11 for ; Thu, 25 Jan 2018 01:38: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=iBnVhlx7anrRxzyUfp+D3UJgQD+aISN78imLJHs8zw0=; b=GGgJDlkNAKtSNJhjJGvMtoki2KzIP1JczjYMuGE1Dl+aBBugVCKwCAaoEGLn+RkyNu zEaphBSjKmL9evUGwEVA+c25HIp/5dYg+g74VAyJGfctqXQw5tsy5Vntr7NRb9biVdcv 2Dif/7ghTh6EhHiFyAWFySUxEhfQ9cJzgtd35TO68OFsqhKUcE5jGb+6M5EUfxElNgEk 2rThbMYJHS4xQYAvct58qaV6zxUSX8XDQKYxwYNBhwfGF2LMEt1kDXPHUjAHADlIc3J2 TUn0aDIjYkUGMGbrHrXP95C/SJ4SlKhmz9b7foPV3z3B2suz6x/v5lhlQEMso09p116Z 1E2A== X-Gm-Message-State: AKwxyteAL8PnrFHdAPaEj3TIgZnahUmXSo7CebBUePt2dZ6ii1uD99Eo S0C/SBxstzCRj3JIOtHtP4IpHw== X-Google-Smtp-Source: AH8x2266TQ7O4WaM1MXjQImDbToa/Vzm0dWlm5Ikyf73HXcxxsCP1mvbz6B91BeZs510g9bfy4sQEw== X-Received: by 10.223.199.14 with SMTP id k14mr7449440wrg.276.1516873124310; Thu, 25 Jan 2018 01:38: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 p15sm3767493wre.47.2018.01.25.01.38.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Jan 2018 01:38: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, 25 Jan 2018 09:38:31 +0000 Message-Id: <1516873114-7449-5-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 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 | 86 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 24 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 937faa2..9b4d09e 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1404,14 +1404,21 @@ file_entry::include_dir (const line_header *lh) const need this much information. */ struct partial_die_info { + 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. */ @@ -18273,9 +18312,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); @@ -18353,7 +18392,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); - memcpy (part_die, &pdi, sizeof (pdi)); + part_die = new (part_die) partial_die_info (pdi); + /* We'll save this DIE so link it in. */ part_die->die_parent = parent_die; part_die->die_sibling = NULL; @@ -18447,6 +18487,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 * @@ -18466,15 +18512,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); @@ -18674,9 +18713,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)));