Using less as gdb pager

Starting with version 9.1, GDB has a pipe command, so you can send a command's output to the pager of your choice. From the documentation:

pipe [command] | shell_command
Executes command and sends its output to shell_command. Note that no space is needed around |. If no command is provided, the last command executed is repeated.


Is it possible to replace the default pager with another one

No: GDB doesn't call into external program to display the output, it simply pauses the output every screenfull (and you can make it not pause by set height 0).

In addtion to running inside emacs, you could also use screen or tmux (learning them will generally help you in a lot of other situations), or ask GDB to log output (set logging on) and then search in gdb.txt with any $PAGER you want.


you can put the following user-defined commands in ~/.gdbinit, then

% cat ~/.gdbinit
python import os
define less1
    python os.popen("less","w").write(gdb.execute("$arg0",to_string=True))
end

define less2
    python os.popen("less","w").write(gdb.execute("$arg0 $arg1",to_string=True))
end
...
% gdb
(gdb) less2 info var
...
(gdb) less1 disass
...

run gdb inside of emacs and you should be able to use emacs' paging commands.

  1. run emacs
  2. type M-x gdb return (M stands for meta - alt key or option on Macs)
  3. The Emacs message bar will now display the message: Run gdb (like this): gdb

More information is available here: http://tedlab.mit.edu/~dr/gdbintro.html

HTH

Tags:

Gdb