因為還沒研究出在 embedded 上使用 valgrind 的方法,

所以退而求其次, 把 source 搬到 VM (ubuntu) 上,

寫個簡單的執行檔去使用這包 source,

再用 valgrind 來觀察情況.

 

先把 source 搬到 VM 上,

修改 makefile 的 tool-chain, 相關的路徑, compilation/linkage options, so檔的搬移位置等等.

再寫個執行檔,

先開 thread, load shared object 和所有會用到的 symbol.

再回到主 thread 去決定執行時間, 然後終止.

 

最後, 用 valgrind 去追追追 ...

 

 

1. pthread 相關:

1-1. include <pthread.h>

1-2. gcc xxx.c -lpthread

 

2. shared object 相關:

2-1. include <dlfcn.h>

2-2. gcc ... -ldl

2-3. 如果要用 valgrind, 記得拿掉 dlclose.

 

3. valgrind 相關:

3-1.

使用 valgrind 測試 memory leak 情況:

valgrind --leak-check=full --log-file=XXX --track-fds=yes --read-var-info=yes -v ./your_program

3-2. 

compile 時, 可加上 debug option

gcc ... -g

so 檔的 compilation 也是.

 

4. 編譯指令與注意事項:

4-0:

執行檔位置: ./work/

so 檔存放位置: ./work/lib

so檔 source code 位置: ./work/source

4-1: make libxxx.so 檔:

記得把最終結果移到 ./work/lib/ 下

4-2: 編譯執行檔:

gcc main.c -g -ldl -pthread -lxxx -L./lib -I./source/...

-g: gdb

-ldl: shared object 相關

-pthread: pthread 相關

-lxxx: link libxxx.so

-L./lib: libxxx.so 位置

-I./source/...: 有 include 到的 header file 位置

 

 

參考聯結:

pthread_join vs pthread_exit

http://stackoverflow.com/questions/8513894/pthread-join-and-pthread-exit

 

valgrind 簡介

http://daydreamer.idv.tw/rewrite.php/read-18.html

 

valgrind 測出 still reachable leak ?

http://stackoverflow.com/questions/3840582/still-reachable-leak-detected-by-valgrind

 

valgrind + gdb

http://vision-expert.blogspot.tw/2011/03/valgrind-gdb.html

 

gdb

http://www.cmlab.csie.ntu.edu.tw/~daniel/linux/gdb.html 

 

 

 

文章標籤
全站熱搜
創作者介紹
創作者 kk 的頭像
kk

kk

kk 發表在 痞客邦 留言(0) 人氣(386)