[Lldb-commits] [PATCH] D88266: Check that the "StructuredData Plugin weak pointer" is good before trying to turn it into a shared pointer

Jim Ingham via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 24 15:30:13 PDT 2020

jingham created this revision.
jingham added reviewers: labath, clayborg.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
jingham requested review of this revision.
Herald added a subscriber: JDevlieghere.

Prevent a crash using SBStructuredData.GetDescription.


For some reason SBStructuredData requires a plugin for printing, and
doesn't have a default version that just prints the current contents
as JSON or something sensible?


I'm not sure what is supposed to happen here, but as the code stands
now, trying to call GetDescription on an SBStructuredData will crash
when the empty weak pointer is turned into a shared pointer.


This patch just adds a check that the weak pointer hasn't expired
 before trying to access it.  That prevents the crash.

This fix seems fairly obvious, but I put it up here in case somebody knows what is 
actually supposed to happen here, the state of things doesn't make much sense to me.

  rG LLVM Github Monorepo



Index: lldb/include/lldb/Core/StructuredDataImpl.h
--- lldb/include/lldb/Core/StructuredDataImpl.h
+++ lldb/include/lldb/Core/StructuredDataImpl.h
@@ -69,6 +69,11 @@
     // Grab the plugin.
+    if (m_plugin_wp.expired()) {
+      error.SetErrorString("Cannot pretty print structured data: "
+                           "plugin is expired.");
+      return error;    
+    }
     auto plugin_sp = lldb::StructuredDataPluginSP(m_plugin_wp);
     if (!plugin_sp) {
       error.SetErrorString("Cannot pretty print structured data: "

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88266.294189.patch
Type: text/x-patch
Size: 609 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200924/38f6d092/attachment.bin>

More information about the lldb-commits mailing list