very weird SIGBUS error

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Noko
Posts: 23
Joined: Sat Sep 06, 2008 8:35 pm

very weird SIGBUS error

Post by Noko »

I have some very strange error in SDL. Here's the output of gdb:

Code: Select all

GNU gdb 6.4
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-cygwin --target=psp"...
(gdb) target remote :10001
Remote debugging using :10001
[New thread 0]
_start (args=0, argp=0x0) at crt0.c:105
105             if ((&module_info != NULL) && (module_info.modattribute & 0x1000)) {
(gdb) c
Continuing.
[New thread 13506353]

Program received signal SIGBUS, Bus error.
[Switching to thread 13506353]
SDL_LowerBlit (src=0x8ad0780, srcrect=0x88f7cb0, dst=0x8ab4450, dstrect=0x88f7ca8) at SDL_surface.c:424
424             if ( (src->map->dst != dst) ||
(gdb) disas
Dump of assembler code for function SDL_LowerBlit:
0x089f47a8 <SDL_LowerBlit+0>&#58;   addiu   sp,sp,-40
0x089f47ac <SDL_LowerBlit+4>&#58;   sw      s3,28&#40;sp&#41;
0x089f47b0 <SDL_LowerBlit+8>&#58;   sw      s2,24&#40;sp&#41;
0x089f47b4 <SDL_LowerBlit+12>&#58;  sw      s1,20&#40;sp&#41;
0x089f47b8 <SDL_LowerBlit+16>&#58;  sw      s0,16&#40;sp&#41;
0x089f47bc <SDL_LowerBlit+20>&#58;  sw      ra,32&#40;sp&#41;
0x089f47c0 <SDL_LowerBlit+24>&#58;  lw      t0,48&#40;a0&#41;
0x089f47c4 <SDL_LowerBlit+28>&#58;  move    s3,a0
0x089f47c8 <SDL_LowerBlit+32>&#58;  move    s2,a2
0x089f47cc <SDL_LowerBlit+36>&#58;  lw      v0,0&#40;t0&#41;
0x089f47d0 <SDL_LowerBlit+40>&#58;  move    s0,a1
0x089f47d4 <SDL_LowerBlit+44>&#58;  bne     v0,a2,0x89f47ec <SDL_LowerBlit+68>
0x089f47d8 <SDL_LowerBlit+48>&#58;  move    s1,a3
<omitted>
&#40;gdb&#41; p/x $pc
$1 = 0x89f47cc
&#40;gdb&#41; p/x $t0
$2 = 0x0
&#40;gdb&#41; p/x $a0
$3 = 0x8ad0780
&#40;gdb&#41; p/x *&#40;int *&#41;&#40;$a0+48&#41;
$4 = 0x8b7e530
&#40;gdb&#41; set $t0=*&#40;int *&#41;&#40;$a0+48&#41;
&#40;gdb&#41; p/x $t0
$5 = 0x8b7e530
&#40;gdb&#41; c
Continuing.
Can't send signals to this remote system.  SIGBUS not sent.
The faulty operation is lw t0,48(a0) because t0 is 0. But t0 is supposed to be set at 0x089f47c0, with lw t0,48(a0). And when I set $t0 to *(int *)($a0+48) manually, program continues to work like lnothing happened.

This error happens randomly, I call SDL_LowerBlit many times, and only in some rare cases this hasppens.

EDIT:
I am a fucking idiot and another thread deleted the surface, that's why I had SIGBUS, and then this thread allocated surface again and that's why everything worked in debugger.
Thank you for reading.
Last edited by Noko on Fri Sep 12, 2008 2:41 am, edited 1 time in total.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

Well, honestly, reading carefully your output of gdb, the only sensible explanation i might see is a cache issue : how is it possible for lw $t0, 48($a0) randomly to read different values in run-time (as you say it happens randomly) ?

I would first have thought something might randomly set src->map to 0 but your gdb output seems to prove that it wasn't the case since you had a zero value at run-time and then you had the right value in debug-time by manually setting t0 from the same memory reference just after the exception with t0 == 0.

I'm sure there is a logical reason why it messes up, but we haven't enough information to tell you why.
Post Reply