A change in how we search for saved register values unintentionally
authorJason Molenda <jmolenda@apple.com>
Fri, 16 Nov 2012 01:03:31 +0000 (01:03 +0000)
committerJason Molenda <jmolenda@apple.com>
Fri, 16 Nov 2012 01:03:31 +0000 (01:03 +0000)
allowed volatile registers to be returned up the stack.  That leads
to unexpected/incorrect values provided to the user and we need to
avoid that.
<rdar://problem/12714247>

llvm-svn: 168123

lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
lldb/source/Plugins/Process/Utility/RegisterContextLLDB.h
lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp
lldb/source/Plugins/Process/Utility/UnwindLLDB.h

index d0d1928..b8561dc 100644 (file)
@@ -903,7 +903,7 @@ RegisterContextLLDB::IsSkipFrame () const
 
 // Answer the question: Where did THIS frame save the CALLER frame ("previous" frame)'s register value?
 
-bool
+enum UnwindLLDB::RegisterSearchResult
 RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc)
 {
     // Have we already found this register location?
@@ -914,7 +914,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
         if (iterator != m_registers.end())
         {
             regloc = iterator->second;
-            return true;
+            return UnwindLLDB::RegisterSearchResult::eRegisterFound;
         }
     }
 
@@ -937,7 +937,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
         regloc.type = UnwindLLDB::RegisterLocation::eRegisterValueInferred;
         regloc.location.inferred_value = m_cfa;
         m_registers[lldb_regnum] = regloc;
-        return true;
+        return UnwindLLDB::RegisterSearchResult::eRegisterFound;
     }
 
     // Look through the available UnwindPlans for the register location.
@@ -955,7 +955,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
         {
             UnwindLogMsg ("could not convert lldb regnum %d into %d RegisterKind reg numbering scheme",
                     lldb_regnum, (int) unwindplan_registerkind);
-            return false;
+            return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
         }
         if (active_row->GetRegisterInfo (row_regnum, unwindplan_regloc))
         {
@@ -993,7 +993,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
                     else
                         UnwindLogMsg ("could not convert lldb regnum %d into %d RegisterKind reg numbering scheme",
                                 lldb_regnum, (int) unwindplan_registerkind);
-                    return false;
+                    return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
                 }
             }
 
@@ -1064,7 +1064,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
             if (reg_info && abi->RegisterIsVolatile (reg_info))
             {
                 UnwindLogMsg ("did not supply reg location for %d because it is volatile", lldb_regnum);
-                return false;
+                return UnwindLLDB::RegisterSearchResult::eRegisterIsVolatile;
             }
         }
 
@@ -1076,11 +1076,11 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
             new_regloc.location.register_number = lldb_regnum;
             m_registers[lldb_regnum] = new_regloc;
             regloc = new_regloc;
-            return true;
+            return UnwindLLDB::RegisterSearchResult::eRegisterFound;
         }
         else
         UnwindLogMsg ("could not supply caller's reg %d location", lldb_regnum);
-        return false;
+        return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
     }
 
     // unwindplan_regloc has valid contents about where to retrieve the register
@@ -1090,7 +1090,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
         new_regloc.type = UnwindLLDB::RegisterLocation::eRegisterNotSaved;
         m_registers[lldb_regnum] = new_regloc;
         UnwindLogMsg ("could not supply caller's reg %d location", lldb_regnum);
-        return false;
+        return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
     }
 
     if (unwindplan_regloc.IsSame())
@@ -1098,11 +1098,11 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
         if (IsFrameZero ())
         {
             UnwindLogMsg ("could not supply caller's reg %d location", lldb_regnum);
-            return false;
+            return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
         }
         else
         {
-            return false;
+            return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
         }
     }
 
@@ -1112,7 +1112,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
         regloc.type = UnwindLLDB::RegisterLocation::eRegisterValueInferred;
         regloc.location.inferred_value = m_cfa + offset;
         m_registers[lldb_regnum] = regloc;
-        return true;
+        return UnwindLLDB::RegisterSearchResult::eRegisterFound;
     }
 
     if (unwindplan_regloc.IsAtCFAPlusOffset())
@@ -1121,7 +1121,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
         regloc.type = UnwindLLDB::RegisterLocation::eRegisterSavedAtMemoryLocation;
         regloc.location.target_memory_location = m_cfa + offset;
         m_registers[lldb_regnum] = regloc;
-        return true;
+        return UnwindLLDB::RegisterSearchResult::eRegisterFound;
     }
 
     if (unwindplan_regloc.IsInOtherRegister())
@@ -1131,12 +1131,12 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
         if (!m_thread.GetRegisterContext()->ConvertBetweenRegisterKinds (unwindplan_registerkind, unwindplan_regnum, eRegisterKindLLDB, row_regnum_in_lldb))
         {
             UnwindLogMsg ("could not supply caller's reg %d location", lldb_regnum);
-            return false;
+            return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
         }
         regloc.type = UnwindLLDB::RegisterLocation::eRegisterInRegister;
         regloc.location.register_number = row_regnum_in_lldb;
         m_registers[lldb_regnum] = regloc;
-        return true;
+        return UnwindLLDB::RegisterSearchResult::eRegisterFound;
     }
 
     if (unwindplan_regloc.IsDWARFExpression() || unwindplan_regloc.IsAtDWARFExpression())
@@ -1157,25 +1157,25 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
                 regloc.type = UnwindLLDB::RegisterLocation::eRegisterValueInferred;
                 regloc.location.inferred_value = val;
                 m_registers[lldb_regnum] = regloc;
-                return true;
+                return UnwindLLDB::RegisterSearchResult::eRegisterFound;
             }
             else
             {
                regloc.type = UnwindLLDB::RegisterLocation::eRegisterSavedAtMemoryLocation;
                regloc.location.target_memory_location = val;
                m_registers[lldb_regnum] = regloc;
-               return true;
+               return UnwindLLDB::RegisterSearchResult::eRegisterFound;
             }
         }
         UnwindLogMsg ("tried to use IsDWARFExpression or IsAtDWARFExpression for reg %d but failed", lldb_regnum);
-        return false;
+        return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
     }
 
     UnwindLogMsg ("could not supply caller's reg %d location", lldb_regnum);
 
     // FIXME UnwindPlan::Row types atDWARFExpression and isDWARFExpression are unsupported.
 
-    return false;
+    return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
 }
 
 // If the Full unwindplan has been determined to be incorrect, this method will
index d659846..1b60996 100644 (file)
@@ -131,7 +131,7 @@ private:
     // If a non-volatile register (a "preserved" register) is requested mid-stack and no frames "below" the requested
     // stack have saved the register anywhere, it is safe to assume that frame 0's register values are still the same
     // as the requesting frame's.
-    bool
+    lldb_private::UnwindLLDB::RegisterSearchResult
     SavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc);
 
     bool
index 587ec88..459a729 100644 (file)
@@ -272,15 +272,21 @@ UnwindLLDB::SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
     // isn't saved by frame_num, none of the frames lower on the stack will have a useful value.
     if (pc_or_return_address_reg)
     {
-        if (m_frames[frame_num]->reg_ctx_lldb_sp->SavedLocationForRegister (lldb_regnum, regloc))
+        UnwindLLDB::RegisterSearchResult result;
+        result = m_frames[frame_num]->reg_ctx_lldb_sp->SavedLocationForRegister (lldb_regnum, regloc);
+        if (result == UnwindLLDB::RegisterSearchResult::eRegisterFound)
           return true;
         else
           return false;
     }
     while (frame_num >= 0)
     {
-        if (m_frames[frame_num]->reg_ctx_lldb_sp->SavedLocationForRegister (lldb_regnum, regloc))
+        UnwindLLDB::RegisterSearchResult result;
+        result = m_frames[frame_num]->reg_ctx_lldb_sp->SavedLocationForRegister (lldb_regnum, regloc);
+        if (result == UnwindLLDB::RegisterSearchResult::eRegisterFound)
             return true;
+        if (result == UnwindLLDB::RegisterSearchResult::eRegisterIsVolatile)
+            return false;
         frame_num--;
     }
     return false;
index 26dc968..ed3be5b 100644 (file)
@@ -30,6 +30,13 @@ public:
     virtual
     ~UnwindLLDB() { }
 
+    enum RegisterSearchResult
+    {
+        eRegisterFound = 0,
+        eRegisterNotFound,
+        eRegisterIsVolatile
+    };
+
 protected:
     friend class lldb_private::RegisterContextLLDB;