[Lldb-commits] [lldb] r286413 - Fix weak symbol linkage in SBStructuredData, update docs.

Todd Fiala via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 9 15:21:07 PST 2016


Author: tfiala
Date: Wed Nov  9 17:21:04 2016
New Revision: 286413

URL: http://llvm.org/viewvc/llvm-project?rev=286413&view=rev
Log:
Fix weak symbol linkage in SBStructuredData, update docs.

Summary:
This change fixes an issue where I was leaking a weakly-linked symbol in
the SBAPI. It also updates the docs to call out what I did wrong.

Fixes:
rdar://28882483

Reviewers: jingham

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D26470

Modified:
    lldb/trunk/include/lldb/API/SBStructuredData.h
    lldb/trunk/source/API/SBStructuredData.cpp
    lldb/trunk/www/SB-api-coding-rules.html

Modified: lldb/trunk/include/lldb/API/SBStructuredData.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStructuredData.h?rev=286413&r1=286412&r2=286413&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBStructuredData.h (original)
+++ lldb/trunk/include/lldb/API/SBStructuredData.h Wed Nov  9 17:21:04 2016
@@ -13,6 +13,8 @@
 #include "lldb/API/SBDefines.h"
 #include "lldb/API/SBModule.h"
 
+class StructuredDataImpl;
+
 namespace lldb {
 
 class SBStructuredData {
@@ -36,8 +38,7 @@ public:
   lldb::SBError GetDescription(lldb::SBStream &stream) const;
 
 private:
-  class Impl;
-  std::unique_ptr<Impl> m_impl_up;
+  std::unique_ptr<StructuredDataImpl> m_impl_up;
 };
 }
 

Modified: lldb/trunk/source/API/SBStructuredData.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBStructuredData.cpp?rev=286413&r1=286412&r2=286413&view=diff
==============================================================================
--- lldb/trunk/source/API/SBStructuredData.cpp (original)
+++ lldb/trunk/source/API/SBStructuredData.cpp Wed Nov  9 17:21:04 2016
@@ -20,23 +20,23 @@ using namespace lldb;
 using namespace lldb_private;
 
 #pragma mark--
-#pragma mark Impl
+#pragma mark StructuredDataImpl
 
-class SBStructuredData::Impl {
+class StructuredDataImpl {
 public:
-  Impl() : m_plugin_wp(), m_data_sp() {}
+  StructuredDataImpl() : m_plugin_wp(), m_data_sp() {}
 
-  Impl(const Impl &rhs) = default;
+  StructuredDataImpl(const StructuredDataImpl &rhs) = default;
 
-  Impl(const EventSP &event_sp)
+  StructuredDataImpl(const EventSP &event_sp)
       : m_plugin_wp(
             EventDataStructuredData::GetPluginFromEvent(event_sp.get())),
         m_data_sp(EventDataStructuredData::GetObjectFromEvent(event_sp.get())) {
   }
 
-  ~Impl() = default;
+  ~StructuredDataImpl() = default;
 
-  Impl &operator=(const Impl &rhs) = default;
+  StructuredDataImpl &operator=(const StructuredDataImpl &rhs) = default;
 
   bool IsValid() const { return m_data_sp.get() != nullptr; }
 
@@ -45,7 +45,7 @@ public:
     m_data_sp.reset();
   }
 
-  SBError GetAsJSON(lldb::SBStream &stream) const {
+  SBError GetAsJSON(lldb_private::Stream &stream) const {
     SBError sb_error;
 
     if (!m_data_sp) {
@@ -53,33 +53,29 @@ public:
       return sb_error;
     }
 
-    m_data_sp->Dump(stream.ref());
+    m_data_sp->Dump(stream);
     return sb_error;
   }
 
-  lldb::SBError GetDescription(lldb::SBStream &stream) const {
-    SBError sb_error;
+  Error GetDescription(lldb_private::Stream &stream) const {
+    Error error;
 
     if (!m_data_sp) {
-      sb_error.SetErrorString("Cannot pretty print structured data: "
-                              "no data to print.");
-      return sb_error;
+      error.SetErrorString("Cannot pretty print structured data: "
+                           "no data to print.");
+      return error;
     }
 
     // Grab the plugin.
     auto plugin_sp = StructuredDataPluginSP(m_plugin_wp);
     if (!plugin_sp) {
-      sb_error.SetErrorString("Cannot pretty print structured data: "
-                              "plugin doesn't exist.");
-      return sb_error;
+      error.SetErrorString("Cannot pretty print structured data: "
+                           "plugin doesn't exist.");
+      return error;
     }
 
     // Get the data's description.
-    auto error = plugin_sp->GetDescription(m_data_sp, stream.ref());
-    if (!error.Success())
-      sb_error.SetError(error);
-
-    return sb_error;
+    return plugin_sp->GetDescription(m_data_sp, stream);
   }
 
 private:
@@ -90,13 +86,13 @@ private:
 #pragma mark--
 #pragma mark SBStructuredData
 
-SBStructuredData::SBStructuredData() : m_impl_up(new Impl()) {}
+SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {}
 
 SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs)
-    : m_impl_up(new Impl(*rhs.m_impl_up.get())) {}
+    : m_impl_up(new StructuredDataImpl(*rhs.m_impl_up.get())) {}
 
 SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp)
-    : m_impl_up(new Impl(event_sp)) {}
+    : m_impl_up(new StructuredDataImpl(event_sp)) {}
 
 SBStructuredData::~SBStructuredData() {}
 
@@ -111,9 +107,12 @@ bool SBStructuredData::IsValid() const {
 void SBStructuredData::Clear() { m_impl_up->Clear(); }
 
 SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const {
-  return m_impl_up->GetAsJSON(stream);
+  return m_impl_up->GetAsJSON(stream.ref());
 }
 
 lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const {
-  return m_impl_up->GetDescription(stream);
+  Error error = m_impl_up->GetDescription(stream.ref());
+  SBError sb_error;
+  sb_error.SetError(error);
+  return sb_error;
 }

Modified: lldb/trunk/www/SB-api-coding-rules.html
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/www/SB-api-coding-rules.html?rev=286413&r1=286412&r2=286413&view=diff
==============================================================================
--- lldb/trunk/www/SB-api-coding-rules.html (original)
+++ lldb/trunk/www/SB-api-coding-rules.html Wed Nov  9 17:21:04 2016
@@ -36,7 +36,7 @@
 
                                       <p>You also need to choose the ivars for the class with care, since you can't add or remove ivars
                                         without breaking binary compatibility.  In some cases, the SB class is a thin wrapper around
-                                        an interal lldb_private object.  In that case, the class can have a single ivar, which is 
+                                        an internal lldb_private object.  In that case, the class can have a single ivar, which is
                                         either a pointer, shared_ptr or unique_ptr to the object in the lldb_private API.  All the
                                         lldb_private classes that get used this way are declared as opaque classes in lldb_forward.h,
                                         which is included in SBDefines.h.  So if you need an SB class to wrap an lldb_private class
@@ -47,8 +47,9 @@
                                         as a direct ivar in the SB Class.  Instead, make an Impl class in the SB's .cpp file, and then
                                         make the SB object hold a shared or unique pointer to the Impl object.  The theory behind this is
                                         that if you need more state in the SB object, those needs are likely to change over time, 
-                                        and this way the impl class can pick up members without changing the size of the object.
-                                        An example of this is the SBValue class.
+                                        and this way the Impl class can pick up members without changing the size of the object.
+                                        An example of this is the SBValue class.  Please note that you should not put this Impl class
+                                        in the lldb namespace.  Failure to do so leads to leakage of weak-linked symbols in the SBAPI.
                                         
                                       <p>In order to fit into the Python API's, we need to be able to default construct all the SB objects.
                                         Since the ivars of the classes are all pointers of one sort or other, this can easily be done, but




More information about the lldb-commits mailing list