10

I am trying to use gdb to debug caffe. I prefer to use the tui mode because it allows me to see the whole source code rather than just a single line. But there is a problem: whenever the program caffe outputs something on stderr, the output distorts the tui interface. See the below snapshot for an illustration:

normal

when there is output on stderr

Is this an inherent limitation of gdb tui or is there any way to solve this problem?

Siyuan Ren
  • 7,573
  • 6
  • 47
  • 61
  • Did you try to redirect the stderr to dev/null when running the app from GDB (in case you do not attach to a running process)? Just like: run $your_args 2> /dev/null – bikjub Oct 10 '14 at 08:01
  • @bikjub That works, but more of a hack. Can't gab handles any program not silent? – Siyuan Ren Oct 10 '14 at 08:24
  • How about using cgdb? It provides a very nice curses interface for gdb. – bikjub Oct 10 '14 at 09:31
  • Any output from the target, even to stdout, is going to appear somewhere in the tui display; usually it appears at the top of the cmd window, near the status line, since that is usually where the cursor is just after you start or continue a process. You can use the `tty` command to have the target use a different terminal for its input and output. – Mark Plotnick Oct 10 '14 at 21:41
  • 1
    Thanks for all your suggestion for workarounds. I filled a bug report and decide to switch to lldb. – Siyuan Ren Oct 11 '14 at 00:22
  • @bikjub: I will accept the `cgdb` suggestion as answer. It does solve my problem. – Siyuan Ren Oct 13 '14 at 04:19
  • 2
    You can also press Ctrl-L to refresh tui screen. But you will have to do it every time after tui gets distorted. – ks1322 Oct 13 '14 at 07:56
  • 1
    Late to the party, but sometimes in cases like this, I start the program on one terminal, then run the debugger on another terminal and attach to the program. If necessary I add a five-second sleep to the start of the program to give me time to attach before it starts doing anything. – Edward Falk Feb 09 '22 at 15:00

2 Answers2

5

As suggested by @ks1322 you can press Ctrl-L to refresh the screen. Or define a hook in .gdbinit to refresh after every next command:

define hook-next
    refresh
end
builder-7000
  • 7,131
  • 3
  • 19
  • 43
0

I never found a solution to such TUI annoyances, and eventually gave up and moved to more reliable methods that:

  • use the GDB Python API to get GDB data
  • output some pre-configured views to stdout after every stop instead of putting the terminal in a magic ncurses mode

GDB Dashboard is one such solution, and I have described it at: gdb split view with code

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985