This is an archive of the discontinued LLVM Phabricator instance.

[lldb/qemu] Add support for pty redirection
ClosedPublic

Authored by labath on Nov 30 2021, 6:19 AM.

Details

Summary

Lldb uses a pty to read/write to the standard input and output of the
debugged process. For host processes this would be automatically set up
by Target::FinalizeFileActions. The Qemu platform is in a unique
position of not really being a host platform, but not being remote
either. It reports IsHost() = false, but it is sufficiently host-like
that we can use the usual pty mechanism.

This patch adds the necessary glue code to enable pty redirection. It
includes a small refactor of Target::FinalizeFileActions and
ProcessLaunchInfo::SetUpPtyRedirection to reduce the amount of
boilerplate that would need to be copied.

I will note that qemu is not able to separate output from the emulated
program from the output of the emulator itself, so the two will arrive
intertwined. Normally this should not be a problem since qemu should not
produce any output during regular operation, but some output can slip
through in case of errors. This situation should be pretty obvious (to a
human), and it is the best we can do anyway.

For testing purposes, and inspired by lldb-server tests, I have extended
the mock emulator with the ability "program" the behavior of the
"emulated" program via command-line arguments.

Diff Detail

Event Timeline

labath requested review of this revision.Nov 30 2021, 6:19 AM
labath created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 30 2021, 6:19 AM
DavidSpickett added inline comments.Nov 30 2021, 7:06 AM
lldb/source/Target/Target.cpp
3324

What's the logic to this change? I thought maybe the !in_file_spec... were redundant but not 100% sure.

lldb/test/API/qemu/TestQemuLaunch.py
75

out -> our?

labath marked an inline comment as done.Nov 30 2021, 7:39 AM
labath added inline comments.
lldb/source/Target/Target.cpp
3324

The original code was trying to avoid calling this function in case all three actions were set. It was almost redundant, as SetUpPtyRedirection had the same checks already -- the only difference was that the function would unconditionally create the pty master (and then not use it). So I've added an early exit to that function and that way I could avoid doing the same checks in the new platform.

labath updated this revision to Diff 390722.Nov 30 2021, 7:39 AM

fix typo

This revision is now accepted and ready to land.Dec 1 2021, 3:06 AM
This revision was automatically updated to reflect the committed changes.