在OpenEuler中安裝輕量化調試工具CGDB
前言
調試工具在開發過程中是必不可少的,linux系統下可以使用cgdb
,ddd
這樣輕量化的調試工具,也可以安裝vscode
這樣的IDE,但上述調試工具在 OpenEuler 系統中,都沒有集成到軟件源中,我們只能使用linux系統下的傳統調試工具GDB
,這就給我們帶來諸多不便。
CGDB簡介
CGDB is a very lightweight console frontend to the GNU debugger.
It provides a split screen interface showing the GDB session below and the program's source code above.
The interface is modelled after vim's, so vim users should feel right at home using it.
cgdb可以看作gdb的界面增強版,用來替代gdb的 gdb -tui。cgdb主要功能是在調試時進行代碼的同步顯示,這無疑增加了調試的方便性,提高了調試效率。界面類似vi,符合unix/Linux下開發人員習慣,所以如果熟悉gdb和vi,幾乎可以立即使用cgdb。
CGDB功能
主要功能介紹:
- 相比GDB,增加了語法加亮的代碼窗口,顯示在GDB窗口的上部,隨GDB的調試位置代碼同步顯示。
- 斷點設置可視化 。
- 在代碼窗口中可使用GDB常用命令 。
- 在代碼窗口可進行代碼查找,支持正則表達式 。
CGDB在OpenEuler系統中安裝
CGDB依賴
CGDB依賴於以下軟件或環境
Dependencies
- sh
- autoconf
- automake
- aclocal
- autoheader
- libtool
- flex
- bison
- gcc/g++ (c11/c++11 support)
若為OpenEuler20.03LTS 則需要安裝 flex
bison
通過yum install “”來安裝
通過git安裝
git clone https://gitee.com/mirrors/CGDB.git
./configure --prefix=/usr/local
由於依賴可能會出現各種報錯
出現錯誤:
configure: error: CGDB requires curses.h or ncurses/curses.h to build.
解決方案:
yum install ncurses-devel
出現錯誤:
configure: error: Please install makeinfo before installing
示例:
解決方案:
示例:
yum install texinfo
如果是 CentOS 8.0 及以上系統,需要先執行:
yum config-manager --set-enabled PowerTools
出現錯誤:
configure: error: Please install help2man
解決方案:
yum install help2man
出現錯誤:
configure: error: CGDB requires GNU readline 5.1 or greater to link.
If you used --with-readline instead of using the system readline library,
make sure to set the correct readline library on the linker search path
via LD_LIBRARY_PATH or some other facility.
解決方案:
yum install readline-devel
出現錯誤:
configure: error: Please install flex before installing
解決方案:
yum install flex
在報錯后執行
make
sudo make install
通過wget安裝
wget http://cgdb.me/files/cgdb-0.7.0.tar.gz
tar -zvxf cgdb-0.7.0.tar.gz
cd cgdb-0.7.0
./configure –prefix=/usr/local
make && make install
同樣安裝過程中出現各種依賴錯誤
解決方案同上
安裝成功與使用
輸入 cgdb
+ 要調試的程序名
即可以進行調試
CGDB 大部分命令 與 GDB 一致
其他詳情可參考 《CGDB中文手冊》
少量補充
-
調整代碼窗口的大小
先按esc退出輸入gdb命令, 按 '-'或'='號會上下移動窗口分隔欄 -
打開TTY窗口
tty窗口可以顯示程序輸出,也可以在這里輸入參數
按shift+t會打開TTY窗口,再按shift+t關閉TTY窗口
按esc后,再按 I 可以把焦點切到tty窗口上
按esc后,再按 i 可以把焦點切到gdb窗口上 -
調整TTY窗口大小
shift+-或shift+=會放大或縮小TTY窗口 -
按o打開瀏覽文件
-
F5: 發送一個run命令至GDB
-
F6: 發送一個continue命令至GDB
-
F7: 發送一個finish命令至GDB
-
F8: 發送一個next命令至GDB
-
F10: 發送一個step命令至GDB
PS:軟件源里沒有的程序裝起來是真的麻煩
還是希望OpenEuler能夠將更多應用進行適配和打包。
20191331lyx
2021/9/19