简体   繁体   中英

How to use Python to create GDB subprocess and send commands dynamically based on output?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM