public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Torbjörn SVENSSON" <torbjorn.svensson@foss.st.com>
To: <gdb-patches@sourceware.org>
Cc: "Torbjörn SVENSSON" <torbjorn.svensson@foss.st.com>,
	"Yvan Roux" <yvan.roux@foss.st.com>
Subject: [PATCH v3 1/2] gdb/arm: Use if-else if instead of switch
Date: Fri, 22 Jul 2022 22:59:33 +0200	[thread overview]
Message-ID: <20220722205930.2461429-2-torbjorn.svensson@foss.st.com> (raw)
In-Reply-To: <1dde8763-9da8-1590-ac3f-06f0555bc14a@arm.com>

As the register number for the alternative Arm SP register are not
contstant, it's not possible to use switch statement to define the
rules. In order to not have a mix, replace the few existing
switch-statement with regular if-else if statments.
This patch is a preparation for the next one in the series.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
---
 gdb/arm-tdep.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index d3b4fce98a3..7d0944f9e3f 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -3785,9 +3785,8 @@ arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
   CORE_ADDR lr;
   ULONGEST cpsr;
 
-  switch (regnum)
+  if (regnum == ARM_PC_REGNUM)
     {
-    case ARM_PC_REGNUM:
       /* The PC is normally copied from the return column, which
 	 describes saves of LR.  However, that version may have an
 	 extra bit set to indicate Thumb state.  The bit is not
@@ -3807,18 +3806,18 @@ arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
       lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
       return frame_unwind_got_constant (this_frame, regnum,
 					arm_addr_bits_remove (gdbarch, lr));
-
-    case ARM_PS_REGNUM:
+    }
+  else if (regnum == ARM_PS_REGNUM)
+    {
       /* Reconstruct the T bit; see arm_prologue_prev_register for details.  */
       cpsr = get_frame_register_unsigned (this_frame, regnum);
       lr = frame_unwind_register_unsigned (this_frame, ARM_LR_REGNUM);
       cpsr = reconstruct_t_bit (gdbarch, lr, cpsr);
       return frame_unwind_got_constant (this_frame, regnum, cpsr);
-
-    default:
-      internal_error (__FILE__, __LINE__,
-		      _("Unexpected register %d"), regnum);
     }
+
+  internal_error (__FILE__, __LINE__,
+		  _("Unexpected register %d"), regnum);
 }
 
 /* Implement the stack_frame_destroyed_p gdbarch method.  */
@@ -4944,17 +4943,13 @@ arm_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
       return;
     }
 
-  switch (regnum)
+  if (regnum == ARM_PC_REGNUM || regnum == ARM_PS_REGNUM)
     {
-    case ARM_PC_REGNUM:
-    case ARM_PS_REGNUM:
       reg->how = DWARF2_FRAME_REG_FN;
       reg->loc.fn = arm_dwarf2_prev_register;
-      break;
-    case ARM_SP_REGNUM:
-      reg->how = DWARF2_FRAME_REG_CFA;
-      break;
     }
+  else if (regnum == ARM_SP_REGNUM)
+    reg->how = DWARF2_FRAME_REG_CFA;
 }
 
 /* Given BUF, which is OLD_LEN bytes ending at ENDADDR, expand
-- 
2.25.1


  parent reply	other threads:[~2022-07-22 21:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07  9:17 [PATCH V2 0/2] gdb/arm: Sync sp with other *sp registers Yvan Roux
2022-07-07  9:19 ` [PATCH V2 1/2] gdb/arm: Rename arm_cache_is_sp_register to Yvan Roux
2022-07-16  2:03   ` Luis Machado
2022-07-21 13:01     ` Luis Machado
2022-07-07  9:21 ` [PATCH V2 2/2] gdb/arm: Sync sp with other *sp registers Yvan Roux
2022-07-16  2:03   ` Luis Machado
2022-07-21  8:33     ` Torbjorn SVENSSON
2022-07-21  8:48       ` Luis Machado
2022-07-22 20:59         ` [PATCH V3 0/2] " Torbjörn SVENSSON
2022-07-22 20:59         ` Torbjörn SVENSSON [this message]
2022-07-25  9:48           ` [PATCH v3 1/2] gdb/arm: Use if-else if instead of switch Luis Machado
2022-07-22 20:59         ` [PATCH v3 2/2] gdb/arm: Sync sp with other *sp registers Torbjörn SVENSSON
2022-07-25  9:52           ` Luis Machado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220722205930.2461429-2-torbjorn.svensson@foss.st.com \
    --to=torbjorn.svensson@foss.st.com \
    --cc=gdb-patches@sourceware.org \
    --cc=yvan.roux@foss.st.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).