From patchwork Fri Apr 12 23:25:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 32275 Received: (qmail 40408 invoked by alias); 12 Apr 2019 23:25:48 -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 40294 invoked by uid 89); 12 Apr 2019 23:25:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=beside, Different, displaced, Possible X-HELO: mail-wr1-f67.google.com Received: from mail-wr1-f67.google.com (HELO mail-wr1-f67.google.com) (209.85.221.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 12 Apr 2019 23:25:46 +0000 Received: by mail-wr1-f67.google.com with SMTP id p10so13944218wrq.1 for ; Fri, 12 Apr 2019 16:25:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=EzECR3BZbEbV/VQhpJeWY8ovB0fN2cN5BWAe8xfCFqo=; b=UKUdT5tG6+CjC94bbBKNhPzD7iyJFheBKe2nXElUWVbJFXwJli/Nuk5kMH/OUr0PoA 4kthw8ClDzTEzY5JyOza+NZiWyD7R2EWK4ul0CYFr1o9ukjNy22536NIq9RAIJ0wfGcE jgnlBpWLh6MwJrAijimy7zFtslZNDECTXSBS91q9VYNC5IWu3RcNMUylEjW3I8Hgvr9c 7JaEO5B3fjM0YRnHG67C4ncTWhiZZRfcwL2OFzsmdagUlRCWFi4glAE01v+NuYMTbJyc Ms/4l7rNRoWvatC3ZtfSSfmE38uOKfVzrhQDBjqNdtKp1RDy9U/7xmBPPPgRP+bxjTBS Likw== Return-Path: Received: from localhost (host86-164-133-98.range86-164.btcentralplus.com. [86.164.133.98]) by smtp.gmail.com with ESMTPSA id y125sm15536517wmc.39.2019.04.12.16.25.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Apr 2019 16:25:42 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: alan.hayward@arm.com, Andrew Burgess Subject: [PATCH 2/3] gdb/arm: Use type_align instead of arm_type_align Date: Sat, 13 Apr 2019 00:25:33 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Replaces use of arm_type_align with common type_align function. Doing this fixes a bug in arm_type_align where static fields are considered as part of the alignment calculation of a struct, which results in arguments passed on the stack being misaligned, this bug was causing a failure in gdb.cp/many-args.exp. Part of the old arm_type_align is retained and used as the gdbarch type align callback in order to correctly align vectors. gdb/ChangeLog: * arm-tdep.c (arm_type_align): Only handle vector override case. (arm_push_dummy_call): Use type_align. (arm_gdbarch_init): Register arm_type_align gdbarch function. --- gdb/ChangeLog | 6 ++++++ gdb/arm-tdep.c | 68 +++++++++++++++------------------------------------------- 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 599f785b349..742bfa57069 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -3314,62 +3314,25 @@ pop_stack_item (struct stack_item *si) return si; } +/* Implement the gdbarch type alignment method, overrides the generic + alignment algorithm for anything that is arm specific. */ -/* Return the alignment (in bytes) of the given type. */ - -static int -arm_type_align (struct type *t) +static ULONGEST +arm_type_align (gdbarch *gdbarch, struct type *t) { - int n; - int align; - int falign; - t = check_typedef (t); - switch (TYPE_CODE (t)) + if (TYPE_CODE (t) == TYPE_CODE_ARRAY && TYPE_VECTOR (t)) { - default: - /* Should never happen. */ - internal_error (__FILE__, __LINE__, _("unknown type alignment")); - return 4; - - case TYPE_CODE_PTR: - case TYPE_CODE_ENUM: - case TYPE_CODE_INT: - case TYPE_CODE_FLT: - case TYPE_CODE_SET: - case TYPE_CODE_RANGE: - case TYPE_CODE_REF: - case TYPE_CODE_RVALUE_REF: - case TYPE_CODE_CHAR: - case TYPE_CODE_BOOL: - return TYPE_LENGTH (t); - - case TYPE_CODE_ARRAY: - if (TYPE_VECTOR (t)) - { - /* Use the natural alignment for vector types (the same for - scalar type), but the maximum alignment is 64-bit. */ - if (TYPE_LENGTH (t) > 8) - return 8; - else - return TYPE_LENGTH (t); - } + /* Use the natural alignment for vector types (the same for + scalar type), but the maximum alignment is 64-bit. */ + if (TYPE_LENGTH (t) > 8) + return 8; else - return arm_type_align (TYPE_TARGET_TYPE (t)); - case TYPE_CODE_COMPLEX: - return arm_type_align (TYPE_TARGET_TYPE (t)); - - case TYPE_CODE_STRUCT: - case TYPE_CODE_UNION: - align = 1; - for (n = 0; n < TYPE_NFIELDS (t); n++) - { - falign = arm_type_align (TYPE_FIELD_TYPE (t, n)); - if (falign > align) - align = falign; - } - return align; + return TYPE_LENGTH (t); } + + /* Allow the common code to calculate the alignment. */ + return 0; } /* Possible base types for a candidate for passing and returning in @@ -3715,7 +3678,7 @@ arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function, typecode = TYPE_CODE (arg_type); val = value_contents (args[argnum]); - align = arm_type_align (arg_type); + align = type_align (arg_type); /* Round alignment up to a whole number of words. */ align = (align + INT_REGISTER_SIZE - 1) & ~(INT_REGISTER_SIZE - 1); /* Different ABIs have different maximum alignments. */ @@ -9309,6 +9272,9 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) else set_gdbarch_wchar_signed (gdbarch, 1); + /* Compute type alignment. */ + set_gdbarch_type_align (gdbarch, arm_type_align); + /* Note: for displaced stepping, this includes the breakpoint, and one word of additional scratch space. This setting isn't used for anything beside displaced stepping at present. */