Refactor register access from StackVisitor
Moves register access checking up to StackVisitor by adding methods
IsAccessibleGPR and IsAccessibleFPR in Context class. It allows to
simplify GetGPR/FPR and SetGPR/FPR methods in the Context class (and
its subclasses).
Also simplifies code in StackVisitor by adding IsAccessibleRegister,
GetRegister and SetRegister methods which then call either GPR or FPR
specific methods in Context depending on the nature of the accessed
register.
Bug: 18547544
Bug: 19106446
Change-Id: I6e707608d935a71571d0e975a6e766053de3763a
diff --git a/runtime/arch/context.h b/runtime/arch/context.h
index 20a84dd..ed8cab0 100644
--- a/runtime/arch/context.h
+++ b/runtime/arch/context.h
@@ -49,24 +49,30 @@
// Sets the program counter value.
virtual void SetPC(uintptr_t new_pc) = 0;
+ // Returns whether the given GPR is accessible (read or write).
+ virtual bool IsAccessibleGPR(uint32_t reg) = 0;
+
// Gets the given GPRs address.
virtual uintptr_t* GetGPRAddress(uint32_t reg) = 0;
- // Reads the given GPR. Returns true if we successfully read the register and
- // set its value into 'val', returns false otherwise.
- virtual bool GetGPR(uint32_t reg, uintptr_t* val) = 0;
+ // Reads the given GPR. The caller is responsible for checking the register
+ // is accessible with IsAccessibleGPR.
+ virtual uintptr_t GetGPR(uint32_t reg) = 0;
- // Sets the given GPR. Returns true if we successfully write the given value
- // into the register, returns false otherwise.
- virtual bool SetGPR(uint32_t reg, uintptr_t value) = 0;
+ // Sets the given GPR. The caller is responsible for checking the register
+ // is accessible with IsAccessibleGPR.
+ virtual void SetGPR(uint32_t reg, uintptr_t value) = 0;
- // Reads the given FPR. Returns true if we successfully read the register and
- // set its value into 'val', returns false otherwise.
- virtual bool GetFPR(uint32_t reg, uintptr_t* val) = 0;
+ // Returns whether the given FPR is accessible (read or write).
+ virtual bool IsAccessibleFPR(uint32_t reg) = 0;
- // Sets the given FPR. Returns true if we successfully write the given value
- // into the register, returns false otherwise.
- virtual bool SetFPR(uint32_t reg, uintptr_t value) = 0;
+ // Reads the given FPR. The caller is responsible for checking the register
+ // is accessible with IsAccessibleFPR.
+ virtual uintptr_t GetFPR(uint32_t reg) = 0;
+
+ // Sets the given FPR. The caller is responsible for checking the register
+ // is accessible with IsAccessibleFPR.
+ virtual void SetFPR(uint32_t reg, uintptr_t value) = 0;
// Smashes the caller save registers. If we're throwing, we don't want to return bogus values.
virtual void SmashCallerSaves() = 0;