本文介绍了如何从PythonGDB(GDB 7.1)中的gdb.execute获取输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个Python GDB脚本。问题是它必须与GDB 7.1兼容。因此,我首先编写了GDB 7.3.1的脚本,并使用以下函数接收gdb命令(GDB 7.3.1)的输出:

  myvar = gdb.execute(info target,False,True)

这个函数的最后一个参数是它应该返回结果作为一个字符串(这很合理;为什么我会执行这样的命令;))

在GDB版本7.1虽然看起来最后一个参数因此,这一行(GDB 7.1):

$ p code $ myvar = gdb.execute(info target,False)

返回



是否有机会检索此命令的输出?我已经尝试将我的python脚本的标准输出重定向到一个文件中,然后加载这个文件,但显然我的python脚本的标准输入和输出是,因此gdb.execute命令的输出不会写入我的文件。



现在我唯一能想到的就是用一个bash脚本包装我的脚本,该脚本首先用一个执行各种命令的python脚本打开gdb,然后将其转换为文件。然后再次打开gdb,但使用另一个加载文件的python脚本,解析它,然后根据文件的输入执行其他命令等等。但是,这真是我能想到的最丑陋的解决方案。



那么有没有办法在GDB 7.1中接收gdb.execute的输出?

解决方案

没有。



最好的办法是安排GDB-7.3可用。由于GDB通常不使用共享库(除了libc和libpython之外),您可以将gdb binary与您的脚本一起复制。这比您提出的替代方案更容易,更易维护。


I'm currently writing a Python GDB script. The problem is that it has to be compatible with GDB 7.1. So I first wrote the script for GDB 7.3.1 and used the following function to receive the output of an gdb command (GDB 7.3.1):

myvar = gdb.execute("info target", False, True)

The last parameter of this function is that it should return the result as a string (which makes perfectly sense; why else would I execute such a command ;) )

In GDB Version 7.1 though it seems that the last parameter isn't available thus this line(GDB 7.1):

myvar = gdb.execute("info target", False)

returns None.

Is there any chance to retrieve the output of this command? I already tried to redirect the standard output of my python script into a file, then loading this file but apparently the standard input and output of my python script is overwritten by the gdb environment so the output from the gdb.execute command is not be written to my file.

The only thing I could think of now is to wrap my script up with a bash script that first opens gdb with a python script that executes various commands and then pipe that into a file. Then open gdb again but with another python script that loads the file, parses it and then executes other commands based on the input from the file and so on. But this is a really the ugliest solution I can think of.

So is there a way to receive the output of an gdb.execute in GDB 7.1?

解决方案

No.

Your best bet is to arrange for GDB-7.3 to be available. Since GDB doesn't usually use shared libraries (beyond libc and perhaps libpython), you can just copy gdb binary with your script. That will be much easier and more maintainable solution than the alternative you proposed.

这篇关于如何从PythonGDB(GDB 7.1)中的gdb.execute获取输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 08:22