ubuntu 在 R40e 上 還有 Debian 在 Sempron 2600 上

2014年2月5日 星期三

Segmentation fault -- Android C program debug

某個 C program - MccAccess,run 到後來會出現 Segmentation fault
然後沒有任何 message, 也沒有 core dump, kernel denug message 等。
要 debug (找出 fault 的位置)..

先是用 None-stripped version (包含 debug symbol).
在 out/target/product/ss7/obj/EXECUTABLES/MccAccess_intermediates/LINKED/ 下的 MccAccess 就是 none-stripped 版。

push 到system/bin/ 取代 stripped 版後。

再來,設定不限制 core dump size:
#ulimit -c unlimited

然後 run program, 讓他發生 core dump..

之後,在你所在目錄就會有 core dump file, 一般是 core.pid, pid 是那個 program 的 pid.
但是在這個 android 系統,沒有附加 pid,所以就是 core

接著開啟 gdb 吃 MccAccess 和 core:
# gdb /System/bin/MccAccess core

gdb 就會直接顯示最後的 fault 位置:
sh-4.2# gdb /system/bin/McuAccess core
GNU gdb (Linaro GDB) 7.3-2011.10
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-none-linux-gnueabi".
For bug reporting instructions, please see:
...
Reading symbols from /system/bin/McuAccess...done.

warning: exec file is newer than core file.
[New LWP 1108]
[New LWP 1107]
[New LWP 1109]
[New LWP 1110]
Core was generated by `McuAccess'.
Program terminated with signal 11, Segmentation fault.
#0  memcpy () at bionic/libc/arch-arm/bionic/memcpy.S:203
203     bionic/libc/arch-arm/bionic/memcpy.S: No such file or directory.
        in bionic/libc/arch-arm/bionic/memcpy.S

不清楚的話 (像,是在 std c lib 中),可以用 bt 列出 stack backtrace:
(gdb) bt
#0  memcpy () at bionic/libc/arch-arm/bionic/memcpy.S:203
#1  0x0000b2fe in CheckMcuCmdID () at RT/Tony/MccAccess/FunctionDef.c:484
#2  0x0000b636 in CheckRxDataFromMcu ()
    at RT/Tony0921/MccAccess/FunctionDef.c:754
#3  0x0000b6e2 in RxUart (arg=)
    at RT/Tony/MccAccess/FunctionDef.c:780
#4  0x00011c10 in __thread_entry (func=0xb6d1 , arg=0x0,
    tls=) at bionic/libc/bionic/pthread.c:213
#5  0x000117d0 in pthread_create (thread_out=, attr=0x159f0,
    start_routine=0xb6d1 , arg=0x0) at bionic/libc/bionic/pthread.c:349
#6  0x00000000 in ?? ()


這樣就很清楚了。


ref: debugging segment fault with gdb

沒有留言:

標籤

網誌存檔