source annotation now prints source line

Robert Rossi bob@brasko.net
Sun May 5 15:36:13 GMT 2024


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
>>
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sourceprint.diff
Type: text/x-patch
Size: 2556 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/gdb/attachments/20240505/fc305ac8/attachment.bin>


More information about the Gdb mailing list