How can I scroll back in GDB's command window in the TUI mode?
Asked Answered
B

5

83

Suppose that

(gdb) print *this

resulted in 20 lines of output. Yes, there would be Type <return> to continue, or q <return> to quit, but I'd like to scroll back to the top after I got to the bottom of the output.

I don't think http://sourceware.org/gdb/onlinedocs/gdb/TUI-Keys.html answers my question. It states

<PgUp>
Scroll the active window one page up.

but when the focus is on the command window, PgUp rewinds the command history, instead of scrolling back in the command window. Is it only me who suffers from this behavior?

I'm using PuTTY in order to SSH to Red Hat Linux (if this makes any difference).

Bloater answered 13/2, 2012 at 7:48 Comment(0)
P
51

One way to see the GDB output history in TUI mode is to enable logging:

set trace-commands on
set logging on

and then tail the log in another shell:

cd where/gdb/is/running
tail -f gdb.txt

This has the advantage of separating scrolling from command interaction, so you can type commands while viewing some past section of the GDB output.

None of the scrolling keys work in my CMD window, so GDB effectively consumes and destroys its own output. Switching out of TUI mode allows me to scroll up, but the output that occurred while in TUI mode is not there--the non-TUI window only shows new output generated after switching out of TUI mode. So far log and tail is the only solution I can find.


Edit: if you activate GDB logging (via set logging on) before switching to TUI mode, you may find that the logging stops upon entering TUI (this is a bug in GDB). You can toggle it back on:

set logging off
set logging on
Pisgah answered 14/9, 2012 at 17:40 Comment(5)
Is there a way to set logging on when entering into TUI mode? So that I don't have to do it manually.Consignee
@VivekAgrawal: I would suggest defining a function in your .gdbinit to enter TUI mode and also setup logging (and anything else) the way you need. See this gist for examples of GDB init functions. If you have multiple environments with differences in your GDB logging, you can just customize the .gdbinit function on each machine.Pisgah
This is really awkward compared to either of EmptyData and Rohan Ghige's answers below; recommend either of those should be the accepted answer.Fiscus
@ChrisSmowton No, so far this answer is the only one that even attempts to address the question. You're likely mixing up screen scrolling and command line editing (specifically moving through the history list), these are two different things as others have pointed out before already.Alible
Ah yes so I am, I indeed wanted to scroll the command history.Fiscus
J
44

I found an answer here: http://beej.us/guide/bggdb/

Note that when the SRC window has focus, the arrow keys will move the source code, but when the CMD window has focus, the arrow keys will select the previous and next commands in the command history. (For the record, the commands to move the SRC window single lines and single pages are +, -, <, and >.)

There's also an example session illustrating this:

(gdb) info win
        SRC     (36 lines)  <has focus>
        CMD     (18 lines)
(gdb) fs next
Focus set to CMD window.
(gdb) info win
        SRC     (36 lines)
        CMD     (18 lines)  <has focus>
(gdb) fs SRC
Focus set to SRC window.
(gdb)
Jill answered 30/8, 2012 at 8:58 Comment(7)
instead of fs next one can also switch focus with ctrl+x o as stated in the documentation.Splenitis
@hlin117, still don't know how to scroll cmd window from this answerSharynshashlik
I believe this should be the accepted answer. Btw, fs n also works. :DDanelaw
This doesn't answer the question of how to scroll back through the output.Chesty
How does this answer the question? - "How can I scroll back in GDB's command window in the TUI mode?"Congress
This does not answer the question in any way.Moldau
I don't understand why this got up-voted so many. It does not answer the question at all. "the arrow keys will select the previous and next commands in the command history"Antifederalist
C
18

You can try Ctrl + P for the previous command and Ctrl + N for the next command (when you have used Ctrl + P to go back to the previous commands :)

Caryl answered 24/5, 2017 at 12:27 Comment(1)
This won't scroll the output.Sulphurate
G
12

Use C-x o (usually Ctrl + X, O). Using this you can change your active window and then use normal up down arrow to see previous commands.

Glossectomy answered 28/5, 2018 at 4:55 Comment(1)
The OP is asking about the commands output, not about the commands themselves.Moldau
U
1

I think this is the best answer.
Other answers use output tracing to see the output in separte text output file, but using this you can see the command output in the gdb window by scrolling.
All the answers assumed you are in TUI mode (Text User Interface) using curses library. In this mode, when you use up or down arrow in command window, it only shows previous or next commands which the OP doesn't want.

The sure memthod is : you exit the TUI mode by giving 'tui disable' command in command window. Then when the command output is very long, you can scroll up to see the command output. If you want to come back to TUI mode, do 'tui enable'
I tested this after installing gdb-dashboard by which you can see all the information, but I think you can use it without gdb-dashboard.

Ultranationalism answered 12/5, 2023 at 5:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.