From 2b695ee36b51c16109a5b2fc24b3a1de395f3de2 Mon Sep 17 00:00:00 2001 From: StalkR Date: Tue, 25 Mar 2014 16:27:26 +0100 Subject: [PATCH] $cpsr struct not always defined, extract bits from $cpsr manually --- gdbinit | 67 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/gdbinit b/gdbinit index 0e3d218..60ff812 100644 --- a/gdbinit +++ b/gdbinit @@ -463,7 +463,7 @@ define flagsarm # Carry/Borrow/Extend (C), bit 29 # Overflow (V), bit 28 # negative/less than (N), bit 31 of CPSR - if ($cpsr->n & 1) + if (($cpsr >> 0x1f) & 1) printf "N " set $_n_flag = 1 else @@ -471,7 +471,7 @@ define flagsarm set $_n_flag = 0 end # zero (Z), bit 30 - if ($cpsr->z & 1) + if (($cpsr >> 0x1e) & 1) printf "Z " set $_z_flag = 1 else @@ -479,7 +479,7 @@ define flagsarm set $_z_flag = 0 end # Carry/Borrow/Extend (C), bit 29 - if ($cpsr->c & 1) + if (($cpsr >> 0x1d) & 1) printf "C " set $_c_flag = 1 else @@ -487,7 +487,7 @@ define flagsarm set $_c_flag = 0 end # Overflow (V), bit 28 - if ($cpsr->v & 1) + if (($cpsr >> 0x1c) & 1) printf "V " set $_v_flag = 1 else @@ -495,7 +495,7 @@ define flagsarm set $_v_flag = 0 end # Sticky overflow (Q), bit 27 - if ($cpsr->q & 1) + if (($cpsr >> 0x1b) & 1) printf "Q " set $_q_flag = 1 else @@ -506,7 +506,7 @@ define flagsarm # When T=1: # J = 0 The processor is in Thumb state. # J = 1 The processor is in ThumbEE state. - if ($cpsr->j & 1) + if (($cpsr >> 0x18) & 1) printf "J " set $_j_flag = 1 else @@ -514,7 +514,7 @@ define flagsarm set $_j_flag = 0 end # Data endianness bit (E), bit 9 - if ($cpsr->e & 1) + if (($cpsr >> 9) & 1) printf "E " set $_e_flag = 1 else @@ -524,7 +524,7 @@ define flagsarm # Imprecise abort disable bit (A), bit 8 # The A bit is set to 1 automatically. It is used to disable imprecise data aborts. # It might not be writable in the Nonsecure state if the AW bit in the SCR register is reset. - if ($cpsr->a & 1) + if (($cpsr >> 8) & 1) printf "A " set $_a_flag = 1 else @@ -533,7 +533,7 @@ define flagsarm end # IRQ disable bit (I), bit 7 # When the I bit is set to 1, IRQ interrupts are disabled. - if ($cpsr->i & 1) + if (($cpsr >> 7) & 1) printf "I " set $_i_flag = 1 else @@ -543,7 +543,7 @@ define flagsarm # FIQ disable bit (F), bit 6 # When the F bit is set to 1, FIQ interrupts are disabled. # FIQ can be nonmaskable in the Nonsecure state if the FW bit in SCR register is reset. - if ($cpsr->f & 1) + if (($cpsr >> 6) & 1) printf "F " set $_f_flag = 1 else @@ -552,7 +552,7 @@ define flagsarm end # Thumb state bit (F), bit 5 # if 1 then the processor is executing in Thumb state or ThumbEE state depending on the J bit - if ($cpsr->t & 1) + if (($cpsr >> 5) & 1) printf "T " set $_t_flag = 1 else @@ -656,15 +656,16 @@ end define eflags if $ARM == 1 + # http://www.heyrick.co.uk/armwiki/The_Status_register printf " N <%d> Z <%d> C <%d> V <%d>",\ - ($cpsr->n & 1), ($cpsr->z & 1), \ - ($cpsr->c & 1), ($cpsr->v & 1) + (($cpsr >> 0x1f) & 1), (($cpsr >> 0x1e) & 1), \ + (($cpsr >> 0x1d) & 1), (($cpsr >> 0x1c) & 1) printf " Q <%d> J <%d> GE <%d> E <%d> A <%d>",\ - ($cpsr->q & 1), ($cpsr->j & 1),\ - ($cpsr->ge), ($cpsr->e & 1), ($cpsr->a & 1) + (($cpsr >> 0x1b) & 1), (($cpsr >> 0x18) & 1),\ + (($cpsr >> 0x10) & 7), (($cpsr >> 9) & 1), (($cpsr >> 8) & 1) printf " I <%d> F <%d> T <%d> \n",\ - ($cpsr->i & 1), ($cpsr->f & 1), \ - ($cpsr->t & 1) + (($cpsr >> 7) & 1), (($cpsr >> 6) & 1), \ + (($cpsr >> 5) & 1) else printf " OF <%d> DF <%d> IF <%d> TF <%d>",\ (((unsigned int)$eflags >> 0xB) & 1), (((unsigned int)$eflags >> 0xA) & 1), \ @@ -1495,11 +1496,16 @@ define ddump help ddump else color $COLOR_SEPARATOR - if ($64BITS == 1) - printf "[0x%04X:0x%016lX]", $ds, $data_addr + if $ARM == 1 + printf "[0x%08X]", $data_addr else - printf "[0x%04X:0x%08X]", $ds, $data_addr + if ($64BITS == 1) + printf "[0x%04X:0x%016lX]", $ds, $data_addr + else + printf "[0x%04X:0x%08X]", $ds, $data_addr + end end + color $COLOR_SEPARATOR printf "------------------------" printf "-------------------------------" @@ -1610,7 +1616,8 @@ define dumpjump # 12 bits for any immediate value # $_t_flag == 0 => ARM mode # $_t_flag == 1 => Thumb or ThumbEE - if ($cpsr->t & 1) + # State bit (T), bit 5 + if (($cpsr >> 5) & 1) set $_t_flag = 1 else set $_t_flag = 0 @@ -2031,11 +2038,15 @@ define context end if $SHOWSTACK == 1 color $COLOR_SEPARATOR - if ($64BITS == 1) - printf "[0x%04X:0x%016lX]", $ss, $rsp + if $ARM == 1 + printf "[0x%08X]", $sp else - printf "[0x%04X:0x%08X]", $ss, $esp - end + if ($64BITS == 1) + printf "[0x%04X:0x%016lX]", $ss, $rsp + else + printf "[0x%04X:0x%08X]", $ss, $esp + end + end color $COLOR_SEPARATOR printf "-------------------------" printf "-----------------------------" @@ -2130,14 +2141,16 @@ define context if ($SETCOLOUR1STLINE == 1) color $GREEN if ($ARM == 1) - x/i $pc | $cpsr.t + # | $cpsr.t (Thumb flag) + x/i (unsigned int)$pc | (($cpsr >> 5) & 1) else x/i $pc end color_reset else if ($ARM == 1) - x/i $pc | $cpsr.t + # | $cpsr.t (Thumb flag) + x/i (unsigned int)$pc | (($cpsr >> 5) & 1) else x/i $pc end