From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 790E03858D35; Mon, 13 Feb 2023 22:29:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 790E03858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676327386; bh=ahNGN8FB5mok+kLscz2caylx6NwPkmMjkFqZ8uIl/i0=; h=From:To:Subject:Date:From; b=nNEzERvQ2MFWnAwSg6+msThD12qjY4a6d1QFC4lJ216uJcx440q5puDIySGdBdT9V NQOpXk7AMVZp1Sv+ol4SndantSSFtxXkPZ7HBHZtNOWqMunqgK8qowSTzj9eGebqVn FX4np/35t9i3OPpbHeAaz9QSwMBlQhM9qebyCXGc= 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 value_contents_eq into a method X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 82ca8f72011ed3d4661fc05e908cfa8f01c8f6f2 X-Git-Newrev: 02744ba9a2cfb7d1d2b8ebb6e80178a68bf56e06 Message-Id: <20230213222946.790E03858D35@sourceware.org> Date: Mon, 13 Feb 2023 22:29:46 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D02744ba9a2cf= b7d1d2b8ebb6e80178a68bf56e06 commit 02744ba9a2cfb7d1d2b8ebb6e80178a68bf56e06 Author: Tom Tromey Date: Tue Jan 31 14:11:48 2023 -0700 Turn value_contents_eq into a method =20 This changes value_contents_eq to be a method of value. It also converts the static function value_contents_bits_eq into a private method. =20 Approved-By: Simon Marchi Diff: --- gdb/ada-valprint.c | 6 +-- gdb/f-valprint.c | 4 +- gdb/mi/mi-main.c | 4 +- gdb/stack.c | 8 ++-- gdb/valprint.c | 2 +- gdb/value.c | 37 ++++++++------- gdb/value.h | 134 ++++++++++++++++++++++++++++---------------------= ---- 7 files changed, 102 insertions(+), 93 deletions(-) diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 05d30649887..491346b450d 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -199,9 +199,9 @@ val_print_packed_array_elements (struct type *type, con= st gdb_byte *valaddr, if (check_typedef (v0->type ())->length () !=3D check_typedef (v1->type ())->length ()) break; - if (!value_contents_eq (v0, v0->embedded_offset (), - v1, v1->embedded_offset (), - check_typedef (v0->type ())->length ())) + if (!v0->contents_eq (v0->embedded_offset (), + v1, v1->embedded_offset (), + check_typedef (v0->type ())->length ())) break; } =20 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index 1867962e7b0..4fbda5dc78e 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -271,7 +271,7 @@ public: elt_off_prev); repeated =3D ((value_entirely_available (e_prev) && value_entirely_available (e_val) - && value_contents_eq (e_prev, e_val)) + && e_prev->contents_eq (e_val)) || (value_entirely_unavailable (e_prev) && value_entirely_unavailable (e_val))); } @@ -378,7 +378,7 @@ private: =20 return ((value_entirely_available (e_val1) && value_entirely_available (e_val2) - && value_contents_eq (e_val1, e_val2)) + && e_val1->contents_eq (e_val2)) || (value_entirely_unavailable (e_val1) && value_entirely_unavailable (e_val2))); } diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 609872455ff..f2e680cb0d3 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -983,8 +983,8 @@ register_changed_p (int regnum, readonly_detached_regca= che *prev_regs, gdb_assert (prev_value !=3D NULL); gdb_assert (this_value !=3D NULL); =20 - auto ret =3D !value_contents_eq (prev_value, 0, this_value, 0, - register_size (gdbarch, regnum)); + auto ret =3D !prev_value->contents_eq (0, this_value, 0, + register_size (gdbarch, regnum)); =20 release_value (prev_value); release_value (this_value); diff --git a/gdb/stack.c b/gdb/stack.c index 983c99e5860..cd5e391debe 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -585,7 +585,7 @@ read_frame_arg (const frame_print_options &fp_opts, if (entryval->lazy ()) entryval->fetch_lazy (); =20 - if (value_contents_eq (val, 0, entryval, 0, type->length ())) + if (val->contents_eq (0, entryval, 0, type->length ())) { /* Initialize it just to avoid a GCC false warning. */ struct value *val_deref =3D NULL, *entryval_deref; @@ -610,9 +610,9 @@ read_frame_arg (const frame_print_options &fp_opts, /* If the reference addresses match but dereferenced content does not match print them. */ if (val !=3D val_deref - && value_contents_eq (val_deref, 0, - entryval_deref, 0, - type_deref->length ())) + && val_deref->contents_eq (0, + entryval_deref, 0, + type_deref->length ())) val_equal =3D 1; } catch (const gdb_exception_error &except) diff --git a/gdb/valprint.c b/gdb/valprint.c index 1beec19dcb6..2fa18b8f8e8 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -2029,7 +2029,7 @@ value_print_array_elements (struct value *val, struct= ui_file *stream, bit_stride); bool repeated =3D ((available && value_entirely_available (rep_elt) - && value_contents_eq (element, rep_elt)) + && element->contents_eq (rep_elt)) || (unavailable && value_entirely_unavailable (rep_elt))); if (!repeated) diff --git a/gdb/value.c b/gdb/value.c index 1268e7c46f2..6198fb84d22 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -648,29 +648,28 @@ find_first_range_overlap_and_match (struct ranges_and= _idx *rp1, with LENGTH bits of VAL2's contents starting at OFFSET2 bits. Return true if the available bits match. */ =20 -static bool -value_contents_bits_eq (const struct value *val1, int offset1, - const struct value *val2, int offset2, - int length) +bool +value::contents_bits_eq (int offset1, const struct value *val2, int offset= 2, + int length) const { /* Each array element corresponds to a ranges source (unavailable, optimized out). '1' is for VAL1, '2' for VAL2. */ struct ranges_and_idx rp1[2], rp2[2]; =20 /* See function description in value.h. */ - gdb_assert (!val1->m_lazy && !val2->m_lazy); + gdb_assert (!m_lazy && !val2->m_lazy); =20 /* We shouldn't be trying to compare past the end of the values. */ gdb_assert (offset1 + length - <=3D val1->m_enclosing_type->length () * TARGET_CHAR_BIT); + <=3D m_enclosing_type->length () * TARGET_CHAR_BIT); gdb_assert (offset2 + length <=3D val2->m_enclosing_type->length () * TARGET_CHAR_BIT); =20 memset (&rp1, 0, sizeof (rp1)); memset (&rp2, 0, sizeof (rp2)); - rp1[0].ranges =3D &val1->m_unavailable; + rp1[0].ranges =3D &m_unavailable; rp2[0].ranges =3D &val2->m_unavailable; - rp1[1].ranges =3D &val1->m_optimized_out; + rp1[1].ranges =3D &m_optimized_out; rp2[1].ranges =3D &val2->m_optimized_out; =20 while (length > 0) @@ -698,7 +697,7 @@ value_contents_bits_eq (const struct value *val1, int o= ffset1, } =20 /* Compare the available/valid contents. */ - if (memcmp_with_bit_offsets (val1->m_contents.get (), offset1, + if (memcmp_with_bit_offsets (m_contents.get (), offset1, val2->m_contents.get (), offset2, l) !=3D 0) return false; =20 @@ -710,26 +709,28 @@ value_contents_bits_eq (const struct value *val1, int= offset1, return true; } =20 +/* See value.h. */ + bool -value_contents_eq (const struct value *val1, LONGEST offset1, - const struct value *val2, LONGEST offset2, - LONGEST length) +value::contents_eq (LONGEST offset1, + const struct value *val2, LONGEST offset2, + LONGEST length) const { - return value_contents_bits_eq (val1, offset1 * TARGET_CHAR_BIT, - val2, offset2 * TARGET_CHAR_BIT, - length * TARGET_CHAR_BIT); + return contents_bits_eq (offset1 * TARGET_CHAR_BIT, + val2, offset2 * TARGET_CHAR_BIT, + length * TARGET_CHAR_BIT); } =20 /* See value.h. */ =20 bool -value_contents_eq (const struct value *val1, const struct value *val2) +value::contents_eq (const struct value *val2) const { - ULONGEST len1 =3D check_typedef (val1->enclosing_type ())->length (); + ULONGEST len1 =3D check_typedef (enclosing_type ())->length (); ULONGEST len2 =3D check_typedef (val2->enclosing_type ())->length (); if (len1 !=3D len2) return false; - return value_contents_eq (val1, 0, val2, 0, len1); + return contents_eq (0, val2, 0, len1); } =20 /* The value-history records all the values printed by print commands diff --git a/gdb/value.h b/gdb/value.h index 0b49dea78e9..b025d678c6d 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -395,6 +395,66 @@ public: it. */ void fetch_lazy (); =20 + /* Compare LENGTH bytes of this value's contents starting at OFFSET1 + with LENGTH bytes of VAL2's contents starting at OFFSET2. + + Note that "contents" refers to the whole value's contents + (value_contents_all), without any embedded offset adjustment. For + example, to compare a complete object value with itself, including + its enclosing type chunk, you'd do: + + int len =3D check_typedef (val->enclosing_type ())->length (); + val->contents_eq (0, val, 0, len); + + Returns true iff the set of available/valid contents match. + + Optimized-out contents are equal to optimized-out contents, and are + not equal to non-optimized-out contents. + + Unavailable contents are equal to unavailable contents, and are not + equal to non-unavailable contents. + + For example, if 'x's represent an unavailable byte, and 'V' and 'Z' + represent different available/valid bytes, in a value with length + 16: + + offset: 0 4 8 12 16 + contents: xxxxVVVVxxxxVVZZ + + then: + + val->contents_eq(0, val, 8, 6) =3D> true + val->contents_eq(0, val, 4, 4) =3D> false + val->contents_eq(0, val, 8, 8) =3D> false + val->contents_eq(4, val, 12, 2) =3D> true + val->contents_eq(4, val, 12, 4) =3D> true + val->contents_eq(3, val, 4, 4) =3D> true + + If 'x's represent an unavailable byte, 'o' represents an optimized + out byte, in a value with length 8: + + offset: 0 4 8 + contents: xxxxoooo + + then: + + val->contents_eq(0, val, 2, 2) =3D> true + val->contents_eq(4, val, 6, 2) =3D> true + val->contents_eq(0, val, 4, 4) =3D> true + + We only know whether a value chunk is unavailable or optimized out + if we've tried to read it. As this routine is used by printing + routines, which may be printing values in the value history, long + after the inferior is gone, it works with const values. Therefore, + this routine must not be called with lazy values. */ + + bool contents_eq (LONGEST offset1, const struct value *val2, LONGEST off= set2, + LONGEST length) const; + + /* An overload of contents_eq that compares the entirety of both + values. */ + bool contents_eq (const struct value *val2) const; + =20 /* Type of value; either not an lval, or one of the various different possible kinds of lval. */ @@ -599,6 +659,17 @@ public: /* Temporary */ yet. If CHECK_SIZE is true, then apply the usual max-value-size checks. */ void allocate_contents (bool check_size); + +private: + + /* Helper function for value_contents_eq. The only difference is that + this function is bit rather than byte based. + + Compare LENGTH bits of this value's contents starting at OFFSET1 + bits with LENGTH bits of VAL2's contents starting at OFFSET2 + bits. Return true if the available bits match. */ + bool contents_bits_eq (int offset1, const struct value *val2, int offset= 2, + int length) const; }; =20 /* Returns value_type or value_enclosing_type depending on @@ -833,69 +904,6 @@ extern void mark_value_bytes_unavailable (struct value= *value, extern void mark_value_bits_unavailable (struct value *value, LONGEST offset, ULONGEST length); =20 -/* Compare LENGTH bytes of VAL1's contents starting at OFFSET1 with - LENGTH bytes of VAL2's contents starting at OFFSET2. - - Note that "contents" refers to the whole value's contents - (value_contents_all), without any embedded offset adjustment. For - example, to compare a complete object value with itself, including - its enclosing type chunk, you'd do: - - int len =3D check_typedef (val->enclosing_type ())->length (); - value_contents_eq (val, 0, val, 0, len); - - Returns true iff the set of available/valid contents match. - - Optimized-out contents are equal to optimized-out contents, and are - not equal to non-optimized-out contents. - - Unavailable contents are equal to unavailable contents, and are not - equal to non-unavailable contents. - - For example, if 'x's represent an unavailable byte, and 'V' and 'Z' - represent different available/valid bytes, in a value with length - 16: - - offset: 0 4 8 12 16 - contents: xxxxVVVVxxxxVVZZ - - then: - - value_contents_eq(val, 0, val, 8, 6) =3D> true - value_contents_eq(val, 0, val, 4, 4) =3D> false - value_contents_eq(val, 0, val, 8, 8) =3D> false - value_contents_eq(val, 4, val, 12, 2) =3D> true - value_contents_eq(val, 4, val, 12, 4) =3D> true - value_contents_eq(val, 3, val, 4, 4) =3D> true - - If 'x's represent an unavailable byte, 'o' represents an optimized - out byte, in a value with length 8: - - offset: 0 4 8 - contents: xxxxoooo - - then: - - value_contents_eq(val, 0, val, 2, 2) =3D> true - value_contents_eq(val, 4, val, 6, 2) =3D> true - value_contents_eq(val, 0, val, 4, 4) =3D> true - - We only know whether a value chunk is unavailable or optimized out - if we've tried to read it. As this routine is used by printing - routines, which may be printing values in the value history, long - after the inferior is gone, it works with const values. Therefore, - this routine must not be called with lazy values. */ - -extern bool value_contents_eq (const struct value *val1, LONGEST offset1, - const struct value *val2, LONGEST offset2, - LONGEST length); - -/* An overload of value_contents_eq that compares the entirety of both - values. */ - -extern bool value_contents_eq (const struct value *val1, - const struct value *val2); - /* Read LENGTH addressable memory units starting at MEMADDR into BUFFER, which is (or will be copied to) VAL's contents buffer offset by BIT_OFFSET bits. Marks value contents ranges as unavailable if