如何使用Python创建GDB子流程并根据输出动态发送命令? [英] How to use Python to create GDB subprocess and send commands dynamically based on output?
问题描述
我想通过创建GDB的子进程来使用Python来实现这一点。然后我想发送命令到GDB并从GDB读取输出。我会使用输出来根据输出的内容动态地发送更多的命令给GDB。
有人可以提供一个简单的例子来说明如何做到这一点吗?
非常感谢您!
使用Pexpect: http://pexpect.readthedocs.org/en/latest/examples.html
更基本的选择是使用 subprocess.Popen()。communicate()
:
http://pymotw.com/2/subprocess/#popen2
Here's a general example of what I need to do:
For example, I would initiate a back trace by sending the command "bt" to GDB from the program. Then I would search for a word such as "pardrivr" and get the line number associated with it by using regular expressions. Then I would input "f [line_number_of_pardriver]" into GDB. This process would be repeated until the correct information is eventually extracted.
I want to use Python to accomplish this by creating a subprocess of GDB. Then I want to send commands to GDB and read output from GDB. I would use the output to send more commands to GDB dynamically based on the content of the output.
Could someone please provide a simple example of how to do this?
Thank you so much!
Use Pexpect: http://pexpect.readthedocs.org/en/latest/examples.html
A more basic option is using subprocess.Popen().communicate()
:
http://pymotw.com/2/subprocess/#popen2
这篇关于如何使用Python创建GDB子流程并根据输出动态发送命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!