From patchwork Thu Feb 9 21:38:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 64567 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 652BB388A417 for ; Thu, 9 Feb 2023 21:40:28 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from outbound-ss-820.bluehost.com (outbound-ss-820.bluehost.com [69.89.24.241]) by sourceware.org (Postfix) with ESMTPS id 14AC83858433 for ; Thu, 9 Feb 2023 21:38:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14AC83858433 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway2.mail.pro1.eigbox.com (Postfix) with ESMTP id 7A6F510047F8C for ; Thu, 9 Feb 2023 21:38:41 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id QEcrpzBOhP796QEcrpwoWD; Thu, 09 Feb 2023 21:38:41 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=MJClJOVl c=1 sm=1 tr=0 ts=63e567e1 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=m04uMKEZRckA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=Qpd1Fwm_um4UBxpiPKoA:9 a=bWskf8CFYxATgCEA:21 a=QEXdDO2ut3YA:10:nop_charset_2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=YUvLdHHdFPLzbiBthO/qbFzZu2jv3TxsfO4FM6xsfU4=; b=Em9axlyLWymo1dHzLNR2eXdFmK iW9MKYZV6qneyeHgJq168iwkHXOfPM88vqrWVsjR/ZXJTklUDbd3YdEkXV27lvdhT2C7CwZI6r+Cb gizITsJlwUc96Dk9svgTM6BVk; Received: from 75-166-130-93.hlrn.qwest.net ([75.166.130.93]:52822 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pQEcr-001ZcE-9t for gdb-patches@sourceware.org; Thu, 09 Feb 2023 14:38:41 -0700 From: Tom Tromey Date: Thu, 09 Feb 2023 14:38:33 -0700 Subject: [PATCH 12/47] Turn value_enclosing_type into method MIME-Version: 1.0 Message-Id: <20230209-submit-value-fixups-2023-v1-12-55dc2794dbb9@tromey.com> References: <20230209-submit-value-fixups-2023-v1-0-55dc2794dbb9@tromey.com> In-Reply-To: <20230209-submit-value-fixups-2023-v1-0-55dc2794dbb9@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.130.93 X-Source-L: No X-Exim-ID: 1pQEcr-001ZcE-9t X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-130-93.hlrn.qwest.net ([192.168.0.21]) [75.166.130.93]:52822 X-Source-Auth: tom+tromey.com X-Email-Count: 13 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This changes value_enclosing_type to be a method of value. Much of this patch was written by script. --- gdb/ada-lang.c | 6 ++-- gdb/bfin-tdep.c | 4 +-- gdb/c-valprint.c | 8 ++--- gdb/cp-valprint.c | 2 +- gdb/gnu-v3-abi.c | 2 +- gdb/i386-darwin-tdep.c | 2 +- gdb/i386-tdep.c | 6 ++-- gdb/m68k-tdep.c | 2 +- gdb/rl78-tdep.c | 2 +- gdb/tilegx-tdep.c | 4 +-- gdb/valops.c | 33 +++++++++--------- gdb/value.c | 54 +++++++++++++---------------- gdb/value.h | 93 +++++++++++++++++++++++++------------------------- gdb/vax-tdep.c | 2 +- gdb/xstormy16-tdep.c | 4 +-- 15 files changed, 108 insertions(+), 116 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 5aec8b77b14..baffea75657 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3060,7 +3060,7 @@ ada_value_ptr_subscript (struct value *arr, int arity, struct value **ind) int k; struct value *array_ind = ada_value_ind (arr); struct type *type - = check_typedef (value_enclosing_type (array_ind)); + = check_typedef (array_ind->enclosing_type ()); if (type->code () == TYPE_CODE_ARRAY && TYPE_FIELD_BITSIZE (type, 0) > 0) @@ -3334,7 +3334,7 @@ ada_array_bound (struct value *arr, int n, int which) if (check_typedef (arr->type ())->code () == TYPE_CODE_PTR) arr = value_ind (arr); - arr_type = value_enclosing_type (arr); + arr_type = arr->enclosing_type (); if (ada_is_constrained_packed_array_type (arr_type)) return ada_array_bound (decode_constrained_packed_array (arr), n, which); @@ -3358,7 +3358,7 @@ ada_array_length (struct value *arr, int n) if (check_typedef (arr->type ())->code () == TYPE_CODE_PTR) arr = value_ind (arr); - arr_type = value_enclosing_type (arr); + arr_type = arr->enclosing_type (); if (ada_is_constrained_packed_array_type (arr_type)) return ada_array_length (decode_constrained_packed_array (arr), n); diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c index 4d84407cc45..e1be4b77071 100644 --- a/gdb/bfin-tdep.c +++ b/gdb/bfin-tdep.c @@ -509,7 +509,7 @@ bfin_push_dummy_call (struct gdbarch *gdbarch, for (i = nargs - 1; i >= 0; i--) { - struct type *value_type = value_enclosing_type (args[i]); + struct type *value_type = args[i]->enclosing_type (); total_len += align_up (value_type->length (), 4); } @@ -525,7 +525,7 @@ bfin_push_dummy_call (struct gdbarch *gdbarch, for (i = nargs - 1; i >= 0; i--) { - struct type *value_type = value_enclosing_type (args[i]); + struct type *value_type = args[i]->enclosing_type (); struct type *arg_type = check_typedef (value_type); int container_len = align_up (arg_type->length (), 4); diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 8d28c45cbfc..0a9e4f49ba6 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -571,18 +571,18 @@ c_value_print (struct value *val, struct ui_file *stream, better to leave the object as-is. */ if (!(full && (real_type->length () - < value_enclosing_type (val)->length ()))) + < val->enclosing_type ()->length ()))) val = value_cast (real_type, val); gdb_printf (stream, "(%s%s) ", real_type->name (), full ? "" : _(" [incomplete object]")); } - else if (type != check_typedef (value_enclosing_type (val))) + else if (type != check_typedef (val->enclosing_type ())) { /* No RTTI information, so let's do our best. */ gdb_printf (stream, "(%s ?) ", - value_enclosing_type (val)->name ()); - val = value_cast (value_enclosing_type (val), val); + val->enclosing_type ()->name ()); + val = value_cast (val->enclosing_type (), val); } } diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index 33ff17b8d2b..476ec9c1b1e 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -763,7 +763,7 @@ test_print_fields (gdbarch *arch) value *val = allocate_value (the_struct); gdb_byte *contents = value_contents_writeable (val).data (); - store_unsigned_integer (contents, value_enclosing_type (val)->length (), + store_unsigned_integer (contents, val->enclosing_type ()->length (), gdbarch_byte_order (arch), 0xe9); string_file out; diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index d9e0d579259..782f5765d6f 100644 --- a/gdb/gnu-v3-abi.c +++ b/gdb/gnu-v3-abi.c @@ -372,7 +372,7 @@ gnuv3_rtti_type (struct value *value, if (full_p) *full_p = (- offset_to_top == value_embedded_offset (value) - && (value_enclosing_type (value)->length () + && (value->enclosing_type ()->length () >= run_time_type->length ())); if (top_p) *top_p = - offset_to_top; diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c index d84e5ed8005..abf68ef7c39 100644 --- a/gdb/i386-darwin-tdep.c +++ b/gdb/i386-darwin-tdep.c @@ -183,7 +183,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function, for (i = 0; i < nargs; i++) { - struct type *arg_type = value_enclosing_type (args[i]); + struct type *arg_type = args[i]->enclosing_type (); if (i386_m128_p (arg_type) && num_m128 < 4) { diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index f82641debee..f2f8db3aa2c 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -2725,11 +2725,11 @@ i386_thiscall_push_dummy_call (struct gdbarch *gdbarch, struct value *function, for (i = thiscall ? 1 : 0; i < nargs; i++) { - int len = value_enclosing_type (args[i])->length (); + int len = args[i]->enclosing_type ()->length (); if (write_pass) { - if (i386_16_byte_align_p (value_enclosing_type (args[i]))) + if (i386_16_byte_align_p (args[i]->enclosing_type ())) args_space_used = align_up (args_space_used, 16); write_memory (sp + args_space_used, @@ -2745,7 +2745,7 @@ i386_thiscall_push_dummy_call (struct gdbarch *gdbarch, struct value *function, } else { - if (i386_16_byte_align_p (value_enclosing_type (args[i]))) + if (i386_16_byte_align_p (args[i]->enclosing_type ())) args_space = align_up (args_space, 16); args_space += align_up (len, 4); } diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c index ae020c89d19..e776060935c 100644 --- a/gdb/m68k-tdep.c +++ b/gdb/m68k-tdep.c @@ -544,7 +544,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function, /* Push arguments in reverse order. */ for (i = nargs - 1; i >= 0; i--) { - struct type *value_type = value_enclosing_type (args[i]); + struct type *value_type = args[i]->enclosing_type (); int len = value_type->length (); int container_len = (len + 3) & ~3; int offset; diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c index 4979e09b15f..cd846669169 100644 --- a/gdb/rl78-tdep.c +++ b/gdb/rl78-tdep.c @@ -1340,7 +1340,7 @@ rl78_push_dummy_call (struct gdbarch *gdbarch, struct value *function, /* Push arguments in reverse order. */ for (i = nargs - 1; i >= 0; i--) { - struct type *value_type = value_enclosing_type (args[i]); + struct type *value_type = args[i]->enclosing_type (); int len = value_type->length (); int container_len = (len + 1) & ~1; diff --git a/gdb/tilegx-tdep.c b/gdb/tilegx-tdep.c index 5dfb2376e99..8f005e81dcc 100644 --- a/gdb/tilegx-tdep.c +++ b/gdb/tilegx-tdep.c @@ -298,7 +298,7 @@ tilegx_push_dummy_call (struct gdbarch *gdbarch, for (i = 0; i < nargs && argreg <= TILEGX_R9_REGNUM; i++) { const gdb_byte *val; - typelen = value_enclosing_type (args[i])->length (); + typelen = args[i]->enclosing_type ()->length (); if (typelen > (TILEGX_R9_REGNUM - argreg + 1) * tilegx_reg_size) break; @@ -325,7 +325,7 @@ tilegx_push_dummy_call (struct gdbarch *gdbarch, { const gdb_byte *contents = value_contents (args[j]).data (); - typelen = value_enclosing_type (args[j])->length (); + typelen = args[j]->enclosing_type ()->length (); slacklen = align_up (typelen, 8) - typelen; gdb::byte_vector val (typelen + slacklen); memcpy (val.data (), contents, typelen); diff --git a/gdb/valops.c b/gdb/valops.c index d0ef2b952c3..9fbcf1740d5 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -327,7 +327,7 @@ value_cast_pointers (struct type *type, struct value *arg2, /* No superclass found, just change the pointer type. */ arg2 = value_copy (arg2); arg2->deprecated_set_type (type); - set_value_enclosing_type (arg2, type); + arg2->set_enclosing_type (type); set_value_pointed_to_offset (arg2, 0); /* pai: chk_val */ return arg2; } @@ -649,7 +649,7 @@ value_cast (struct type *type, struct value *arg2) arg2 = value_copy (arg2); arg2->deprecated_set_type (to_type); - set_value_enclosing_type (arg2, to_type); + arg2->set_enclosing_type (to_type); set_value_pointed_to_offset (arg2, 0); /* pai: chk_val */ return arg2; } @@ -1352,7 +1352,7 @@ value_assign (struct value *toval, struct value *fromval) to by TOVAL retains its original dynamic type after assignment. */ if (type->code () == TYPE_CODE_PTR) { - set_value_enclosing_type (val, value_enclosing_type (fromval)); + val->set_enclosing_type (fromval->enclosing_type ()); set_value_pointed_to_offset (val, value_pointed_to_offset (fromval)); } @@ -1371,14 +1371,14 @@ value_repeat (struct value *arg1, int count) if (count < 1) error (_("Invalid number %d of repetitions."), count); - val = allocate_repeat_value (value_enclosing_type (arg1), count); + val = allocate_repeat_value (arg1->enclosing_type (), count); VALUE_LVAL (val) = lval_memory; set_value_address (val, value_address (arg1)); read_value_memory (val, 0, value_stack (val), value_address (val), value_contents_all_raw (val).data (), - type_length_units (value_enclosing_type (val))); + type_length_units (val->enclosing_type ())); return val; } @@ -1568,13 +1568,13 @@ value_addr (struct value *arg1) struct type *type_ptr = lookup_pointer_type (type->target_type ()); struct type *enclosing_type - = check_typedef (value_enclosing_type (arg1)); + = check_typedef (arg1->enclosing_type ()); struct type *enclosing_type_ptr = lookup_pointer_type (enclosing_type->target_type ()); arg2 = value_copy (arg1); arg2->deprecated_set_type (type_ptr); - set_value_enclosing_type (arg2, enclosing_type_ptr); + arg2->set_enclosing_type (enclosing_type_ptr); return arg2; } @@ -1596,8 +1596,7 @@ value_addr (struct value *arg1) /* This may be a pointer to a base subobject; so remember the full derived object's type ... */ - set_value_enclosing_type (arg2, - lookup_pointer_type (value_enclosing_type (arg1))); + arg2->set_enclosing_type (lookup_pointer_type (arg1->enclosing_type ())); /* ... and also the relative position of the subobject in the full object. */ set_value_pointed_to_offset (arg2, value_embedded_offset (arg1)); @@ -1657,7 +1656,7 @@ value_ind (struct value *arg1) /* We may be pointing to something embedded in a larger object. Get the real type of the enclosing object. */ - enc_type = check_typedef (value_enclosing_type (arg1)); + enc_type = check_typedef (arg1->enclosing_type ()); enc_type = enc_type->target_type (); CORE_ADDR base_addr; @@ -1710,17 +1709,17 @@ value_array (int lowbound, int highbound, struct value **elemvec) { error (_("bad array bounds (%d, %d)"), lowbound, highbound); } - typelength = type_length_units (value_enclosing_type (elemvec[0])); + typelength = type_length_units (elemvec[0]->enclosing_type ()); for (idx = 1; idx < nelem; idx++) { - if (type_length_units (value_enclosing_type (elemvec[idx])) + if (type_length_units (elemvec[idx]->enclosing_type ()) != typelength) { error (_("array elements must all be the same size")); } } - arraytype = lookup_array_range_type (value_enclosing_type (elemvec[0]), + arraytype = lookup_array_range_type (elemvec[0]->enclosing_type (), lowbound, highbound); if (!current_language->c_style_arrays_p ()) @@ -2095,7 +2094,7 @@ struct_field_searcher::search (struct value *arg1, LONGEST offset, boffset += value_embedded_offset (arg1) + offset; if (boffset < 0 - || boffset >= value_enclosing_type (arg1)->length ()) + || boffset >= arg1->enclosing_type ()->length ()) { CORE_ADDR base_addr; @@ -3944,14 +3943,14 @@ value_full_object (struct value *argp, real_type = value_rtti_type (argp, &full, &top, &using_enc); /* If no RTTI data, or if object is already complete, do nothing. */ - if (!real_type || real_type == value_enclosing_type (argp)) + if (!real_type || real_type == argp->enclosing_type ()) return argp; /* In a destructor we might see a real type that is a superclass of the object's type. In this case it is better to leave the object as-is. */ if (full - && real_type->length () < value_enclosing_type (argp)->length ()) + && real_type->length () < argp->enclosing_type ()->length ()) return argp; /* If we have the full object, but for some reason the enclosing @@ -3960,7 +3959,7 @@ value_full_object (struct value *argp, if (full) { argp = value_copy (argp); - set_value_enclosing_type (argp, real_type); + argp->set_enclosing_type (real_type); return argp; } diff --git a/gdb/value.c b/gdb/value.c index eca340cad80..dbc87c6d31c 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -225,7 +225,7 @@ value_entirely_covered_by_range_vector (struct value *value, if (t.offset == 0 && t.length == (TARGET_CHAR_BIT - * value_enclosing_type (value)->length ())) + * value->enclosing_type ()->length ())) return 1; } @@ -710,8 +710,8 @@ value_contents_eq (const struct value *val1, LONGEST offset1, bool value_contents_eq (const struct value *val1, const struct value *val2) { - ULONGEST len1 = check_typedef (value_enclosing_type (val1))->length (); - ULONGEST len2 = check_typedef (value_enclosing_type (val2))->length (); + ULONGEST len1 = check_typedef (val1->enclosing_type ())->length (); + ULONGEST len2 = check_typedef (val2->enclosing_type ())->length (); if (len1 != len2) return false; return value_contents_eq (val1, 0, val2, 0, len1); @@ -912,16 +912,10 @@ value_contents_all_raw (struct value *value) { allocate_value_contents (value); - ULONGEST length = value_enclosing_type (value)->length (); + ULONGEST length = value->enclosing_type ()->length (); return gdb::make_array_view (value->m_contents.get (), length); } -struct type * -value_enclosing_type (const struct value *value) -{ - return value->m_enclosing_type; -} - /* Look at value.h for description. */ struct type * @@ -959,7 +953,7 @@ value_actual_type (struct value *value, int resolve_simple_types, { if (real_type_found) *real_type_found = 1; - result = value_enclosing_type (value); + result = value->enclosing_type (); } } @@ -998,7 +992,7 @@ value_contents_for_printing (struct value *value) if (value->m_lazy) value_fetch_lazy (value); - ULONGEST length = value_enclosing_type (value)->length (); + ULONGEST length = value->enclosing_type ()->length (); return gdb::make_array_view (value->m_contents.get (), length); } @@ -1007,7 +1001,7 @@ value_contents_for_printing_const (const struct value *value) { gdb_assert (!value->m_lazy); - ULONGEST length = value_enclosing_type (value)->length (); + ULONGEST length = value->enclosing_type ()->length (); return gdb::make_array_view (value->m_contents.get (), length); } @@ -1485,7 +1479,7 @@ value_release_to_mark (const struct value *mark) struct value * value_copy (const value *arg) { - struct type *encl_type = value_enclosing_type (arg); + struct type *encl_type = arg->enclosing_type (); struct value *val; if (value_lazy (arg)) @@ -1511,7 +1505,7 @@ value_copy (const value *arg) if (!value_lazy (val) && !value_entirely_optimized_out (val)) { gdb_assert (arg->m_contents != nullptr); - ULONGEST length = value_enclosing_type (arg)->length (); + ULONGEST length = arg->enclosing_type ()->length (); const auto &arg_view = gdb::make_array_view (arg->m_contents.get (), length); copy (arg_view, value_contents_all_raw (val)); @@ -1538,12 +1532,11 @@ struct value * make_cv_value (int cnst, int voltl, struct value *v) { struct type *val_type = v->type (); - struct type *m_enclosing_type = value_enclosing_type (v); + struct type *m_enclosing_type = v->enclosing_type (); struct value *cv_val = value_copy (v); cv_val->deprecated_set_type (make_cv_type (cnst, voltl, val_type, NULL)); - set_value_enclosing_type (cv_val, - make_cv_type (cnst, voltl, m_enclosing_type, NULL)); + cv_val->set_enclosing_type (make_cv_type (cnst, voltl, m_enclosing_type, NULL)); return cv_val; } @@ -1555,7 +1548,7 @@ value_non_lval (struct value *arg) { if (VALUE_LVAL (arg) != not_lval) { - struct type *enc_type = value_enclosing_type (arg); + struct type *enc_type = arg->enclosing_type (); struct value *val = allocate_value (enc_type); copy (value_contents_all (arg), value_contents_all_raw (val)); @@ -2808,17 +2801,16 @@ value_static_field (struct type *type, int fieldno) data. */ void -set_value_enclosing_type (struct value *val, struct type *new_encl_type) +value::set_enclosing_type (struct type *new_encl_type) { - if (new_encl_type->length () > value_enclosing_type (val)->length ()) + if (new_encl_type->length () > enclosing_type ()->length ()) { check_type_length_before_alloc (new_encl_type); - val->m_contents - .reset ((gdb_byte *) xrealloc (val->m_contents.release (), - new_encl_type->length ())); + m_contents.reset ((gdb_byte *) xrealloc (m_contents.release (), + new_encl_type->length ())); } - val->m_enclosing_type = new_encl_type; + m_enclosing_type = new_encl_type; } /* Given a value ARG1 (offset by OFFSET bytes) @@ -2898,12 +2890,12 @@ value_primitive_field (struct value *arg1, LONGEST offset, boffset = arg_type->field (fieldno).loc_bitpos () / 8; if (value_lazy (arg1)) - v = allocate_value_lazy (value_enclosing_type (arg1)); + v = allocate_value_lazy (arg1->enclosing_type ()); else { - v = allocate_value (value_enclosing_type (arg1)); + v = allocate_value (arg1->enclosing_type ()); value_contents_copy_raw (v, 0, arg1, 0, - value_enclosing_type (arg1)->length ()); + arg1->enclosing_type ()->length ()); } v->m_type = type; v->m_offset = arg1->offset (); @@ -3616,7 +3608,7 @@ readjust_indirect_value_type (struct value *value, struct type *enc_type, value->deprecated_set_type (resolved_original_target_type); /* Add embedding info. */ - set_value_enclosing_type (value, enc_type); + value->set_enclosing_type (enc_type); set_value_embedded_offset (value, value_pointed_to_offset (original_value)); /* We may be pointing to an object of some derived type. */ @@ -3637,7 +3629,7 @@ coerce_ref (struct value *arg) if (!TYPE_IS_REFERENCE (value_type_arg_tmp)) return arg; - enc_type = check_typedef (value_enclosing_type (arg)); + enc_type = check_typedef (arg->enclosing_type ()); enc_type = enc_type->target_type (); CORE_ADDR addr = unpack_pointer (arg->type (), value_contents (arg).data ()); @@ -3749,7 +3741,7 @@ value_fetch_lazy_memory (struct value *val) gdb_assert (VALUE_LVAL (val) == lval_memory); CORE_ADDR addr = value_address (val); - struct type *type = check_typedef (value_enclosing_type (val)); + struct type *type = check_typedef (val->enclosing_type ()); if (type->length ()) read_value_memory (val, 0, value_stack (val), diff --git a/gdb/value.h b/gdb/value.h index 360e8c5bc33..73ee8b5c34e 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -216,6 +216,52 @@ struct value int deprecated_modifiable () const { return m_modifiable; } + /* If a value represents a C++ object, then the `type' field gives the + object's compile-time type. If the object actually belongs to some + class derived from `type', perhaps with other base classes and + additional members, then `type' is just a subobject of the real + thing, and the full object is probably larger than `type' would + suggest. + + If `type' is a dynamic class (i.e. one with a vtable), then GDB can + actually determine the object's run-time type by looking at the + run-time type information in the vtable. When this information is + available, we may elect to read in the entire object, for several + reasons: + + - When printing the value, the user would probably rather see the + full object, not just the limited portion apparent from the + compile-time type. + + - If `type' has virtual base classes, then even printing `type' + alone may require reaching outside the `type' portion of the + object to wherever the virtual base class has been stored. + + When we store the entire object, `enclosing_type' is the run-time + type -- the complete object -- and `embedded_offset' is the offset + of `type' within that larger type, in bytes. The value_contents() + macro takes `embedded_offset' into account, so most GDB code + continues to see the `type' portion of the value, just as the + inferior would. + + If `type' is a pointer to an object, then `enclosing_type' is a + pointer to the object's run-time type, and `pointed_to_offset' is + the offset in bytes from the full object to the pointed-to object + -- that is, the value `embedded_offset' would have if we followed + the pointer and fetched the complete object. (I don't really see + the point. Why not just determine the run-time type when you + indirect, and avoid the special case? The contents don't matter + until you indirect anyway.) + + If we're not doing anything fancy, `enclosing_type' is equal to + `type', and `embedded_offset' is zero, so everything works + normally. */ + + struct type *enclosing_type () const + { return m_enclosing_type; } + + void set_enclosing_type (struct type *new_type); + /* Type of value; either not an lval, or one of the various different possible kinds of lval. */ @@ -383,51 +429,6 @@ struct value std::vector m_optimized_out; }; -/* If a value represents a C++ object, then the `type' field gives the - object's compile-time type. If the object actually belongs to some - class derived from `type', perhaps with other base classes and - additional members, then `type' is just a subobject of the real - thing, and the full object is probably larger than `type' would - suggest. - - If `type' is a dynamic class (i.e. one with a vtable), then GDB can - actually determine the object's run-time type by looking at the - run-time type information in the vtable. When this information is - available, we may elect to read in the entire object, for several - reasons: - - - When printing the value, the user would probably rather see the - full object, not just the limited portion apparent from the - compile-time type. - - - If `type' has virtual base classes, then even printing `type' - alone may require reaching outside the `type' portion of the - object to wherever the virtual base class has been stored. - - When we store the entire object, `enclosing_type' is the run-time - type -- the complete object -- and `embedded_offset' is the offset - of `type' within that larger type, in bytes. The value_contents() - macro takes `embedded_offset' into account, so most GDB code - continues to see the `type' portion of the value, just as the - inferior would. - - If `type' is a pointer to an object, then `enclosing_type' is a - pointer to the object's run-time type, and `pointed_to_offset' is - the offset in bytes from the full object to the pointed-to object - -- that is, the value `embedded_offset' would have if we followed - the pointer and fetched the complete object. (I don't really see - the point. Why not just determine the run-time type when you - indirect, and avoid the special case? The contents don't matter - until you indirect anyway.) - - If we're not doing anything fancy, `enclosing_type' is equal to - `type', and `embedded_offset' is zero, so everything works - normally. */ - -extern struct type *value_enclosing_type (const struct value *); -extern void set_value_enclosing_type (struct value *val, - struct type *new_type); - /* Returns value_type or value_enclosing_type depending on value_print_options.objectprint. @@ -758,7 +759,7 @@ extern void mark_value_bits_unavailable (struct value *value, example, to compare a complete object value with itself, including its enclosing type chunk, you'd do: - int len = check_typedef (value_enclosing_type (val))->length (); + int len = check_typedef (val->enclosing_type ())->length (); value_contents_eq (val, 0, val, 0, len); Returns true iff the set of available/valid contents match. diff --git a/gdb/vax-tdep.c b/gdb/vax-tdep.c index c229e660423..c46010d0b13 100644 --- a/gdb/vax-tdep.c +++ b/gdb/vax-tdep.c @@ -117,7 +117,7 @@ vax_store_arguments (struct regcache *regcache, int nargs, /* Push arguments in reverse order. */ for (i = nargs - 1; i >= 0; i--) { - int len = value_enclosing_type (args[i])->length (); + int len = args[i]->enclosing_type ()->length (); sp -= (len + 3) & ~3; count += (len + 3) / 4; diff --git a/gdb/xstormy16-tdep.c b/gdb/xstormy16-tdep.c index 0c33b9a7554..c12d83213ae 100644 --- a/gdb/xstormy16-tdep.c +++ b/gdb/xstormy16-tdep.c @@ -247,7 +247,7 @@ xstormy16_push_dummy_call (struct gdbarch *gdbarch, would fit in the remaining unused registers. */ for (i = 0; i < nargs && argreg <= E_LST_ARG_REGNUM; i++) { - typelen = value_enclosing_type (args[i])->length (); + typelen = args[i]->enclosing_type ()->length (); if (typelen > E_MAX_RETTYPE_SIZE (argreg)) break; @@ -272,7 +272,7 @@ xstormy16_push_dummy_call (struct gdbarch *gdbarch, { const gdb_byte *bytes = value_contents (args[j]).data (); - typelen = value_enclosing_type (args[j])->length (); + typelen = args[j]->enclosing_type ()->length (); slacklen = typelen & 1; gdb::byte_vector val (typelen + slacklen); memcpy (val.data (), bytes, typelen);