问题描述
众所周知,随着IDE的普及,越来越多的人不习惯命令行调试,但是Linux开发又绕不开GDB,所以有大佬开发了程序用来显示常见的一些调试参数,gdb-dashboard
是比较热门的程序之一。附链接。
使用参考
神仙GDB调试工具 gdb-dashboard
还有github的wiki
可能存在的问题
- 设置语法高亮
gdb-dashboard
安装完成之后,安装pygments
,调试source显示这样:
显然没有高亮,所以需要找问题出在哪里。
所以先看看可选的pygments
的style
,在gdb中执行:
python
from pygments.styles import *
for style in get_all_styles():
print(style)
end
提示没有安装pygments
。这时就要考虑python的环境了。
python
import sys
print(sys.version)
end
可见此处的python
版本是3.6.9,我们去gdb外看一下:(ubuntu1804)
所以可得该GDB内部的interpreter是python3。
下图链接。
#1、如果已经安装python2和python3,但没有安装pip
#python2安装pip:
sudo apt install python-pip
#python3安装pip:
sudo apt install python3-pip
#2、如果已经安装python2和python3,同时两个环境下也分别安装了相应的pip
#使用pip给python2环境装软件:
python2 -m pip install XXX
#使用pip给python3环境装软件:
python3 -m pip install XXX
再回到gdb环境
查看可选的style可在gdb环境中执行get_all_styles
,输出:
default
emacs
friendly
friendly_grayscale
colorful
autumn
murphy
manni
material
monokai
perldoc
pastie
borland
trac
native
fruity
bw
vim
vs
tango
rrt
xcode
igor
paraiso-light
paraiso-dark
lovelace
algol
algol_nu
arduino
rainbow_dash
abap
solarized-dark
solarized-light
sas
staroffice
stata
stata-light
stata-dark
inkpot
zenburn
gruvbox-dark
gruvbox-light
dracula
one-dark
lilypond
nord
nord-darker
github-dark
修改为rainbow_dash
:
dashboard -style syntax_highlighting 'rainbow_dash'
不过这种修改是临时的,如果需要永久生效,则:
每次配置完,执行:
dashboard -configuration ~/.gdbinit.d/init
随便聊聊
通过配置gdb-dashboard
大体上知道了gdb对python
的支持,gdb manual中有Basic Python
章节可以参考,以及这篇Python in GDB博文.
(gdb) python print(gdb.PYTHONDIR)
对于交叉编译器,
安装到/usr/local(可选)
结合上一篇,配置configure
:
#由于gdb在host上跑,所以不配置host,默认当前ubuntu系统下运行
#--with-python指定python路径
./configure --with-python=/usr/bin/python3 --prefix="/usr/local" --target=aarch64-himix100-linux --program-prefix=hisi-
make -j16
make install
如果未生效,将程序路径加入配置项:
vi /etc/profile
#让环境变量立即生效需要执行如下命令:
source /etc/profile
附:Linux里设置环境变量的方法(export PATH)
GDB Tips and Tricks #1: A Tale of Two Terminals
AutoTools的使用
Changing the Install Directory with make install,这个网站有一些很不错的内容。