I am working on dm8168, with the DVRRDK4.1
In my opinion, prints the call stack is very easy in user mode. On DVRRDK3.5, when an application crashes can print out the call stack.
BUT, ON DVRRDK4.1, The call stack cannot be backtrace. Please help me, although this is supposed to be file system problem.
1) My test code as follows:
#ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #ifndef __USE_GNU #define __USE_GNU #endif #include <execinfo.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ucontext.h> #include <unistd.h> /* This structure mirrors the one found in /usr/include/asm/ucontext.h */ typedef struct _sig_ucontext { unsigned long uc_flags; struct ucontext *uc_link; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; } sig_ucontext_t; void crit_err_hdlr(int sig_num, siginfo_t * info, void * ucontext) { void * array[50]; void * caller_address; char ** messages; int size, i; sig_ucontext_t * uc; uc = (sig_ucontext_t *)ucontext; /* Get the address at the time the signal was raised */ #if 0 #if defined(__i386__) // gcc specific caller_address = (void *) uc->uc_mcontext.eip; // EIP: x86 specific #elif defined(__x86_64__) // gcc specific caller_address = (void *) uc->uc_mcontext.rip; // RIP: x86_64 specific #else #error Unsupported architecture. // TODO: Add support for other arch. #endif #else caller_address =(void *) uc->uc_mcontext.arm_pc; #endif fprintf(stderr, "signal %d (%s), address is %p from %p\n", sig_num, strsignal(sig_num), info->si_addr, (void *)caller_address); size = backtrace(array, 50); fprintf(stderr, "size %d\n", size); /* overwrite sigaction with caller's address */ array[1] = caller_address; messages = backtrace_symbols(array, size); /* skip first stack frame (points here) */ for (i = 1; i < size && messages != NULL; ++i) { fprintf(stderr, "[bt]: (%d) %s\n", i, messages[i]); } free(messages); exit(EXIT_FAILURE); } int crash() { char * p = NULL; *p = 0; return 0; } int foo4() { crash(); return 0; } int foo3() { foo4(); return 0; } int foo2() { foo3(); return 0; } int foo1() { foo2(); return 0; } int main(int argc, char ** argv) { #if 1 struct sigaction sigact; sigact.sa_sigaction = crit_err_hdlr; sigact.sa_flags = SA_RESTART | SA_SIGINFO; if (sigaction(SIGSEGV, &sigact, (struct sigaction *)NULL) != 0) { fprintf(stderr, "error setting signal handler for %d (%s)\n", SIGSEGV, strsignal(SIGSEGV)); exit(EXIT_FAILURE); } #endif foo1(); exit(EXIT_SUCCESS); }
2) Compile command is as follows:
(RDK4.1)
/home/kez/DVRRDK_04.01.00.02/dvr_rdk/../ti_tools/cgt_a8/arago/linux-devkit/bin/arm-arago-linux-gnueabi-gcc -g1 -rdynamic -o test stack_test.c
(RDK3.5 )
/usr/local/bin/DM8168_compiler_cgt_a8/arm-2009q1/bin/arm-none-linux-gcc -g1 -rdynamic -o test stack_test.c
3) Download it on the target machine, execute ./test. The result is follow:
(RDK4.1)
signal 11 (Segmentation fault), address is (nil) from 0x8968 size 0
(RDK3.5)
root@dm816x:/opt/dvr_rdk# ./test signal 11 (Segmentation fault), address is (nil) from 0x8a24 size 9 [bt]: (1) ./test(crash+0x1c) [0x8a24] [bt]: (2) ./test(crash+0x1c) [0x8a24] [bt]: (3) ./test(foo4+0xc) [0x8a48] [bt]: (4) ./test(foo3+0xc) [0x8a60] [bt]: (5) ./test(foo2+0xc) [0x8a78] [bt]: (6) ./test(foo1+0xc) [0x8a90] [bt]: (7) ./test(main+0x74) [0x8b10] [bt]: (8) /lib/libc.so.6(__libc_start_main+0x120) [0x400f1fd4]
4)Another compilation command ON RDK4.1:
/home/kez/DVRRDK_04.01.00.02/dvr_rdk/../ti_tools/cgt_a8/arago/linux-devkit/bin/arm-arago-linux-gnueabi-gcc -g1 -rdynamic -lSegFault -o test stack_test.c
Results are as follows:
root@dm816x:/opt/dvr_rdk# ./test *** Segmentation fault Register dump: R0: 00000001 R1: be869c84 R2: 00000000 R3: 00000000 R4: 402d7b70 R5: 402d6000 R6: 000089cc R7: 00000000 R8: 00000000 R9: 00000000 SL: 40115000 FP: be869b04 IP: 00000140 SP: be869af8 LR: 00008958 PC: 00008934 CPSR: 60000010 Trap: 0000000e Error: 00000817 OldMask: 00000000 Addr: 00000000 Backtrace: Memory map: 00008000-00009000 r-xp 00000000 00:0f 4958 /opt/dvr_rdk/test 00010000-00011000 rw-p 00000000 00:0f 4958 /opt/dvr_rdk/test 00011000-00032000 rw-p 00000000 00:00 0 [heap] 40010000-40011000 rw-p 00000000 00:00 0 40066000-40067000 rw-p 00000000 00:00 0 400f0000-4010c000 r-xp 00000000 00:0f 874 /lib/ld-2.12.2.so 40114000-40115000 r--p 0001c000 00:0f 874 /lib/ld-2.12.2.so 40115000-40116000 rw-p 0001d000 00:0f 874 /lib/ld-2.12.2.so 40116000-4011f000 r-xp 00000000 00:0f 887 /lib/libgcc_s.so.1 4011f000-40126000 ---p 00009000 00:0f 887 /lib/libgcc_s.so.1 40126000-40127000 rw-p 00008000 00:0f 887 /lib/libgcc_s.so.1 401a4000-401a6000 r-xp 00000000 00:0f 795 /lib/libSegFault.so 401a6000-401ad000 ---p 00002000 00:0f 795 /lib/libSegFault.so 401ad000-401ae000 r--p 00001000 00:0f 795 /lib/libSegFault.so 401ae000-401af000 rw-p 00002000 00:0f 795 /lib/libSegFault.so 401af000-402cc000 r-xp 00000000 00:0f 830 /lib/libc-2.12.2.so 402cc000-402d4000 ---p 0011d000 00:0f 830 /lib/libc-2.12.2.so 402d4000-402d6000 r--p 0011d000 00:0f 830 /lib/libc-2.12.2.so 402d6000-402d7000 rw-p 0011f000 00:0f 830 /lib/libc-2.12.2.so 402d7000-402da000 rw-p 00000000 00:00 0 be849000-be86a000 rw-p 00000000 00:00 0 [stack] ffff0000-ffff1000 r-xp 00000000 00:00 0 [vectors] Segmentation fault