GDB 使用python

Please read the user spec Debugging with GDB (Tenth Edition, for GDB version 13.0.50.20221115-git)chapter 23.3 Extending GDB using Python.

Please notice that: if the GDB version which you are using is old (maybe version 6 or older), maybe it does not support python. Update your GDB.

1. Check PYTHONDIR

复制代码
(gdb) python
> print(gdb.PYTHONDIR)
> end
/usr/bin/share/gdb/python

By the command print(gdb.PYTHONDIR) , we can get the directory of python that GDB are using.

2. Config ~/.gdbinit

复制代码
python
import sys
sys.path.insert(0, "/usr/share/gcc-8/python")
from libstdcxx.v6 import register_libstdcxx_printers
register_libstdcxx_printers(None)
end

Insert python path and register the pretty printers for printing c++ containers.

3. Example

复制代码
(gdb) python
>print(gdb.parse_and_eval("1+1"))
>end
2

You can parse and evalute the value of expression by using command gdb.parse_and_eval("expression")). The "expression" can be a pointer or an object in c++ context, and python wil evalute the value automatically. The feature is very useful, and you can wrap a function in ~/.gdbinit in order to impove debugging experience.

At the end, Suggest you oftern read GDB user spec.

相关推荐
_dindong9 小时前
Linux网络编程:结合内核数据结构详谈epoll的工作原理
linux·服务器·网络
了一梨9 小时前
在Ubuntu中配置适配泰山派的交叉编译环境
linux·c语言·ubuntu
buyutang_9 小时前
Linux网络编程:Socket套接字编程概念及常用API接口介绍
linux·服务器·网络·tcp/ip
杨云龙UP9 小时前
从0搭建Oracle ODA NFS异地备份:从YUM源到RMAN定时任务的全流程
linux·运维·数据库·oracle
DN金猿9 小时前
恢复 Linux 上误删除的文件
linux·运维·服务器
远瞻。10 小时前
【环境配置】Ubuntu系统安装cuda
linux·运维·ubuntu
kyle~10 小时前
Linux---<unistd.h>类Unix系统编程核心头文件
linux·运维·unix
ID_1800790547310 小时前
基于 Python 的 Cdiscount 商品详情 API 调用与 JSON 核心字段解析(含多规格 SKU 提取)
开发语言·python·json
python百炼成钢10 小时前
55.Linux ADC框架(IIO续)
linux·运维·服务器·驱动开发
祎直向前10 小时前
重装Ubuntu之后重连VSCode
linux·vscode·ubuntu