Android NDK使用addr2line符號化得到錯誤函數名的問題

       一般Android NDK出現崩潰之後,我們會使用addr2line工具來進行符號化。如果你使用了C++11的一些特性,那麼要注意了,有可能你將得到錯誤的函數名。我們公司是提供崩潰分析相關的服務的,採集用戶的崩潰日誌,上傳到後臺服務器後,會進行符號化操作。之前一直好好的,最近有用戶說符號化後的結果不正確,函數名和文件及行號不一致。

        這個問題其實蠻奇怪的,要說addr2line可是操作系統級別的工具,無數人使用,不可能出這種低級錯誤啊。不過爲了進一步驗證,準備在自己的PC上用addr2line重現一下,結果發現,沒有問題,符號化是正確的。又到服務器上測試,發現仍然不對。查看addr2line的版本,發現是不同的,如下所示。

[root@tdata ~]# addr2line --version
GNU addr2line version 2.20.51.0.2-5.42.el6 20100205
Copyright 2009 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
xxx@xxx-desktop:~/Templates/Tyrion-debug-tusuo$ addr2line --version
GNU addr2line (GNU Binutils for Ubuntu) 2.24
Copyright 2013 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

看來應該是這個問題了,同時操作系統也不同,自己的是Ubuntu,服務器是CentOS。大家都知道,CentOS上的軟件一般版本都比較老,而且repo源沒有最新版本的更新,需要自己添加源。


        首先想是不是將自己PC上的addr2line放到服務器上,就可以解決問題了,因爲這個文件是C語言寫的二進制文件。結果出現了下面的錯誤:

[root@tdata ~]# ./addr2line -f -e libgame.so 0x33e17b
./addr2line: error while loading shared libraries: libbfd-2.24-system.so: cannot open shared object file: No such file or directory

查閱了addr2line的源碼可以發現,它會引用#include "bfd.h",會依賴libbfdxxx.so。


        接着只能從官方下載新版本,再重新編譯,進行addr2line的版本升級。官網地址爲

ftp://sourceware.org/pub/binutils/snapshots/binutils-2.24.90.tar.bz2,你也可以從git上同步代碼下來重新編譯。


        注意最好到目標機器上進行編譯。在升級了addr2line之後,一切正常了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章