From fcdb1af655a80b4f1b4f17929235613216ebaaf5 Mon Sep 17 00:00:00 2001 From: Todd Fiala Date: Sat, 10 Sep 2016 00:06:29 +0000 Subject: async structured data packet handling improvements This change does the following: * Changes the signature for the continuation delegate method that handles async structured data from accepting an already-parsed structured data element to taking just the packet contents. * Moves the conversion of the JSON-async: packet contents from GDBRemoteClientBase to the continuation delegate method. * Adds a new unit test for verifying that the $JSON-asyc: packets get decoded and that the decoded packets get forwarded on to the delegate for further processing. Thanks to Pavel for making that whole section of code easily unit testable! * Tightens up the packet verification on reception of a $JSON-async: packet contents. The code prior to this change is susceptible to a segfault if a packet is carefully crafted that starts with $J but has a total length shorter than the length of "$JSON-async:". Reviewers: labath, clayborg, zturner Differential Revision: https://reviews.llvm.org/D23884 llvm-svn: 281121 --- .../Process/gdb-remote/GDBRemoteClientBase.cpp | 33 ++-------------------- 1 file changed, 2 insertions(+), 31 deletions(-) (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp') diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp index 3b27c10db4a..853e201249b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp @@ -103,38 +103,9 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse( delegate.HandleAsyncMisc( llvm::StringRef(response.GetStringRef()).substr(1)); break; - case 'J': - // Asynchronous JSON packet, destined for a - // StructuredDataPlugin. - { - // Parse the content into a StructuredData instance. - auto payload_index = strlen("JSON-async:"); - StructuredData::ObjectSP json_sp = StructuredData::ParseJSON( - response.GetStringRef().substr(payload_index)); - if (log) { - if (json_sp) - log->Printf("GDBRemoteCommmunicationClientBase::%s() " - "received Async StructuredData packet: %s", - __FUNCTION__, - response.GetStringRef().substr(payload_index).c_str()); - else - log->Printf("GDBRemoteCommmunicationClientBase::%s" - "() received StructuredData packet:" - " parse failure", - __FUNCTION__); - } - - // Pass the data to the process to route to the - // appropriate plugin. The plugin controls what happens - // to it from there. - bool routed = delegate.HandleAsyncStructuredData(json_sp); - if (log) - log->Printf("GDBRemoteCommmunicationClientBase::%s()" - " packet %s", - __FUNCTION__, routed ? "handled" : "not handled"); - break; - } + delegate.HandleAsyncStructuredDataPacket(response.GetStringRef()); + break; case 'T': case 'S': // Do this with the continue lock held. -- cgit v1.2.3