Bug 181722 - gdb on ARM unable to sensibly debug core file from assert(3)
Summary: gdb on ARM unable to sensibly debug core file from assert(3)
Status: Closed Overcome By Events
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: 10.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-arm (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-01 12:00 UTC by Peter Jeremy
Modified: 2018-04-03 21:41 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Jeremy freebsd_committer freebsd_triage 2013-09-01 12:00:00 UTC
	Whilst trying to build head r254986 with clang on my Raspberry Pi,
	I consistently get an assertion failure and core file.  Attempting
	to examine the core file with gdb gives a truncated backtrace (see
	below).  If clang is run under gdb, setting a breakpoint at
	__assert, correct backtraces are shown.

root@rpi1:/a # gdb /a/obj/usr/src/tmp/usr/bin/cc cc.core 
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 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 "armv6-marcel-freebsd"...
Core was generated by `cc'.
Program terminated with signal 6, Aborted.
#0  0x01f92094 in kill ()
(gdb) where
#0  0x01f92094 in kill ()
#1  0x01f92038 in raise ()
#2  0x01f901a0 in abort ()
#3  0x01f7b55c in __assert ()
#4  0x01f7b55c in __assert ()
(gdb) 
...
(gdb) up
#4  0x01f7b55c in __assert ()
(gdb) info regi
r0             0x0      0
r1             0x0      0
r2             0x0      0
r3             0xffffffdf       -33
r4             0x0      0
r5             0xbfffcb74       -1073755276
r6             0x3      3
r7             0x57     87
r8             0x228152b8       578900664
r9             0x2284fb00       579140352
r10            0x22876000       579297280
r11            0xbfffcba8       -1073755224
r12            0xbfffcb94       -1073755244
sp             *value not available*
lr             0x1f7b55c        33011036
pc             0x1f7b55c        33011036
fps            0x0      0
cpsr           0x80000010       -2147483632
(gdb) disas 0x1f7b55c
Dump of assembler code for function $d:
0x01f7b55c <$d+0>:      eorseq  r8, r11, #12845056      ; 0xc40000
0x01f7b560 <$d+4>:      eorseq  r3, r10, #16515072      ; 0xfc0000
0x01f7b564 <$d+8>:      eorseq  r3, r10, #655360        ; 0xa0000
End of assembler dump.
(gdb) disas __assert
Dump of assembler code for function __assert:
0x01f7b4fc <__assert+0>:        mov     r12, sp
0x01f7b500 <__assert+4>:        push    {r11, r12, lr, pc}
0x01f7b504 <__assert+8>:        sub     r11, r12, #4    ; 0x4
0x01f7b508 <__assert+12>:       sub     sp, sp, #8      ; 0x8
0x01f7b50c <__assert+16>:       mov     lr, r1
0x01f7b510 <__assert+20>:       mov     r4, r3
0x01f7b514 <__assert+24>:       subs    r12, r0, #0     ; 0x0
0x01f7b518 <__assert+28>:       bne     0x1f7b53c <__assert+64>
0x01f7b51c <__assert+32>:       ldr     r3, [pc, #56]   ; 0x1f7b55c <$d>
0x01f7b520 <__assert+36>:       ldr     r0, [r3]
0x01f7b524 <__assert+40>:       str     r2, [sp]
0x01f7b528 <__assert+44>:       ldr     r1, [pc, #48]   ; 0x1f7b560 <$d+4>
0x01f7b52c <__assert+48>:       mov     r2, r4
0x01f7b530 <__assert+52>:       mov     r3, lr
0x01f7b534 <__assert+56>:       bl      0x1f7b6c0 <fprintf>
0x01f7b538 <__assert+60>:       b       0x1f7b558 <__assert+92>
0x01f7b53c <__assert+64>:       ldr     r3, [pc, #24]   ; 0x1f7b55c <$d>
0x01f7b540 <__assert+68>:       ldr     r0, [r3]
0x01f7b544 <__assert+72>:       stm     sp, {r1, r2}
0x01f7b548 <__assert+76>:       ldr     r1, [pc, #20]   ; 0x1f7b564 <$d+8>
0x01f7b54c <__assert+80>:       mov     r2, r4
0x01f7b550 <__assert+84>:       mov     r3, r12
0x01f7b554 <__assert+88>:       bl      0x1f7b6c0 <fprintf>
0x01f7b558 <__assert+92>:       bl      0x1f90104 <abort>
End of assembler dump.
(gdb) x/20x $r12
0xbfffcb94:     Cannot access memory at address 0xbfffcb94
(gdb)

Fix: 

Unknown.
How-To-Repeat: 
	$ cat <<E*O*F > /tmp/test.i
extern void __stack_chk_fail (void);

void
__attribute__((visibility ("hidden")))
__stack_chk_fail_local (void)
{
  __stack_chk_fail ();
}
E*O*F
	$ clang -cc1 -triple armv6--freebsd10.0-gnueabi -S -disable-free -main-file-name ssp-local.c -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -mconstructor-aliases -target-abi aapcs-linux -target-cpu arm1136jf-s -msoft-float -mfloat-abi soft -target-feature +soft-float -target-feature +soft-float-abi -target-feature -neon -g -coverage-file /tmp/test.s -O2 -std=gnu99 -fno-dwarf-directory-asm -fdebug-compilation-dir /usr/obj/usr/src/gnu/lib/libssp/libssp_nonshared -ferror-limit 19 -fmessage-length 168 -fvisibility hidden -mstackrealign -fno-signed-char -fobjc-runtime=gnustep -fobjc-default-synthesize-properties -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o /tmp/test.s -x c /tmp/test.i
	$ gdb clang clang.core
	(gdb) where
Comment 1 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2018-04-03 21:41:04 UTC
Looks like this bug has been already fixed, I am able to get a proper backtrace from the core file:

root@:~ # gdb ./a.out ./a.out.core
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 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 "armv6-marcel-freebsd"...(no debugging symbols found)...
Core was generated by `./a.out'.
Program terminated with signal 6, Aborted.
Reading symbols from /lib/libc.so.7...Reading symbols from /usr/lib/debug//lib/libc.so.7.debug...done.
done.
Loaded symbols for /lib/libc.so.7
Reading symbols from /libexec/ld-elf.so.1...Reading symbols from /usr/lib/debug//libexec/ld-elf.so.1.debug...done.
done.
Loaded symbols for /libexec/ld-elf.so.1
#0  0x201b0da4 in thr_kill () from /lib/libc.so.7
(gdb) bt
#0  0x201b0da4 in thr_kill () from /lib/libc.so.7
#1  0x201b0d84 in __raise (s=6) at /src/FreeBSD/11/lib/libc/gen/raise.c:52
#2  0x201b0d08 in abort () at /src/FreeBSD/11/lib/libc/stdlib/abort.c:65
#3  0x2022afec in __assert (func=<value optimized out>, file=<value optimized out>, line=<value optimized out>, failedexpr=<value optimized out>)
    at /src/FreeBSD/11/lib/libc/gen/assert.c:51
#4  0x000086d0 in f2 ()
#5  0x000086d0 in f2 ()
(gdb)