[Lldb-commits] [PATCH] D93225: [lldb] Add helper class for dealing with key:value; GDB responses

David Spickett via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 14 08:27:36 PST 2020


DavidSpickett created this revision.
Herald added a subscriber: mgorny.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The current handling of qHostInfo is a bunch of if-else,
one for each key we think we might find. This works fine,
but we end up repeating parsing calls and extending it
gets tricky.

To improve this I'm adding KeyValueExtractorGDBRemote.
This is a class that takes the packet response and splits it up
into the key-value pairs. Where a pair is "<key>:<value>;".

Then you can do Get<T>(<key>) to get an Optional<T>.
This Optional is empty if the key was missing or its value
didn't parse as the T you asked for.

Or you can GetWithDefault<T>(<key>, <default value>)
which always gives you a T but if search/parse fails
then you get <default value>.

Plus specific methods to get LazyBool and hex encoded
string keys.

This improves the packet handling code by:

- Putting the type, key name and default value on the same line.
- Reducing the number of repeated parsing calls. (fewer "!value.getAsInteger(0, ...)" means fewer chances to forget a "!")
- Removing the need for num_keys_decoded, which was essentially a boolean but was treated as a running total. (replaced with HadValidKey)

We do pay an up front cost in building the map of keys up
front. However these packets are infrequent and the increase
in readability makes up for it.

This change adds the class and applies it to qHostInfo, keeping
the original logic intact. (future patches will apply it to
other packets and refactor post decode logic)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93225

Files:
  lldb/include/lldb/Utility/KeyValueExtractorGDBRemote.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/KeyValueExtractorGDBRemote.cpp
  lldb/unittests/Utility/CMakeLists.txt
  lldb/unittests/Utility/KeyValueExtractorGDBRemoteTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93225.311601.patch
Type: text/x-patch
Size: 29356 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201214/b11607f4/attachment-0001.bin>


More information about the lldb-commits mailing list