[2/8,AArch64] Refactor aarch64_make_stub_cache

Message ID 1436273518-5959-3-git-send-email-pierre.langlois@arm.com
State New, archived
Headers

Commit Message

Pierre Langlois July 7, 2015, 12:51 p.m. UTC
  We would previously have to make sure the frame cache was not already
created before calling aarch64_make_stub_cache.  This patch makes this
function check it so the caller does not need to do so.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_make_stub_cache): New argument
	this_cache.  Remove unused local variables reg and unwound_fp.
	Return early if this_cache is already set.  Set this_cache.
	(aarch64_stub_this_id): Update call to aarch64_make_stub_cache.
---
 gdb/aarch64-tdep.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
  

Comments

Yao Qi July 8, 2015, 4:10 p.m. UTC | #1
Pierre Langlois <pierre.langlois@arm.com> writes:

>  static struct aarch64_prologue_cache *
> -aarch64_make_stub_cache (struct frame_info *this_frame)
> +aarch64_make_stub_cache (struct frame_info *this_frame, void **this_cache)
>  {

We need comments on this function, about its arguments and return value.

> -  int reg;
>    struct aarch64_prologue_cache *cache;
> -  CORE_ADDR unwound_fp;
> +
> +  if (*this_cache)

     if (*this_cache != NULL)

> +    return *this_cache;

OK with these changes.
  

Patch

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index c4b7fe8..90a63e9 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -1052,14 +1052,16 @@  struct frame_unwind aarch64_prologue_unwind =
    about the prologue of *THIS_FRAME.  */
 
 static struct aarch64_prologue_cache *
-aarch64_make_stub_cache (struct frame_info *this_frame)
+aarch64_make_stub_cache (struct frame_info *this_frame, void **this_cache)
 {
-  int reg;
   struct aarch64_prologue_cache *cache;
-  CORE_ADDR unwound_fp;
+
+  if (*this_cache)
+    return *this_cache;
 
   cache = FRAME_OBSTACK_ZALLOC (struct aarch64_prologue_cache);
   cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
+  *this_cache = cache;
 
   cache->prev_sp
     = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
@@ -1073,11 +1075,8 @@  static void
 aarch64_stub_this_id (struct frame_info *this_frame,
 		      void **this_cache, struct frame_id *this_id)
 {
-  struct aarch64_prologue_cache *cache;
-
-  if (*this_cache == NULL)
-    *this_cache = aarch64_make_stub_cache (this_frame);
-  cache = *this_cache;
+  struct aarch64_prologue_cache *cache
+    = aarch64_make_stub_cache (this_frame, this_cache);
 
   *this_id = frame_id_build (cache->prev_sp, get_frame_pc (this_frame));
 }