public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Robert Rossi <bob@brasko.net>
To: GDB Development <gdb@sourceware.org>
Subject: Re: source annotation now prints source line
Date: Sun, 5 May 2024 11:36:13 -0400	[thread overview]
Message-ID: <CA+L9JkiybdBKZS-9_hKPgbj2GXi+8dtb6i47vs7gaH3b-wnOyg@mail.gmail.com> (raw)
In-Reply-To: <CA+L9Jkh28L==sf7=4Gs1AJuL2TCzVqWb4gJ3P-qpUzymc3rEjg@mail.gmail.com>


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

I've created and attached a patch that might achieve the desired goal.
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


On Sat, May 4, 2024 at 4:09 PM Robert Rossi <bob@brasko.net> wrote:

> Sorry to respond to an ancient thread. I thought the context might be
> helpful.
>
> I've been happily using the mi new-ui feature from gdb in cgdb for quite a
> while.
> Occasionally, I get people unhappy with gdb printing code out to the
> console when stepping through code.
>
> Here is an example,
> https://github.com/cgdb/cgdb/issues/336
> Here is another example,
> https://github.com/cgdb/cgdb/issues/223
>
> In the past, it was expressed by Pedro (i believe) that this was a feature.
> You can see from the requests some people do not want to see the code in
> the console.
> That's because they already see it more clearly in the code view.
>
> Can we consider disabling this behavior or making it optional somehow?
> Thoughts?
>
> Thanks,
> Bob Rossi
>
> On Mon, Mar 15, 2021 at 9:10 AM Pedro Alves <palves@redhat.com> wrote:
>
>> On 13/03/21 17:01, Bob Rossi wrote:
>> > On Thu, Apr 16, 2020 at 06:41:28PM +0100, Andrew Burgess wrote:
>> >> I'll take a look to see if there's a good way to give you the
>> >> functionality you're looking for and close the bugs off.
>> >
>> > Thank you for doing this Andrew, I appreciate it.
>> >
>> > Ironically, I just upgraded CGDB to no longer use annotations.
>> > I'm moved it from annotations to gdb/mi, in the same way that
>> > Eclipse uses MI, by using the new-ui feature of gdb. Now i see the
>> > source linse are still visible in the console. gdb doesn't know
>> > to not show them in this mode.
>> >
>> > To recap,
>> >  - cgdb using annotations does not show code in console
>> >  - cgdb using mi using new-ui does show code in console
>> >  - gdb tui does not show code in console
>> >  - eclipse probably shows code in console, as it uses mi and new-ui
>> >
>> > Would it be to much to ask that if new-ui is being used, that we
>> > assume a front end is being used, and not display the code in the
>> console?
>> >
>> > I've CC'd Pedro and Marc as I believe they may be the relevant people to
>> > have an opinion on how this would impact eclipse.
>> >
>>
>> A driving idea behind the new-ui work was that the CLI running inside
>> the console window would work exactly like a GDB running on a terminal.
>>
>> It should be possible even to start a GDB on a terminal, and then spawn a
>> separate Eclipse GUI connected to the GDB running on the terminal, still
>> outside
>> Eclipse, like a "launch-gui" command or some such written in python that
>> would spawn eclipse and have it connect to gdb with new-ui.   I don't
>> know whether
>> anyone ever implemented this in Eclipse, but it was a consideration in the
>> original design.  It isn't clear to me that in this scenario you would
>> not want
>> print the source line in the console.  I think I would want it.
>>
>> Also, while the new-ui feature was originally designed alongside Eclipse,
>> it has
>> potential for more usecases.  A secondary MI channel could not be
>> displaying any
>> GUI at all, for example.
>>
>> I think that if you want to make GDB not print source lines, then that
>> should
>> be a separate option.
>>
>> Thanks,
>> Pedro Alves
>>
>>

[-- 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".  */

  reply	other threads:[~2024-05-05 15:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-04 23:54 Bob Rossi
2020-04-14 11:23 ` Bob Rossi
2020-04-14 12:17   ` Andrew Burgess
2020-04-14 12:57     ` Andrew Burgess
2020-04-15  2:13     ` Bob Rossi
2020-04-16 17:41       ` Andrew Burgess
2021-03-13 17:01         ` Bob Rossi
2021-03-15 13:10           ` Pedro Alves
2024-05-04 20:09             ` Robert Rossi
2024-05-05 15:36               ` Robert Rossi [this message]
2024-05-05 16:06                 ` Eli Zaretskii

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+L9JkiybdBKZS-9_hKPgbj2GXi+8dtb6i47vs7gaH3b-wnOyg@mail.gmail.com \
    --to=bob@brasko.net \
    --cc=gdb@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).