aboutsummaryrefslogtreecommitdiff
path: root/gdb/gmp-utils.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-03-27 14:35:17 -0600
committerTom Tromey <tromey@adacore.com>2023-04-17 10:43:06 -0600
commit767c4b92bc4333cb1b49a42b8d012170a40900fe (patch)
tree767c74a10a155e97e09806c2208d43510598c691 /gdb/gmp-utils.c
parentc53c6186c8d69586a71a7f8284a9ed7fa8cb207f (diff)
downloadgdb-767c4b92bc4333cb1b49a42b8d012170a40900fe.zip
gdb-767c4b92bc4333cb1b49a42b8d012170a40900fe.tar.gz
gdb-767c4b92bc4333cb1b49a42b8d012170a40900fe.tar.bz2
Additions to gdb_mpz
In preparation for adding more 128-bit support to gdb, a few additions to gdb_mpz are needed. First, this adds a new 'as_integer_truncate' method. This method works like 'as_integer' but does not require the value to fit in the target type -- it just truncates. Second, gdb_mpz::export_bits is changed to handle the somewhat unusual situation of zero-length types. This can happen for a Rust '()' type; but I think other languages have zero-bit integer types as well. Finally, this adds some operator== overloads.
Diffstat (limited to 'gdb/gmp-utils.c')
-rw-r--r--gdb/gmp-utils.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/gdb/gmp-utils.c b/gdb/gmp-utils.c
index 0afa344..13fa61d 100644
--- a/gdb/gmp-utils.c
+++ b/gdb/gmp-utils.c
@@ -69,19 +69,21 @@ void
gdb_mpz::export_bits (gdb::array_view<gdb_byte> buf, int endian, bool unsigned_p,
bool safe) const
{
- gdb_assert (buf.size () > 0);
-
int sign = mpz_sgn (m_val);
if (sign == 0)
{
/* Our value is zero, so no need to call mpz_export to do the work,
especially since mpz_export's documentation explicitly says
that the function is a noop in this case. Just write zero to
- BUF ourselves. */
- memset (buf.data (), 0, buf.size ());
+ BUF ourselves, if it is non-empty. In some languages, a
+ zero-bit type can exist and this is also fine. */
+ if (buf.size () > 0)
+ memset (buf.data (), 0, buf.size ());
return;
}
+ gdb_assert (buf.size () > 0);
+
if (safe)
{
/* Determine the maximum range of values that our buffer can