This is an archive of the discontinued LLVM Phabricator instance.

Generalize child process monitoring functions
ClosedPublic

Authored by labath on May 10 2016, 8:27 AM.

Details

Summary

This replaces the C-style "void *" baton of the child process monitoring functions with a more
C++-like API taking a std::function. The motivation for this was that it was very difficult to
handle the ownership of the object passed into the callback function -- each caller ended up
implementing his own way of doing it, some doing it better than others. With the new API, one can
just pass a smart pointer into the callback and all of the lifetime management will be handled
automatically.

This has enabled me to simplify the rather complicated handshake in Host::RunShellCommand. I have
left handling of MonitorDebugServerProcess (my original motivation for this change) to a separate
commit to reduce the scope of this change.

Diff Detail

Repository
rL LLVM

Event Timeline

labath updated this revision to Diff 56721.May 10 2016, 8:27 AM
labath retitled this revision from to Generalize child process monitoring functions.
labath updated this object.
labath added a subscriber: lldb-commits.

I am going to try building this on as many systems as I can get my hands on tomorrow, as I am pretty sure I have missed some changes on host-specific code. I am posting this here now, to get early feedback and some round-trips.

I am going to try building this on as many systems as I can get my hands on tomorrow, as I am pretty sure I have missed some changes on host-specific code. I am posting this here now, to get early feedback and some round-trips.

... avoid some round-trips.

clayborg requested changes to this revision.May 10 2016, 12:39 PM
clayborg edited edge metadata.

Just get rid of the extra typedef as specified in inline comments and this is good to go.

include/lldb/Host/HostProcess.h
41 ↗(On Diff #56721)

We can probably get rid of this and just use Host::MonitorChildProcessCallback

54 ↗(On Diff #56721)

Use Host::MonitorChildProcessCallback directly.

include/lldb/Host/posix/HostProcessPosix.h
43 ↗(On Diff #56721)

Use Host::MonitorChildProcessCallback directly

This revision now requires changes to proceed.May 10 2016, 12:39 PM
zturner edited edge metadata.May 10 2016, 12:43 PM
zturner added a subscriber: zturner.

It's too bad llvm doesn't have an equivalent of boost::any, because that
would be perfect here :-/

emaste edited edge metadata.May 10 2016, 12:51 PM

Nice.

For test building FreeBSD, snapshot VM images are available at ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/VM-IMAGES/11.0-CURRENT/amd64/Latest/ and I have some instructions for building lldb on FreeBSD at https://wiki.freebsd.org/lldb.

labath updated this revision to Diff 56903.May 11 2016, 6:47 AM
labath edited edge metadata.
labath marked 3 inline comments as done.

Remove the typedef and add changes to windows, osx, and freebsd-specific code. I didn't
try building NetBSD, but given that there is no Plugins/Process/NetBSD, I don't think I
need to do any changes there at all. I'll keep an eye out on the buildbots after
submitting this.

I'd like to draw attention to the osx change in Host.mm in particular, as I not too
familiar with objjective c, but making a copy there made the thing work for me (without
that, I was getting errors, presumably because the block was only capturing the
reference, which was not enough if to keep the function object alive).

It's too bad llvm doesn't have an equivalent of boost::any, because that
would be perfect here :-/

I actually think that a std::function is better here than an any type because it ensures type safety (even though std::function will use something equivalent to any underneath). What makes this API slightly cumbersome in my mind is the fact that we have 4 arguments which we are forwarding. If we condensed that into say 2 (pid, and a struct StopInfo), then I think it would be perfect.

clayborg accepted this revision.May 11 2016, 9:35 AM
clayborg edited edge metadata.
This revision is now accepted and ready to land.May 11 2016, 9:35 AM
krytarowski edited edge metadata.May 11 2016, 9:47 AM

I'm going to test NetBSD.

This revision was automatically updated to reflect the committed changes.