4

Is it possible to define an arbitrary key combination to a command in GDB? I would like to know if there is something like the VIM map command. For example, I would like to map to next, to step, and so on..

JohnTortugo
  • 6,356
  • 7
  • 36
  • 69

2 Answers2

3

To map keys in gdb (tested on gdb/cygwin/win7)

1. Start gdb
2. Find the key generated by F7, Press C-v F7
   (gdb) ^[[18~
3. vi ~/.inputrc
   # Map F7 to next
   "\e[18~": "n\n" 
4. Restart gdb, and now F7 will be mapped to "next\n" 

More Info here https://sourceware.org/gdb/onlinedocs/gdb/Readline-Init-File-Syntax.html

# Sample ~/.inputrc
$if Gdb
"\e[23~": "next\n # [F7] next.\n"  
"\e[A":  "# Up key\n"
"\e[B":  "next\n # [Down]  next line.\n"
"\e[C":  "step\n # [Right] step into func.\n"
"\e[D":  "finish\n # [Left] to finish.\n"
$endif

gdb has builtin text based gui called TUI mode, even works in cygwin/win7, Sample usage:

> g++ -Wall -g -lm -std=c++14 hello.cpp
> gdb -tui a.exe

Press C-x s .. for Single key mode

    q - quit, exit SingleKey mode.  
    c - continue
    d - down
    f - finish
    n - next
    r - run 
    s - step 
    u - up 
    v - info locals 
    w - where  

More info https://volse.anduin.net/rabalder/2015/06/01/gdb-tricks-text-based-ui.html and here https://ftp.gnu.org/old-gnu/Manuals/gdb/html_chapter/gdb_19.html

mosh
  • 1,402
  • 15
  • 16
2

GDB uses GNU readline to read the input. Documentation here (or just type man readline).

In particular, pay attention to the example of how to bind F1 to insert text Function key 1.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362