This is an archive of the discontinued LLVM Phabricator instance.

NPL: Clean up handling of inferior exit
ClosedPublic

Authored by labath on Dec 11 2017, 7:39 AM.

Details

Summary

lldb-server was sending the "exit" packet (W??) twice. This happened
because it was handling both the pre-exit (PTRACE_EVENT_EXIT) and
post-exit (WIFEXITED) as exit events. We had some code which was trying
to detect when we've already sent the exit packet, but this stopped
working quite a while ago.

This never really caused any problems in practice because the client
automatically closes the connection after receiving the first packet, so
the only effect of this was some warning messages about extra packets
from the lldb-server test suite, which were ignored because they didn't
fail the test.

The new test suite will be stricter about this, so I fix this issue
ignoring the first event. I think this is the correct behavior, as the
inferior is not really dead at that point, so it's premature to send the
exit packet.

There isn't an actual test yet which would verify the exit behavior, but
in my next patch I will add a test which will also test this
functionality.

Event Timeline

labath created this revision.Dec 11 2017, 7:39 AM

Is the lldb_private::Process we have an exit status in the class itself. The first person to set the exit status wins and no one can set it twice. Doesn't look like what we are doing here. I am not able to tell what actually fixes things here?

unittests/tools/lldb-server/tests/TestClient.cpp
43

space after if and not after (

Is the lldb_private::Process we have an exit status in the class itself. The first person to set the exit status wins and no one can set it twice. Doesn't look like what we are doing here. I am not able to tell what actually fixes things here?

The Process class is in the client. The problem I am fixing is in server code, which was sending the Wxx packet multiple times. The happened because on linux we get one ptrace stop before the process dies (in this state its memory still exists, so we could still inspect it, if we wanted to) and then another one after its death (this happens after zombification of the process), and we were sending the packet after both.

source/Plugins/Process/Linux/NativeProcessLinux.cpp
439

This is where the second packet got sent. Now it's the only place that sends death packets.

681

This is what sent the first packet (it eventually trickles down into GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited, which is what does the sending). Deleting it fixes things.

labath updated this revision to Diff 126389.Dec 11 2017, 9:43 AM

apply clang-format

eugene accepted this revision.Dec 11 2017, 1:40 PM
This revision is now accepted and ready to land.Dec 11 2017, 1:40 PM
This revision was automatically updated to reflect the committed changes.