有時(shí)候需要去檢查哪些代碼調(diào)用了某些接口,但是經(jīng)常發(fā)生的問(wèn)題是,某些模塊,實(shí)際上看不到代碼,只能看到庫(kù)文件。這種情況下,可借助GNU工具來(lái)檢查。
先寫(xiě)個(gè)簡(jiǎn)單的測(cè)試代碼:
$ cat PCString.h
#ifndef __PCSTRING_H__
#define __PCSTRING_H__
class PCString
{
public:
static bool Copy(const char *from, char *to, int size);
};
#endif //__PCSTRING_H__
$ cat PCString.cpp
#include “PCString.h”
bool PCString::Copy(const char *from, char *to, int size)
{
}
g++ -g -c PCString.cpp -o PCString.o
ar -rsv libPCString.a PCString.o
$ cat test2.cpp
#include “PCString.h”
void fun(void)
{
char test[10];
PCString::Copy(“AAAA”, test, 10);
}
g++ test2.cpp -g -c -o test.o
ar -rsv libTest.a test.o
假如,我們要檢查哪些地方調(diào)用了 PCString::Copy(), 但是又看不到test2.cpp文件,只能看到 libTest.a。
1)使用 readelf:
2)使用 nm
3)如果 庫(kù)文件是 debug版的(可以反匯編出源碼),也可以用 objdump:
另外,這些工具也可以查詢(xún)某個(gè)模塊定義哪些可供外部使用的符號(hào)。
-
工具
+關(guān)注
關(guān)注
4文章
314瀏覽量
28157 -
虛擬機(jī)
+關(guān)注
關(guān)注
1文章
962瀏覽量
29006 -
gun
+關(guān)注
關(guān)注
0文章
6瀏覽量
7665
發(fā)布評(píng)論請(qǐng)先 登錄
無(wú)法在Armv7l樹(shù)莓派3b+上運(yùn)行binutils-esp32ulp工具鏈怎么解決?
關(guān)于typedef的用法總結(jié)
可執(zhí)行映像文件objdump反匯編代碼.txt,objdump應(yīng)該怎么翻譯
查詢(xún)Linux應(yīng)用程序運(yùn)行依賴(lài)哪些庫(kù)的方法
學(xué)習(xí)ARM反匯編工具objdump和一個(gè)簡(jiǎn)單實(shí)例 精選資料分享
OK3399開(kāi)發(fā)板的程序的庫(kù)依賴(lài)關(guān)系是什么?
總結(jié)一下STM32串口的用法
enum的用法總結(jié)
Java數(shù)組的常用方法_Java:數(shù)組工具類(lèi)Arrays類(lèi)的常用方法的用法及代碼
Linux后臺(tái)開(kāi)發(fā)常用調(diào)試工具
用于查看目標(biāo)文件或可執(zhí)行文件的組成信息的命令:objdump命令

評(píng)論