This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [wide-int 5/5] Add dump () method for gdb debugging


don't you think that it would be easier to understand the number if you printed it largest index first, as in the routines in wide-int-print.cc?

kenny
On 04/25/2014 09:58 AM, Richard Sandiford wrote:
This patch adds a dump () method so that it's easier to read the
contents of the various wide-int types in gdb.  I've deliberately not
done any extension for "small_prec" cases because I think here
we want to see the raw values as much as possible.

Tested on x86_64-linux-gnu.  OK to install?

Thanks,
Richard


Index: gcc/wide-int.cc
===================================================================
--- gcc/wide-int.cc	2014-04-25 14:48:03.263213403 +0100
+++ gcc/wide-int.cc	2014-04-25 14:48:25.186333842 +0100
@@ -2130,3 +2130,9 @@ wi::only_sign_bit_p (const wide_int_ref
  void gt_ggc_mx (widest_int *) { }
  void gt_pch_nx (widest_int *, void (*) (void *, void *), void *) { }
  void gt_pch_nx (widest_int *) { }
+
+template void wide_int::dump () const;
+template void generic_wide_int <wide_int_ref_storage <false> >::dump () const;
+template void generic_wide_int <wide_int_ref_storage <true> >::dump () const;
+template void offset_int::dump () const;
+template void widest_int::dump () const;
Index: gcc/wide-int.h
===================================================================
--- gcc/wide-int.h	2014-04-25 14:34:54.823652619 +0100
+++ gcc/wide-int.h	2014-04-25 14:48:06.218229309 +0100
@@ -709,6 +709,9 @@ #define INCDEC_OPERATOR(OP, DELTA) \
  #undef ASSIGNMENT_OPERATOR
  #undef INCDEC_OPERATOR
+ /* Debugging functions. */
+  void dump () const;
+
    static const bool is_sign_extended
      = wi::int_traits <generic_wide_int <storage> >::is_sign_extended;
  };
@@ -859,6 +862,23 @@ generic_wide_int <storage>::operator = (
    return *this;
  }
+/* Dump the contents of the integer to stderr, for debugging. */
+template <typename storage>
+void
+generic_wide_int <storage>::dump () const
+{
+  unsigned int len = this->get_len ();
+  const HOST_WIDE_INT *val = this->get_val ();
+  unsigned int precision = this->get_precision ();
+  fprintf (stderr, "[");
+  if (len * HOST_BITS_PER_WIDE_INT < precision)
+    fprintf (stderr, "...,");
+  for (unsigned int i = 0; i < len - 1; ++i)
+    fprintf (stderr, HOST_WIDE_INT_PRINT_HEX ",", val[len - 1 - i]);
+  fprintf (stderr, HOST_WIDE_INT_PRINT_HEX "], precision = %d\n",
+	   val[0], precision);
+}
+
  namespace wi
  {
    template <>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]