本文在Xcode4.6基礎上介紹的,不一定適用其他版本的Xcode。
關於DWARF與dSYM
DWARF is a debugging file format used by many compilers and debuggers to support source level debugging. It addresses the requirements of a number of procedural languages, such as C, C++, and Fortran, and is designed to be extensible to other languages. DWARF is architecture independent and applicable to any processor or operating system. It is widely used on Unix, Linux and other operating systems, as well as in stand-alone environments.
DWARF與dSYM的關系是,DWARF是文件格式,而dSYM往往指一個單獨的文件。在Xcode中如果不做特殊制定,debug information是被保存在executable文件中,可以使用dsymutil從executable中提取dSYM文件。
dsymutil
dsymutil is a tool to manipulate archived DWARF debug symbol files. 使用dsymutil可以對dSYM文件進行如下操作:從exe_path中提取成dSYM文件、將executable或者object文件中的symbol table dump出來、更新dSYM文件以讓dSYM文件包含最新的accelerator tables and other DWARF optimizations。
Debug Info Format
在Xcode中可以選擇DWARF和DWARF with dSYM file,推薦的設置是Debug用DWARF;Release使用DWARF with dSYM file。
使用dSYM file
如果我們有若干的build,有若干dSYM文件,而名字又有點亂,想知道哪個dSYM跟哪個build匹配,從而可以使用它們呢?辦法就是查看UUID。
下面就是看怎么加載dSYM file了
關於dSYM和debug,這里有更多的信息。
Build Architecture in Xcode
在Xcode中可以指定‘64-bit Intel’, '32-bit Intel'和’Standard (32/64-bit Intel)‘三種Architecture,但是實際上是只有兩種:i386和x86_64。’Standard (32/64-bit Intel)‘也被映射為x86_64。這個可以從Valid Architecture中看到。i386是為32位上編譯的,而且只能在32bit OS上執行;x86_64而是為64位編譯的。
Mac OS X running on 64-bit hardware can (so far) always run 32-bit software, but Mac OS X running on 32-bit hardware can only run 32-bit software. Mac OS X itself was built for both until Lion; now, it requires a 64-bit Mac.
So the only reason to build for 32-bit is that you want to support five-year-old hardware (e.g., if that's what you have). If you'd rather get the newer language features and don't mind abandoning the customers who have five-year-old Macs, then go 64-bit-only and don't look back.
That's assuming, of course, that you don't have any hand-written i386 assembly code or code that uses no-longer-supported functions in Carbon. If you do, then that's another potential incentive to stick with 32-bit. Just be aware that support for 32-bit programs in Mac OS X may go away someday.
Add new framework/link binaries to Xcode
下面是添加framework的步驟:
- In the project navigator, select your project
- Select your target
- Select the 'Build Phases' tab
- Open 'Link Binaries With Libraries' expander
- Click the '+' button
- Select your framework
當我們打開'Build Phases' tab時,可以看到還有其他項目:Target Dependencies, Compile Sources, Link Binaries With Libraries,Copy Bundle Resources四項。已經介紹過一個了,Target Dependencies是將本project文件中的target建立依賴關系,Compile Sources是包含這個target需要編譯的文件列表,還有就是Copy Bundle Resources就是一些xib文件、strings文件等。
如果我們有兩個project文件A和B,A中編譯出一個static library AS,一個dynamic library AD, 而B的target需要引入對他們的依賴,如何操作呢? 不論static 還是dynamic的都是在Link Binaries With Libraries中設置的。
Xcode中使用xcconfig文件
創建xcconfig文件:Pick File | New, choose Other and "Configuration Settings File", this gets you a new .xcconfig file.
制定xcconfig文件:Then click on the project icon on the upper left in the Project Navigator, on the right side, project/target list will show and click the project you want to edit, then it will show a page with Info and Build Settings tabs, choose Info tab, then you will see Deployment Target/Configurations/Localizations. In the Configurations section, you can specify which config you want to use for debug/Release, etc. 'Based on Configuration File' column is the xcconfig file name will be used.
使用Xcode中的Scheme
Scheme是包含描述Xcode一系列行為的配置,每次我們在Xcode中添加一個Target,就會自動添加一個Scheme,但這是Xcode的行為,並不意味着Target與Scheme是一一對應的關系。Scheme可以對應多個Target,一個Target也可以在多個Scheme被描述。Scheme描述了如下行為:Build,Run Test, Test, Profile, Analyze和Archive。其中Run Test是制定一個第三方的應用來啟動我們的程序,並配置好命令行參數等信息來執行的。
Xcode、GDB與LLDB
LLDB is a next generation, high-performance debugger. It is built as a set of reusable components which highly leverage existing libraries in the larger LLVM Project, such as the Clang expression parser and LLVM disassembler.
LLDB is the default debugger in Xcode on Mac OS X and supports debugging C, Objective-C and C++ on the desktop and iOS devices and simulator.
雖然LLDB是默認的debugger,但是LLDB還不成熟,而GDB卻經歷多年發展,非常程序,LLDB能干的事,GDB都可以,所以,在LLDB成熟之前,還是選GDB吧。