From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16475 invoked by alias); 7 Nov 2013 19:00:44 -0000 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 Received: (qmail 16450 invoked by uid 89); 7 Nov 2013 19:00:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL,BAYES_05,RDNS_NONE,SPAM_SUBJECT,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from Unknown (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Nov 2013 19:00:42 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA7J0YpF014212 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 7 Nov 2013 14:00:34 -0500 Received: from barimba (ovpn-113-94.phx2.redhat.com [10.3.113.94]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rA7J0TLc001098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 7 Nov 2013 14:00:33 -0500 From: Tom Tromey To: Sanimir Agovic Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 02/10] type: add c99 variable length array support References: <1382366424-21010-1-git-send-email-sanimir.agovic@intel.com> <1382366424-21010-3-git-send-email-sanimir.agovic@intel.com> Date: Thu, 07 Nov 2013 19:02:00 -0000 In-Reply-To: <1382366424-21010-3-git-send-email-sanimir.agovic@intel.com> (Sanimir Agovic's message of "Mon, 21 Oct 2013 16:40:16 +0200") Message-ID: <87eh6sujea.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-11/txt/msg00201.txt.bz2 >>>>> "Sanimir" == Sanimir Agovic writes: Sanimir> The dwarf standard allow certain attributes to be expressed as Sanimir> dwarf expressions rather than constants. For instance Sanimir> upper-/lowerbound attributes. In case of a c99 variable length Sanimir> array the upperbound is a dynamic attribute. Sanimir> +int Sanimir> +dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, Sanimir> + CORE_ADDR addr, CORE_ADDR *valp) Need an introductory comment. It can just say "See dwarf2loc.h.", since you put the real comment there. Sanimir> + switch (ctx->location) Sanimir> + { Sanimir> + case DWARF_VALUE_REGISTER: Sanimir> + *valp = dwarf_expr_read_reg (&baton, dwarf_expr_fetch_address (ctx, 0)); Sanimir> + break; Sanimir> + case DWARF_VALUE_MEMORY: Sanimir> + *valp = dwarf_expr_fetch_address (ctx, 0); Sanimir> + break; Sanimir> + } It seems that something should be done for other DWARF_VALUE_* results here. Sanimir> +static struct dwarf2_locexpr_baton* attr_to_locexprbaton Sanimir> +(const struct attribute *, struct dwarf2_cu *); Sanimir> + Sanimir> +static struct dwarf2_locexpr_baton* attr_to_locexprbaton_1 Sanimir> +(const struct attribute *, struct dwarf2_cu *, const gdb_byte *additional_data, Sanimir> + int extra_size); Sanimir> + Sanimir> +static int attr_to_dwarf2_prop Sanimir> +(struct die_info *, const struct attribute *, struct dwarf2_cu *, Sanimir> + struct dwarf2_prop *); In cases like this we usually indent the subsequent lines a bit, like: static int attr_to_dwarf2_prop (struct die_info *, const struct attribute *, struct dwarf2_cu *, struct dwarf2_prop *); However in this case I think it may be preferable to rearrange the functions so that forward declarations are not needed. What do you think? Sanimir> +static struct dwarf2_locexpr_baton* Sanimir> +attr_to_locexprbaton (const struct attribute *attribute, struct dwarf2_cu *cu) Sanimir> +{ Sanimir> + return attr_to_locexprbaton_1 (attribute, cu, NULL, 0); Sanimir> +} If there is just a single caller (there is in this patch, but I haven't read all the patches yet), I would remove this function and just update the caller. Sanimir> +static struct dwarf2_locexpr_baton* Sanimir> +attr_to_locexprbaton_1 (const struct attribute *attribute, struct dwarf2_cu *cu, Sanimir> + const gdb_byte *additional_data, int extra_size) Needs an introductory comment. Sanimir> + /* Copy the data pointer as the blocks lifetime is Missing apostrophe: "block's". Sanimir> + gdb_assert(baton->data != NULL); Space before open paren. Sanimir> +/* Parse dwarf attribute if it's a block, reference or constant and put the Sanimir> + resulting value of the attribute into struct dwarf2_prop. */ Sanimir> + Sanimir> +static int Sanimir> +attr_to_dwarf2_prop (struct die_info *die, const struct attribute *attr, Sanimir> + struct dwarf2_cu *cu, Sanimir> + struct dwarf2_prop *prop) I think it would be good if the introductory comment describe the return value. Sanimir> + else if (attr_form_is_ref (attr)) Sanimir> + { Sanimir> + struct dwarf2_cu *target_cu = cu; Sanimir> + struct die_info *target_die; Sanimir> + struct attribute *target_attr; Sanimir> + const gdb_byte append_ops[] = { DW_OP_deref }; Sanimir> + Sanimir> + target_die = follow_die_ref (die, attr, &target_cu); Sanimir> + target_attr = dwarf2_attr (target_die, DW_AT_location, target_cu); Sanimir> + Sanimir> + prop->data.locexpr = Sanimir> + attr_to_locexprbaton_1 (target_attr, cu, append_ops, Sanimir> + sizeof (append_ops) / sizeof (append_ops[0])); Sanimir> + prop->kind = DWARF_LOCEXPR; Sanimir> + gdb_assert (prop->data.locexpr != NULL); I don't understand this hunk. Could you say why it is needed? I wonder if this series also needs to handle DW_AT_count. Maybe no compiler generates it. Sanimir> + dwarf2_invalid_attrib_class_complaint(dwarf_form_name (attr->form), Sanimir> + dwarf2_name (die, cu)); Missing space before a paren. Sanimir> +static int Sanimir> +has_static_range (const struct range_bounds *bounds) Sanimir> +{ Sanimir> + return bounds->low.kind == DWARF_CONST Sanimir> + && bounds->high.kind == DWARF_CONST; Sanimir> +} THis needs parens around the argument to "return" and then an indentation fix on the second line. Sanimir> +/* Calculates the size of a type given the upper and lower bound of a dynamic Sanimir> + type. */ Sanimir> + Sanimir> +static ULONGEST Sanimir> +get_type_length (const struct type *type) Sanimir> +{ Sanimir> + const struct type *range_type, *target_type; Sanimir> + ULONGEST len = TYPE_LENGTH (type); Sanimir> + LONGEST low_bound, high_bound; Sanimir> + Sanimir> + if (TYPE_CODE (type) != TYPE_CODE_ARRAY Sanimir> + && TYPE_CODE (type) != TYPE_CODE_STRING) Sanimir> + return len; Sanimir> + Sanimir> + range_type = TYPE_INDEX_TYPE (type); Sanimir> + Sanimir> + if (!has_static_range (TYPE_RANGE_DATA (range_type))) Sanimir> + return len; This seems like it doesn't follow what the introductory comment says it does. Sanimir> + Sanimir> +static void Sanimir> +resolve_dynamic_bounds (struct type *type, CORE_ADDR address) Introductory comment. Sanimir> + do { Sanimir> + struct type *range_type = TYPE_INDEX_TYPE (ary_dim); It's hard to know but perhaps a check_typedef is required here. Sanimir> + ary_dim = TYPE_TARGET_TYPE (ary_dim); Here too. Sanimir> +struct type * Sanimir> +resolve_dynamic_type (struct type *type, CORE_ADDR address) Sanimir> +{ [...] Sanimir> + if (!TYPE_OBJFILE_OWNED (ty)) Sanimir> + return type; This seems like a bit of a wart, though I am not sure whether the situation can actually arise. One thing I didn't see in here is error-checking of whether resolution makes sense. E.g., suppose I print the value of a pointer-to-VLA. Then I move to some other frame and "print *$". In this situation the bounds have not been resolved -- but applying the DWARF expression in the currently-selected frame will silently do the wrong thing. Tom