This is an archive of the discontinued LLVM Phabricator instance.

[lldb/test] Add ability to terminate connection from a gdb-client handler
ClosedPublic

Authored by labath on Nov 18 2021, 5:35 AM.

Details

Summary

We were using the client socket close as a way to terminate the handler
thread. But this kind of concurrent access to the same socket is not
safe. It also complicates running the handler without a dedicated thread
(next patch).

Instead, here I add an explicit way for a packet handler to request
termination. Waiting for lldb to terminate the connection would almost
be sufficient, but in the pty test we want to keep the pty open so we
can examine its state. Ability to disconnect at an arbitrary point may
be useful for testing other aspects of lldb functionality as well.

The way this works is that now each packet handler can optionally return
a list of responses (instead of just one). One of those responses (it
only makes sense for it to be the last one) can be a special
RESPONSE_DISCONNECT object, which triggers a disconnection (via a new
TerminateConnectionException).

As the mock server now cleans up the connection whenever it disconnects,
the pty test needs to explicitly dup(2) the descriptors in order to
inspect the post-disconnect state.

Diff Detail

Event Timeline

labath requested review of this revision.Nov 18 2021, 5:35 AM
labath created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 18 2021, 5:35 AM
mgorny added inline comments.Nov 18 2021, 6:20 AM
lldb/packages/Python/lldbsuite/test/gdbclientutils.py
89

How about making it a class instead? It should make debugging easier, if it ever comes to that.

In [6]: RESPONSE_DISCONNECT = object()

In [7]: RESPONSE_DISCONNECT
Out[7]: <object at 0x7f406dd328e0>

In [8]: class RESPONSE_DISCONNECT: pass

In [9]: RESPONSE_DISCONNECT
Out[9]: __main__.RESPONSE_DISCONNECT
611

It feels weird that you're raising class rather than an object.

labath added inline comments.Nov 18 2021, 9:48 AM
lldb/packages/Python/lldbsuite/test/gdbclientutils.py
89

I wouldn't call myself an expert on idiomatic python, but I was under the impression this is how one is expected to do these things https://python-patterns.guide/python/sentinel-object/ (?)

611

It looks like the class gets automatically instantiated (https://docs.python.org/3/tutorial/errors.html#raising-exceptions), though now that I think about it, I am actually surprised that it does :P

labath updated this revision to Diff 388248.Nov 18 2021, 9:52 AM

Don't try to raise classes

mgorny added inline comments.Nov 18 2021, 10:07 AM
lldb/packages/Python/lldbsuite/test/gdbclientutils.py
89

Well, I see both versions in CPython stdlib but the advantage of using a class is that it gives clear repr() rather than identifying as an arbitrary object. You can also create an object of the sentinel class ;-).

labath updated this revision to Diff 388263.Nov 18 2021, 10:39 AM

use a class sentinel

mgorny accepted this revision.Nov 18 2021, 11:19 AM

LGTM

This revision is now accepted and ready to land.Nov 18 2021, 11:19 AM