[Lldb-commits] [lldb] r166005 - in /lldb/trunk: include/lldb/Target/ABI.h source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h source/Plugins/Process/Utility/RegisterContextLLDB.cpp

Jason Molenda jmolenda at apple.com
Mon Oct 15 19:39:24 PDT 2012


Author: jmolenda
Date: Mon Oct 15 21:39:21 2012
New Revision: 166005

URL: http://llvm.org/viewvc/llvm-project?rev=166005&view=rev
Log:
Add a new ABI plugin method which specifies whether the architecture
must push something on the stack for a function call or not.  In
x86, the stack pointer is decremented when the caller's pc is saved
on the stack.  In arm, the stack pointer and frame pointer don't
necessarily have to change for a function call, although most
functions need to use some stack space during their execution.

Use this information in the RegisterContextLLDB to detect invalid 
unwind scenarios more accurately.

<rdar://problem/12348574>

Modified:
    lldb/trunk/include/lldb/Target/ABI.h
    lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h
    lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h
    lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h
    lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp

Modified: lldb/trunk/include/lldb/Target/ABI.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ABI.h?rev=166005&r1=166004&r2=166005&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ABI.h (original)
+++ lldb/trunk/include/lldb/Target/ABI.h Mon Oct 15 21:39:21 2012
@@ -46,7 +46,6 @@
     GetArgumentValues (Thread &thread,
                        ValueList &values) const = 0;
     
-public:
     lldb::ValueObjectSP
     GetReturnValueObject (Thread &thread,
                           ClangASTType &type,
@@ -72,12 +71,22 @@
     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.
+    // This function should return true if "cfa" is valid call frame address for
+    // the ABI, and false otherwise. This is used by the generic stack frame unwinding
+    // code to help determine when a stack ends.
     virtual bool
     CallFrameAddressIsValid (lldb::addr_t cfa) = 0;
 
+    // Validates a possible PC value and returns true if an opcode can be at "pc".
     virtual bool
     CodeAddressIsValid (lldb::addr_t pc) = 0;    
 
@@ -93,7 +102,15 @@
     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=166005&r1=166004&r2=166005&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h (original)
+++ lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h Mon Oct 15 21:39:21 2012
@@ -93,6 +93,12 @@
         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-i386/ABIMacOSX_i386.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h?rev=166005&r1=166004&r2=166005&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h (original)
+++ lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h Mon Oct 15 21:39:21 2012
@@ -93,7 +93,13 @@
         // Just make sure the address is a valid 32 bit address. 
         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-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=166005&r1=166004&r2=166005&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 Mon Oct 15 21:39:21 2012
@@ -91,7 +91,13 @@
         // aren't fixed width...
         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=166005&r1=166004&r2=166005&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp Mon Oct 15 21:39:21 2012
@@ -604,7 +604,7 @@
                 repeating_frames = true;
             }
         }
-        if (repeating_frames)
+        if (repeating_frames && abi->FunctionCallsChangeCFA())
         {
             if (log)
             {





More information about the lldb-commits mailing list