public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature
@ 2022-04-23  9:12 Enze Li
  2022-04-23  9:14 ` [PATCH v8 1/3] " Enze Li
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Enze Li @ 2022-04-23  9:12 UTC (permalink / raw)
  To: pedro, tom; +Cc: gdb-patches

New in v8:

- Address Tom's comments, modified the form of the digit separator
  implementation and added exporting nibbles to the python layer.

- Address Pedro's comments, modified the way testcase are implemented.

New in v7:

- Address Tom's comments, use specific digit separator when debuging C++
  and Rust programs.

New in v6:

- Address Eli's comments, use a new complementary method with number 0.

New in v5:
- Address Bruno's comments, fix regressions caused by conflicts.

This patch sets implements the display of binary values in groups to
enhance the readability of binary.

Enze Li (3):
  gdb: Add new 'print nibbles' feature
  gdb/doc: Documentation for the new print command
  gdb/python: Export nibbles to python layer

 gdb/NEWS                                      |  5 ++
 gdb/c-lang.c                                  |  4 +
 gdb/doc/gdb.texinfo                           | 35 ++++++++-
 gdb/doc/python.texi                           |  5 ++
 gdb/language.h                                |  7 ++
 gdb/printcmd.c                                |  2 +-
 gdb/python/py-value.c                         |  7 +-
 gdb/rust-lang.h                               |  5 ++
 gdb/testsuite/gdb.base/options.exp            |  1 +
 gdb/testsuite/gdb.base/printcmds.exp          | 43 +++++++++++
 gdb/testsuite/gdb.python/py-format-string.exp | 73 +++++++++++++++++++
 gdb/valprint.c                                | 48 +++++++++++-
 gdb/valprint.h                                |  6 +-
 13 files changed, 233 insertions(+), 8 deletions(-)

-- 
2.35.3


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v8 1/3] gdb: Add new 'print nibbles' feature
  2022-04-23  9:12 [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature Enze Li
@ 2022-04-23  9:14 ` Enze Li
  2022-04-23  9:15 ` [PATCH v8 2/3] gdb/doc: Documentation for the new print command Enze Li
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Enze Li @ 2022-04-23  9:14 UTC (permalink / raw)
  To: pedro, tom; +Cc: gdb-patches

Make an introduction of a new print setting that can be set by 'set
print nibbles [on|off]'.  The default value if OFF, which can be changed
by user manually.  Of course, 'show print nibbles' is also included in
the patch.

The new feature displays binary values by group, with four bits per
group.  The motivation for this work is to enhance the readability of
binary values.

Here's a GDB session before this patch is applied.
  (gdb) print var_a
  $1 = 1230
  (gdb) print/t var_a
  $2 = 10011001110

With this patch applied, we can use the new print setting to display the
new form of the binary values.
  (gdb) print var_a
  $1 = 1230
  (gdb) print/t var_a
  $2 = 10011001110
  (gdb) set print nibbles on
  (gdb) print/t var_a
  $3 = 0100 1100 1110

Tested on x86_64 openSUSE Tumbleweed(VERSION_ID="20220413").
---
 gdb/c-lang.c                         |  4 +++
 gdb/language.h                       |  7 ++++
 gdb/printcmd.c                       |  2 +-
 gdb/rust-lang.h                      |  5 +++
 gdb/testsuite/gdb.base/options.exp   |  1 +
 gdb/testsuite/gdb.base/printcmds.exp | 43 +++++++++++++++++++++++++
 gdb/valprint.c                       | 48 +++++++++++++++++++++++++++-
 gdb/valprint.h                       |  6 +++-
 8 files changed, 113 insertions(+), 3 deletions(-)

diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index be9ee073f58..a1b26524c38 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -857,6 +857,10 @@ class cplus_language : public language_defn
   const char *natural_name () const override
   { return "C++"; }
 
+  /* See language.h  */
+  const char *get_digit_separator () const override
+  { return "\'"; }
+
   /* See language.h.  */
 
   const std::vector<const char *> &filename_extensions () const override
diff --git a/gdb/language.h b/gdb/language.h
index f2885000259..c6812c52634 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -282,6 +282,13 @@ struct language_defn
 
   virtual const char *natural_name () const = 0;
 
+  /* Digit separator of the language.  */
+
+  virtual const char *get_digit_separator () const
+  {
+    return " ";
+  }
+
   /* Return a vector of file extensions for this language.  The extension
      must include the ".", like ".c".  If this language doesn't need to
      provide any filename extensions, this may be an empty vector (which is
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 102058a8579..ba1bf0ed2f5 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -485,7 +485,7 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type,
       break;
 
     case 't':
-      print_binary_chars (stream, valaddr, len, byte_order, size > 0);
+      print_binary_chars (stream, valaddr, len, byte_order, size > 0, options);
       break;
     case 'x':
       print_hex_chars (stream, valaddr, len, byte_order, size > 0);
diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h
index 514494a2c82..6da57f8633f 100644
--- a/gdb/rust-lang.h
+++ b/gdb/rust-lang.h
@@ -71,6 +71,11 @@ class rust_language : public language_defn
 
   /* See language.h.  */
 
+  const char *get_digit_separator () const override
+  { return "_"; }
+
+  /* See language.h.  */
+
   const std::vector<const char *> &filename_extensions () const override
   {
     static const std::vector<const char *> extensions = { ".rs" };
diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp
index 41466614282..d10e7f8d66f 100644
--- a/gdb/testsuite/gdb.base/options.exp
+++ b/gdb/testsuite/gdb.base/options.exp
@@ -168,6 +168,7 @@ proc_with_prefix test-print {{prefix ""}} {
 	"-elements"
 	"-max-depth"
 	"-memory-tag-violations"
+	"-nibbles"
 	"-null-stop"
 	"-object"
 	"-pretty"
diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
index 3260c8a3c09..04d390d3658 100644
--- a/gdb/testsuite/gdb.base/printcmds.exp
+++ b/gdb/testsuite/gdb.base/printcmds.exp
@@ -709,6 +709,48 @@ proc test_print_char_arrays {} {
     gdb_test_no_output "set print address off" "address off char arrays"
 }
 
+proc test_print_nibbles {} {
+    gdb_test_no_output "set print nibbles on"
+    foreach lang_line {
+	{"ada" "0" "0" "0011 0000" "1111 1111" "1111" "0001" "1111 0000 1111"}
+	{"asm" "0" "0" "0011 0000" "1111 1111" "1111" "0001" "1111 0000 1111"}
+	{"c" "0" "0" "0011 0000" "1111 1111" "1111" "0001" "1111 0000 1111"}
+	{"c++" "0" "0" "0011'0000" "1111'1111" "1111" "0001" "1111'0000'1111"}
+	{"d" "0" "0" "0011 0000" "1111 1111" "1111" "0001" "1111 0000 1111"}
+	{"fortran" "0" "0" "0011 0000" "1111 1111" "1111" "0001" "1111 0000 1111"}
+	{"go" "0" "0" "0011 0000" "1111 1111" "1111" "0001" "1111 0000 1111"}
+	{"minimal" "0" "0" "0011 0000" "1111 1111" "1111" "0001" "1111 0000 1111"}
+	{"objective-c" "0" "0" "0011 0000" "1111 1111" "1111" "0001" "1111 0000 1111"}
+	{"opencl" "0" "0" "0011 0000" "1111 1111" "1111" "0001" "1111 0000 1111"}
+	{"pascal" "0" "0" "0011 0000" "1111 1111" "1111" "0001" "1111 0000 1111"}
+	{"rust" "0" "0" "0011_0000" "1111_1111" "1111" "0001" "1111_0000_1111"}
+    } {
+	set lang [lindex $lang_line 0]
+	set val1 [lindex $lang_line 1]
+	set val2 [lindex $lang_line 2]
+	set val3 [lindex $lang_line 3]
+	set val4 [lindex $lang_line 4]
+	set val5 [lindex $lang_line 5]
+	set val6 [lindex $lang_line 6]
+	set val7 [lindex $lang_line 7]
+	set val8 [lindex $lang_line 8]
+
+	with_test_prefix "$lang" {
+	    gdb_test_no_output "set language $lang"
+	    gdb_test "p/t 0" $val1
+	    gdb_test "p/t 0x0" $val2
+	    gdb_test "p/t 0x30" $val3
+	    gdb_test "p/t 0xff" $val4
+	    gdb_test "p/t 0x0f" $val5
+	    gdb_test "p/t 0x01" $val6
+	    gdb_test "p/t 0xf0f" $val7
+	    gdb_test "p/t 0x70f" $val8
+	    gdb_test_no_output "set language auto"
+	}
+    }
+    gdb_test_no_output "set print nibbles off"
+}
+
 proc test_print_string_constants {} {
     global gdb_prompt
 
@@ -1086,6 +1128,7 @@ test_print_int_arrays
 test_print_typedef_arrays
 test_artificial_arrays
 test_print_char_arrays
+test_print_nibbles
 # We used to do the runto main here.
 test_print_string_constants
 test_print_array_constants
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 47114676934..e63ec30f4c7 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -105,6 +105,7 @@ struct value_print_options user_print_options =
   0,				/* vtblprint */
   1,				/* unionprint */
   1,				/* addressprint */
+  false,			/* nibblesprint */
   0,				/* objectprint */
   PRINT_MAX_DEFAULT,		/* print_max */
   10,				/* repeat_count_threshold */
@@ -257,6 +258,17 @@ show_unionprint (struct ui_file *file, int from_tty,
 	      value);
 }
 
+/* Controls the format of printing binary values.  */
+
+static void
+show_nibbles (struct ui_file *file, int from_tty,
+		       struct cmd_list_element *c, const char *value)
+{
+  gdb_printf (file,
+	      _("Printing binary values in groups is %s.\n"),
+	      value);
+}
+
 /* If nonzero, causes machine addresses to be printed in certain contexts.  */
 
 static void
@@ -1357,18 +1369,23 @@ print_floating (const gdb_byte *valaddr, struct type *type,
 
 void
 print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
-		    unsigned len, enum bfd_endian byte_order, bool zero_pad)
+		    unsigned len, enum bfd_endian byte_order, bool zero_pad,
+		    const struct value_print_options *options)
 {
   const gdb_byte *p;
   unsigned int i;
   int b;
   bool seen_a_one = false;
+  const char *digit_separator = nullptr;
 
   /* Declared "int" so it will be signed.
      This ensures that right shift will shift in zeros.  */
 
   const int mask = 0x080;
 
+  if (options->nibblesprint)
+    digit_separator = current_language->get_digit_separator();
+
   if (byte_order == BFD_ENDIAN_BIG)
     {
       for (p = valaddr;
@@ -1380,6 +1397,9 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
 
 	  for (i = 0; i < (HOST_CHAR_BIT * sizeof (*p)); i++)
 	    {
+	      if (options->nibblesprint && seen_a_one && i % 4 == 0)
+		gdb_putc (*digit_separator, stream);
+
 	      if (*p & (mask >> i))
 		b = '1';
 	      else
@@ -1387,6 +1407,13 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
 
 	      if (zero_pad || seen_a_one || b == '1')
 		gdb_putc (b, stream);
+	      else if (options->nibblesprint)
+		{
+		  if ((0xf0 & (mask >> i) && (*p & 0xf0))
+		      || (0x0f & (mask >> i) && (*p & 0x0f)))
+		    gdb_putc (b, stream);
+		}
+
 	      if (b == '1')
 		seen_a_one = true;
 	    }
@@ -1400,6 +1427,9 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
 	{
 	  for (i = 0; i < (HOST_CHAR_BIT * sizeof (*p)); i++)
 	    {
+	      if (options->nibblesprint && seen_a_one && i % 4 == 0)
+		gdb_putc (*digit_separator, stream);
+
 	      if (*p & (mask >> i))
 		b = '1';
 	      else
@@ -1407,6 +1437,13 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
 
 	      if (zero_pad || seen_a_one || b == '1')
 		gdb_putc (b, stream);
+	      else if (options->nibblesprint)
+		{
+		  if ((0xf0 & (mask >> i) && (*p & 0xf0))
+		      || (0x0f & (mask >> i) && (*p & 0x0f)))
+		    gdb_putc (b, stream);
+		}
+
 	      if (b == '1')
 		seen_a_one = true;
 	    }
@@ -2837,6 +2874,15 @@ static const gdb::option::option_def value_print_option_defs[] = {
     NULL, /* help_doc */
   },
 
+  boolean_option_def {
+    "nibbles",
+    [] (value_print_options *opt) { return &opt->nibblesprint; },
+    show_nibbles, /* show_cmd_cb */
+    N_("Set whether to print binary values in groups of four bits."),
+    N_("Show whether to print binary values in groups of four bits."),
+    NULL, /* help_doc */
+  },
+
   uinteger_option_def {
     "elements",
     [] (value_print_options *opt) { return &opt->print_max; },
diff --git a/gdb/valprint.h b/gdb/valprint.h
index ff536fbe4f0..d6ad45d7580 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -44,6 +44,9 @@ struct value_print_options
   /* Controls printing of addresses.  */
   bool addressprint;
 
+  /* Controls printing of nibbles.  */
+  bool nibblesprint;
+
   /* Controls looking up an object's derived type using what we find
      in its vtables.  */
   bool objectprint;
@@ -149,7 +152,8 @@ extern void value_print_scalar_formatted
    int size, struct ui_file *stream);
 
 extern void print_binary_chars (struct ui_file *, const gdb_byte *,
-				unsigned int, enum bfd_endian, bool);
+				unsigned int, enum bfd_endian, bool,
+				const struct value_print_options *options);
 
 extern void print_octal_chars (struct ui_file *, const gdb_byte *,
 			       unsigned int, enum bfd_endian);
-- 
2.35.3


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v8 2/3] gdb/doc: Documentation for the new print command
  2022-04-23  9:12 [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature Enze Li
  2022-04-23  9:14 ` [PATCH v8 1/3] " Enze Li
@ 2022-04-23  9:15 ` Enze Li
  2022-04-23  9:20   ` Eli Zaretskii
  2022-04-23  9:16 ` [PATCH v8 3/3] gdb/python: Export nibbles to python layer Enze Li
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Enze Li @ 2022-04-23  9:15 UTC (permalink / raw)
  To: pedro, tom; +Cc: gdb-patches

Document the new command "print nibbles" and add a NEWS entry.
---
 gdb/NEWS            |  5 +++++
 gdb/doc/gdb.texinfo | 35 +++++++++++++++++++++++++++++++----
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 760cb2b7abc..f8502d5d238 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -23,6 +23,11 @@ maintenance show ignore-prologue-end-flag
   used to force GDB to use prologue analyzers if the line-table is constructed
   from erroneous debug information.
 
+set print nibbles [on|off]
+show print nibbles
+  This controls whether the 'print/t' command will display binary values
+  in groups of four bits, known as "nibbles".  The default is 'off'.
+
 * Changed commands
 
 maintenance info line-table
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c1e9b09e833..7be872570a1 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -2142,10 +2142,10 @@ on @code{-} after the command name.  For example:
 
 @smallexample
 (@value{GDBP}) print -@key{TAB}@key{TAB}
--address         -max-depth               -pretty          -symbol
--array           -memory-tag-violations   -raw-values      -union
--array-indexes   -null-stop               -repeats         -vtbl
--elements        -object                  -static-members
+-address         -max-depth               -object          -static-members
+-array           -memory-tag-violations   -pretty          -symbol
+-array-indexes   -nibbles                 -raw-values      -union
+-elements        -null-stop               -repeats         -vtbl
 @end smallexample
 
 Completion will in some cases guide you with a suggestion of what kind
@@ -10021,6 +10021,10 @@ Set limit on string chars or array elements to print.  The value
 Set the threshold after which nested structures are replaced with
 ellipsis.  Related setting: @ref{set print max-depth}.
 
+@item -nibbles [@code{on}|@code{off}]
+Set whether to print binary values in groups of four bits, known
+as ``nibbles''.  @xref{set print nibbles}.
+
 @item -memory-tag-violations [@code{on}|@code{off}]
 Set printing of additional information about memory tag violations.
 @xref{set print memory-tag-violations}.
@@ -11385,6 +11389,29 @@ Stop printing element indexes when displaying arrays.
 Show whether the index of each element is printed when displaying
 arrays.
 
+@anchor{set print nibbles}
+@item set print nibbles
+@itemx set print nibbles on
+@cindex print binary values in groups of four bits
+Print binary values in groups of four bits, known as @dfn{nibbles},
+when using the print command of @value{GDBN} with the option @samp{/t}.
+For example, this is what it looks like with @code{set print nibbles on}:
+
+@smallexample
+@group
+(@value{GDBP}) print val_flags
+$1 = 1230
+(@value{GDBP}) print/t val_flags
+$2 = 0100 1100 1110
+@end group
+@end smallexample
+
+@item set print nibbles off
+Don't printing binary values in groups.  This is the default.
+
+@item show print nibbles
+Show whether to print binary values in groups of four bits.
+
 @anchor{set print elements}
 @item set print elements @var{number-of-elements}
 @itemx set print elements unlimited
-- 
2.35.3


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v8 3/3] gdb/python: Export nibbles to python layer
  2022-04-23  9:12 [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature Enze Li
  2022-04-23  9:14 ` [PATCH v8 1/3] " Enze Li
  2022-04-23  9:15 ` [PATCH v8 2/3] gdb/doc: Documentation for the new print command Enze Li
@ 2022-04-23  9:16 ` Enze Li
  2022-04-23  9:22   ` Eli Zaretskii
  2022-06-06 13:41 ` [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature Tom Tromey
  2022-06-18  3:29 ` Enze Li
  4 siblings, 1 reply; 11+ messages in thread
From: Enze Li @ 2022-04-23  9:16 UTC (permalink / raw)
  To: pedro, tom; +Cc: gdb-patches

This patch makes it possible to allow Value.format_string() to return
nibbles output.

When we set the parameter of nibbles to True, we can achieve the
displaying binary values in groups of every four bits.

Here's an example:
  (gdb) py print (gdb.Value (1230).format_string (format='t', nibbles=True))
  0100 1100 1110
  (gdb)

Note that the parameter nibbles is only useful if format='t' is also used.

This patch also includes update to the relevant testcase and
documentation.

Tested on x86_64 openSUSE Tumbleweed(VERSION_ID="20220413").
---
 gdb/doc/python.texi                           |  5 ++
 gdb/python/py-value.c                         |  7 +-
 gdb/testsuite/gdb.python/py-format-string.exp | 73 +++++++++++++++++++
 3 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index cb5283e03c0..5fd757d4891 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -1094,6 +1094,11 @@ union} in @ref{Print Settings}).
 address, @code{False} if it shouldn't (see @code{set print address} in
 @ref{Print Settings}).
 
+@item nibbles
+@code{True} if binary values should be displayed in groups of four bits,
+known as nibbles. @code{False} if it shouldn't (see @code{set print
+nibbles} in @ref{Print Settings}).
+
 @item deref_refs
 @code{True} if C@t{++} references should be resolved to the value they
 refer to, @code{False} (the default) if they shouldn't.  Note that, unlike
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index e779f491b5b..4a51ff0f94d 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -640,6 +640,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw)
       "unions",			/* See set print union on|off.  */
       "address",		/* See set print address on|off.  */
       "styling",		/* Should we apply styling.  */
+      "nibbles",		/* See set print nibbles on|off.  */
       /* C++ options.  */
       "deref_refs",		/* No corresponding setting.  */
       "actual_objects",		/* See set print object on|off.  */
@@ -685,13 +686,14 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw)
   PyObject *unions_obj = NULL;
   PyObject *address_obj = NULL;
   PyObject *styling_obj = Py_False;
+  PyObject *nibbles_obj = NULL;
   PyObject *deref_refs_obj = NULL;
   PyObject *actual_objects_obj = NULL;
   PyObject *static_members_obj = NULL;
   char *format = NULL;
   if (!gdb_PyArg_ParseTupleAndKeywords (args,
 					kw,
-					"|O!O!O!O!O!O!O!O!O!O!O!IIIs",
+					"|O!O!O!O!O!O!O!O!O!O!O!O!IIIs",
 					keywords,
 					&PyBool_Type, &raw_obj,
 					&PyBool_Type, &pretty_arrays_obj,
@@ -701,6 +703,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw)
 					&PyBool_Type, &unions_obj,
 					&PyBool_Type, &address_obj,
 					&PyBool_Type, &styling_obj,
+					&PyBool_Type, &nibbles_obj,
 					&PyBool_Type, &deref_refs_obj,
 					&PyBool_Type, &actual_objects_obj,
 					&PyBool_Type, &static_members_obj,
@@ -725,6 +728,8 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw)
     return NULL;
   if (!copy_py_bool_obj (&opts.addressprint, address_obj))
     return NULL;
+  if (!copy_py_bool_obj (&opts.nibblesprint, nibbles_obj))
+    return NULL;
   if (!copy_py_bool_obj (&opts.deref_ref, deref_refs_obj))
     return NULL;
   if (!copy_py_bool_obj (&opts.objectprint, actual_objects_obj))
diff --git a/gdb/testsuite/gdb.python/py-format-string.exp b/gdb/testsuite/gdb.python/py-format-string.exp
index 63b87e73476..7705a245ee2 100644
--- a/gdb/testsuite/gdb.python/py-format-string.exp
+++ b/gdb/testsuite/gdb.python/py-format-string.exp
@@ -536,6 +536,78 @@ proc_with_prefix test_address {} {
   }
 }
 
+# Test the nibbles option for gdb.Value.format_string.
+proc_with_prefix test_nibbles {} {
+  global current_lang
+
+  set opts "format='t', nibbles=True"
+  with_test_prefix $opts {
+    if { $current_lang == "c" } {
+	set binary_pointer_regexp "\[ 0-1\]+"
+	gdb_test "python print (gdb.Value (42).format_string (${opts}))" \
+	  "0010 1010" \
+	  "42 with option ${opts}"
+
+	check_format_string "a_point_t" $opts
+	check_format_string "a_point_t_pointer" $opts \
+	  $binary_pointer_regexp
+	check_format_string "another_point" $opts
+
+	check_format_string "a_struct_with_union" $opts \
+	  "\\{the_union = \\{an_int = 0010 1010 0010 1010 0010 1010 0010 1010, a_char = 0010 1010\\}\\}"
+	check_format_string "an_enum" $opts \
+	  "0001"
+	check_format_string "a_string" $opts \
+	  $binary_pointer_regexp
+	check_format_string "a_binary_string" $opts \
+	  $binary_pointer_regexp
+	check_format_string "a_binary_string_array" $opts \
+	  "\\{0110 1000, 0110 0101, 0110 1100, 0110 1100, 0110 1111, 0, 0111 0111, 0110 1111, 0111 0010, 0110 1100, 0110 0100, 0\\}"
+	check_format_string "a_big_string" $opts \
+	  "\\{0100 0001, 0100 0010, 0100 0011, 0100 0100, 0100 0101, \[, 0-1\]+\.\.\.\\}"
+	check_format_string "an_array" $opts \
+	  "\\{0010, 0011, 0101\\}"
+	check_format_string "an_array_with_repetition" $opts \
+	  "\\{0001, 0011 <repeats 12 times>, 0101, 0101, 0101\\}"
+	check_format_string "a_symbol_pointer" $opts \
+	  $binary_pointer_regexp
+    }
+    if { $current_lang == "c++" } {
+	set binary_pointer_regexp "\['0-1\]+"
+	gdb_test "python print (gdb.Value (42).format_string (${opts}))" \
+	  "0010'1010" \
+	  "42 with option ${opts}"
+
+	check_format_string "a_point_t" $opts
+	check_format_string "a_point_t_pointer" $opts \
+	  $binary_pointer_regexp
+	check_format_string "another_point" $opts
+
+	check_format_string "a_struct_with_union" $opts \
+	  "\\{the_union = \\{an_int = 0010'1010'0010'1010'0010'1010'0010'1010, a_char = 0010'1010\\}\\}"
+	check_format_string "an_enum" $opts \
+	  "0001"
+	check_format_string "a_string" $opts \
+	  $binary_pointer_regexp
+	check_format_string "a_binary_string" $opts \
+	  $binary_pointer_regexp
+	check_format_string "a_binary_string_array" $opts \
+	  "\\{0110'1000, 0110'0101, 0110'1100, 0110'1100, 0110'1111, 0, 0111'0111, 0110'1111, 0111'0010, 0110'1100, 0110'0100, 0\\}"
+	check_format_string "a_big_string" $opts \
+	  "\\{0100'0001, 0100'0010, 0100'0011, 0100'0100, 0100'0101, \[, '0-1\]+\.\.\.\\}"
+	check_format_string "an_array" $opts \
+	  "\\{0010, 0011, 0101\\}"
+	check_format_string "an_array_with_repetition" $opts \
+	  "\\{0001, 0011 <repeats 12 times>, 0101, 0101, 0101\\}"
+	check_format_string "a_symbol_pointer" $opts \
+	  $binary_pointer_regexp
+
+	check_format_string "a_point_t_ref" $opts
+	check_format_string "a_base_ref" $opts
+    }
+  }
+}
+
 # Test the deref_refs option for gdb.Value.format_string.
 proc_with_prefix test_deref_refs {} {
   global current_lang
@@ -1047,6 +1119,7 @@ proc_with_prefix test_all_common {} {
   test_symbols
   test_unions
   test_address
+  test_nibbles
   test_deref_refs
   test_actual_objects
   test_static_members
-- 
2.35.3


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v8 2/3] gdb/doc: Documentation for the new print command
  2022-04-23  9:15 ` [PATCH v8 2/3] gdb/doc: Documentation for the new print command Enze Li
@ 2022-04-23  9:20   ` Eli Zaretskii
  0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2022-04-23  9:20 UTC (permalink / raw)
  To: Enze Li; +Cc: pedro, tom, gdb-patches

> Date: Sat, 23 Apr 2022 17:15:57 +0800
> From: Enze Li via Gdb-patches <gdb-patches@sourceware.org>
> Cc: gdb-patches@sourceware.org
> 
> Document the new command "print nibbles" and add a NEWS entry.
> ---
>  gdb/NEWS            |  5 +++++
>  gdb/doc/gdb.texinfo | 35 +++++++++++++++++++++++++++++++----
>  2 files changed, 36 insertions(+), 4 deletions(-)

This is OK, thanks.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v8 3/3] gdb/python: Export nibbles to python layer
  2022-04-23  9:16 ` [PATCH v8 3/3] gdb/python: Export nibbles to python layer Enze Li
@ 2022-04-23  9:22   ` Eli Zaretskii
  2022-06-07 13:44     ` Enze Li
  2022-06-07 13:44     ` Enze Li
  0 siblings, 2 replies; 11+ messages in thread
From: Eli Zaretskii @ 2022-04-23  9:22 UTC (permalink / raw)
  To: Enze Li; +Cc: pedro, tom, gdb-patches

> Date: Sat, 23 Apr 2022 17:16:55 +0800
> From: Enze Li via Gdb-patches <gdb-patches@sourceware.org>
> Cc: gdb-patches@sourceware.org
> 
> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index cb5283e03c0..5fd757d4891 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -1094,6 +1094,11 @@ union} in @ref{Print Settings}).
>  address, @code{False} if it shouldn't (see @code{set print address} in
>  @ref{Print Settings}).
>  
> +@item nibbles
> +@code{True} if binary values should be displayed in groups of four bits,
> +known as nibbles. @code{False} if it shouldn't (see @code{set print
> +nibbles} in @ref{Print Settings}).

The part in parentheses will produce better output if you use @pxref:

  @code{False} if it shouldn't (@pxref{Print Settings, set print nibbles}).

Also, please leave two spaces between sentences, not one.

OK with these nits fixed.

Thanks.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature
  2022-04-23  9:12 [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature Enze Li
                   ` (2 preceding siblings ...)
  2022-04-23  9:16 ` [PATCH v8 3/3] gdb/python: Export nibbles to python layer Enze Li
@ 2022-06-06 13:41 ` Tom Tromey
  2022-06-07 13:29   ` Enze Li
  2022-06-18  3:29 ` Enze Li
  4 siblings, 1 reply; 11+ messages in thread
From: Tom Tromey @ 2022-06-06 13:41 UTC (permalink / raw)
  To: Enze Li via Gdb-patches; +Cc: pedro, tom, Enze Li

> New in v8:
> - Address Tom's comments, modified the form of the digit separator
>   implementation and added exporting nibbles to the python layer.

Thanks.  I think this is ok.

Tom

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature
  2022-06-06 13:41 ` [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature Tom Tromey
@ 2022-06-07 13:29   ` Enze Li
  0 siblings, 0 replies; 11+ messages in thread
From: Enze Li @ 2022-06-07 13:29 UTC (permalink / raw)
  To: Tom Tromey, Enze Li via Gdb-patches; +Cc: pedro

Hi Tom,

Thanks for your review.  I'm going to push this soon, probably this
weekend.

Best Regards,
Enze

On Mon, 2022-06-06 at 07:41 -0600, Tom Tromey wrote:
> > New in v8:
> > - Address Tom's comments, modified the form of the digit separator
> >   implementation and added exporting nibbles to the python layer.
> 
> Thanks.  I think this is ok.
> 
> Tom


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v8 3/3] gdb/python: Export nibbles to python layer
  2022-04-23  9:22   ` Eli Zaretskii
@ 2022-06-07 13:44     ` Enze Li
  2022-06-07 13:44     ` Enze Li
  1 sibling, 0 replies; 11+ messages in thread
From: Enze Li @ 2022-06-07 13:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: tom, gdb-patches, pedro

On Sat, 2022-04-23 at 12:22 +0300, Eli Zaretskii via Gdb-patches wrote:
> > Date: Sat, 23 Apr 2022 17:16:55 +0800
> > From: Enze Li via Gdb-patches <gdb-patches@sourceware.org>
> > Cc: gdb-patches@sourceware.org
> > 
> > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> > index cb5283e03c0..5fd757d4891 100644
> > --- a/gdb/doc/python.texi
> > +++ b/gdb/doc/python.texi
> > @@ -1094,6 +1094,11 @@ union} in @ref{Print Settings}).
> >  address, @code{False} if it shouldn't (see @code{set print
> > address} in
> >  @ref{Print Settings}).
> >  
> > +@item nibbles
> > +@code{True} if binary values should be displayed in groups of four
> > bits,
> > +known as nibbles. @code{False} if it shouldn't (see @code{set
> > print
> > +nibbles} in @ref{Print Settings}).
> 
> The part in parentheses will produce better output if you use @pxref:
> 
>   @code{False} if it shouldn't (@pxref{Print Settings, set print
> nibbles}).
> 
> Also, please leave two spaces between sentences, not one.
> 
> OK with these nits fixed.
> 
> Thanks.

Hi Eli,

I was looking through my drafts, and I realized I never sent this
email.

Thanks for your review.  I have made the changes locally as you pointed
out.

Best Regards,
Enze


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v8 3/3] gdb/python: Export nibbles to python layer
  2022-04-23  9:22   ` Eli Zaretskii
  2022-06-07 13:44     ` Enze Li
@ 2022-06-07 13:44     ` Enze Li
  1 sibling, 0 replies; 11+ messages in thread
From: Enze Li @ 2022-06-07 13:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: tom, gdb-patches, pedro

On Sat, 2022-04-23 at 12:22 +0300, Eli Zaretskii via Gdb-patches wrote:
> > Date: Sat, 23 Apr 2022 17:16:55 +0800
> > From: Enze Li via Gdb-patches <gdb-patches@sourceware.org>
> > Cc: gdb-patches@sourceware.org
> > 
> > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> > index cb5283e03c0..5fd757d4891 100644
> > --- a/gdb/doc/python.texi
> > +++ b/gdb/doc/python.texi
> > @@ -1094,6 +1094,11 @@ union} in @ref{Print Settings}).
> >  address, @code{False} if it shouldn't (see @code{set print
> > address} in
> >  @ref{Print Settings}).
> >  
> > +@item nibbles
> > +@code{True} if binary values should be displayed in groups of four
> > bits,
> > +known as nibbles. @code{False} if it shouldn't (see @code{set
> > print
> > +nibbles} in @ref{Print Settings}).
> 
> The part in parentheses will produce better output if you use @pxref:
> 
>   @code{False} if it shouldn't (@pxref{Print Settings, set print
> nibbles}).
> 
> Also, please leave two spaces between sentences, not one.
> 
> OK with these nits fixed.
> 
> Thanks.

Hi Eli,

I was looking through my drafts, and I realized I never sent this
email.

Thanks for your review.  I have made the changes locally as you pointed
out.

Best Regards,
Enze


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature
  2022-04-23  9:12 [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature Enze Li
                   ` (3 preceding siblings ...)
  2022-06-06 13:41 ` [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature Tom Tromey
@ 2022-06-18  3:29 ` Enze Li
  4 siblings, 0 replies; 11+ messages in thread
From: Enze Li @ 2022-06-18  3:29 UTC (permalink / raw)
  To: pedro, tom; +Cc: gdb-patches

On Sat, 2022-04-23 at 17:12 +0800, Enze Li via Gdb-patches wrote:
> New in v8:
> 
> - Address Tom's comments, modified the form of the digit separator
>   implementation and added exporting nibbles to the python layer.
> 
> - Address Pedro's comments, modified the way testcase are
> implemented.
> 
> New in v7:
> 
> - Address Tom's comments, use specific digit separator when debuging
> C++
>   and Rust programs.
> 
> New in v6:
> 
> - Address Eli's comments, use a new complementary method with number
> 0.
> 
> New in v5:
> - Address Bruno's comments, fix regressions caused by conflicts.
> 
> This patch sets implements the display of binary values in groups to
> enhance the readability of binary.
> 
> Enze Li (3):
>   gdb: Add new 'print nibbles' feature
>   gdb/doc: Documentation for the new print command
>   gdb/python: Export nibbles to python layer
> 
>  gdb/NEWS                                      |  5 ++
>  gdb/c-lang.c                                  |  4 +
>  gdb/doc/gdb.texinfo                           | 35 ++++++++-
>  gdb/doc/python.texi                           |  5 ++
>  gdb/language.h                                |  7 ++
>  gdb/printcmd.c                                |  2 +-
>  gdb/python/py-value.c                         |  7 +-
>  gdb/rust-lang.h                               |  5 ++
>  gdb/testsuite/gdb.base/options.exp            |  1 +
>  gdb/testsuite/gdb.base/printcmds.exp          | 43 +++++++++++
>  gdb/testsuite/gdb.python/py-format-string.exp | 73
> +++++++++++++++++++
>  gdb/valprint.c                                | 48 +++++++++++-
>  gdb/valprint.h                                |  6 +-
>  13 files changed, 233 insertions(+), 8 deletions(-)
> 

I'm checking these in now.

Enze


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-06-18  3:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-23  9:12 [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature Enze Li
2022-04-23  9:14 ` [PATCH v8 1/3] " Enze Li
2022-04-23  9:15 ` [PATCH v8 2/3] gdb/doc: Documentation for the new print command Enze Li
2022-04-23  9:20   ` Eli Zaretskii
2022-04-23  9:16 ` [PATCH v8 3/3] gdb/python: Export nibbles to python layer Enze Li
2022-04-23  9:22   ` Eli Zaretskii
2022-06-07 13:44     ` Enze Li
2022-06-07 13:44     ` Enze Li
2022-06-06 13:41 ` [PING][PATCH v8 0/3] gdb: Add new 'print nibbles' feature Tom Tromey
2022-06-07 13:29   ` Enze Li
2022-06-18  3:29 ` Enze Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).