gospes
gospes

Reputation: 3937

GDB: disable printing of current line after every step

The GNU gdb commandline debugger prints the line it is currently on after every step and next command. Consider the following gdb session where I step through some code:

...
Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd848)
    at src/main.cc:3
3       int main(int argc, char **argv){
(gdb) next
4           Printf("Hello World\n");    // <--- disable this
(gdb) 
5           printf("Hello World 2\n");  // <--- disable this
(gdb) 

Is there a gdb setting to disable this printing? I know this is technically possible because the gdb TUI has exactly the behaviour i'm looking for (accessible through gdb command set enable tui).

Thanks!

Upvotes: 4

Views: 2604

Answers (2)

gospes
gospes

Reputation: 3937

I achieved it through redirection:

define n
    set logging file /dev/null
    set logging redirect on
    set logging enabled on
    next
    set logging enabled off
    display
end

I found that capturing the output of next did not work using gdb.execute (gdb's python API). I expect that this is the case because the source line is not printed by next itself, but by the stop event that is triggered.

Upvotes: 5

Tom Tromey
Tom Tromey

Reputation: 22549

There is no straightforward way to do this when using the gdb CLI. The code that handles printing the "stop" to the user does not check anything that the user can set.

One way you could try solving this would be to alias n to a command that runs the command using a different interpreter, like interpreter-exec tui next. I am not sure if this will actually work.

Another way to accomplish this would be to write a Python command named n that uses gdb.execute to invoke next -- while capturing the output and ignoring it. This approach is somewhat dangerous because sometimes you probably do want some of the stop message, just not the source display.

The best approach would be to modify gdb to add a new set command to disable the source printing. This is easy to do.

Upvotes: 1

Related Questions