1

我有一个函数dump(),当在 type 对象上调用时X,它会打印出对 stderr 有用的东西。

我正在尝试编写一个 GDB 漂亮打印脚本,该脚本利用某些命令的输出返回一个描述值的字符串,类似于以下内容:

return gdb.execute(str(self.val) + '.dump()', False, True)

不幸的是,这给了我:

警告:当前输出协议不支持重定向

我该如何解决这个问题?这甚至是获得 stderr 输出的正确方法吗?

4

1 回答 1

2

It isn't totally clear from your question, but I assume that "dump" is a method in your program, not a method on a Python object in gdb.

In this case, the only way I can think of to accomplish what you want is to temporarily redirect stderr to a string (using iostreams or the libc equivalent), call the function, and then restore stderr. Finally, have gdb use the resulting string.

This is extremely roundabout. It would be simpler to change your "dump" function.

It is usually best not to have pretty-printers do inferior function calls. First, this can break or otherwise act weirdly in some scenarios (like: "break dump" and then "bt" -- probably something bad happens). Also, it prevents you from using pretty-printing with core files.

于 2013-05-30T01:41:39.910 回答