[users/palves/format_strings] %pS/%pN -> %p[/%p]

Message ID 8216adbc-9d34-a29a-02e3-42e0a1ef49fb@redhat.com
State New, archived
Headers

Commit Message

Pedro Alves July 1, 2019, 7:27 p.m. UTC
  On 7/1/19 6:20 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
> 
> Pedro> The visual balance of brackets is appealing as well, so I can't say
> Pedro> I have a strong preference either way.  If you've been converting things
> Pedro> already, you'll have a better judgment, so I'll defer to you.
> 
> I haven't really converted much, just what you saw on the branch.
> 
> I suspect using some kind of paired brackets will make it a little
> harder to forget to close the style.  But probably only a little.  Also
> I guess we could add asserts to check that the closing parameter is
> always null.

Let's try this.  I pushed the patch below to the branch.

From 5984c619b7ee91e6414b1a56d0a735240fb5afce Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Mon, 1 Jul 2019 19:07:44 +0100
Subject: [PATCH] %pS/%pN -> %p[/%p]

---
 gdb/common/format.c |  3 ++-
 gdb/ui-out.c        | 12 ++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)
  

Patch

diff --git a/gdb/common/format.c b/gdb/common/format.c
index 177f79afee3..345bdfc4cca 100644
--- a/gdb/common/format.c
+++ b/gdb/common/format.c
@@ -259,7 +259,8 @@  format_pieces::format_pieces (const char **arg, bool gdb_extensions)
 		  case 's':
 		  case 'S':
 		  case 'F':
-		  case 'N':
+		  case '[':
+		  case ']':
 		    f++;
 		    break;
 		  }
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index d50fb3a3e3f..065a9209656 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -617,12 +617,16 @@  ui_out::vmessage (const char *format, va_list args)
 		call_do_message (ss->style (), "%s", ss->str ());
 	      }
 	      break;
-	    case 'S':
+	    case '[':
 	      style = *va_arg (args, const ui_file_style *);
 	      break;
-	    case 'N':
-	      va_arg (args, void *);
-	      style = {};
+	    case ']':
+	      {
+		void *arg = va_arg (args, void *);
+		gdb_assert (arg == nullptr);
+
+		style = {};
+	      }
 	      break;
 	    default:
 	      call_do_message (style, current_substring, va_arg (args, void *));