[Lldb-commits] [lldb] r147646 - in /lldb/trunk: include/lldb/Host/FileSpec.h source/Core/Section.cpp source/Host/common/FileSpec.cpp source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp source/Target/Target.cpp

Greg Clayton gclayton at apple.com
Thu Jan 5 18:01:06 PST 2012


Author: gclayton
Date: Thu Jan  5 20:01:06 2012
New Revision: 147646

URL: http://llvm.org/viewvc/llvm-project?rev=147646&view=rev
Log:
<rdar://problem/10652336>

Fixed a crasher when trying to load an expression prefix file:

% touch /tmp/carp.txt
% xcrun lldb
(lldb) settings set target.expr-prefix /tmp/carp.txt
Segmentation fault


Modified:
    lldb/trunk/include/lldb/Host/FileSpec.h
    lldb/trunk/source/Core/Section.cpp
    lldb/trunk/source/Host/common/FileSpec.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Host/FileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSpec.h?rev=147646&r1=147645&r2=147646&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Host/FileSpec.h Thu Jan  5 20:01:06 2012
@@ -462,10 +462,10 @@
     ///     pointer must be checked prior to using it.
     //------------------------------------------------------------------
     lldb::DataBufferSP
-    ReadFileContents (off_t offset = 0, size_t length = SIZE_MAX) const;
+    ReadFileContents (off_t offset = 0, size_t length = SIZE_MAX, Error *error_ptr = NULL) const;
 
     size_t
-    ReadFileContents (off_t file_offset, void *dst, size_t dst_len) const;
+    ReadFileContents (off_t file_offset, void *dst, size_t dst_len, Error *error_ptr) const;
 
     //------------------------------------------------------------------
     /// Change the file specificed with a new path.

Modified: lldb/trunk/source/Core/Section.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Section.cpp?rev=147646&r1=147645&r2=147646&view=diff
==============================================================================
--- lldb/trunk/source/Core/Section.cpp (original)
+++ lldb/trunk/source/Core/Section.cpp Thu Jan  5 20:01:06 2012
@@ -339,7 +339,7 @@
             if (section_offset < file_size)
             {
                 off_t section_file_offset = objfile->GetOffset() + GetFileOffset() + section_offset;
-                bytes_read = file.ReadFileContents (section_file_offset, dst, dst_len);
+                bytes_read = file.ReadFileContents (section_file_offset, dst, dst_len, NULL);
                 if (bytes_read >= dst_len)
                     return bytes_read;
                 bytes_left -= bytes_read;

Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=147646&r1=147645&r2=147646&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Thu Jan  5 20:01:06 2012
@@ -771,13 +771,13 @@
 
 
 size_t
-FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len) const
+FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len, Error *error_ptr) const
 {
+    Error error;
     size_t bytes_read = 0;
     char resolved_path[PATH_MAX];
     if (GetPath(resolved_path, sizeof(resolved_path)))
     {
-        Error error;
         File file;
         error = file.Open(resolved_path, File::eOpenOptionRead);
         if (error.Success())
@@ -787,6 +787,12 @@
             error = file.Read(dst, bytes_read, file_offset_after_seek);
         }
     }
+    else
+    {
+        error.SetErrorString("invalid file specification");
+    }
+    if (error_ptr)
+        *error_ptr = error;
     return bytes_read;
 }
 
@@ -802,18 +808,24 @@
 // verified using the DataBuffer::GetByteSize() function.
 //------------------------------------------------------------------
 DataBufferSP
-FileSpec::ReadFileContents (off_t file_offset, size_t file_size) const
+FileSpec::ReadFileContents (off_t file_offset, size_t file_size, Error *error_ptr) const
 {
+    Error error;
     DataBufferSP data_sp;
     char resolved_path[PATH_MAX];
     if (GetPath(resolved_path, sizeof(resolved_path)))
     {
-        Error error;
         File file;
         error = file.Open(resolved_path, File::eOpenOptionRead);
         if (error.Success())
             error = file.Read (file_size, file_offset, data_sp);
     }
+    else
+    {
+        error.SetErrorString("invalid file specification");
+    }
+    if (error_ptr)
+        *error_ptr = error;
     return data_sp;
 }
 

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp?rev=147646&r1=147645&r2=147646&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp Thu Jan  5 20:01:06 2012
@@ -234,7 +234,7 @@
                 xcode_dir_path.append (xcode_select_prefix_dir);
             xcode_dir_path.append ("/usr/share/xcode-select/xcode_dir_path");
             temp_file_spec.SetFile(xcode_dir_path.c_str(), false);
-            size_t bytes_read = temp_file_spec.ReadFileContents(0, developer_dir_path, sizeof(developer_dir_path));
+            size_t bytes_read = temp_file_spec.ReadFileContents(0, developer_dir_path, sizeof(developer_dir_path), NULL);
             if (bytes_read > 0)
             {
                 developer_dir_path[bytes_read] = '\0';

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=147646&r1=147645&r2=147646&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Thu Jan  5 20:01:06 2012
@@ -2308,6 +2308,8 @@
             case eVarSetOperationAssign:
             case eVarSetOperationAppend:
                 {
+                    m_expr_prefix_contents.clear();
+
                     if (!m_expr_prefix_file.GetCurrentValue().Exists())
                     {
                         err.SetErrorToGenericError ();
@@ -2315,15 +2317,19 @@
                         return;
                     }
             
-                    DataBufferSP file_contents = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
+                    DataBufferSP file_data_sp (m_expr_prefix_file.GetCurrentValue().ReadFileContents(0, SIZE_MAX, &err));
                     
-                    if (!file_contents && file_contents->GetByteSize() == 0)
+                    if (err.Success())
                     {
-                        err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
-                        m_expr_prefix_contents.clear();
+                        if (file_data_sp && file_data_sp->GetByteSize() > 0)
+                        {
+                            m_expr_prefix_contents.assign((const char*)file_data_sp->GetBytes(), file_data_sp->GetByteSize());
+                        }
+                        else
+                        {
+                            err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
+                        }
                     }
-                    
-                    m_expr_prefix_contents.assign((const char*)file_contents->GetBytes(), file_contents->GetByteSize());
                 }
                 break;
             case eVarSetOperationClear:





More information about the lldb-commits mailing list