[Lldb-commits] [lldb] r168123 - in /lldb/trunk/source/Plugins/Process/Utility: RegisterContextLLDB.cpp RegisterContextLLDB.h UnwindLLDB.cpp UnwindLLDB.h

Jason Molenda jmolenda at apple.com
Thu Nov 15 17:03:31 PST 2012


Author: jmolenda
Date: Thu Nov 15 19:03:31 2012
New Revision: 168123

URL: http://llvm.org/viewvc/llvm-project?rev=168123&view=rev
Log:
A change in how we search for saved register values unintentionally
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>


Modified:
    lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
    lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h
    lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp
    lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.h

Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp?rev=168123&r1=168122&r2=168123&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp Thu Nov 15 19:03:31 2012
@@ -903,7 +903,7 @@
 
 // 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 @@
         if (iterator != m_registers.end())
         {
             regloc = iterator->second;
-            return true;
+            return UnwindLLDB::RegisterSearchResult::eRegisterFound;
         }
     }
 
@@ -937,7 +937,7 @@
         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 @@
         {
             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 @@
                     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 @@
             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 @@
             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 @@
         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 @@
         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 @@
         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 @@
         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 @@
         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 @@
                 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

Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h?rev=168123&r1=168122&r2=168123&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h Thu Nov 15 19:03:31 2012
@@ -131,7 +131,7 @@
     // 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

Modified: lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp?rev=168123&r1=168122&r2=168123&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp Thu Nov 15 19:03:31 2012
@@ -272,15 +272,21 @@
     // 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;

Modified: lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.h?rev=168123&r1=168122&r2=168123&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.h Thu Nov 15 19:03:31 2012
@@ -30,6 +30,13 @@
     virtual
     ~UnwindLLDB() { }
 
+    enum RegisterSearchResult
+    {
+        eRegisterFound = 0,
+        eRegisterNotFound,
+        eRegisterIsVolatile
+    };
+
 protected:
     friend class lldb_private::RegisterContextLLDB;
 





More information about the lldb-commits mailing list