public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* source annotation now prints source line
@ 2020-04-04 23:54 Bob Rossi
  2020-04-14 11:23 ` Bob Rossi
  0 siblings, 1 reply; 11+ messages in thread
From: Bob Rossi @ 2020-04-04 23:54 UTC (permalink / raw)
  To: gdb

Hi,

When the source annotation is sent to the front end, the source line
is now also sent to the front end console. I believe this commit
introduced it,
  https://github.com/bminor/binutils-gdb/commit/ec8e2b6d3051f0b4b2a8eee9917898e95046c62f

Now CGDB displays,
    (gdb) n
    43          int i = 3;
    (gdb) 

Instead of,
    (gdb) n
    (gdb) 

CGDB is a front end, and so it has a source view to display the code to
the user. Why did GDB decide to also print the line of code to the front
end's console window as well? This is confusing.

Thanks,
Bob Rossi

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

* Re: source annotation now prints source line
  2020-04-04 23:54 source annotation now prints source line Bob Rossi
@ 2020-04-14 11:23 ` Bob Rossi
  2020-04-14 12:17   ` Andrew Burgess
  0 siblings, 1 reply; 11+ messages in thread
From: Bob Rossi @ 2020-04-14 11:23 UTC (permalink / raw)
  To: gdb

On Sat, Apr 04, 2020 at 07:54:24PM -0400, Bob Rossi wrote:
> When the source annotation is sent to the front end, the source line
> is now also sent to the front end console. I believe this commit
> introduced it,
>   https://github.com/bminor/binutils-gdb/commit/ec8e2b6d3051f0b4b2a8eee9917898e95046c62f
> 
> Now CGDB displays,
>     (gdb) n
>     43          int i = 3;
>     (gdb) 
> 
> Instead of,
>     (gdb) n
>     (gdb) 
> 
> CGDB is a front end, and so it has a source view to display the code to
> the user. Why did GDB decide to also print the line of code to the front
> end's console window as well? This is confusing.

The concept behind this commit seems incorrect.

The motivation for the patch isn't clearly explained in
the commit message. I believe I've given a reasonable explanation
on why this patch makes no sense for front ends.

Should I submit a patch reverting it?

Thanks,
Bob Rossi

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

* Re: source annotation now prints source line
  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
  0 siblings, 2 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-04-14 12:17 UTC (permalink / raw)
  To: Bob Rossi; +Cc: gdb

* Bob Rossi <bob@brasko.net> [2020-04-14 07:23:04 -0400]:

> On Sat, Apr 04, 2020 at 07:54:24PM -0400, Bob Rossi wrote:
> > When the source annotation is sent to the front end, the source line
> > is now also sent to the front end console. I believe this commit
> > introduced it,
> >   https://github.com/bminor/binutils-gdb/commit/ec8e2b6d3051f0b4b2a8eee9917898e95046c62f
> > 
> > Now CGDB displays,
> >     (gdb) n
> >     43          int i = 3;
> >     (gdb) 
> > 
> > Instead of,
> >     (gdb) n
> >     (gdb) 
> > 
> > CGDB is a front end, and so it has a source view to display the code to
> > the user. Why did GDB decide to also print the line of code to the front
> > end's console window as well? This is confusing.
> 
> The concept behind this commit seems incorrect.
> 
> The motivation for the patch isn't clearly explained in
> the commit message. I believe I've given a reasonable explanation
> on why this patch makes no sense for front ends.
> 
> Should I submit a patch reverting it?

The patch in context is discussed here:

  https://sourceware.org/pipermail/gdb-patches/2019-June/158310.html
  https://sourceware.org/pipermail/gdb-patches/2019-June/158350.html
  https://sourceware.org/pipermail/gdb-patches/2019-June/158351.html
  https://sourceware.org/pipermail/gdb-patches/2019-June/158352.html
  https://sourceware.org/pipermail/gdb-patches/2019-June/158353.html

I'm not sure you've convinced me yet that the idea behind the patch is
incorrect.  Annotations should be a (deprecated) way for F/Es to parse
GDB's output, but they shouldn't impact _what_ GDB prints.

In this particular case, printing the source line actually updates
some internal state, which impacts how later commands operate.  What
this means is that the users session will behave differently if they
have annotations on than when annotations are off.

I guess, what I don't understand is that if a F/E wants to hide a
particular piece of the output, why can't it just strip that from the
output stream?  The F/E must already be removing the annotation
markers, so all the output must be going through the F/E anyway.

Further, removing this particular piece of output makes sense for this
F/E, but is it always going to be true for all F/Es?

I haven't gone back and looked at the old behaviour, maybe I'll have
more thoughts once I've looked at that again.

Thanks,
Andrew

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

* Re: source annotation now prints source line
  2020-04-14 12:17   ` Andrew Burgess
@ 2020-04-14 12:57     ` Andrew Burgess
  2020-04-15  2:13     ` Bob Rossi
  1 sibling, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-04-14 12:57 UTC (permalink / raw)
  To: Bob Rossi; +Cc: gdb

* Andrew Burgess <andrew.burgess@embecosm.com> [2020-04-14 13:17:05 +0100]:

> * Bob Rossi <bob@brasko.net> [2020-04-14 07:23:04 -0400]:
>
> > On Sat, Apr 04, 2020 at 07:54:24PM -0400, Bob Rossi wrote:
> > > When the source annotation is sent to the front end, the source line
> > > is now also sent to the front end console. I believe this commit
> > > introduced it,
> > >   https://github.com/bminor/binutils-gdb/commit/ec8e2b6d3051f0b4b2a8eee9917898e95046c62f
> > >
> > > Now CGDB displays,
> > >     (gdb) n
> > >     43          int i = 3;
> > >     (gdb)
> > >
> > > Instead of,
> > >     (gdb) n
> > >     (gdb)
> > >
> > > CGDB is a front end, and so it has a source view to display the code to
> > > the user. Why did GDB decide to also print the line of code to the front
> > > end's console window as well? This is confusing.
> >
> > The concept behind this commit seems incorrect.
> >
> > The motivation for the patch isn't clearly explained in
> > the commit message. I believe I've given a reasonable explanation
> > on why this patch makes no sense for front ends.
> >
> > Should I submit a patch reverting it?
>
> The patch in context is discussed here:
>
>   https://sourceware.org/pipermail/gdb-patches/2019-June/158310.html
>   https://sourceware.org/pipermail/gdb-patches/2019-June/158350.html
>   https://sourceware.org/pipermail/gdb-patches/2019-June/158351.html
>   https://sourceware.org/pipermail/gdb-patches/2019-June/158352.html
>   https://sourceware.org/pipermail/gdb-patches/2019-June/158353.html
>
> I'm not sure you've convinced me yet that the idea behind the patch is
> incorrect.  Annotations should be a (deprecated) way for F/Es to parse
> GDB's output, but they shouldn't impact _what_ GDB prints.
>
> In this particular case, printing the source line actually updates
> some internal state, which impacts how later commands operate.  What
> this means is that the users session will behave differently if they
> have annotations on than when annotations are off.
>
> I guess, what I don't understand is that if a F/E wants to hide a
> particular piece of the output, why can't it just strip that from the
> output stream?  The F/E must already be removing the annotation
> markers, so all the output must be going through the F/E anyway.
>
> Further, removing this particular piece of output makes sense for this
> F/E, but is it always going to be true for all F/Es?
>
> I haven't gone back and looked at the old behaviour, maybe I'll have
> more thoughts once I've looked at that again.

For the record, here's GDB's output before the patch (8.3.1):

  ## START ##
  Temporary breakpoint 1, main () at hello.c:6
  6	  printf ("Hello World\n");
  (gdb) set annotate 0xff

  ��pre-prompt
  (gdb)
  ��prompt
  n

  ��post-prompt

  ��starting
  Hello World

  ��source /home/andrew/tmp/hello.c:7:62:beg:0x401134

  ��stopped

  ��pre-prompt
  (gdb)
  ��prompt
  ## END ##

And here's the output after the patch (9.1):

  ## START ##
  Temporary breakpoint 1, main () at hello.c:6
  6	  printf ("Hello World\n");
  (gdb) set annotate 0xff

  ��pre-prompt
  (gdb)
  ��prompt
  n

  ��post-prompt

  ��starting
  Hello World

  ��source /home/andrew/tmp/hello.c:7:62:beg:0x401134
  7	  return 0;

  ��stopped

  ��pre-prompt
  (gdb)
  ��prompt
  ## END ##

I guess I'd still suggest that the "right" thing would be to strip the
output when processing GDB's output.  But, if you strongly disagree
then you could put forward a patch for discussion.  However, I think
you'd need to do more than revert the original patch.

If you look inside source.c:print_source_lines_base then you'll see
the current source line and symtab being updated.  This is done as
part of printing the '7  ..... return 0' line.  If you'd going to stop
this being printed, then you'd need to duplicate this behaviour
somewhere else, so that the current line/symtab are updated when
annotations are on.

Thanks,
Andrew

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

* Re: source annotation now prints source line
  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
  1 sibling, 1 reply; 11+ messages in thread
From: Bob Rossi @ 2020-04-15  2:13 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb

On Tue, Apr 14, 2020 at 01:17:05PM +0100, Andrew Burgess wrote:
> * Bob Rossi <bob@brasko.net> [2020-04-14 07:23:04 -0400]:
> 
> > On Sat, Apr 04, 2020 at 07:54:24PM -0400, Bob Rossi wrote:
> > > When the source annotation is sent to the front end, the source line
> > > is now also sent to the front end console. I believe this commit
> > > introduced it,
> > >   https://github.com/bminor/binutils-gdb/commit/ec8e2b6d3051f0b4b2a8eee9917898e95046c62f
> > > 
> > > Now CGDB displays,
> > >     (gdb) n
> > >     43          int i = 3;
> > >     (gdb) 
> > > 
> > > Instead of,
> > >     (gdb) n
> > >     (gdb) 
> > > 
> > > CGDB is a front end, and so it has a source view to display the code to
> > > the user. Why did GDB decide to also print the line of code to the front
> > > end's console window as well? This is confusing.
> > 
> > The concept behind this commit seems incorrect.
> > 
> > The motivation for the patch isn't clearly explained in
> > the commit message. I believe I've given a reasonable explanation
> > on why this patch makes no sense for front ends.
> > 
> > Should I submit a patch reverting it?
> 
> The patch in context is discussed here:
> 
>   https://sourceware.org/pipermail/gdb-patches/2019-June/158310.html
>   https://sourceware.org/pipermail/gdb-patches/2019-June/158350.html
>   https://sourceware.org/pipermail/gdb-patches/2019-June/158351.html
>   https://sourceware.org/pipermail/gdb-patches/2019-June/158352.html
>   https://sourceware.org/pipermail/gdb-patches/2019-June/158353.html
> 
> I'm not sure you've convinced me yet that the idea behind the patch is
> incorrect.  Annotations should be a (deprecated) way for F/Es to parse
> GDB's output, but they shouldn't impact _what_ GDB prints.

Annotation are still useful for the single purpose of allowing GDB
to tell you when the user is at the prompt. This allows front ends
to know when to issue a new command.

> In this particular case, printing the source line actually updates
> some internal state, which impacts how later commands operate.  What
> this means is that the users session will behave differently if they
> have annotations on than when annotations are off.

I see. Seems good to have fixed that. Although I wonder how relevant
that information was as front ends have been using annotations for 
20+ years without having noticed. Was this found from a user bug report?

> I guess, what I don't understand is that if a F/E wants to hide a
> particular piece of the output, why can't it just strip that from the
> output stream?  The F/E must already be removing the annotation
> markers, so all the output must be going through the F/E anyway.

Front ends can not parse gdb's output. It's the golden rule.
It's unreliable and will ultimately fail.

> Further, removing this particular piece of output makes sense for this
> F/E, but is it always going to be true for all F/Es?

Yes, it does. It worked this way for 20+ years, and everyone was happy.
Was this added in because an actual user complained?

Even the tui does not show the source output in the console, even
after your patch.

Thanks,
Bob Rossi

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

* Re: source annotation now prints source line
  2020-04-15  2:13     ` Bob Rossi
@ 2020-04-16 17:41       ` Andrew Burgess
  2021-03-13 17:01         ` Bob Rossi
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Burgess @ 2020-04-16 17:41 UTC (permalink / raw)
  To: Bob Rossi; +Cc: gdb

* Bob Rossi <bob@brasko.net> [2020-04-14 22:13:24 -0400]:

> On Tue, Apr 14, 2020 at 01:17:05PM +0100, Andrew Burgess wrote:
> > * Bob Rossi <bob@brasko.net> [2020-04-14 07:23:04 -0400]:
> > 
> > > On Sat, Apr 04, 2020 at 07:54:24PM -0400, Bob Rossi wrote:
> > > > When the source annotation is sent to the front end, the source line
> > > > is now also sent to the front end console. I believe this commit
> > > > introduced it,
> > > >   https://github.com/bminor/binutils-gdb/commit/ec8e2b6d3051f0b4b2a8eee9917898e95046c62f
> > > > 
> > > > Now CGDB displays,
> > > >     (gdb) n
> > > >     43          int i = 3;
> > > >     (gdb) 
> > > > 
> > > > Instead of,
> > > >     (gdb) n
> > > >     (gdb) 
> > > > 
> > > > CGDB is a front end, and so it has a source view to display the code to
> > > > the user. Why did GDB decide to also print the line of code to the front
> > > > end's console window as well? This is confusing.
> > > 
> > > The concept behind this commit seems incorrect.
> > > 
> > > The motivation for the patch isn't clearly explained in
> > > the commit message. I believe I've given a reasonable explanation
> > > on why this patch makes no sense for front ends.
> > > 
> > > Should I submit a patch reverting it?
> > 
> > The patch in context is discussed here:
> > 
> >   https://sourceware.org/pipermail/gdb-patches/2019-June/158310.html
> >   https://sourceware.org/pipermail/gdb-patches/2019-June/158350.html
> >   https://sourceware.org/pipermail/gdb-patches/2019-June/158351.html
> >   https://sourceware.org/pipermail/gdb-patches/2019-June/158352.html
> >   https://sourceware.org/pipermail/gdb-patches/2019-June/158353.html
> > 
> > I'm not sure you've convinced me yet that the idea behind the patch is
> > incorrect.  Annotations should be a (deprecated) way for F/Es to parse
> > GDB's output, but they shouldn't impact _what_ GDB prints.
> 
> Annotation are still useful for the single purpose of allowing GDB
> to tell you when the user is at the prompt. This allows front ends
> to know when to issue a new command.
> 
> > In this particular case, printing the source line actually updates
> > some internal state, which impacts how later commands operate.  What
> > this means is that the users session will behave differently if they
> > have annotations on than when annotations are off.
> 
> I see. Seems good to have fixed that. Although I wonder how relevant
> that information was as front ends have been using annotations for 
> 20+ years without having noticed. Was this found from a user bug report?
> 
> > I guess, what I don't understand is that if a F/E wants to hide a
> > particular piece of the output, why can't it just strip that from the
> > output stream?  The F/E must already be removing the annotation
> > markers, so all the output must be going through the F/E anyway.
> 
> Front ends can not parse gdb's output. It's the golden rule.
> It's unreliable and will ultimately fail.
> 
> > Further, removing this particular piece of output makes sense for this
> > F/E, but is it always going to be true for all F/Es?
> 
> Yes, it does. It worked this way for 20+ years, and everyone was happy.
> Was this added in because an actual user complained?
> 
> Even the tui does not show the source output in the console, even
> after your patch.

To our great shame, the relevant code here is (from stack.c):

      if (deprecated_print_frame_info_listing_hook)
	deprecated_print_frame_info_listing_hook (sal.symtab, sal.line,
						  sal.line + 1, 0);
      else
	{
          // .... print the source lines ....
        }

And in tui/tui-hooks.c we have:

  deprecated_print_frame_info_listing_hook
    = tui_dummy_print_frame_info_listing_hook;

and:

  static void
  tui_dummy_print_frame_info_listing_hook (struct symtab *s,
                                           int line,
                                           int stopline,
                                           int noerror)
  {
  }

Why am I telling you this? It basically is a convoluted way of saying:

  if (!tui)
  {
     // ...... print the source lines ....
  }

This certainly backs up your point that GUI users don't want to see
the information in both the GDB terminal _and_ in their GUI.  Which
interestingly, would suggest that the TUI is going to have the same
set of bugs that the annotations would trigger.  But in terms of
implementation the TUI is special casing itself.

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.

Thanks,
Andrew



> 
> Thanks,
> Bob Rossi

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

* Re: source annotation now prints source line
  2020-04-16 17:41       ` Andrew Burgess
@ 2021-03-13 17:01         ` Bob Rossi
  2021-03-15 13:10           ` Pedro Alves
  0 siblings, 1 reply; 11+ messages in thread
From: Bob Rossi @ 2021-03-13 17:01 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb, Marc Khouzam, Pedro Alves

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.

Thanks,
Bob Rossi

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

* Re: source annotation now prints source line
  2021-03-13 17:01         ` Bob Rossi
@ 2021-03-15 13:10           ` Pedro Alves
  2024-05-04 20:09             ` Robert Rossi
  0 siblings, 1 reply; 11+ messages in thread
From: Pedro Alves @ 2021-03-15 13:10 UTC (permalink / raw)
  To: Bob Rossi, Andrew Burgess; +Cc: gdb, Marc Khouzam, Pedro Alves

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


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

* Re: source annotation now prints source line
  2021-03-15 13:10           ` Pedro Alves
@ 2024-05-04 20:09             ` Robert Rossi
  2024-05-05 15:36               ` Robert Rossi
  0 siblings, 1 reply; 11+ messages in thread
From: Robert Rossi @ 2024-05-04 20:09 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Andrew Burgess, gdb, Marc Khouzam

[-- Attachment #1: Type: text/plain, Size: 3068 bytes --]

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

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

* Re: source annotation now prints source line
  2024-05-04 20:09             ` Robert Rossi
@ 2024-05-05 15:36               ` Robert Rossi
  2024-05-05 16:06                 ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Robert Rossi @ 2024-05-05 15:36 UTC (permalink / raw)
  To: GDB Development


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

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

* Re: source annotation now prints source line
  2024-05-05 15:36               ` Robert Rossi
@ 2024-05-05 16:06                 ` Eli Zaretskii
  0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2024-05-05 16:06 UTC (permalink / raw)
  To: Robert Rossi; +Cc: gdb

> From: Robert Rossi <bob@brasko.net>
> Date: Sun, 5 May 2024 11:36:13 -0400
> 
> I've created and attached a patch that might achieve the desired goal.
> Could I have some feedback?

Bob, thanks for the patch, but I suggest to post it to gdb-patches
instead, not here.

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

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

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-04 23:54 source annotation now prints source line 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
2024-05-05 16:06                 ` Eli Zaretskii

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