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.

相关推荐
咖猫18 分钟前
Guava 库中的 `Multimap` 是一个允许一个键对应多个值的集合 Guava `Multimap` 的基本代码示例:
开发语言·python·guava
枫叶红花26 分钟前
【Linux系统编程】:信号(1)——前置知识,了解信号
linux·运维·服务器
觅远1 小时前
python实现Word转PDF(comtypes、win32com、docx2pdf)
python·pdf·自动化·word
7yewh1 小时前
嵌入式驱动RK3566 HDMI eDP MIPI 背光 屏幕选型与调试提升篇-eDP屏
linux·arm开发·驱动开发·嵌入式硬件·嵌入式linux·rk·edp
CV猿码人2 小时前
在已经加载的页面中动态显示一段话或者一张图片
python
工业3D_大熊2 小时前
HOOPS Communicator功能剖析:3D Web模型树交互的实用指南!
linux·windows·macos·3d·docker·c#·.net
宸码2 小时前
【项目实战】ISIC 数据集上的实验揭秘:UNet + SENet、Spatial Attention 和 CBAM 的最终表现
人工智能·python·深度学习·神经网络·机器学习·计算机视觉
丶Darling.2 小时前
进程间通信博客总结目录
linux·网络编程·进程同步·系统编程·c/c++·阻塞和非阻塞
lly_csdn1232 小时前
【路径规划】原理及实现
python·算法·路径规划
豌豆花下猫2 小时前
Python 潮流周刊#82:美国 CIA 如何使用 Python?(摘要)
后端·python·ai