From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id AF1D33858404 for ; Mon, 13 Feb 2023 03:15:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF1D33858404 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 cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id 327891004060C for ; Mon, 13 Feb 2023 03:15:27 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id RPJPpjBR2Bkq3RPJPptmf8; Mon, 13 Feb 2023 03:15:27 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=DdHSFthW c=1 sm=1 tr=0 ts=63e9ab4f 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=7d_E57ReAAAA:8 a=sIuQ76nCGIqbid_AdFQA:9 a=bWskf8CFYxATgCEA:21 a=QEXdDO2ut3YA:10:nop_charset_2 a=jhqOcbufqs7Y1TYCrUUU:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=3jTC4e94rA2UVjLTwp4Hk4+opKsnA7L4jSWYbUlMU1g=; b=N6sLn+/TQYdQIKk3ae1e0oY5xl VybT28g7REz7vOBbVU7ErMuD6KfQLD9+HA2w3ws1ZvYsQuIKxuMSj49A6txZhkgHZIMLkWFhP7mrf wei+CxcVxdVJyTvsEpPfiBD9+; Received: from 75-166-130-93.hlrn.qwest.net ([75.166.130.93]:37668 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 1pRPJO-001AGJ-UB; Sun, 12 Feb 2023 20:15:26 -0700 From: Tom Tromey Date: Sun, 12 Feb 2023 20:15:29 -0700 Subject: [PATCH v3 13/50] Turn value_enclosing_type into method MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230209-submit-value-fixups-2023-v3-13-45e91a20c742@tromey.com> References: <20230209-submit-value-fixups-2023-v3-0-45e91a20c742@tromey.com> In-Reply-To: <20230209-submit-value-fixups-2023-v3-0-45e91a20c742@tromey.com> To: gdb-patches@sourceware.org Cc: Simon Marchi 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: 1pRPJO-001AGJ-UB 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]:37668 X-Source-Auth: tom+tromey.com X-Email-Count: 29 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.4 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 List-Id: This changes value_enclosing_type to be a method of value. Much of this patch was written by script. Approved-By: Simon Marchi --- 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 | 60 ++++++++++++++------------------ gdb/value.h | 93 +++++++++++++++++++++++++------------------------- gdb/vax-tdep.c | 2 +- gdb/xstormy16-tdep.c | 4 +-- 15 files changed, 111 insertions(+), 119 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 090f5468067..aea5e12f387 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 f462da8b564..9870e0da337 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 783ef7deae7..efa780a897a 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -177,7 +177,7 @@ value_bits_available (const struct value *value, /* Don't pretend we have anything available there in the history beyond the boundaries of the value recorded. It's not like inferior memory where there is actual stuff underneath. */ - ULONGEST val_len = TARGET_CHAR_BIT * value_enclosing_type (value)->length (); + ULONGEST val_len = TARGET_CHAR_BIT * value->enclosing_type ()->length (); return !((value->m_in_history && (offset < 0 || offset + length > val_len)) || ranges_contain (value->m_unavailable, offset, length)); @@ -240,7 +240,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; } @@ -725,8 +725,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); @@ -934,7 +934,7 @@ allocate_value_contents (struct value *val, bool check_size) { if (!val->m_contents) { - struct type *enclosing_type = value_enclosing_type (val); + struct type *enclosing_type = val->enclosing_type (); ULONGEST len = enclosing_type->length (); if (check_size) @@ -1042,16 +1042,10 @@ value_contents_all_raw (struct value *value) { allocate_value_contents (value, true); - 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 * @@ -1089,7 +1083,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 (); } } @@ -1128,7 +1122,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); } @@ -1137,7 +1131,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); } @@ -1614,7 +1608,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; val = allocate_value_lazy (encl_type); @@ -1643,7 +1637,7 @@ value_copy (const value *arg) { ULONGEST length = val->m_limited_length; if (length == 0) - length = value_enclosing_type (val)->length (); + length = val->enclosing_type ()->length (); gdb_assert (arg->m_contents != nullptr); const auto &arg_view @@ -1676,12 +1670,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; } @@ -1693,7 +1686,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)); @@ -1788,7 +1781,7 @@ set_value_component_location (struct value *component, int record_latest_value (struct value *val) { - struct type *enclosing_type = value_enclosing_type (val); + struct type *enclosing_type = val->enclosing_type (); struct type *type = val->type (); /* We don't want this value to have anything to do with the inferior anymore. @@ -2972,17 +2965,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) @@ -3062,12 +3054,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 (); @@ -3780,7 +3772,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. */ @@ -3801,7 +3793,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 ()); @@ -3913,7 +3905,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 ()); /* Figure out how much we should copy from memory. Usually, this is just the size of the type, but, for arrays, we might only be loading a diff --git a/gdb/value.h b/gdb/value.h index befd41789ee..a3d07c0b5fd 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -215,6 +215,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. */ @@ -393,51 +439,6 @@ struct value ULONGEST m_limited_length = 0; }; -/* 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. @@ -768,7 +769,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); -- 2.39.1