cgdb的安装与使用

[[toc]]

前言

安装gdb cgdb就是一个带了curses 界面的gdb前端,比直接使用gdb好用一点点

noilinux 2.0 就是 ubuntu 20.04 ,ubuntu 20.04 下面的cgdb版本为0.6,有bug,所以这里我们手动编译安装cgdb 0.8

安装过程

安装依赖的包

sudo apt-get install -y libncurses5-dev flex bison texinfo libreadline-dev automake autotools-dev
ghproxy="https://mirror.ghproxy.com"
git clone -b v0.8.0 $ghproxy/https://github.com/cgdb/cgdb

编译安装

cd cgdb
./autogen.sh
./configure
make
sudo make install

配置

mkdir -p ~/.cgdb
cat << EOF > ~/.cgdb/cgdbrc
set winsplitorientation=vertical
EOF

上面的配置是使CGDB左边显示代码,右边显示调试界面

运行

cgdb -q 1

怎么使用

脚本

#!/usr/bin/env bash
# 快速调试程序的脚本
# 需要的程序 cgdb fzf find
# g 默认使用cgdb 调试 1.out < in
# g c 选择输入的程序与 in 文件

selected_program=1.out
selected_input_file=in

if [ -n "$1" ] && { [ "$1" = "c" ] || [ "$1" = "choose" ]; }; then
    selected_program=$(find . -maxdepth 1 -type f -name "*.out" | fzf \
        --height=~20% --tac --layout=reverse --border=top \
        --border-label="choose program" --border-label-pos=4 \
        --select-1 --ansi
    )
    # echo $selected_program

    if [ -z "$selected_program" ];then
        exit 0
    fi

    selected_input_file=$(find . -maxdepth 2 -type f -name "*in*" | fzf \
        --height=~20% --tac --layout=reverse --border=top \
        --border-label="choose input" --border-label-pos=4 \
        --select-1 --ansi
    )

    if [ -z "$selected_input_file" ];then
        exit 0
    fi
fi

if [ ! -f "$selected_program" ]; then
    echo "$selected_program 程序不存在"
fi


if [ ! -f "$selected_input_file" ]; then
    echo "$selected_input_file 输入文件不存在"
    cgdb $selected_program -- -q --ex "start"
else
    cgdb $selected_program -- -q --ex "start <${selected_input_file}"
fi

# echo $selected_program
# echo $selected_input_file

参考