Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically refresh gdb in tui mode?

Tags:

If I'am debugging files with gdb -tui the source window always becomes messed up. So every time I hit enter I have to immediately type ctrl+L to get rid of this problem, this is how gdb refeshes the window. I am working on tty with gnu screen.

Is there a possibility to automatically refresh gdb in tui mode?
If gdb doesn't have this ability Python could be a solution because gdb is able to source Python files, but I don't know about Python.

This Python snippet works fine in Bash but not inside gdb:

import sys r = "\033[2J"    # here I try to emulate [ctrl-L] t = "" while 1:     i = sys.stdin.read(1)     t = t +i     if i == '\n':         print(r) 

Of course I accept every other language supported by gdb.
Every help is appreciated.

By the way, here is a screencast https://youtu.be/DqiH6Jym1JY that show my problem.

This is the file I used for demonstrating in gdb like the link above show's, mess_up.c

#include <stdio.h>  int main(void){     //int n = 120;     int n;     n = 120;     char stuff[n+2];      printf( "Max: %d\n", n );      printf( "Sizeof int:  %d\n", sizeof(int)  );     printf( "Sizeof char: %d\n", sizeof(char) );     printf( "Sizeof n:  %d\n", sizeof n   );     printf( "Sizeof stuff: %d\n", sizeof stuff  );      fgets ( stuff , n , stdin );     printf( "The stuff:\n%s\n", stuff );     printf( "Sizeof stuff after input = %d\n", sizeof stuff  );  return 0; } 

My actual ncurses version displayed by tic -V is ncurses 5.9.20140118

like image 317
John Goofy Avatar asked Aug 06 '16 11:08

John Goofy


People also ask

How do you invoke tui in GDB?

The GDB Text User Interface, TUI in short, is a terminal interface which uses the curses library to show the source file, the assembly output, the program registers and GDB commands in separate text windows. The TUI is enabled by invoking GDB using either `gdbtui' or `gdb -tui' .

How do I exit tui mode?

To disable ​TUI​ mode, you can type ​tui disable​. If the layout of the ​TUI​becomes unreadable, pressing ​Ctrl-l​will reload it. Once you are running TUI mode, there are several commands you can use to change the display. One of them is layout name.

How do I change focus in GDB?

Text you type always goes into the command window, so normally you only need to change focus for scrolling around in registers, asm, or source. You can use command history while the focus is on the asm window by using control-p and control-n, like emacs.


1 Answers

Had the exact same problem. Have you tried GDB user-defined hooks or commands ?

In your ~/.gdbinit or in your session, you can do:

define hook-next   refresh end 

This will call the refresh command each time you enter the next command or one of its aliases.

Or you can define:

define mynext   next   refresh end 

and call mynext instead of next.

Hooks are automatically called whenever a command C is entered and a hook-C exists, that's so cool, I've just discovered that in the docs.

See https://sourceware.org/gdb/current/onlinedocs/gdb/Define.html and https://sourceware.org/gdb/current/onlinedocs/gdb/Hooks.html#Hooks

You can add as many hooks/defines as you want.

like image 100
hdl Avatar answered Sep 26 '22 09:09

hdl