🦅Swift Syntax

#1-2. LLDB(Low-Level Debugger) 디버거 [스위프트]

msi 2021. 4. 15. 01:16

LLDB(Low-Level Debugger)

LLVM은 컴파일 프로젝트이고 그 서브 프로젝트인 LLDB는 디버깅을 맡고 있다.
LLDB는 LLVM의 Debugger Component를 개발하는 서브 프로젝트이다.
C, C++, Objective-C, Swift를 지원하며, 현재 Xcode의 기본 디버거로 내장되어 있다.

기본 문법

(lldb) command [subcommand] -option "this is argument"

구성요소: Command, Subcommand, Option, Argument

 

예시: (lldb) breakpoint set --file test.c --line 12

breakpoint(Command)와 set(Subcommand)을 이용하며 --file option을 통해 test.c 파일 내 --line option을 통해 12번째 라인에 중단점을 set 해줍니다.

Help

// LLDB에서 제공하는 Command가 궁금하다면,

(lldb) help

// 특정 Command의 Subcommand나, Option이 궁금하다면,

(lldb) help breakpoint

(lldb) help breakpoint set

Apropos

//referent count를 체크할 수 있는 명령어가 있을까? 궁금하다면,

(lldb) apropos "refernce count"

// 결과 # The following commands may relate to 'reference count': # refcount -- Inspect the reference count data for a Swift object

 

breakpoint 걸기

그냥 왼쪽 행 번호 클릭해서 사용 중...

명령어를 줄여서 사용할 수도 있구나...

함수명, 파일 라인(행)에 걸 수도 있구나...

Condtion 조건에 따라

//viewWillAppear 호출시, animated가 true인 경우에만 break

(lldb) breakpoint set --name "viewWillAppear" --condition animated

(lldb) br s -n "viewWillAppear" -c animated

Command 실행 & AutoContinue

-command (-C) option을 이용하면 break시 원하는 lldb command를 실행 할 수 있습니다.
–auto-continue (-G) option의 기능은 auto continue로, command 실행 후 break에 걸린채로 있지 않고 프로그램을 자동 진행하게 해줍니다`

(lldb) breakpoint set -n "viewDidLoad" --command "po $arg1" -G1

(lldb) br s -n "viewDidLoad" -C "po $arg1" -G1

b (_regexp-break) Command

# 특정 이름을 가진 function에서 break

(lldb) b viewDidLoad

# 현재 파일 20번째 line에서 break

(lldb) b 20

# 특정 파일 20번째 line에서 break

(lldb) b ViewController.swift:12

# 현재 파일 내 특정 text를 포함한 line에서 break

(lldb) b /stop here/

# 특정 주소값에서 break

(lldb) b 0x1234000

Stepping

run next(n) step-in(s) finish
버튼을 눌러서 사용하자


Expression

po

 

음... 아직까진 어떻게 사용할지 별로 감이 안오네

 

https://yagom.net/courses/start-lldb/lessons/expression/topic/po/

출처: https://yagom.net/courses/start-lldb/lessons/lldblow-level-debugger란/