Hello there,
I have a really strange error and I have no idea how this could
happen. Maybe you can help me. I am trying to cross debug a binary on
an ARM926ej-s running Linux 2.6.35 on top of a microvisor (OKL4).
My testing code looks as follows:
#include <stdio.h>
void printout(unsigned int i){
if(i == 1){
printf("1\n");
}else{
printf("0\n");
}
}
int main( int argc, char *argv[] ){
unsigned int i=1;
printout(i);
return 0;
}
If I run the binary without gdb on target I get "1" as output. But if
I run it with gdb, using 'single step' command, I get "0" as output.
Dissassembly of the if statement looks as follows:
│0x10418 <printout+16> ldr r3, [r11, #-8] │
│0x1041c <printout+20> cmp r3, #1 │
│0x10420 <printout+24> bne 0x10430 <printout+40>
content of r3 is #1. After executing 0x1041c CPSR is still 0x0 but
should be 0x40000000 (Zero bit equals 1). Therefore bne does not jump
to the right address.
If I step over "printout" function (using next step instruction) I get
"1" as output. I tried changing the CPSR register value to 0x40000000
after reaching 0x10420 and now it prints "1". So it looks like while
single stepping gdb is overwriting the CPSR register value.
I tried using thumb and arm mode (compile with -marm and -mthumb) but
this made no difference. I tried different toolchains with the same
result (toolchains build with crosstools-ng 1.23.0 once for armv5t
architecture and once for arm296ej-s cpu) but still get the same
result.
I also tried the following compiler options:
* cross-gcc -g -O0 main.c -o main
* cross-gcc -ggdb -Oo main.c -o main
* cross-gc -Ogdb main.c -o main
Unfortunately all with the same result.
gdbserver is 7.12.1 (rootfs build via buildroot using the self-build
toolchain). I also tried different toolchains from Linaro project, all
with the same strange result.
Any idea how this could happen?