------------------------------------------------------------
辅助工具
------------------------------------------------------------
[/pts/1@linuxidc ~/test]$ cat addr2line.sh
#!/bin/sh
if [ $# != 3 ]; then
echo 'Usage: addr2line.sh executefile addressfile functionfile'
exit
fi;
rm $3
cat $2 | while read line
do
if [ "$line" = 'Enter' ]; then
read line1
read line2
addr2line -e $1 -f $line1 -s >> $3
echo "-----> call" >> $3
addr2line -e $1 -f $line2 -s | sed 's/^/ /' >> $3
echo >> $3
elif [ "$line" = 'Exit' ]; then
read line1
read line2
addr2line -e $1 -f $line2 -s | sed 's/^/ /' >> $3
echo "<----- return" >> $3
addr2line -e $1 -f $line1 -s >> $3
echo >> $3
fi;
done
------------------------------------------------------------
执行过程:
1.生成执行文件
2.执行文件,生成调用记录文件->instrument.log
3.生成调用函数文件
------------------------------------------------------------
[/pts/1@linuxidc ~/test]$ make
gcc -c -g -finstrument-functions -o test.o test.c
gcc -c -g -finstrument-functions -o instrument.o instrument.c
gcc -o test test.o instrument.o
ok!
[/pts/1@linuxidc ~/test]$ ./test
result is 23
[/pts/1@linuxidc ~/test]$ cat instrument.log
Enter
0x4006c6
0x400701
Enter
0x400739
0x40075c
Exit
0x400739
0x40075c
Exit
0x4006c6
0x400701
[/pts/1@linuxidc ~/test]$ ./addr2line.sh test instrument.log instrument.txt
[/pts/1@linuxidc ~/test]$ cat instrument.txt
main
test.c:9
-----> call
addmul
test.c:17
addmul
test.c:20
-----> call
mul
test.c:25
mul
test.c:25
<----- return
addmul
test.c:20
addmul
test.c:17
<----- return
main
test.c:9
Ubuntu 12.04嵌入式交叉编译环境arm-linux-GCC搭建过程图解