public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Optionally print source code to gdb console window
@ 2024-05-05 20:57 Robert Rossi
  2024-05-06 22:18 ` Robert Rossi
  2024-05-07 16:52 ` Tom Tromey
  0 siblings, 2 replies; 13+ messages in thread
From: Robert Rossi @ 2024-05-05 20:57 UTC (permalink / raw)
  To: gdb-patches


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

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.diff --]
[-- Type: text/x-patch, Size: 2556 bytes --]

diff -urNp gdb-14.2.orig/gdb/stack.c gdb-14.2/gdb/stack.c
--- gdb-14.2.orig/gdb/stack.c	2024-03-03 00:55:00.000000000 -0500
+++ gdb-14.2/gdb/stack.c	2024-05-05 11:27:07.735576624 -0400
@@ -1161,7 +1161,9 @@ print_frame_info (const frame_print_opti
 	      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 -urNp gdb-14.2.orig/gdb/valprint.c gdb-14.2/gdb/valprint.c
--- gdb-14.2.orig/gdb/valprint.c	2024-03-03 00:55:00.000000000 -0500
+++ gdb-14.2/gdb/valprint.c	2024-05-05 11:24:32.447511834 -0400
@@ -113,6 +113,7 @@ struct value_print_options user_print_op
   true,				/* addressprint */
   false,			/* nibblesprint */
   false,			/* objectprint */
+  true,	    		/* sourceprint */
   PRINT_MAX_DEFAULT,		/* print_max */
   PRINT_MAX_CHARS_DEFAULT,	/* print_max_chars */
   10,				/* repeat_count_threshold */
@@ -2878,6 +2879,16 @@ Printing of C++ virtual function tables
 	      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
@@ -3088,6 +3099,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 -urNp gdb-14.2.orig/gdb/valprint.h gdb-14.2/gdb/valprint.h
--- gdb-14.2.orig/gdb/valprint.h	2024-03-03 00:55:00.000000000 -0500
+++ gdb-14.2/gdb/valprint.h	2024-05-05 11:16:22.418856087 -0400
@@ -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".  */

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

end of thread, other threads:[~2024-05-10 19:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-05 20:57 Optionally print source code to gdb console window Robert Rossi
2024-05-06 22:18 ` Robert Rossi
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

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).