This is an archive of the discontinued LLVM Phabricator instance.

update ScriptInterpreterPython to use File, not FILE*
ClosedPublic

Authored by lawrence_danna on Oct 14 2019, 4:37 PM.

Details

Summary

ScriptInterpreterPython needs to save and restore sys.stdout and
friends when LLDB runs a python script.

It currently does this using FILE*, which is not optimal. If
whatever was in sys.stdout can not be represented as a FILE*, then
it will not be restored correctly when the script is finished.

It also means that if the debugger's own output stream is not
representable as a file, ScriptInterpreterPython will not be able
to redirect python's output correctly.

This patch updates ScriptInterpreterPython to represent files with
lldb_private::File, and to represent whatever the user had in
sys.stdout as simply a PythonObject.

This will make lldb interoperate better with other scripts or programs
that need to manipulate sys.stdout.

Diff Detail

Event Timeline

lawrence_danna created this revision.Oct 14 2019, 4:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2019, 4:37 PM
labath accepted this revision.Oct 15 2019, 12:46 AM
labath added inline comments.
lldb/source/Core/Debugger.cpp
977

The call to reset seems superfluous, as the value will be overwritten anyway.

This revision is now accepted and ready to land.Oct 15 2019, 12:46 AM
lawrence_danna marked an inline comment as done.

remove superfluous resets

This revision was automatically updated to reflect the committed changes.