This is an archive of the discontinued LLVM Phabricator instance.

[lldb] [gdb-remote client] Refactor SetCurrentThread*()
ClosedPublic

Authored by mgorny on Apr 14 2021, 3:01 AM.

Details

Summary

Refactor SetCurrentThread() and SetCurrentThreadForRun() to reduce code
duplication and simplify it. Both methods now call common
SendSetCurrentThreadPacket() that implements the common protocol
exchange part (the only variable is sending Hg vs Hc) and returns
the selected TID. The logic is rewritten to use a StreamString
instead of snprintf().

A side effect of the change is that thread-id sent is now zero-padded.
However, this should not have practical impact on the server as both
forms are equivalent.

Diff Detail

Event Timeline

mgorny requested review of this revision.Apr 14 2021, 3:01 AM
mgorny created this revision.
rovka added a subscriber: rovka.Apr 28 2021, 2:14 AM

This looks good to me, but I'll let others comment on whether or not we want to send extra leading zeroes for the thread ID. In my opinion it would be nice to 1) be consistent between all packages that deal with thread ids, and 2) send as little clutter as possible. But these are just theoretical concerns, I'm not sure if it matters in practice.

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
339

Nitpick: You could call this 'op' instead of 'type', to match the documentation for the H packet.

mgorny marked an inline comment as done.Apr 28 2021, 2:41 AM

This looks good to me, but I'll let others comment on whether or not we want to send extra leading zeroes for the thread ID. In my opinion it would be nice to 1) be consistent between all packages that deal with thread ids, and 2) send as little clutter as possible. But these are just theoretical concerns, I'm not sure if it matters in practice.

To be honest, I didn't want to touch it because I don't know if one of the other uses of PutHex64() doesn't actually require fixed-width output.

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
339

Sounds like a good idea. Thanks!

mgorny updated this revision to Diff 341112.Apr 28 2021, 2:42 AM
mgorny marked an inline comment as done.

typeop.

JDevlieghere accepted this revision.Jul 1 2021, 1:53 PM
JDevlieghere added a subscriber: JDevlieghere.

LGTM

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
2648

Should this be LLDB_INVALID_THREAD_ID?

This revision is now accepted and ready to land.Jul 1 2021, 1:53 PM
mgorny added inline comments.Jul 1 2021, 2:13 PM
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
2648

No, LLDB_INVALID_THREAD_ID is 0, while here we expect -1. In fact, the original functions are called with literal -1 that gets converted to UINT64_MAX. I find it kinda ugly but I suppose it's a matter of taste.

This revision was landed with ongoing or failed builds.Jul 2 2021, 5:36 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 2 2021, 5:36 AM