Subject: Re: bus error in mktemp
To: None <port-pc532@NetBSD.ORG>
From: Jon Buller <jonb@metronet.com>
List: port-pc532
Date: 10/25/1995 07:36:43
Phil Budne wrote:
> Could the buffer be "const"?

FILE * intermedf = (FILE *) NULL;
char *interfn = 
#ifdef DOSTMP
 "frtXXXXXX";
#else
 "/tmp/frankasm.XXXXXX";
#endif

It used to be /usr/tmp/fr..., but that didn't work too well with no tmp
directory on the /usr partition 8-)

Matthias Pfaller wrote:
> Could you please have a look at the assembler instructions? I think
> you could see a code gen bug. I'm no longer running 2.6.3 on my machine.
> I'm using 2.7.0.

jonb@bullbox[1]% gdb as8051
GDB is free software and you are welcome to 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.
GDB 4.11 (ns32k-netbsd), Copyright 1993 Free Software Foundation, Inc...
(gdb) break mktemp
Breakpoint 1 at 0x9507: file mktemp.c, line 66.
(gdb) run as8051.tst
Starting program: /misc/jonb/mcs51/jdb/asm/as8051 as8051.tst

Breakpoint 1, mktemp (path=0x1744 "/tmp/frankasm.XXXXXX") at mktemp.c:66
66              return(_gettemp(path, (int *)NULL) ? path : (char *)NULL);
(gdb) step
_gettemp (path=0x1744 "/tmp/frankasm.XXXXXX", doopen=0xfdbfdff0) at mktemp.c:79
79              pid = getpid();
(gdb) step
80              for (trv = path; *trv; ++trv);          /* extra X's get set to 0's */
(gdb) step
81              while (*--trv == 'X') {
(gdb) step
82                      *trv = (pid % 10) + '0';
(gdb) step

Program received signal SIGBUS (10), Bus error
0x95a0 in _gettemp (path=0x1744 "/tmp/frankasm.XXXXXX", doopen=0x0)
    at mktemp.c:82
82                      *trv = (pid % 10) + '0';
(gdb) print path
$1 = 0x1744 "/tmp/frankasm.XXXXXX"
(gdb) print pid
$2 = 2182
(gdb) print trv
$3 = 0x1757 "X"
(gdb) disassemble
Dump of assembler code for function _gettemp:
0x9524 <_gettemp>:      enter   0xf8, 116
0x9528 <_gettemp+4>:    movd    12(fp), r3
0x952b <_gettemp+7>:    bsr     0xc104 <_DYNAMIC+260>
0x9530 <_gettemp+12>:   movd    r0, -100(fp)
0x9534 <_gettemp+16>:   movd    8(fp), -116(fp)
0x9539 <_gettemp+21>:   movd    -116(fp), r5
0x953d <_gettemp+25>:   cmpqb   0, 0(r5)
0x9540 <_gettemp+28>:   bne     0x9544 <_gettemp+32>
0x9542 <_gettemp+30>:   br      0x954c <_gettemp+40>
0x9544 <_gettemp+32>:   addqd   1, -116(fp)
0x9548 <_gettemp+36>:   br      0x9539 <_gettemp+21>
0x954a <_gettemp+38>:   nop
0x954b <_gettemp+39>:   nop
0x954c <_gettemp+40>:   addqd   -1, -116(fp)
0x9550 <_gettemp+44>:   movd    -116(fp), r4
0x9554 <_gettemp+48>:   cmpb    0(r4), $88
0x9558 <_gettemp+52>:   beq     0x9560 <_gettemp+60>
0x955a <_gettemp+54>:   br      0x95cc <_gettemp+168>
0x955d <_gettemp+57>:   nop
0x955e <_gettemp+58>:   nop
0x955f <_gettemp+59>:   nop
0x9560 <_gettemp+60>:   movd    -100(fp), r0
0x9564 <_gettemp+64>:   movd    $-858993459, r1
0x956a <_gettemp+70>:   movd    r0, r4
0x956c <_gettemp+72>:   meid    r1, r4
0x956f <_gettemp+75>:   movd    r4, -108(fp)
0x9573 <_gettemp+79>:   movd    r5, -104(fp)
0x9577 <_gettemp+83>:   movd    -104(fp), r6
0x957b <_gettemp+87>:   lshd    $0, r6
0x957f <_gettemp+91>:   movqd   0, r7
0x9581 <_gettemp+93>:   movd    r6, r2
0x9583 <_gettemp+95>:   lshd    $-3, r2
0x9587 <_gettemp+99>:   movd    r2, r1
0x9589 <_gettemp+101>:  lshd    $2, r1
0x958d <_gettemp+105>:  addd    r2, r1
0x958f <_gettemp+107>:  movd    r1, r2
0x9591 <_gettemp+109>:  lshd    $1, r2
0x9595 <_gettemp+113>:  subd    r2, r0
0x9597 <_gettemp+115>:  movb    r0, r4
0x9599 <_gettemp+117>:  addb    $48, r4
0x959c <_gettemp+120>:  movd    -116(fp), r5
0x95a0 <_gettemp+124>:  movb    r4, 0(r5)
0x95a3 <_gettemp+127>:  movd    -100(fp), r0
0x95a7 <_gettemp+131>:  movd    $-858993459, r2
0x95ad <_gettemp+137>:  movd    r0, r4
0x95af <_gettemp+139>:  meid    r2, r4
0x95b2 <_gettemp+142>:  movd    r4, r6
0x95b4 <_gettemp+144>:  movd    r5, r7
0x95b6 <_gettemp+146>:  movd    r7, r0
0x95b8 <_gettemp+148>:  lshd    $0, r0
0x95bc <_gettemp+152>:  movqd   0, r1
0x95be <_gettemp+154>:  movd    r0, r2
0x95c0 <_gettemp+156>:  lshd    $-3, r2
0x95c4 <_gettemp+160>:  movd    r2, -100(fp)
0x95c8 <_gettemp+164>:  br      0x954c <_gettemp+40>
0x95cb <_gettemp+167>:  nop
0x95cc <_gettemp+168>:  movd    -116(fp), r5
0x95d0 <_gettemp+172>:  addr    1(r5), -112(fp)
0x95d5 <_gettemp+177>:  cmpd    -116(fp), 8(fp)
0x95da <_gettemp+182>:  bhi     0x95e0 <_gettemp+188>
0x95dc <_gettemp+184>:  br      0x963c <_gettemp+280>
0x95df <_gettemp+187>:  nop
0x95e0 <_gettemp+188>:  movd    -116(fp), r4
0x95e4 <_gettemp+192>:  cmpb    0(r4), $47
0x95e8 <_gettemp+196>:  bne     0x9634 <_gettemp+272>
0x95eb <_gettemp+199>:  movd    -116(fp), r5
0x95ef <_gettemp+203>:  movqb   0, 0(r5)
0x95f2 <_gettemp+206>:  addr    -96(fp), r0
(gdb) quit
The program is running.  Quit anyway (and kill it)? (y or n) y
jonb@bullbox[2]% exit


I'm not sure if the code is correct or not, since it turned the
(pid % 10) into a multiply, but that shouldn't affect the destination
at 0(r5).  and it's not like that address should be there, since
the for loop just above it scaned the whole string...  I compiled
it with "-S -g", and noticed that it put the line markers in at
0x95a1 for line 83 "pid /= 10;" and line 82 starts at 0x9560.  Like
I said before, it's probably something stupid, but it looks real
wierd to me right now.

Thanks again,
Jon