[Lldb-commits] [lldb] r144760 - in /lldb/trunk: include/lldb/Target/Target.h source/Target/Target.cpp

Sean Callanan scallanan at apple.com
Tue Nov 15 17:54:58 PST 2011


Author: spyffe
Date: Tue Nov 15 19:54:57 2011
New Revision: 144760

URL: http://llvm.org/viewvc/llvm-project?rev=144760&view=rev
Log:
Fixed a problem where the target didn't use a
NULL-terminated C string to store the contents
of the expression prefix file.  This meant that
expressions, when printing the contents of the
prefix into the expression's text, would
invariably put in bad data after the end of the
expression.

Now, instead, we store the prefix contents in a
std::string, which handles null-termination
correctly.

Modified:
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=144760&r1=144759&r2=144760&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Tue Nov 15 19:54:57 2011
@@ -221,7 +221,7 @@
     CreateInstanceName ();
     
     OptionValueFileSpec m_expr_prefix_file;
-    lldb::DataBufferSP m_expr_prefix_contents_sp;
+    std::string m_expr_prefix_contents;
     int m_prefer_dynamic_value;
     OptionValueBoolean m_skip_prologue;
     PathMappingList m_source_map;

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=144760&r1=144759&r2=144760&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Tue Nov 15 19:54:57 2011
@@ -1430,8 +1430,8 @@
 const char *
 Target::GetExpressionPrefixContentsAsCString ()
 {
-    if (m_expr_prefix_contents_sp)
-        return (const char *)m_expr_prefix_contents_sp->GetBytes();
+    if (!m_expr_prefix_contents.empty())
+        return m_expr_prefix_contents.c_str();
     return NULL;
 }
 
@@ -2160,7 +2160,7 @@
 ) :
     InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
     m_expr_prefix_file (),
-    m_expr_prefix_contents_sp (),
+    m_expr_prefix_contents (),
     m_prefer_dynamic_value (2),
     m_skip_prologue (true, true),
     m_source_map (NULL, NULL),
@@ -2198,7 +2198,7 @@
 TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
     InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
     m_expr_prefix_file (rhs.m_expr_prefix_file),
-    m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp),
+    m_expr_prefix_contents (rhs.m_expr_prefix_contents),
     m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
     m_skip_prologue (rhs.m_skip_prologue),
     m_source_map (rhs.m_source_map),
@@ -2231,7 +2231,7 @@
     if (this != &rhs)
     {
         m_expr_prefix_file = rhs.m_expr_prefix_file;
-        m_expr_prefix_contents_sp = rhs.m_expr_prefix_contents_sp;
+        m_expr_prefix_contents = rhs.m_expr_prefix_contents;
         m_prefer_dynamic_value = rhs.m_prefer_dynamic_value;
         m_skip_prologue = rhs.m_skip_prologue;
         m_source_map = rhs.m_source_map;
@@ -2280,17 +2280,19 @@
                         return;
                     }
             
-                    m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
-            
-                    if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0)
+                    DataBufferSP file_contents = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
+                    
+                    if (!file_contents && file_contents->GetByteSize() == 0)
                     {
                         err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
-                        m_expr_prefix_contents_sp.reset();
+                        m_expr_prefix_contents.clear();
                     }
+                    
+                    m_expr_prefix_contents.assign((const char*)file_contents->GetBytes(), file_contents->GetByteSize());
                 }
                 break;
             case eVarSetOperationClear:
-                m_expr_prefix_contents_sp.reset();
+                m_expr_prefix_contents.clear();
             }
         }
     }





More information about the lldb-commits mailing list