GDB中的键映射

时间:2012-10-26 16:22:06

标签: debugging gcc gdb binutils

是否可以在GDB中为命令定义任意组合键?我想知道是否有类似VIM map命令的东西。例如,我想映射到下一步,步骤等等..

2 个答案:

答案 0 :(得分:3)

GDB使用GNU readline来读取输入。文档here(或只需键入man readline)。

特别要注意如何绑定F1以插入文本Function key 1

答案 1 :(得分:0)

映射gdb中的密钥(在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" 

更多信息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内置基于文本的gui称为TUI模式,甚至适用于cygwin / win7,样例用法:

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

按C-x s ..进行单键模式

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

更多信息https://volse.anduin.net/rabalder/2015/06/01/gdb-tricks-text-based-ui.html和此处https://ftp.gnu.org/old-gnu/Manuals/gdb/html_chapter/gdb_19.html