public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Convert Go printing to value-based API
Date: Sat, 14 Mar 2020 00:06:17 +0000 (GMT)	[thread overview]
Message-ID: <20200314000617.227783AAA093@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=23b0f06be43054a9b182e7ea60a763c35302924a

commit 23b0f06be43054a9b182e7ea60a763c35302924a
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Mar 13 17:39:52 2020 -0600

    Convert Go printing to value-based API
    
    This introduces go_value_print_inner, a modified copy of go_val_print.
    Unlike some of the other languages, Go was straightforward to convert
    to the value-based API all at once, so this patch takes that approach.
    
    gdb/ChangeLog
    2020-03-13  Tom Tromey  <tom@tromey.com>
    
            * go-valprint.c (go_value_print_inner): New function.
            * go-lang.h (go_value_print_inner): Declare.
            * go-lang.c (go_language_defn): Use go_value_print_inner.

Diff:
---
 gdb/ChangeLog     |  6 ++++++
 gdb/go-lang.c     |  2 +-
 gdb/go-lang.h     |  6 ++++++
 gdb/go-valprint.c | 37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 79ed0241255..862d4bc7e93 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-13  Tom Tromey  <tom@tromey.com>
+
+	* go-valprint.c (go_value_print_inner): New function.
+	* go-lang.h (go_value_print_inner): Declare.
+	* go-lang.c (go_language_defn): Use go_value_print_inner.
+
 2020-03-13  Tom Tromey  <tom@tromey.com>
 
 	* rust-lang.c (val_print_struct, rust_print_enum): Use the value
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 314c2811972..667c4aeb1a5 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -596,7 +596,7 @@ extern const struct language_defn go_language_defn =
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
   go_val_print,			/* Print a value using appropriate syntax.  */
-  nullptr,			/* la_value_print_inner */
+  go_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value.  */
   default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline.  */
diff --git a/gdb/go-lang.h b/gdb/go-lang.h
index ccfcb8d8caf..8647964ab60 100644
--- a/gdb/go-lang.h
+++ b/gdb/go-lang.h
@@ -88,4 +88,10 @@ extern void go_val_print (struct type *type,
 			  struct value *val,
 			  const struct value_print_options *options);
 
+/* Implement la_value_print_inner for Go.  */
+
+extern void go_value_print_inner (struct value *value,
+				  struct ui_file *stream, int recurse,
+				  const struct value_print_options *options);
+
 #endif /* !defined (GO_LANG_H) */
diff --git a/gdb/go-valprint.c b/gdb/go-valprint.c
index 1648a6c02c0..79b3ad58d5a 100644
--- a/gdb/go-valprint.c
+++ b/gdb/go-valprint.c
@@ -122,3 +122,40 @@ go_val_print (struct type *type, int embedded_offset,
 	break;
     }
 }
+
+/* See go-lang.h.  */
+
+void
+go_value_print_inner (struct value *val, struct ui_file *stream,
+		      int recurse, const struct value_print_options *options)
+{
+  struct type *type = check_typedef (value_type (val));
+
+  switch (TYPE_CODE (type))
+    {
+      case TYPE_CODE_STRUCT:
+	{
+	  enum go_type go_type = go_classify_struct_type (type);
+
+	  switch (go_type)
+	    {
+	    case GO_TYPE_STRING:
+	      if (! options->raw)
+		{
+		  print_go_string (type, value_embedded_offset (val),
+				   value_address (val),
+				   stream, recurse, val, options);
+		  return;
+		}
+	      break;
+	    default:
+	      break;
+	    }
+	}
+	/* Fall through.  */
+
+      default:
+	c_value_print_inner (val, stream, recurse, options);
+	break;
+    }
+}


                 reply	other threads:[~2020-03-14  0:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200314000617.227783AAA093@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).