Using LLDB Commands in XCode 4

And command mapping between GDB and LLDB

The rationale for Apple’s move to LLVM and slowly parting with the aging GCC has a long history and is out of the scope of this brief tutorial on LLVM commands. The primary reason for switching from GCC to Clang — probably — is the incompatibility of GCC’s GPL v3 license with the goals of the FreeBSD project. There are also political issues to do with corporate investment, as well as user base requirements. Finally, there are expected technical advantages to do with standards compliance and ease of debugging. Real world performance improvements in compilation and execution are code-specific and under continuous debate; cases can be made for both compilers. For those interested, some good reading is available out there, from brainstorming notes (“mkspecs and patches for LLVM compile of Qt4“) to Steve Naroff’s 2007 presentation. Moreover, GCC front–end support for Objective-C is a low priority for GCC developers. GCC does not fit smoothly into Apple’s IDE and — probably — also in its XCode product roadmap. Since GCC is GPL version 3 licensed it requires developers who distribute extensions for (or modified versions of) GCC to make their source code available; LLVM has a BSD-like license which permits including the source into proprietary software. Bottomline, Apple decided that GCC

[is] not pragmatic, we respect GCC’s ubiquity [but] our goals are fundamentally different than GCC…

The LLDB Debugger (LLDB) is a high-performance debugger built as a set of reusable components which extensively use existing libraries from the larger LLVM Project, such as the Clang expression parser and LLVM disassembler. For more information on LLVM, the project page is a good starting point, also the page on wikipedia and several benchmarking resuls. It might also be useful to read more about dynamic compilation, static assignment, just–in–time compilation and all related pages.

While working on a project I ran into the need of extensive debugging so I thought it would be useful to share some info. Here’s a short tutorial of how to run lldb in XCode 4 if you are familiar with the gdb command set. We will start with some details on lldb command structure and syntax to help orient you.

char *test;
test = (char*)malloc(sizeof(char) * 10);

Breakpoint commands

GDB LLDB
(gdb) info break (lldb) breakpoint list
(lldb) br l
(lldb) br l
Current breakpoints:
1: file =’AppDelegate.m’, line = 42, locations = 1, resolved = 1
1.1: where = NSStringInstanceMthods`-[AppDelegate awakeFromNib] + 90 at AppDelegate.m:44, address = 0x00000001000019da, resolved, hit count = 1
(gdb) br set -l:49
error: Breakpoint creation failed: No breakpoint created.
(lldb) br set -l49
Breakpoint 2: where = NSStringInstanceMthods`-[AppDelegate awakeFromNib] + 153 at AppDelegate.m:49, address = 0x0000000100001a19
(lldb) br l
Current breakpoints:
1: file =’AppDelegate.m’, line = 42, locations = 1, resolved = 1
1.1: where = NSStringInstanceMthods`-[AppDelegate awakeFromNib] + 90 at AppDelegate.m:44, address = 0x00000001000019da, resolved, hit count = 1
2: file =’AppDelegate.m’, line = 49, locations = 1, resolved = 1
2.1: where = NSStringInstanceMthods`-[AppDelegate awakeFromNib] + 153 at AppDelegate.m:49, address = 0x0000000100001a19, resolved, hit count = 0
(lldb)
Filed in Apple Programming, Debugging and tagged , , .

Leave a Reply

Your email address will not be published. Required fields are marked *