arm
qemu-aarch -g [port] [debug_file]
gdb-multiarch [debug_file]
(gdb) target remote localhost:1234
ddd –debugger gdb-multiarch –gdb [name of your ARM binary]
若要在無linux環境下執行(bare)
-nostdlib:不使用system call
-static:或是包成static
arm-linux-gnueabi-gcc -o test test.c
或是直接打包
執行:
qemu-arm -L /usr/arm-linux-gnueabi/ test
解決方法:
此執行檔會優先使用arm-linux-gnueabihf
rpath 是 runtime 時期的library search path,這些字串會完整的被複製到runtime linker (也就是ld.so)用來尋找共享函式庫;如果rpath 沒有設定,則linker 會使用LD_RUN_PATH 的值。
我們可以使用兩種方式在連結時加入rpath設定rpath
或是直接設定LD_RUN_PATH
以上兩種都可以透過readelf讀出
另外還有一種是 -L,它會設定連接時搜尋共享函式庫的目錄,這裡只給一個最粗淺的例子:
arm-linux-gnueabihf-gcc -c hello.c -o hello.o
arm-linux-gnueabihf-ld hell.o -o hello
會發生undefined reference to puts 的錯誤,因為我們沒有連接所需要的 c library,另外我們也沒有指定程式的進入點為何,要能連結通過至少要:
arm-linux-gnueabihf-ld hell.o -o -lc -L/usr/arm-linux-gnueabihf/lib hello –entry main
當然這樣不代表可以執行,試著執行會發現dynamic linker 並沒有正確設定,除此之外還有各種runtime 的library 需要連結進去才會動;要看到可運作的呼叫方式,可以用gcc -v (-verbose) 來觀察。
-rpath-link 則只指定link 時搜尋shared library的路徑,這個路徑不會包含到executable 裡面
使用-rpath-link 須知它也會蓋掉原本的搜尋路徑,因此用-rpath-link有個危害是:link time linker(ld)跟runtime linker (ld.so) 可能會使用不同的shared library,因為後者並沒有設定這個路徑,而是去預設的路徑尋找。
因為LD_LIBRARY_PATH的優先順序高過ldconfig因此可以被qemu連結
Why LD_LIBRARY_PATH is bad: http://xahlee.info/UnixResource_dir/_/ldpath.html
-L
flag要先確定沒有設定LD_LIBRARY_PATH
,因為他的優先順序比LD_LIBRARY_PATH要低
https://paper.dropbox.com/doc/Week7-Lab42-ti7vbuiHPSdKZYkbpQxQ4
https://paper.dropbox.com/doc/Week3-Lab39-SxyMP3KWtO5OtyHiObQcP
https://drive.google.com/open?id=0B5GW0aIORHIBUjVvUXJ2NVhPckU
https://drive.google.com/open?id=0B5GW0aIORHIBLW0ycldfZHhieHc
pie
關閉後才可以single step debughttps://www.ptt.cc/bbs/LinuxDev/M.1270355520.A.468.html