From patchwork Sun Jan 25 19:53:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 4805 Received: (qmail 29442 invoked by alias); 25 Jan 2015 19:56:00 -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 27827 invoked by uid 89); 25 Jan 2015 19:55:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f44.google.com Received: from mail-pa0-f44.google.com (HELO mail-pa0-f44.google.com) (209.85.220.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 25 Jan 2015 19:54:38 +0000 Received: by mail-pa0-f44.google.com with SMTP id rd3so7682492pab.3 for ; Sun, 25 Jan 2015 11:54:13 -0800 (PST) X-Received: by 10.70.38.71 with SMTP id e7mr29067179pdk.130.1422215653816; Sun, 25 Jan 2015 11:54:13 -0800 (PST) Received: from seba.sebabeach.org.gmail.com (173-13-178-53-sfba.hfc.comcastbusiness.net. [173.13.178.53]) by mx.google.com with ESMTPSA id rg6sm7900294pbc.43.2015.01.25.11.54.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Jan 2015 11:54:13 -0800 (PST) From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH 2/5] Remove struct main_type.vptr_{fieldno, basetype}: gnu-v3-abi.c Date: Sun, 25 Jan 2015 11:53:26 -0800 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. While testing this patchset I got an assert failure, and digging into that I found we were calling INIT_CPLUS_SPECIFIC on a TYPE_CODE_INT object when doing "info vtbl integer". Oops. This patch adds some asserts to help clarify what are legitimate types to pass to these functions (structs and sometimes unions), and some checks to not call them with other types. 2015-01-24 Doug Evans * gnu-v3-abi.c (gnuv3_dynamic_class): Assert only passed structs or unions. Return zero if union. (gnuv3_get_vtable): Call check_typedef. Assert only passed structs. (gnuv3_rtti_type): Pass already-check_typedef'd value to gnuv3_get_vtable. (compute_vtable_size): Assert only passed structs. (gnuv3_print_vtable): Don't call gnuv3_get_vtable for non-structs. diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index 41c6735..a62599b 100644 --- a/gdb/gnu-v3-abi.c +++ b/gdb/gnu-v3-abi.c @@ -202,6 +202,12 @@ gnuv3_dynamic_class (struct type *type) { int fieldnum, fieldelem; + gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT + || TYPE_CODE (type) == TYPE_CODE_UNION); + + if (TYPE_CODE (type) == TYPE_CODE_UNION) + return 0; + if (TYPE_CPLUS_DYNAMIC (type)) return TYPE_CPLUS_DYNAMIC (type) == 1; @@ -246,9 +252,12 @@ gnuv3_get_vtable (struct gdbarch *gdbarch, struct value *vtable_pointer; CORE_ADDR vtable_address; + CHECK_TYPEDEF (container_type); + gdb_assert (TYPE_CODE (container_type) == TYPE_CODE_STRUCT); + /* If this type does not have a virtual table, don't read the first field. */ - if (!gnuv3_dynamic_class (check_typedef (container_type))) + if (!gnuv3_dynamic_class (container_type)) return NULL; /* We do not consult the debug information to find the virtual table. @@ -301,7 +310,7 @@ gnuv3_rtti_type (struct value *value, if (using_enc_p) *using_enc_p = 0; - vtable = gnuv3_get_vtable (gdbarch, value_type (value), + vtable = gnuv3_get_vtable (gdbarch, values_type, value_as_address (value_addr (value))); if (vtable == NULL) return NULL; @@ -821,6 +830,8 @@ compute_vtable_size (htab_t offset_hash, void **slot; struct value_and_voffset search_vo, *current_vo; + gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT); + /* If the object is not dynamic, then we are done; as it cannot have dynamic base types either. */ if (!gnuv3_dynamic_class (type)) @@ -949,8 +960,11 @@ gnuv3_print_vtable (struct value *value) } gdbarch = get_type_arch (type); - vtable = gnuv3_get_vtable (gdbarch, type, - value_as_address (value_addr (value))); + + vtable = NULL; + if (TYPE_CODE (type) == TYPE_CODE_STRUCT) + vtable = gnuv3_get_vtable (gdbarch, type, + value_as_address (value_addr (value))); if (!vtable) {