[Lldb-commits] [lldb] r216992 - RegisterContextLLDB::InitializeNonZerothFrame had a bit of code to
Jason Molenda
jmolenda at apple.com
Tue Sep 2 16:04:02 PDT 2014
Author: jmolenda
Date: Tue Sep 2 18:04:01 2014
New Revision: 216992
URL: http://llvm.org/viewvc/llvm-project?rev=216992&view=rev
Log:
RegisterContextLLDB::InitializeNonZerothFrame had a bit of code to
detct unwind loops but there was a code path through there (using
architecture default unwind plans) that didn't do the check, and
could end up with an infinite loop unwind. Move that code into a
separate method and call it from both places where it is needed.
Also remove the use of ABI::FunctionCallsChangeCFA in that check.
I thought about it a lot and none of the architecutres that we're
supporting today can have a looping CFA.
Since the unwinder isn't using ABI::FunctionCallsChangeCFA() and
ABI::StackUsesFrames(), and the unwinder was the only reason
those methods exists, I removed them from the ABI and all its
plugins.
<rdar://problem/17364005>
Modified:
lldb/trunk/include/lldb/Target/ABI.h
lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h
lldb/trunk/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h
lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h
lldb/trunk/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h
lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h
lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h
Modified: lldb/trunk/include/lldb/Target/ABI.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ABI.h?rev=216992&r1=216991&r2=216992&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ABI.h (original)
+++ lldb/trunk/include/lldb/Target/ABI.h Tue Sep 2 18:04:01 2014
@@ -112,12 +112,6 @@ public:
virtual bool
RegisterIsVolatile (const RegisterInfo *reg_info) = 0;
- // Should return true if your ABI uses frames when doing stack backtraces. This
- // means a frame pointer is used that points to the previous stack frame in some
- // way or another.
- virtual bool
- StackUsesFrames () = 0;
-
// Should take a look at a call frame address (CFA) which is just the stack
// pointer value upon entry to a function. ABIs usually impose alignment
// restrictions (4, 8 or 16 byte aligned), and zero is usually not allowed.
@@ -143,15 +137,6 @@ public:
virtual const RegisterInfo *
GetRegisterInfoArray (uint32_t &count) = 0;
- // Some architectures (e.g. x86) will push the return address on the stack and decrement
- // the stack pointer when making a function call. This means that every stack frame will
- // have a unique CFA.
- // Other architectures (e.g. arm) pass the return address in a register so it is possible
- // to have a frame on a backtrace that does not push anything on the stack or change the
- // CFA.
- virtual bool
- FunctionCallsChangeCFA () = 0;
-
bool
GetRegisterInfoByName (const ConstString &name, RegisterInfo &info);
Modified: lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h?rev=216992&r1=216991&r2=216992&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h (original)
+++ lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h Tue Sep 2 18:04:01 2014
@@ -53,13 +53,7 @@ public:
virtual bool
RegisterIsVolatile (const lldb_private::RegisterInfo *reg_info);
-
- virtual bool
- StackUsesFrames ()
- {
- return true;
- }
-
+
virtual bool
CallFrameAddressIsValid (lldb::addr_t cfa)
{
@@ -88,12 +82,6 @@ public:
return pc & ~(lldb::addr_t)1;
}
- virtual bool
- FunctionCallsChangeCFA ()
- {
- return false;
- }
-
virtual const lldb_private::RegisterInfo *
GetRegisterInfoArray (uint32_t &count);
Modified: lldb/trunk/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h?rev=216992&r1=216991&r2=216992&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h (original)
+++ lldb/trunk/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h Tue Sep 2 18:04:01 2014
@@ -46,15 +46,7 @@ public:
virtual bool
RegisterIsVolatile (const lldb_private::RegisterInfo *reg_info);
-
-
- virtual bool
- StackUsesFrames ()
- {
- // MacOSX uses frame pointers.
- return true;
- }
-
+
// The arm64 ABI requires that stack frames be 16 byte aligned.
// When there is a trap handler on the stack, e.g. _sigtramp in userland
// code, we've seen that the stack pointer is often not aligned properly
@@ -87,12 +79,6 @@ public:
return true;
}
- virtual bool
- FunctionCallsChangeCFA ()
- {
- return false;
- }
-
virtual const lldb_private::RegisterInfo *
GetRegisterInfoArray (uint32_t &count);
Modified: lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h?rev=216992&r1=216991&r2=216992&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h (original)
+++ lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h Tue Sep 2 18:04:01 2014
@@ -64,13 +64,7 @@ public:
virtual bool
RegisterIsVolatile (const lldb_private::RegisterInfo *reg_info);
-
- virtual bool
- StackUsesFrames ()
- {
- return true;
- }
-
+
// The Darwin i386 ABI requires that stack frames be 16 byte aligned.
// When there is a trap handler on the stack, e.g. _sigtramp in userland
// code, we've seen that the stack pointer is often not aligned properly
@@ -102,12 +96,6 @@ public:
return pc <= UINT32_MAX;
}
- virtual bool
- FunctionCallsChangeCFA ()
- {
- return true;
- }
-
virtual const lldb_private::RegisterInfo *
GetRegisterInfoArray (uint32_t &count);
Modified: lldb/trunk/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h?rev=216992&r1=216991&r2=216992&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h Tue Sep 2 18:04:01 2014
@@ -75,13 +75,7 @@ public:
virtual bool
RegisterIsVolatile ( const lldb_private::RegisterInfo *reg_info );
-
- virtual bool
- StackUsesFrames ( void )
- {
- return true;
- }
-
+
virtual bool
CallFrameAddressIsValid ( lldb::addr_t cfa )
{
@@ -101,12 +95,6 @@ public:
return true;
}
- virtual bool
- FunctionCallsChangeCFA ( void )
- {
- return true;
- }
-
virtual const lldb_private::RegisterInfo *
GetRegisterInfoArray ( uint32_t &count );
Modified: lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h?rev=216992&r1=216991&r2=216992&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h Tue Sep 2 18:04:01 2014
@@ -61,13 +61,7 @@ public:
virtual bool
RegisterIsVolatile (const lldb_private::RegisterInfo *reg_info);
-
- virtual bool
- StackUsesFrames ()
- {
- return true;
- }
-
+
// The SysV x86_64 ABI requires that stack frames be 16 byte aligned.
// When there is a trap handler on the stack, e.g. _sigtramp in userland
// code, we've seen that the stack pointer is often not aligned properly
@@ -97,12 +91,6 @@ public:
return true;
}
- virtual bool
- FunctionCallsChangeCFA ()
- {
- return true;
- }
-
virtual const lldb_private::RegisterInfo *
GetRegisterInfoArray (uint32_t &count);
//------------------------------------------------------------------
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=216992&r1=216991&r2=216992&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp Tue Sep 2 18:04:01 2014
@@ -406,6 +406,13 @@ RegisterContextLLDB::InitializeNonZeroth
return;
}
+ if (CheckIfLoopingStack ())
+ {
+ UnwindLogMsg ("same CFA address as next frame, assuming the unwind is looping - stopping");
+ m_frame_type = eNotAValidFrame;
+ return;
+ }
+
UnwindLogMsg ("initialized frame cfa is 0x%" PRIx64, (uint64_t) m_cfa);
return;
}
@@ -574,6 +581,20 @@ RegisterContextLLDB::InitializeNonZeroth
return;
}
+ if (CheckIfLoopingStack ())
+ {
+ UnwindLogMsg ("same CFA address as next frame, assuming the unwind is looping - stopping");
+ m_frame_type = eNotAValidFrame;
+ return;
+ }
+
+ UnwindLogMsg ("initialized frame current pc is 0x%" PRIx64 " cfa is 0x%" PRIx64,
+ (uint64_t) m_current_pc.GetLoadAddress (exe_ctx.GetTargetPtr()), (uint64_t) m_cfa);
+}
+
+bool
+RegisterContextLLDB::CheckIfLoopingStack ()
+{
// If we have a bad stack setup, we can get the same CFA value multiple times -- or even
// more devious, we can actually oscillate between two CFA values. Detect that here and
// break out to avoid a possible infinite loop in lldb trying to unwind the stack.
@@ -581,29 +602,19 @@ RegisterContextLLDB::InitializeNonZeroth
addr_t next_next_frame_cfa = LLDB_INVALID_ADDRESS;
if (GetNextFrame().get() && GetNextFrame()->GetCFA(next_frame_cfa))
{
- bool repeating_frames = false;
if (next_frame_cfa == m_cfa)
{
- repeating_frames = true;
- }
- else
- {
- if (GetNextFrame()->GetNextFrame() && GetNextFrame()->GetNextFrame()->GetCFA(next_next_frame_cfa)
- && next_next_frame_cfa == m_cfa)
- {
- repeating_frames = true;
- }
+ // We have a loop in the stack unwind
+ return true;
}
- if (repeating_frames && abi && abi->FunctionCallsChangeCFA())
+ if (GetNextFrame()->GetNextFrame().get() && GetNextFrame()->GetNextFrame()->GetCFA(next_next_frame_cfa)
+ && next_next_frame_cfa == m_cfa)
{
- UnwindLogMsg ("same CFA address as next frame, assuming the unwind is looping - stopping");
- m_frame_type = eNotAValidFrame;
- return;
+ // We have a loop in the stack unwind
+ return true;
}
}
-
- UnwindLogMsg ("initialized frame current pc is 0x%" PRIx64 " cfa is 0x%" PRIx64,
- (uint64_t) m_current_pc.GetLoadAddress (exe_ctx.GetTargetPtr()), (uint64_t) m_cfa);
+ return false;
}
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=216992&r1=216991&r2=216992&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h Tue Sep 2 18:04:01 2014
@@ -98,6 +98,12 @@ private:
// UnwindLLDB needs to pass around references to RegisterLocations
friend class UnwindLLDB;
+
+ // Returns true if we have an unwind loop -- the same stack frame unwinding
+ // multiple times.
+ bool
+ CheckIfLoopingStack ();
+
// Indicates whether this frame is frame zero -- the currently
// executing frame -- or not.
bool
More information about the lldb-commits
mailing list