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.

相关推荐

  1. GDB 使用python

    2024-05-12 17:42:06       37 阅读
  2. <span style='color:red;'>gdb</span><span style='color:red;'>使用</span>

    gdb使用

    2024-05-12 17:42:06      63 阅读
  3. gdb使用

    2024-05-12 17:42:06       34 阅读
  4. GDB使用

    2024-05-12 17:42:06       28 阅读
  5. gdb print,gdb x和gdb display的使用

    2024-05-12 17:42:06       67 阅读
  6. 在docker容器中使用gdb调试python3.11的进程

    2024-05-12 17:42:06       29 阅读
  7. Linux中gdb使用说明书

    2024-05-12 17:42:06       32 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-12 17:42:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-12 17:42:06       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-12 17:42:06       82 阅读
  4. Python语言-面向对象

    2024-05-12 17:42:06       91 阅读

热门阅读

  1. sql中的lag()和lead()是什么意思

    2024-05-12 17:42:06       36 阅读
  2. Go语言基础知识学习

    2024-05-12 17:42:06       26 阅读
  3. Android App开机启动

    2024-05-12 17:42:06       37 阅读
  4. vim 查找字符串的命令

    2024-05-12 17:42:06       35 阅读
  5. 关于XDC 约束固化flash流程

    2024-05-12 17:42:06       101 阅读
  6. 学习Uni-app开发小程序Day8

    2024-05-12 17:42:06       33 阅读