سؤال

I have a function dump() which, when invoked on an object of type X, prints out something useful to stderr.

I'm trying to write a GDB pretty-print script that utilizes the output of some command to return a string describing a value, something along these lines:

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

Unfortunately, this gives me:

warning: Current output protocol does not support redirection

How can I solve this issue? Is this even the right approach to get the stderr output?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top