9. osxdev.org
Introduction
• LLVM
- Low-Level Virtual Machine
• An Infrastructure for Multi-stage Optimization
- by Chris Arthur Lattner @2002
• Design and Implementation of a compiler infrastructure
- support a unique multi-stage optimization system
- support inter-procedural and profile-driven optimizations
• LLVM virtual instruction (IR)
- with high-level type information
• Sponsored by APPLE
21. osxdev.org
ARC
• Automatic Reference Counting
- Automatic memory management of Objective-C objects
- Just Compile-time, Not Run-time
• Not Garbage-Collector
• Migration Tool in Xcode 4.2
- with LLVM 3.0
- build-settings : -fobjc-arc (cf. -fno-objc-arc)
• New Rules
- remove dealloc, retain/release/autorelease
✴ can still use CFRetain / CFRelease in CF
- Can’t use NSAllocateObject / NSDeallocateObject
- Can’t use object pointer in C Structures
- no casual casting id -> void*
- Can’t use NSAutoreleasePool -> @autoreleasepool
- Can’t use memory zone (NSZone)
- Can’t give a property name with new-
Automatic Reference Coun
28. osxdev.org
LLDB Command Syntax
Command Syntax
<type> <action> [-options [option-value]] [argument [argument...]]
Uses standard getopt_long() for predicate behavior
(lldb) process launch a.out --stop-at-entry
(lldb) process launch a.out -- --arg0 --arg1
(lldb) process launch a.out -st
Options know which other options they are compatible with
(lldb) process attach --pid 123 --name a.out
Type : breakpoint, commands, frame, image, log, memory, process,
regexp-break, register, settings, source, target, thread
29. osxdev.org
Common Commands
GDB LLDB
(gdb) ^C
(gdb) signal 2
(gdb) info break
(gdb) continue
(gdb) step
(gdb) stepi
(gdb) next
(gdb) nexti
(gdb) finish
(gdb) info threads
(gdb) backtrace
(lldb) process interrupt
(lldb) process signal SIGINT
(lldb) breakpoint list
(lldb) process continue
(lldb) thread step-in
(lldb) thread step-inst
(lldb) thread step-over
(lldb) thread step-over-inst
(lldb) thread step-out
(lldb) thread list
(lldb) thread backtrace
30. osxdev.org
Common Commands
GDB LLDB
(gdb) ^C
(gdb) signal 2
(gdb) in br
(gdb) c
(gdb) s
(gdb) si
(gdb) n
(gdb) ni
(gdb) f
(gdb) info threads
(gdb) bt
(lldb) pro int
(lldb) pro s SIGINT
(lldb) br l
(lldb) c
(lldb) s
(lldb) si
(lldb) n
(lldb) ni
(lldb) f
(lldb) th l
(lldb) bt
31. osxdev.org
Apropos Command
(lldb) apropos thread
The following commands may relate to 'thread':
breakporint command add -- Add a set of commands to a breakpoint, to be executed whenever ...
breakpoint modify -- Modify the options on a breakpoint or set of breakpoints...
breakpoint set -- Sets a breakpoint or set of breakpoints in the executable.
frame -- A set of commands for operating on the current thread's...
frame info -- List information about the currently selected frame in the...
frame select -- Select a frame by index from within the current thread...
log enable -- Enable logging for a single log channel.
process continue -- Continue execution of all threads in the current process.
register -- A set of commands to access thread registers.
thread -- A set of commands for operating on one or more...
thread backtrace -- Show the stack for one or more threads. If no threads are...
thread continue -- Continue execution of one or more threads in an active...
thread list -- Show a summary of all current threads in a process.
thread select -- Select a thread as the currently active thread.
thread step-in -- Source level single step in specified thread (current...
thread step-inst -- Single step one instruction in specified thread (current..
35. 새로워진 Instruments #1
✴ The Jump Bar
✴ Improved View Access
✴ Collapsible, Track, Full screen
✴ The Call Tree
✴ Backtrace Compression with Filtering
✴ The Source View
✴ Timeline Flags
- Navigating the improved UI
36. 새로워진 Instruments #2
✴ Immediate vs. Deferred Mode
✴ Immediate mode - “Classic Instruments mode”
✴ Deferred mode
✴ Processes and displays data at end of recording
✴ Vastly reduces “observer effect”
✴ More samples relate to your app.
✴ Launch Daemons and Agents (Mac OS X only)
✴ over Wi-Fi (iPhone OS 3.1+)
✴ Re-Symbolication
- Recording Techniques
37. 새로워진 Instruments #3
✴ Time Profiler
✴ more efficient than CPU Sampler
✴ Deferred mode
✴ Heapshots
✴ Part of Allocation template
✴ VM Tracker
✴ Tracks the virtual memory of a process
- Advancement to existing Instruments
38. 새로워진 Instruments #4
✴ Energy Diagnostics
✴ Provides diagnostics regarding energy usage
✴ Records battery power and CPU usage
✴ Automation
✴ Simulate UI interaction with iOS app.
✴ Leverages JavaScript to script iPhone UI
components
✴ OpenGL ES Analysis
- Significant New Instrumentation
39. UI Automation
✴ Automates UIKit based applications
✴ Touch based
✴ iPhone, iPod touch and iPhone Simulator
✴ Integrated in Instruments
✴ Accessibility based
✴ JavaScript automation scripts
✴ UI Automation Reference Collection
- What is this?
40. 새로워진 Instruments #4
✴ System Trace
✴ Provides comprehensive information on system
behavior
✴ Identifies when threads are scheduled and why
✴ Display thread transition from user space into
system code
✴ System calls, VM operations
✴ Highlights View - summary
- Really New Instrumentation
43. DTrace is...
✴ dynamic tracing facility
✴ developed by Sun Microsystems
✴ for Solaris 10
✴ designed by Bryan Cantrill, Mike Shapiro, and Adam
Leventhal.
✴ introduced with Leopard (Prior to 10.5 ktrace)
✴ http://hub.opensolaris.org/bin/view/Community+Group
+dtrace/WebHome
✴ http://en.wikipedia.org/wiki/DTrace
46. osxdev.org
D Language
✴ A Large subset of C
✴ with a special set of functions to analyzing system
behavior.
✴ run in kernel-land.
✴ compiled into a safe form (similar to java bytecode)
✴ validated for safety.
✴ filename extension .d
50. osxdev.org
Probes
✴ Providers - the instruments
✴ Module - a specific program location
✴ Function - a specific function name
✴ Name - an indication of the probe’s semantic meaning
syscall :: open : entry
syscall :: open* : entry
syscall ::: entry
syscall :::
51. osxdev.org
BEGIN - END Providers
/* show the BEGIN and END providers
run with:
sudo dtrace -s begin-end.d
*/
BEGIN
{
trace("begin the beguine");
exit(0);
}
END
{
trace("that's all, folks...");
}
52. osxdev.org
syscall Provider
/* show all system calls being made, system-wide
Run with
sudo dtrace -qs syscalls.d
*/
syscall:::
/execname != "dtrace"/
{
printf("%s fired in %s", probefunc, execname);
}
53. osxdev.org
profile Provider
/* show the profile (timer) provider.
Run with
sudo dtrace -s lubdub.d
*/
profile:::tick-5sec
{
trace("five second timer");
}
profile:::tick-1min
{
trace("one minute timer");
}
profile:::tick-800msec
{
trace("800 millisecond timer");
}
54. osxdev.org
proc Provider
/* Show procoess launches across the system.
Run with
sudo dtrace -s execs.d
*/
proc:::exec-success
{
trace(execname);
}
55. osxdev.org
Actions
✴ the lines of code
✴ assign values to variables, perform computations,
aggregate values over time...
✴ no flow control (no if, no loops)
✴ use predicates
56. osxdev.org
Variables
✴ C standard types : char, int, short, long, long long...
✴ display floating point values from probes
✴ cannot perform floating point math
✴ cannot cast float to integer
✴ global by default
✴ standard C operators all work
✴ do comparison operators (^^ XOR)
✴ use strcmp()
57. osxdev.org
example 9.6
/* sings a pretty song.
run with:
sudo dtrace -qs beer.d
*/
int bottles; /* optional */
BEGIN
{
bottles = 99;
}
profile:::tick-1sec
{
printf("%d bottles of beer on the walln", bottles);
printf("%d bottles of beer.n", bottles);
printf("take one down, pass it aroundn");
printf("%d bottles of beer on the wallnn", bottles);
bottles--;
}
END
{
printf("that's all, folks...");
}
60. osxdev.org
example 9.7
/* show all system calls being made, system-wide
Run with
sudo dtrace -qs syscalls.d
*/
syscall:::
/execname != "dtrace"/
{
printf("%s fired in %s", probefunc, execname);
}