uftrace實現原理

2021-10-24 17:23:41 字數 908 閱讀 9560

"-pg"指定編譯器在函式入口插入對mcount()樁函式的呼叫,而「-finstrument-functions」會指定編譯器在函式入口插入對__cyg_profile_func_enter()函式的呼叫,在函式返回時插入對__cyg_profile_func_exit()函式的呼叫。 uftrace對這2種情況都能支援。正常情況下,c庫提供了對這些樁函式的定義,所以我們鏈結程式時,是可以鏈結到c庫裡面的樁函式定義。 

[root@localhost test]# readelf -s /lib64/libc.so.6 | grep mcount

111: 0000000000101780 91 func global default 12 _mcount@@glibc_2.2.5

2010: 0000000000101780 91 func weak default 12 mcount@@glibc_2.2.5

2151: 0000000000000000 0 file local default abs mcount.c

4225: 0000000000100a00 335 func local default 12 __mcount_internal

6183: 0000000000101780 91 func global default 12 _mcount

6220: 0000000000101780 91 func weak default 12 mcount

如何利用mcount樁函式:

weak型別的符號與強型別符號相同時,會被強型別符號覆蓋,有相同的weak型別符號時,會被占用記憶體最大的weak型別符號覆蓋,通過這個特性,可以利用mcount樁函式。

利用方法1:

自己編寫乙個帶有mcount強符號的動態庫並鏈結該庫,覆蓋掉標準庫中符號

引數傳遞,可以考慮通過環境變數,檔案等方式來傳遞

kvo實現原理 KVC KVO實現原理

一 kvc運用了乙個isa swizzling技術。isa swizzling就是型別混合指標機制。kvc主要通過isa swizzling,來實現其內部查詢定位的。isa指標,如其名稱所指,就是is a kind of的意思 指向維護分發表的物件的類。該分發表實際上包含了指向實現類中的方法的指標,...

實現原理 Vuex的實現原理

你知道vuex如何工作的嗎?先來看下圖了解下 了解圖之後看來下 的實現原理吧 let vue class store this.mutations this.actions this.vm new vue const options if getters if mutations if action...

afn原理 ios iOS AFN實現原理

nsurlsessiondatatask datataskwithrequest nsurlrequest request completionhandler void nsurlresponse response,id responseobject,nserror error completion...