Kaie"s Blog 2.0 beta!
Back to "Top"

My Secret Notebook
 Show "Table of Contents"
Contact Me
Subscribe to my Posts feed
Subscribe to my Comments feed
My Flickr
Back to "Top"
My Secret Notebook
 Show "Table of Contents"
Contact Me
Subscribe to my Posts feed
Subscribe to my Comments feed
My Flickr

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)
  GDB: The GNU Project Debugger
  6.8版,還蠻新的嘛。接著再下 sudo port install gdb ,就會出現底下不堪入目的畫面---> Computing dependencies for 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.
  哪泥......macports裡頭竟然連gdb的檔案都沒放了,不再是萬能的了,此時只好靠萬能的”source code”以及"gcc"了,心想只要有心,沒有porting不過來呀...科科,就是這"灌C"的威力。先來抓個最新版的weekly build的GDB來嚐鮮一下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
$ make && make install
  這個時候build成功了,很開心的跑 gdb ./hello ,我想應該會出現GNU gdb (GDB) 7.0.50.20091110
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)
  心想,搓屎…怎麼會這樣,找不到debug symbol..囧rz。(後來發現,好像每次都會出現,但還是可以正常使用,先不管…堪用),再接著執行(gdb) b main
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)
  後來求助於Google,似乎是權限的關係,假使你當初就用root權限安裝的話,就沒這問題了。若你和我一樣喜歡安裝在個人目錄下(有代--prefix=/Users/xxx/參數),記得將gdb作個權限相關設定$ sudo chgrp procmod /yourpath/gdb
$ sudo chmod g+s /yourpath/gdb

  前一篇有個網友提到的擾人的"^M"符號的問題,果然從gdb v6.3.5升到gdb v7.0之後就迎刃而解了,照慣例,抓張圖吧。

7 Comments:

Who: Anonymous Class:
When: November 17, 2009 11:00 AM  

Great!! 版大真的是太強大了,果然真的是解決那個擾人的 ^M,且還可以用最新的 gdb,Good!! ^^b
看版大的 Blog 果真可以長知識啊! :)

Who: Tsung-Kai Chen Class:
When: November 17, 2009 11:33 AM  

@Anonymous
好說好說,是Google強大... :)
但在gdb v7.0新支援的強大reverse debugging功能,似乎有只特定平台才有作用,鬱悶呀...囧

Who: Anonymous Class:
When: November 17, 2009 2:19 PM  

真的是很強大的功能,希望可以在 Mac OS X 上用到。此外,也希望 MacPorts 對於 gdb 的支援,可以快點恢復。 :)

Who: NeoBetas Class:
When: November 23, 2009 8:24 PM  

雖然不知道為甚麼,我裝完之後 6.x 卻還在 = =...

變成我必須用絕對路徑才能叫出 7.0...囧...

手邊暫時還沒有軟體需要用到 gdb 來搞定的...

Who: Tsung-Kai Chen Class:
When: November 23, 2009 9:46 PM  

@NeoBetas
這是正常的啦,因為我們是手動build的,除非你make install時,蓋掉原本的6.x 版gdb,否則會有共存的可能性。在Unix的作業系統,是以path這個環境變數來找binary的位置的,你可以打這指令查看 ”echo $PATH”,看看這篇文章會更清楚 http://linux.vbird.org/linux_basic/0220filemanager.php#dir_path

Who: NeoBetas Class:
When: November 25, 2009 1:32 AM  

echo $patch?

我記得要找 System 預設 XXX 的位置(例如 touch)可以用 "which touch"...

不過國外有人建議不要蓋掉,因為 Xcode 內建的 gdb 是客制化的版本,也就是自己 compile 的 7.0 其實跟 Xcode 3 不完全相容...

Who: Tsung-Kai Chen Class:
When: November 25, 2009 8:39 AM  

@NeoBetas
透過which找出來的,也不太算是系統預設的位置,算是目前你的$PATH中,由前到後,最先找到的地方。像是我有透過mac port裝binutils,所以我找'which ls'時得到"/opt/local/bin/ls",然而Snow Leopard預設的ls工具在"/bin/ls"。

我的$PATH內容是
/Users/kent/usr/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin

嗯,還是別蓋掉好,手動build的7.0版沒有完全被驗證過,只是build過可run,自己拿來額外使用就好,跟原先的Xcode整合,我想不會那麼順利的。