LLDB Introduction

     Jaemok Jeong
        2012. 8.
Overview

LLDB is a next generation, high performance
debugger

Available under the standard LLVM license,
an open source ‘BSD-Style’ license



Default debugger in Xcode on MAC OS X
Features

Supports modern multi-threaded program

Upto date language support for C, C++,
Objective C



Extensible : Python scriptable and use a
plug-in architecture
General


(lldb) help <command> <subcommand>



(lldb) <noun> <verb> [-options [option-value]]
[argument [argument...]]
Execution
(lldb) r / run (run)

(lldb) s / step (source level single step in)

(lldb) n / next (source level single step over)

(lldb) si / ni (instruction level single step in)

(lldb) finish (step out of currently selected
frame)
Hooks
(lldb) target stop-hook add
Enter your stop hook command(s). Type ‘DONE’ to end.
> print i
> DONE
Stop hook #1 added
(lldb) n
(int) $32 = 1
Breakpoint
(lldb) b main (Set a break point at all function named
main)

(lldb) b test.c:12 (Set a breakpoint in file test.c at line
12)

(lldb) b -[NSString stringWithFormat:]

(lldb) br s -S count / br set -S
vtDataCenterFetchComplete:userData:

(lldb) br delete [n]
Watchpoint
(lldb) watch set var -w write global_var (set
write watchpoint)

(lldb) watch set exp -w write -- my_ptr (set
write watchpoint in pointer)

(lldb) watch set var -w read global_var (set read
watchpoint)

(lldb) watch modify -c ‘(global==5)’ (set
condition on watchpoint)
Examining Variables
(lldb) frame variable (show arguments for the
current frame)

(lldb) frame v -a (--no-args) (show the local
variables for the current frame)

(lldb) frame v isChanged (p isChanged)

(lldb) target v (show the global/static variables)

(lldb) print a_var / po a_var
Examining Thread state
 (lldb) thread backtrace (show the stack
 backtrace)

 (lldb) bt

 (lldb) up (select the stack frame that called
 the current stack frame)

 (lldb) down (select the stack frame that is
 called by the current stack frame)
Executable & Shared
      Library

(lldb) image list (list the main executable and
all dependent shared libraries)

(lldb) image dump sections (dump all sections
from the main executable and any shared
libraries)
LLDB Python

(lldb) script help(lldb)

(lldb) script help(lldb.SBFrame)

(lldb) script (Python interpreter)

Define New Command with Python

Define New Breakpoint action with Python
Tips

Alias

  (lldb) command alias bfl breakpoint set -f
  %1 -l %2

  (lldb) bfl foo.c 12

Init file

  Reads the file ~/.lldbinit at startup
Examples


br set -S invalidateCache

br set -S
vtDataCenterFetchComplete:userData:

watch set var -w read selectedDate
Links

Homepage

  http://lldb.llvm.org/

Source code

  svn co http://llvm.org/svn/llvm-project/
  lldb/trunk lldb

LLDB Introduction

  • 1.
    LLDB Introduction Jaemok Jeong 2012. 8.
  • 2.
    Overview LLDB is anext generation, high performance debugger Available under the standard LLVM license, an open source ‘BSD-Style’ license Default debugger in Xcode on MAC OS X
  • 3.
    Features Supports modern multi-threadedprogram Upto date language support for C, C++, Objective C Extensible : Python scriptable and use a plug-in architecture
  • 4.
    General (lldb) help <command><subcommand> (lldb) <noun> <verb> [-options [option-value]] [argument [argument...]]
  • 5.
    Execution (lldb) r /run (run) (lldb) s / step (source level single step in) (lldb) n / next (source level single step over) (lldb) si / ni (instruction level single step in) (lldb) finish (step out of currently selected frame)
  • 6.
    Hooks (lldb) target stop-hookadd Enter your stop hook command(s). Type ‘DONE’ to end. > print i > DONE Stop hook #1 added (lldb) n (int) $32 = 1
  • 7.
    Breakpoint (lldb) b main(Set a break point at all function named main) (lldb) b test.c:12 (Set a breakpoint in file test.c at line 12) (lldb) b -[NSString stringWithFormat:] (lldb) br s -S count / br set -S vtDataCenterFetchComplete:userData: (lldb) br delete [n]
  • 8.
    Watchpoint (lldb) watch setvar -w write global_var (set write watchpoint) (lldb) watch set exp -w write -- my_ptr (set write watchpoint in pointer) (lldb) watch set var -w read global_var (set read watchpoint) (lldb) watch modify -c ‘(global==5)’ (set condition on watchpoint)
  • 9.
    Examining Variables (lldb) framevariable (show arguments for the current frame) (lldb) frame v -a (--no-args) (show the local variables for the current frame) (lldb) frame v isChanged (p isChanged) (lldb) target v (show the global/static variables) (lldb) print a_var / po a_var
  • 10.
    Examining Thread state (lldb) thread backtrace (show the stack backtrace) (lldb) bt (lldb) up (select the stack frame that called the current stack frame) (lldb) down (select the stack frame that is called by the current stack frame)
  • 11.
    Executable & Shared Library (lldb) image list (list the main executable and all dependent shared libraries) (lldb) image dump sections (dump all sections from the main executable and any shared libraries)
  • 12.
    LLDB Python (lldb) scripthelp(lldb) (lldb) script help(lldb.SBFrame) (lldb) script (Python interpreter) Define New Command with Python Define New Breakpoint action with Python
  • 13.
    Tips Alias (lldb)command alias bfl breakpoint set -f %1 -l %2 (lldb) bfl foo.c 12 Init file Reads the file ~/.lldbinit at startup
  • 14.
    Examples br set -SinvalidateCache br set -S vtDataCenterFetchComplete:userData: watch set var -w read selectedDate
  • 15.
    Links Homepage http://lldb.llvm.org/ Sourcecode svn co http://llvm.org/svn/llvm-project/ lldb/trunk lldb