This is an archive of the discontinued LLVM Phabricator instance.

[lldb/Lua] Use the debugger's output and error file for Lua's I/O library.
ClosedPublic

Authored by JDevlieghere on Jun 21 2020, 12:35 AM.

Details

Reviewers
labath
Group Reviewers
Restricted Project
Summary

Add support for changing the stdout and stderr file in Lua's I/O library and hook it up with the debugger's output and error file respectively for the interactive Lua interpreter.

Diff Detail

Event Timeline

JDevlieghere created this revision.Jun 21 2020, 12:35 AM

I have some questions (but no definitive answers) inline...

lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
64

What should be the behavior if this is null? Can it even be null (should we be asserting that it isn't)?
It's not clear to me that we should be reusing the previously set stdout if these arguments are null... Maybe we should be saving the original stdout value and restoring it when we are done? That's what the python interpreter seems to be doing..

65–66

lua_getfield(m_lua_state, -1, "stdout")

68

I guess it would be better to use luaL_testudata(m_lua_state, -1, LUA_FILEHANDLE) as that also checks that the user data is of the expected type (and e.g. it was not replaced by the user).

Or it might actually be better to just overwrite the value of io.stdout/err with a new value/userdata object, instead of fiddling with the existing one.

JDevlieghere marked 4 inline comments as done.
JDevlieghere added inline comments.
lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
64

I don't really see a benefit to storing it, I'm fine with just asserting that the file is not null.

labath accepted this revision.Jun 23 2020, 12:52 AM
labath added inline comments.
lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
64

Ok, that's fine. But then you should remove the =nullptr default arguments.

This revision is now accepted and ready to land.Jun 23 2020, 12:52 AM
JDevlieghere closed this revision.Jun 23 2020, 10:35 AM
JDevlieghere marked an inline comment as done.

Forgot the Differential revision in front of the phab URL. Closed by fa1b4a96a0110c87cdd83eb4ea3e9a0d002c3c3d