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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88266

Files:
  lldb/include/lldb/Core/StructuredDataImpl.h


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: "


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: "
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to