From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 671BF3858CDB; Mon, 13 Feb 2023 22:29:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 671BF3858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676327381; bh=XMDThCgCeWy7BClvMji/baCISnukwnmrJQr/92/hRK0=; h=From:To:Subject:Date:From; b=QjiRrtQj1sIjnO1NKloZRW9AgfTXBKSd0J4FM4leo+KM8GqXidxM0930+3Us3XPCQ yD4iab84ZuIhzoVIUt8J3AA9xQlVCPfPmlrvlVKYrYVQQnczI79S7fbC8xhV7Cl4aT 5y1IrpUkFxVp5Tzd0H7JpTj0EHVlDbz+GtbS5tQY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Turn allocate_value_contents into a method X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 78259c365fb3c8e4fba9c19020fb8bdd8546c9f9 X-Git-Newrev: 82ca8f72011ed3d4661fc05e908cfa8f01c8f6f2 Message-Id: <20230213222941.671BF3858CDB@sourceware.org> Date: Mon, 13 Feb 2023 22:29:41 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D82ca8f72011e= d3d4661fc05e908cfa8f01c8f6f2 commit 82ca8f72011ed3d4661fc05e908cfa8f01c8f6f2 Author: Tom Tromey Date: Tue Jan 31 13:59:56 2023 -0700 Turn allocate_value_contents into a method =20 This turns the static function allocate_value_contents into a method on value. It is temporarily public, until some users are converted. set_limited_array_length is converted as well. =20 Approved-By: Simon Marchi Diff: --- gdb/value.c | 52 ++++++++++++++++++++++++---------------------------- gdb/value.h | 13 +++++++++++++ 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index d1f06174d97..1268e7c46f2 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -901,39 +901,35 @@ calculate_limited_array_length (struct type *array_ty= pe) return len; } =20 -/* Try to limit ourselves to only fetching the limited number of - elements. However, if this limited number of elements still - puts us over max_value_size, then we still refuse it and - return failure here, which will ultimately throw an error. */ +/* See value.h. */ =20 -static bool -set_limited_array_length (struct value *val) +bool +value::set_limited_array_length () { - ULONGEST limit =3D val->m_limited_length; - ULONGEST len =3D val->type ()->length (); + ULONGEST limit =3D m_limited_length; + ULONGEST len =3D type ()->length (); =20 if (array_length_limiting_element_count.has_value ()) - len =3D calculate_limited_array_length (val->type ()); + len =3D calculate_limited_array_length (type ()); =20 if (limit !=3D 0 && len > limit) len =3D limit; if (len > max_value_size) return false; =20 - val->m_limited_length =3D max_value_size; + m_limited_length =3D max_value_size; return true; } =20 -/* Allocate the contents of VAL if it has not been allocated yet. - If CHECK_SIZE is true, then apply the usual max-value-size checks. */ +/* See value.h. */ =20 -static void -allocate_value_contents (struct value *val, bool check_size) +void +value::allocate_contents (bool check_size) { - if (!val->m_contents) + if (!m_contents) { - struct type *enclosing_type =3D val->enclosing_type (); - ULONGEST len =3D enclosing_type->length (); + struct type *enc_type =3D enclosing_type (); + ULONGEST len =3D enc_type->length (); =20 if (check_size) { @@ -942,16 +938,16 @@ allocate_value_contents (struct value *val, bool chec= k_size) an element limit in effect, then we can possibly try to load only a sub-set of the array contents into GDB's memory. */ - if (val->type () =3D=3D enclosing_type - && val->type ()->code () =3D=3D TYPE_CODE_ARRAY + if (type () =3D=3D enc_type + && type ()->code () =3D=3D TYPE_CODE_ARRAY && len > max_value_size - && set_limited_array_length (val)) - len =3D val->m_limited_length; + && set_limited_array_length ()) + len =3D m_limited_length; else - check_type_length_before_alloc (enclosing_type); + check_type_length_before_alloc (enc_type); } =20 - val->m_contents.reset ((gdb_byte *) xzalloc (len)); + m_contents.reset ((gdb_byte *) xzalloc (len)); } } =20 @@ -963,7 +959,7 @@ value::allocate (struct type *type, bool check_size) { struct value *val =3D value::allocate_lazy (type); =20 - allocate_value_contents (val, check_size); + val->allocate_contents (check_size); val->m_lazy =3D 0; return val; } @@ -1027,7 +1023,7 @@ value::contents_raw () { int unit_size =3D gdbarch_addressable_memory_unit_size (arch ()); =20 - allocate_value_contents (this, true); + allocate_contents (true); =20 ULONGEST length =3D type ()->length (); return gdb::make_array_view @@ -1037,7 +1033,7 @@ value::contents_raw () gdb::array_view value::contents_all_raw () { - allocate_value_contents (this, true); + allocate_contents (true); =20 ULONGEST length =3D enclosing_type ()->length (); return gdb::make_array_view (m_contents.get (), length); @@ -1574,7 +1570,7 @@ value_copy (const value *arg) const auto &arg_view =3D gdb::make_array_view (arg->m_contents.get (), length); =20 - allocate_value_contents (val, false); + val->allocate_contents (false); gdb::array_view val_contents =3D val->contents_all_raw ().slice (0, length); =20 @@ -3963,7 +3959,7 @@ void value::fetch_lazy () { gdb_assert (lazy ()); - allocate_value_contents (this, true); + allocate_contents (true); /* A value is either lazy, or fully fetched. The availability/validity is only established as we try to fetch a value. */ diff --git a/gdb/value.h b/gdb/value.h index a7eed4880b4..0b49dea78e9 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -586,6 +586,19 @@ private: =20 /* Helper for fetch_lazy when the value is in a register. */ void fetch_lazy_register (); + + /* Try to limit ourselves to only fetching the limited number of + elements. However, if this limited number of elements still + puts us over max_value_size, then we still refuse it and + return failure here, which will ultimately throw an error. */ + bool set_limited_array_length (); + +public: /* Temporary */ + + /* Allocate the contents of this value if it has not been allocated + yet. If CHECK_SIZE is true, then apply the usual max-value-size + checks. */ + void allocate_contents (bool check_size); }; =20 /* Returns value_type or value_enclosing_type depending on