GDB: disable printing of current line after every step

孤街浪徒 提交于 2021-01-28 08:51:42

问题


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!


回答1:


I achieved it through redirection:

define n
    set logging file /dev/null
    set logging redirect on
    set logging on
    next
    set logging 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.




回答2:


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.



来源:https://stackoverflow.com/questions/43295269/gdb-disable-printing-of-current-line-after-every-step

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!