LinuxDev 板


LINE

[補充jserv大大的feedback] 各位大大好: 這份是 【2011 十二月份 SA@Tainan 用 Android 學習系統程式 12/24 (六) 】 課程的心得。 感謝工作人員和講師的付出,整理一份當時抄的筆記,由於年代已久不可考,有些 其實已經忘記當初要記的重點。 這份筆記主要是補充投影片中的東西和自己有興趣的內容,建議搭配投影片和紫皮 書【程式設計師的自我修養:連結、載入、程式庫】。投影片可以到jserv 大大的 網站或是【酷!學園】討論區上面都有。 另外我想應該很多錯誤也請指正,謝謝! * Android IPC - Intent -> AIDL -> Binder - cat /sys/kernel/debug/binder 可以觀察相關資訊 - Parcel打包概念 - binder 是去shared memory 撈service - 所有service透過binder 相互聯繫 * Android debuggerd - Android 攔胡process segmentation fault signal,發生不正常錯誤時透過 socket 通知debuggerd - debuggerd在logcat中顯示的address是上次跑完的address - lr -> register for storing return address in ARM - 可以比照crash log和/proc/pid/maps - 參考: https://wiki.linaro.org/WorkingGroups/ToolChain/Outputs/LibunwindDebuggerd * Dynamic linker/program interpreter - 同一個 root file system 底下可有兩個以上的 ELF interpreter - Android下面不同的版本/system/bin/linker的address可能不同 + 安全性考量以及performance因素 - X86 + Entry: libc_start_main + library: libc + linker: ls-linux.so.2 (可以執行) - Android + Entry: __libc_init + library: bionic + linker: /system/bin/linker - 沒有正確處理 stack & calling convention,會發生 SegFault * bionic (Android的libc) - __init_libc有static和dynamic 兩種方式 - init process (pid 1 那個)用static,不可用malloc - 相關說明可以參考AOSP下面的文件(有點過期) - adbd 是static (?) - 看interpreter資訊 - objdump -s -j .interp filename * memory map of a process - cat /proc/pid/maps + 欄位說明: - address - perms + r = read + w = write + x = execute + s = shared + p = private (copy on write) - offset - dev - inode - pathname - 相同的path有兩個以上可能是text/data的差別 adb shell cat /proc/18696/maps (投影片剪貼) 00008000-00009000 r-xp 00000000 b3:02 8959 /data/local/hello 00009000-0000a000 rwxp 00001000 b3:02 8959 /data/local/hello b0001000-b0009000 r-xp 00001000 b3:01 128 /system/bin/linker b0009000-b000a000 rwxp 00009000 b3:01 128 /system/bin/linker b000a000-b0015000 rwxp 00000000 00:00 0 beb07000-beb28000 rw-p 00000000 00:00 0 [stack] ffff0000-ffff1000 r-xp 00000000 00:00 0 [vectors - heap是由address往後面增加 - stack是由address往前面增加 - 可以用來逆向以及trace程式 * ABI - readelf可以讀出來 $ readelf -h ../libs/armeabi/a ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: ARM Version: 0x1 Entry point address: 0x8540 Start of program headers: 52 (bytes into file) Start of section headers: 7592 (bytes into file) Flags: 0x5000002, has entry point, Version5 EABI Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 7 Size of section headers: 40 (bytes) Number of section headers: 22 Section header string table index: 21 - eabi/oabi: e for embedded, o for old - 不同的ABI (包含ABI版本)對於data type的size定義有可能不同 + sizeof (char) - EABI: 1 - OABI: 4 + sizeof (struct empty_struct{};) - EABI: 1 - x86沒有ABI版本的問題 - Embedded的ABI不同的原因可能是 + 改板 + 商業考量,故意讓其他產品不能相容 + 效率 + ref: http://wiki.debian.org/ArmEabiPort - ARM EABI 基本上已大一統了 * Start a process - create a process - load executable file - setup runtime - page valid (?) * Before Hello World.. - UID/GID - Signal - load ld.so - mmap - random - load libstdc++.so - ... * Android GDB - adb forward tcp:port tcp:port - symbol 可能在 - ${PWD}/out/target/product/product_name/symbols/system/bin * LD debug - export LD_DEBUG=files - LD_DEBUG=help /lib/ld-2.13.so * Hear Say/忘記是記啥的 - BUILD_ID + Issue tracking - 忘記講的是ELF還是AOSP/Cyanogenmod - NDK的進版本和Android SDK進板有關聯 - mm -b => make clean; make - 有些elf執行檔沒有main的進入點 + pypy - 2010年開始ELF加入build ID - abort() - ptrace - addr2line -e [file] - Android重寫了libc/linker,size減少,代價就是功能也減少 - libunwind - ELF section的offset一般來說會和/proc/pid/maps會有點差別,主要是安全考量 - ANR + Android Not Responding + 執行很久的程式碼,建議放在 Service 中 - Android中把東西mix起來就叫flinger + Surface flinger + service flinger + ... --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.250.98.253
1F:推 alongalone:推.... 雖然我跟android很不熟..Orz 01/29 15:58
※ 編輯: robinliao 來自: 111.250.98.253 (01/29 18:14)







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:e-shopping站內搜尋

TOP