public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Robert Rossi <bob@brasko.net>
To: gdb-patches@sourceware.org
Subject: Re: Optionally print source code to gdb console window
Date: Mon, 6 May 2024 18:18:59 -0400	[thread overview]
Message-ID: <CA+L9JkgfFw-_=SVa3Q0_TngJqe9R+2A-4r3v2+ONAxOb6Qqwhg@mail.gmail.com> (raw)
In-Reply-To: <CA+L9JkjGv1J546wQScPSnTVzqM7ai65Ye4XQELqMkSBdabTKKg@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 2075 bytes --]

I got an automated email saying I broke a test.

This updated patch fixes the test and updates the code to the GNU standard,
hopefully.

Thanks,
Bob Rossi


On Sun, May 5, 2024 at 4:57 PM Robert Rossi <bob@brasko.net> wrote:

> A little history. When using --annotations, gdb did not print the source
> code to the gdb console window. When using mi with new-ui it does. When I
> reported this in the past, several people said it was a feature that gdb
> printed the source code lines to the console.
>
> I've had several users of cgdb say they do not want gdb to print the
> source code to the gdb console window as they can see the code in the code
> view.
>
> I've created and attached a patch that I hope makes it optional to have
> gdb print the source code to the gdb console window. Could I have some
> feedback?
>
> I've added a new print source option to control printing source code to
> the gdb console.
>
> (gdb) show print source
> Printing of source code to gdb console is on.
>
> You can turn the printing of the source code off as follows.
> (gdb) set print source off
> (gdb)
>
> When the printing of source code is on,
> (gdb) r
> Starting program: /home/bob/rcs/git/gdb/gdb-build/main
> ....
> Breakpoint 1, main (argc=1, argv=0x7fffffffe0c8) at test_main.cpp:42
> 42      {
> (gdb) n
> 43          int i = 3;
> (gdb) n
> 44          int j = 4;
> (gdb) n
> 47          long_func();
>
> When the printing of source code is off,
> (gdb) r
> Starting program: /home/bob/rcs/git/gdb/gdb-build/main
> ...
> Breakpoint 1, main (argc=1, argv=0x7fffffffe098) at test_main.cpp:42
> (gdb) n
> (gdb) n
> (gdb) n
> (gdb)
>
> I don't know gdb code well enough to understand if i've disabled
> functionality
> beyond what i was hoping to.
>
> I'm not sure how to control this from cgdb when using old versions of gdb.
> I get the following error when i run --ex "set print source off" when
> starting gdb.
> Undefined set print command: "source off".  Try "help set print".
>
> Thanks,
> Bob Rossi
>

[-- Attachment #2: sourceprint-round2.diff --]
[-- Type: text/x-patch, Size: 2735 bytes --]

diff --git a/gdb/stack.c b/gdb/stack.c
index c2323e1726d..a9f967113f6 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1154,7 +1154,8 @@ do_print_frame_info (struct ui_out *uiout, const frame_print_options &fp_opts,
 	      uiout->text ("\t");
 	    }
 
-	  print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
+	  if (opts.sourceprint)
+	    print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
 	}
 
       /* If disassemble-next-line is set to on and there is line debug
diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp
index 841e603764c..ac0949cd084 100644
--- a/gdb/testsuite/gdb.base/options.exp
+++ b/gdb/testsuite/gdb.base/options.exp
@@ -182,6 +182,7 @@ proc_with_prefix test-print {{prefix ""}} {
 	"-pretty"
 	"-raw-values"
 	"-repeats"
+	"-source"
 	"-static-members"
 	"-symbol"
 	"-union"
diff --git a/gdb/valprint.c b/gdb/valprint.c
index db8affeb47a..4b178282050 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -114,6 +114,7 @@ struct value_print_options user_print_options =
   true,				/* addressprint */
   false,			/* nibblesprint */
   false,			/* objectprint */
+  true,				/* sourceprint */
   PRINT_MAX_DEFAULT,		/* print_max */
   PRINT_MAX_CHARS_DEFAULT,	/* print_max_chars */
   10,				/* repeat_count_threshold */
@@ -2873,6 +2874,16 @@ Printing of C++ virtual function tables is %s.\n"),
 	      value);
 }
 
+/* Controls printing of source code.  */
+static void
+show_sourceprint (struct ui_file *file, int from_tty,
+		struct cmd_list_element *c, const char *value)
+{
+  gdb_printf (file, _("\
+Printing of source code to gdb console is %s.\n"),
+	      value);
+}
+
 /* Controls looking up an object's derived type using what we find in
    its vtables.  */
 static void
@@ -3083,6 +3094,14 @@ pretty-printers for that value.")
     N_("Show printing of C++ virtual function tables."),
     NULL, /* help_doc */
   },
+  boolean_option_def {
+    "source",
+    [] (value_print_options *opt) { return &opt->sourceprint; },
+    show_sourceprint, /* show_cmd_cb */
+    N_("Set printing of source code to gdb console."),
+    N_("Show printing of source code to gdb console."),
+    NULL, /* help_doc */
+  },
 };
 
 /* See valprint.h.  */
diff --git a/gdb/valprint.h b/gdb/valprint.h
index 4f194b77008..c4672c03a9f 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -62,6 +62,9 @@ struct value_print_options
      in its vtables.  */
   bool objectprint;
 
+  /* Controls printing of source to console.  */
+  bool sourceprint;
+
   /* Maximum number of elements to print for vector contents, or UINT_MAX
      for no limit.  Note that "set print elements 0" stores UINT_MAX in
      print_max, which displays in a show command as "unlimited".  */

  reply	other threads:[~2024-05-06 22:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-05 20:57 Robert Rossi
2024-05-06 22:18 ` Robert Rossi [this message]
2024-05-07 16:52 ` Tom Tromey
2024-05-07 21:33   ` Robert Rossi
2024-05-08  0:52     ` Tom Tromey
2024-05-08  1:29       ` Bob Rossi
2024-05-08 15:46         ` Tom Tromey
2024-05-08 23:07           ` Bob Rossi
2024-05-09 13:58             ` Tom Tromey
2024-05-10 10:19             ` Andrew Burgess
2024-05-10 18:07               ` Tom Tromey
2024-05-10 19:29           ` Pedro Alves
2024-05-10 19:23     ` Pedro Alves

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='CA+L9JkgfFw-_=SVa3Q0_TngJqe9R+2A-4r3v2+ONAxOb6Qqwhg@mail.gmail.com' \
    --to=bob@brasko.net \
    --cc=gdb-patches@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).