tberghammer created this revision.
tberghammer added a reviewer: jasonmolenda.
tberghammer added a subscriber: lldb-commits.
Herald added a subscriber: aemerson.

Improve instruction emulation based stack unwinding

On ARM there is no difference between a pop and a load instruction so
a register can be loaded multiple times during the function. Add check
to threat the load as a restore only if it do the restore from the
same location where the register was saved.

http://reviews.llvm.org/D11947

Files:
  source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
  source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
  source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp

Index: source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
===================================================================
--- source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
+++ source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
@@ -580,8 +580,15 @@
                     const uint32_t generic_regnum = reg_info->kinds[eRegisterKindGeneric];
                     if (reg_num != LLDB_INVALID_REGNUM && generic_regnum != LLDB_REGNUM_GENERIC_SP)
                     {
-                        m_curr_row->SetRegisterLocationToSame (reg_num, /*must_replace*/ false);
-                        m_curr_row_modified = true;
+                        if (m_pushed_regs.find (reg_num) == m_pushed_regs.end() &&
+                            context.info_type == EmulateInstruction::eInfoTypeAddress &&
+                            context.info.address == m_pushed_regs[reg_num])
+                        {
+                            m_curr_row->SetRegisterLocationToSame (reg_num, /*must_replace*/ false);
+                            m_curr_row_modified = true;
+                        }
+                        else
+                            assert (!"unhandled case, add code to handle this!");
                     }
                 }
             }
Index: source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
===================================================================
--- source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
+++ source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
@@ -768,8 +768,6 @@
     Context context_t;
     Context context_t2;
 
-    context_t.SetRegisterToRegisterPlusOffset (reg_info_Rt, reg_info_base, 0);
-    context_t2.SetRegisterToRegisterPlusOffset (reg_info_Rt2, reg_info_base, size);
     uint8_t buffer [RegisterValue::kMaxRegisterByteSize];
     Error error;
 
@@ -787,6 +785,8 @@
                 context_t.type = eContextRegisterStore;
                 context_t2.type = eContextRegisterStore;
             }
+            context_t.SetRegisterToRegisterPlusOffset (reg_info_Rt, reg_info_base, 0);
+            context_t2.SetRegisterToRegisterPlusOffset (reg_info_Rt2, reg_info_base, size);
 
             if (!ReadRegister (&reg_info_Rt, data_Rt))
                 return false;
@@ -820,6 +820,8 @@
                 context_t.type = eContextRegisterLoad;
                 context_t2.type = eContextRegisterLoad;
             }
+            context_t.SetAddress(address);
+            context_t2.SetAddress(address + size);
 
             if (rt_unknown)
                 memset (buffer, 'U', reg_info_Rt.byte_size);
@@ -950,15 +952,14 @@
         return false;
 
     Context context;
-    context.SetRegisterToRegisterPlusOffset (reg_info_Rt, reg_info_base, postindex ? 0 : offset);
-
     switch (memop)
     {
         case MemOp_STORE:
             if (n == 31 || n == GetFramePointerRegisterNumber()) // if this store is based off of the sp or fp register
                 context.type = eContextPushRegisterOnStack;
             else
                 context.type = eContextRegisterStore;
+            context.SetRegisterToRegisterPlusOffset (reg_info_Rt, reg_info_base, postindex ? 0 : offset);
 
             if (!ReadRegister (&reg_info_Rt, data_Rt))
                 return false;
@@ -975,6 +976,7 @@
                 context.type = eContextPopRegisterOffStack;
             else
                 context.type = eContextRegisterLoad;
+            context.SetAddress(address);
 
             if (!ReadMemory (context, address, buffer, reg_info_Rt.byte_size))
                 return false;
Index: source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
===================================================================
--- source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
+++ source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
@@ -578,7 +578,7 @@
         {
             if (BitIsSet (registers, i))
             {
-                context.SetRegisterPlusOffset (sp_reg, addr - sp);
+                context.SetAddress(addr);
                 data = MemARead(context, addr, 4, 0, &success);
                 if (!success)
                     return false;    
@@ -2214,7 +2214,7 @@
         for (i=0; i<regs; ++i)
         {
             GetRegisterInfo (eRegisterKindDWARF, start_reg + d + i, dwarf_reg);
-            context.SetRegisterPlusOffset (sp_reg, addr - sp);
+            context.SetAddress(addr);
             data = MemARead(context, addr, reg_byte_size, 0, &success);
             if (!success)
                 return false;    
@@ -3516,7 +3516,10 @@
                 context.type = EmulateInstruction::eContextRegisterPlusOffset;
                 context.SetRegisterPlusOffset (dwarf_reg, offset);
                 if (wback && (n == 13)) // Pop Instruction
+                {
                     context.type = EmulateInstruction::eContextPopRegisterOffStack;
+                    context.SetAddress(base_address + offset);
+                }
 
                 // R[i] = MemA [address, 4]; address = address + 4;
                 uint32_t data = MemARead (context, base_address + offset, addr_byte_size, 0, &success);
@@ -10307,7 +10310,7 @@
             context.type = eContextPopRegisterOffStack;
         else
             context.type = eContextRegisterLoad;
-        context.SetRegisterPlusOffset (base_reg, address - Rn);
+        context.SetAddress(address);
                   
         const uint32_t addr_byte_size = GetAddressByteSize();
         uint32_t data = MemARead (context, address, addr_byte_size, 0, &success);
@@ -10437,7 +10440,7 @@
             context.type = eContextPopRegisterOffStack;
         else
             context.type = eContextRegisterLoad;
-        context.SetRegisterPlusIndirectOffset (base_reg, offset_reg);
+        context.SetAddress(address);
                   
         // R[t] = MemA[address,4];
         const uint32_t addr_byte_size = GetAddressByteSize();
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to