[Lldb-commits] [lldb] r161716 - in /lldb/trunk: include/lldb/Expression/DWARFExpression.h source/Expression/DWARFExpression.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Greg Clayton gclayton at apple.com
Fri Aug 10 16:33:27 PDT 2012


Author: gclayton
Date: Fri Aug 10 18:33:27 2012
New Revision: 161716

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

Fixed an issue that could cause references the shared data for an object file to stay around longer than intended and could cause memory bloat when debugging multiple times.


Modified:
    lldb/trunk/include/lldb/Expression/DWARFExpression.h
    lldb/trunk/source/Expression/DWARFExpression.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Modified: lldb/trunk/include/lldb/Expression/DWARFExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/DWARFExpression.h?rev=161716&r1=161715&r2=161716&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/DWARFExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/DWARFExpression.h Fri Aug 10 18:33:27 2012
@@ -187,6 +187,36 @@
     SetOpcodeData(const DataExtractor& data, uint32_t data_offset, uint32_t data_length);
 
     //------------------------------------------------------------------
+    /// Copy the DWARF location expression into a local buffer.
+    ///
+    /// It is a good idea to copy the data so we don't keep the entire
+    /// object file worth of data around just for a few bytes of location
+    /// expression. LLDB typically will mmap the entire contents of debug
+    /// information files, and if we use SetOpcodeData, it will get a
+    /// shared reference to all of this data for the and cause the object
+    /// file to have to stay around. Even worse, a very very large ".a"
+    /// that contains one or more .o files could end up being referenced.
+    /// Location lists are typically small so even though we are copying
+    /// the data, it shouldn't amount to that much for the variables we
+    /// end up parsing.
+    ///
+    /// @param[in] data
+    ///     A data extractor configured to read and copy the DWARF
+    ///     location expression's bytecode.
+    ///
+    /// @param[in] data_offset
+    ///     The offset of the location expression in the extractor.
+    ///
+    /// @param[in] data_length
+    ///     The byte length of the location expression.
+    //------------------------------------------------------------------
+    void
+    CopyOpcodeData (const DataExtractor& data,
+                    uint32_t data_offset,
+                    uint32_t data_length);
+    
+
+    //------------------------------------------------------------------
     /// Tells the expression that it refers to a location list.
     ///
     /// @param[in] slide

Modified: lldb/trunk/source/Expression/DWARFExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/DWARFExpression.cpp?rev=161716&r1=161715&r2=161716&view=diff
==============================================================================
--- lldb/trunk/source/Expression/DWARFExpression.cpp (original)
+++ lldb/trunk/source/Expression/DWARFExpression.cpp Fri Aug 10 18:33:27 2012
@@ -261,6 +261,13 @@
 }
 
 void
+DWARFExpression::CopyOpcodeData (const DataExtractor& data, uint32_t data_offset, uint32_t data_length)
+{
+    const uint8_t *bytes = data.PeekData(data_offset, data_length);
+    m_data.SetData(DataBufferSP(new DataBufferHeap(bytes, data_length)));
+}
+
+void
 DWARFExpression::SetOpcodeData (const DataExtractor& data, uint32_t data_offset, uint32_t data_length)
 {
     m_data.SetData(data, data_offset, data_length);

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=161716&r1=161715&r2=161716&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Fri Aug 10 18:33:27 2012
@@ -1012,7 +1012,9 @@
                 // this address is resolved. If they are the same, then the
                 // function for this address didn't make it into the final
                 // executable.
-                bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection ();
+                bool curr_in_final_executable = false;
+                if (info->curr_section_sp->GetLinkedSection ())
+                    curr_in_final_executable = true;
 
                 // If we are doing DWARF with debug map, then we need to carefully
                 // add each line table entry as there may be gaps as functions
@@ -6542,7 +6544,7 @@
 
                                 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
                                 uint32_t block_length = form_value.Unsigned();
-                                location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
+                                location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length);
                             }
                             else
                             {
@@ -6552,7 +6554,7 @@
                                 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
                                 if (loc_list_length > 0)
                                 {
-                                    location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
+                                    location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
                                     assert (func_low_pc != LLDB_INVALID_ADDRESS);
                                     location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
                                 }





More information about the lldb-commits mailing list