This is an archive of the discontinued LLVM Phabricator instance.

Add JSONGenerator::DumpBinaryEscaped method in debugserver, update most callers to use this, skip escaping step
ClosedPublic

Authored by jasonmolenda on Apr 1 2022, 1:48 AM.

Details

Summary

Most packets which return JSON use JSONGenerator::Dump to print the string representation of the data, and then pass that string to another method to escape the #, $, }, and * characters which have special meaning in the gdb remote serial protocol. This generate-then-escape two step process involves duplicating the entire string, and for large data, can result in a lot of memory use.

This patch adds JSONGenerator::DumpBinaryEscaped methods for those cases where this is needed. The Dictionary, Array, and String methods involve duplicating the existing Dump methods, mostly to call the corresponding DumpBinaryEscaped methods on their children. The other JSON types do not need escaping, and call the regular Dump methods.

This is the follow on patch to https://reviews.llvm.org/D122848 , the two of them get us down from 3 string copies being held in heap, plus the JSON object tree, to the JSON object tree and one copy. For a large list of shared libraries, it can add up to quite a bit of memory use, and debugserver should try to be low impact on the system.

Diff Detail

Event Timeline

jasonmolenda created this revision.Apr 1 2022, 1:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2022, 1:48 AM
jasonmolenda requested review of this revision.Apr 1 2022, 1:48 AM
JDevlieghere added inline comments.Apr 1 2022, 8:52 AM
lldb/tools/debugserver/source/JSONGenerator.h
251–265

Can we avoid the quoted string and write directly to the stream?

Update patch to remove unnecessary temporary std::string when dumping a string into its JSON representation.

This revision was not accepted when it landed; it landed in state Needs Review.Apr 4 2022, 2:14 PM
This revision was automatically updated to reflect the committed changes.