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.

相关推荐
jingyu飞鸟4 小时前
linux系统二进制安装MySQL 8.4、8.0版本数据库,配置crontab和xtrabackup数据库热备份脚本
linux·数据库·mysql
无限进步_4 小时前
从Multics到Linux:操作系统的自由之路
linux·运维·服务器
China_Yanhy4 小时前
【云原生实战】从零构建无节点 EKS:Karpenter 极简注入与全自动算力接管指南
linux·运维·云原生
小江的记录本4 小时前
【MySQL】《MySQL日志面试背诵版+思维导图》(核心考点 + MySQL 8.0最新优化)
java·数据库·后端·python·sql·mysql·面试
北山有鸟4 小时前
常用的快捷键
linux·前端·chrome·单片机·学习
西洼工作室4 小时前
Python邮箱工具类封装:高效邮件发送与管理
python·全栈
子午4 小时前
基于YOLO的水稻害虫检测系统~Python+yolov8算法+深度学习+人工智能+模型训练
人工智能·python·yolo
岳来4 小时前
Linux Capabilities(能力机制)细分学习
linux·root
我命由我123454 小时前
Android Framework P2 - 开机启动 Zygote 进程、Zygote 的预加载机制
android·java·开发语言·python·java-ee·intellij-idea·zygote
哈哈浩丶4 小时前
存储相关知识②—eMMC协议
linux·驱动开发·emmc