148

I was just debugging a program in gdb and somehow I found a new feature I've never seen or even heard of before, a split view where I can see and browse the code in addition to giving commands:

Sorry about the picture, but ttys don't have screenshots.

What is this? What did I do, or, more specifically, how can I get this split-screen mode again? Is there a name for this mode, or somewhere I can read about how to use it?

2
  • 3
    For quick reference: You can exit this mode using any of C-x C-a, C-x a, or C-x A.` See this question.
    – Richard
    May 7, 2018 at 20:53
  • But those are my emacs bindings.... thank gud. Aug 15, 2022 at 22:27

10 Answers 10

121

It's called the TUI (no kidding). Start for example with gdbtui or gdb -tui ...


Please also see this answer by Ciro Santilli. It wasn't available in 2012 to the best of my knowledge, but definitely worth a look.

1
  • 20
    you can also use layout next after starting gdb normally
    – khaverim
    Oct 30, 2018 at 21:13
113

You can trigger it dynamically by push ctrl+x and ctrl+a.

3
  • thanks @user146043, this seems the only way if you are running screen at the same time as ctrl-a is the way to initiate screen commands!
    – olik79
    May 29, 2019 at 7:24
  • 1
    Looks like you can close with that combo, too! Apr 1, 2020 at 23:40
  • 1
    Ctrl+X O moves keyboard arrows focus to the next window.
    – thomasa88
    Dec 2, 2021 at 13:05
48

There are two variants of it.

  1. to only see code Press

Press CTRL X together and then 1

  1. To see both source and assembly

Press 'CTRL' 'X' together and then '2'

http://www.cs.fsu.edu/~baker/ada/gnat/html/gdb_23.html

A screen shot of the view with code and assembly. enter image description here

Also check out this amazing Github project.

1
  • Thanks a lot for sharing the github project link. It is too awesome :) Dec 1, 2017 at 13:17
28

GDB Dashboard

https://github.com/cyrus-and/gdb-dashboard

GDB dashboard uses the official GDB Python API and prints the information that you want when GDB stops e.g. after a next, like the native display command.

GDB dashboard vs GDB's TUI mode:

  • more robust, as it just prints to stdout instead of putting the shell on a more magic curses state, e.g.:

  • highly configurable from Python: you can select what you want to output and how big each section is depending on what you are debugging.

    The most useful views are already implemented: source, assembly, registers, stack, memory, threads, expressions... but it should be easy to extend it with any information that is exposed on the GDB Python API.

    TUI only allows showing two of source, assembly and registers and that is it. Unless you want to modify its C source code of course ;-)

GDB Dashboard screenshot

I believe that GDB should ship with a setup like that out of the box and turned on by default, it would attract much more users that way.

Oh, and the main developer, Andrea Cardaci, has been very responsive and awesome. Big kudos.

See also: How to highlight and color gdb output during interactive debugging?

7
  • 3
    There are not enough words to describe how awesome that is. Thanks :) Dec 20, 2019 at 15:57
  • 1
    Nice, I just re-visited this question (or rather my answer) and found your answer. Awesome. Will refer to your answer from mine, to make sure folks don't miss out on it. Sep 15, 2020 at 19:40
  • 1
    Is it possible to configure it to split vertically as opposed to the horizontal split it does by default in the TUI mode? Dec 30, 2020 at 10:43
  • @SamuelMyself I've never seen that, open an issue to double check, might be an interesting feature. Dec 30, 2020 at 10:44
  • 2
    @CiroSantilli郝海东冠状病六四事件法轮功 Well, found this. It was already requested 6 years ago but seems like no one's worked/working on it yet :( Dec 31, 2020 at 8:53
17

You can also start it from the gdb shell using the command "-" (dash). Not sure how to dynamically turn it off though.

2
14

Type layout as a command in gdb and the split window will be shown.

10

When GDB is in the standard mode, using win will automatically switch in the TUI mode.
Other command for TUI mode:

  • info win
    List and give the size of all displayed windows.
  • focus next | prev | src | asm | regs | split
    Set the focus to the named window. This command allows to change the active window so that scrolling keys can be affected to another window.

Read here form more help.

2

There is also interface tool for GDB called cgdb. Even with some color highlighting. "ESC" to switch to code view, "i" to switch back to gdb

cgdb

2

tui mode was clearly inspired by emacs -- I discovered it by accident when I hit ^X-o, which switches among split windows in emacs -- I sometimes hit that absent-mindedly when what I should be doing is switching to a different program. Anyway, that leads to another feature not mentioned yet, that you can move the cursor from the code window (where you can scroll) to the command line, or vice versa, with ^X-o.

1
  • Obviously most of the programs from GNU have emacs like keybindings, mainly because of consistency reasons. I know there is a vi mode in bash, but that is not nearly good enough as emacs mode.
    – 3N4N
    Apr 4, 2019 at 18:26
0

We can use (gdb) layout next to split our interface. This command help us to see higher level language (eg. C, C++ ,etc.) code as well as assembly language code(ASM) with pointer Click here to see split interface in C code, ASM, gdb

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.