【问题标题】:How to access gdb from python如何从python访问gdb
【发布时间】:2015-02-12 03:19:19
【问题描述】:

我正在寻找一种从 python 访问 gdb 的结果的方法。我需要使用 gdb 调试 c 程序并从 python 访问结果。这就像从 python 调用 gdb 来调试 c 程序。

【问题讨论】:

    标签: python linux gdb


    【解决方案1】:

    使用subprocess 在编译后的二进制文件上调用gdb(例如a.out):

    import subprocess
    
    # if you have arguments to gdb, you can supply then in the list itself.
    proc = subprocess.Popen(['gdb', 'a.out'],
                            stdin=subprocess.PIPE,
                            )
    proc.communicate('\tGDB Output:\n')
    

    参考:

    http://pymotw.com/2/subprocess/

    【讨论】:

      【解决方案2】:

      我认为您应该反转问题,而是通过扩展 gdb:https://sourceware.org/gdb/onlinedocs/gdb/Extending-GDB.html 添加所需的支持。当 python 在 gdb 中运行时,它可以访问 gdb API。有关更多详细信息,请参阅How to import 'GDB' in python

      【讨论】:

        猜你喜欢
        • 2023-03-18
        • 1970-01-01
        • 1970-01-01
        • 2011-04-01
        • 2014-07-30
        • 2021-07-08
        • 1970-01-01
        • 2015-08-24
        • 1970-01-01
        相关资源
        最近更新 更多