Tuesday, November 17, 2009
[Mac/Snow Leopard] build GDB v7.0 from source
之前在Leopard (Mac OS X 10.5.X)的時候,都是靠Macports在討生活的,大部份我常用的ports都還Maintain的不錯,但到了Snow Leopard (Mac OS X 10.6.X) 的年代,發現許多ports都被發的bug都一直掛著沒人維護,小弟只好自力救濟了。像是著名的GDB神器,在console底下,只要下個 port search gdb ,就會出現這麼樣一個東西:gdb @6.8 (devel) 6.8版,還蠻新的嘛。接著再下 sudo port install gdb ,就會出現底下不堪入目的畫面
GDB: The GNU Project Debugger---> Computing dependencies for gdb 哪泥......macports裡頭竟然連gdb的檔案都沒放了,不再是萬能的了,此時只好靠萬能的”source code”以及"gcc"了,心想只要有心,沒有porting不過來呀...科科,就是這"灌C"的威力。先來抓個最新版的weekly build的GDB來嚐鮮一下
---> Verifying checksum(s) for gdb
Error: Target org.macports.checksum returned: Could not open file: /opt/local/var/macports/distfiles/gdb/gdb-6.8.tar.bz2
Error: Status 1 encountered during processing.wget ftp://sourceware.org/pub/gdb/snapshots/current/gdb-weekly-7.0.50.20091110.tar.bz2 接著, bunzip2 gdb-*.tar.bz2 解開這壓縮檔。重點戲來了,configure一下,藍色字是key point,記得加,這是在Snow Leopard上編gdb成功的關鍵: $ ./configure --disable-werror --build=x86_64-apple-darwin10 --prefix=/Users/kent/usr 這個時候build成功了,很開心的跑 gdb ./hello ,我想應該會出現
$ make && make installGNU gdb (GDB) 7.0.50.20091110 心想,搓屎…怎麼會這樣,找不到debug symbol..囧rz。(後來發現,好像每次都會出現,但還是可以正常使用,先不管…堪用),再接著執行
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin10".
For bug reporting instructions, please see:
Reading symbols from /Users/kent/RD1-2/practice/GDB/gdb-samples/hello...(no debugging symbols found)...done.
(gdb) (gdb) b main 後來求助於Google,似乎是權限的關係,假使你當初就用root權限安裝的話,就沒這問題了。若你和我一樣喜歡安裝在個人目錄下(有代--prefix=/Users/xxx/參數),記得將gdb作個權限相關設定
Breakpoint 1 at 0x100000f0c: file hello.c, line 6.
(gdb) run
Starting program: /Users/kent/RD1-2/practice/GDB/gdb-samples/hello
Unable to find Mach task port for process-id 80958: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
(gdb) $ sudo chgrp procmod /yourpath/gdb
$ sudo chmod g+s /yourpath/gdb
前一篇有個網友提到的擾人的"^M"符號的問題,果然從gdb v6.3.5升到gdb v7.0之後就迎刃而解了,照慣例,抓張圖吧。
















