[Lldb-commits] [lldb] r187473 - The DisassemblerLLVMC has a retain cycle - the InstructionLLVMC's contained in its instruction

Jim Ingham jingham at apple.com
Tue Jul 30 19:19:15 PDT 2013


Author: jingham
Date: Tue Jul 30 21:19:15 2013
New Revision: 187473

URL: http://llvm.org/viewvc/llvm-project?rev=187473&view=rev
Log:
The DisassemblerLLVMC has a retain cycle - the InstructionLLVMC's contained in its instruction
list have a shared pointer back to their DisassemblerLLVMC.  This checkin force clears the InstructionList
in all the places we use the DisassemblerSP to stop the leaking for now.  I'll go back and fix this
for real when I have time to do so.

<rdar://problem/14581918>

Modified:
    lldb/trunk/source/Core/DataExtractor.cpp
    lldb/trunk/source/Core/Disassembler.cpp
    lldb/trunk/source/Expression/IRExecutionUnit.cpp
    lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
    lldb/trunk/source/Target/ThreadPlanStepRange.cpp

Modified: lldb/trunk/source/Core/DataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataExtractor.cpp?rev=187473&r1=187472&r2=187473&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DataExtractor.cpp Tue Jul 30 21:19:15 2013
@@ -1412,6 +1412,10 @@ DataExtractor::Dump (Stream *s,
                     ExecutionContext exe_ctx;
                     exe_scope->CalculateExecutionContext(exe_ctx);
                     disassembler_sp->GetInstructionList().Dump (s,  show_address, show_bytes, &exe_ctx);
+                    
+                    // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
+                    // I'll fix that but for now, just clear the list and it will go away nicely.
+                    disassembler_sp->GetInstructionList().Clear();
                 }
             }
         }

Modified: lldb/trunk/source/Core/Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Disassembler.cpp?rev=187473&r1=187472&r2=187473&view=diff
==============================================================================
--- lldb/trunk/source/Core/Disassembler.cpp (original)
+++ lldb/trunk/source/Core/Disassembler.cpp Tue Jul 30 21:19:15 2013
@@ -316,14 +316,19 @@ Disassembler::Disassemble
             if (bytes_disassembled == 0)
                 return false;
 
-            return PrintInstructions (disasm_sp.get(),
-                                      debugger,
-                                      arch,
-                                      exe_ctx,
-                                      num_instructions,
-                                      num_mixed_context_lines,
-                                      options,
-                                      strm);
+            bool result = PrintInstructions (disasm_sp.get(),
+                                             debugger,
+                                             arch,
+                                             exe_ctx,
+                                             num_instructions,
+                                             num_mixed_context_lines,
+                                             options,
+                                             strm);
+            
+            // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
+            // I'll fix that but for now, just clear the list and it will go away nicely.
+            disasm_sp->GetInstructionList().Clear();
+            return result;
         }
     }
     return false;
@@ -361,14 +366,19 @@ Disassembler::Disassemble
                                                                       prefer_file_cache);
             if (bytes_disassembled == 0)
                 return false;
-            return PrintInstructions (disasm_sp.get(),
-                                      debugger,
-                                      arch,
-                                      exe_ctx,
-                                      num_instructions,
-                                      num_mixed_context_lines,
-                                      options,
-                                      strm);
+            bool result = PrintInstructions (disasm_sp.get(),
+                                             debugger,
+                                             arch,
+                                             exe_ctx,
+                                             num_instructions,
+                                             num_mixed_context_lines,
+                                             options,
+                                             strm);
+            
+            // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
+            // I'll fix that but for now, just clear the list and it will go away nicely.
+            disasm_sp->GetInstructionList().Clear();
+            return result;
         }
     }
     return false;

Modified: lldb/trunk/source/Expression/IRExecutionUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRExecutionUnit.cpp?rev=187473&r1=187472&r2=187473&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRExecutionUnit.cpp (original)
+++ lldb/trunk/source/Expression/IRExecutionUnit.cpp Tue Jul 30 21:19:15 2013
@@ -171,9 +171,9 @@ IRExecutionUnit::DisassembleFunction (St
     
     const char *plugin_name = NULL;
     const char *flavor_string = NULL;
-    lldb::DisassemblerSP disassembler = Disassembler::FindPlugin(arch, flavor_string, plugin_name);
+    lldb::DisassemblerSP disassembler_sp = Disassembler::FindPlugin(arch, flavor_string, plugin_name);
     
-    if (!disassembler)
+    if (!disassembler_sp)
     {
         ret.SetErrorToGenericError();
         ret.SetErrorStringWithFormat("Unable to find disassembler plug-in for %s architecture.", arch.GetArchitectureName());
@@ -202,9 +202,9 @@ IRExecutionUnit::DisassembleFunction (St
                             DataExtractor::TypeUInt8);
     }
     
-    disassembler->DecodeInstructions (Address (func_remote_addr), extractor, 0, UINT32_MAX, false, false);
+    disassembler_sp->DecodeInstructions (Address (func_remote_addr), extractor, 0, UINT32_MAX, false, false);
     
-    InstructionList &instruction_list = disassembler->GetInstructionList();
+    InstructionList &instruction_list = disassembler_sp->GetInstructionList();
     const uint32_t max_opcode_byte_size = instruction_list.GetMaxOpcocdeByteSize();
     
     for (size_t instruction_index = 0, num_instructions = instruction_list.GetSize();
@@ -219,7 +219,9 @@ IRExecutionUnit::DisassembleFunction (St
                            &exe_ctx);
         stream.PutChar('\n');
     }
-    
+    // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
+    // I'll fix that but for now, just clear the list and it will go away nicely.
+    disassembler_sp->GetInstructionList().Clear();
     return ret;
 }
 

Modified: lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp?rev=187473&r1=187472&r2=187473&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp (original)
+++ lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp Tue Jul 30 21:19:15 2013
@@ -264,6 +264,9 @@ UnwindAssemblyInstEmulation::GetNonCallS
                     }
                 }
             }
+            // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
+            // I'll fix that but for now, just clear the list and it will go away nicely.
+            disasm_sp->GetInstructionList().Clear();
         }
         
         if (log && log->GetVerbose ())

Modified: lldb/trunk/source/Target/ThreadPlanStepRange.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepRange.cpp?rev=187473&r1=187472&r2=187473&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadPlanStepRange.cpp (original)
+++ lldb/trunk/source/Target/ThreadPlanStepRange.cpp Tue Jul 30 21:19:15 2013
@@ -66,6 +66,16 @@ ThreadPlanStepRange::ThreadPlanStepRange
 ThreadPlanStepRange::~ThreadPlanStepRange ()
 {
     ClearNextBranchBreakpoint();
+    
+    size_t num_instruction_ranges = m_instruction_ranges.size();
+    
+    // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
+    // I'll fix that but for now, just clear the list and it will go away nicely.
+    for (size_t i = 0; i < num_instruction_ranges; i++)
+    {
+        if (m_instruction_ranges[i])
+            m_instruction_ranges[i]->GetInstructionList().Clear();
+    }
 }
 
 void
@@ -99,6 +109,9 @@ ThreadPlanStepRange::AddRange(const Addr
     // condense the ranges if they overlap, though I don't think it is likely
     // to be very important.
     m_address_ranges.push_back (new_range);
+    
+    // Fill the slot for this address range with an empty DisassemblerSP in the instruction ranges. I want the
+    // indices to match, but I don't want to do the work to disassemble this range if I don't step into it.
     m_instruction_ranges.push_back (DisassemblerSP());
 }
 





More information about the lldb-commits mailing list