session 415 - debugging with lldb

436
These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 415 Debugging with LLDB Greg Clayton LLDB Architect

Upload: foufoutos73

Post on 03-Jan-2016

245 views

Category:

Documents


0 download

DESCRIPTION

Session 415 - Debugging With LLDB

TRANSCRIPT

Page 1: Session 415 - Debugging With LLDB

These are confidential sessions—please refrain from streaming, blogging, or taking pictures

Session 415

Debugging with LLDB

Greg ClaytonLLDB Architect

Page 2: Session 415 - Debugging With LLDB
Page 3: Session 415 - Debugging With LLDB

Year in review

Page 4: Session 415 - Debugging With LLDB

J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R

Page 5: Session 415 - Debugging With LLDB

J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R

Page 6: Session 415 - Debugging With LLDB

J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R2 0 1 1

LLDB was available in Xcode seeds

Page 7: Session 415 - Debugging With LLDB

J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R

LLDB was available in Xcode seeds

Page 8: Session 415 - Debugging With LLDB

J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R

Page 9: Session 415 - Debugging With LLDB

J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R2 0 1 1

LLDB became the default debugger

Xcode 4.3

Page 10: Session 415 - Debugging With LLDB

J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R

LLDB became the default debugger

Xcode 4.3

Page 11: Session 415 - Debugging With LLDB

J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R

Page 12: Session 415 - Debugging With LLDB

J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R2 0 1 2

Xcode 4.5 seeded

Page 13: Session 415 - Debugging With LLDB

J A N U A R Y F E B R U A R Y M A R C H A P R I L M A Y J U N E J U L Y A U G U S T S E P T E M B E R O C T O B E R N O V E M B E R D E C E M B E R2 0 1 2

Vastly improved LLDBXcode 4.5 seeded

Page 14: Session 415 - Debugging With LLDB

Fixes and featuresLLDB Improvements

Page 15: Session 415 - Debugging With LLDB

Fixes and featuresLLDB Improvements

Page 16: Session 415 - Debugging With LLDB

Fixes and featuresLLDB Improvements

• Improved Objective-C debugging support■ Objective-C property syntax■ Full Objective-C class definitions

Page 17: Session 415 - Debugging With LLDB

Fixes and featuresLLDB Improvements

• Improved Objective-C debugging support■ Objective-C property syntax■ Full Objective-C class definitions

• Data formatters now in LLDB■ Objective-C■ C++ STL types and collections

Page 18: Session 415 - Debugging With LLDB

Fixes and featuresLLDB Improvements

• Improved Objective-C debugging support■ Objective-C property syntax■ Full Objective-C class definitions

• Data formatters now in LLDB■ Objective-C■ C++ STL types and collections

• Watchpoints for desktop and iOS

Page 19: Session 415 - Debugging With LLDB

Fixes and featuresLLDB Improvements

• Improved Objective-C debugging support■ Objective-C property syntax■ Full Objective-C class definitions

• Data formatters now in LLDB■ Objective-C■ C++ STL types and collections

• Watchpoints for desktop and iOS• Improved Python scripting

Page 20: Session 415 - Debugging With LLDB

Introduction LLDB in depth Examples Conclusion

Overview

Page 21: Session 415 - Debugging With LLDB

Introduction

LLDB in depth Examples Conclusion

Overview

Page 22: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

Page 23: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

• Wanted better debugger

Page 24: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

• Wanted better debugger• What was wrong with GDB?

Page 25: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

• Wanted better debugger• What was wrong with GDB?

■ Architecture

Page 26: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

• Wanted better debugger• What was wrong with GDB?

■ Architecture■ Parses information in large chunks

Page 27: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

• Wanted better debugger• What was wrong with GDB?

■ Architecture■ Parses information in large chunks■ GDB was not designed to vend an API

Page 28: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

• Wanted better debugger• What was wrong with GDB?

■ Architecture■ Parses information in large chunks■ GDB was not designed to vend an API■ Global variables contain program state

Page 29: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

• Wanted better debugger• What was wrong with GDB?

■ Architecture■ Parses information in large chunks■ GDB was not designed to vend an API■ Global variables contain program state■ Different GDB binaries for each architecture

Page 30: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

• Wanted better debugger• What was wrong with GDB?

■ Architecture■ Parses information in large chunks■ GDB was not designed to vend an API■ Global variables contain program state■ Different GDB binaries for each architecture

■ Pervasive preprocessor macros

Page 31: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

• Wanted better debugger• What was wrong with GDB?

■ Architecture■ Parses information in large chunks■ GDB was not designed to vend an API■ Global variables contain program state■ Different GDB binaries for each architecture

■ Pervasive preprocessor macros■ Issues with expression parser

Page 32: Session 415 - Debugging With LLDB

Why create LLDB?Introduction

• Wanted better debugger• What was wrong with GDB?

■ Architecture■ Parses information in large chunks■ GDB was not designed to vend an API■ Global variables contain program state■ Different GDB binaries for each architecture

■ Pervasive preprocessor macros■ Issues with expression parser

■ Objective-C properties

Page 33: Session 415 - Debugging With LLDB

Design goalsIntroduction

Page 34: Session 415 - Debugging With LLDB

Design goalsIntroduction

• Performance• Memory• Customizable• Compiler integration• Modern architecture

Page 35: Session 415 - Debugging With LLDB

Design goalsIntroduction

• Performance• Memory• Customizable• Compiler integration• Modern architecture

Page 36: Session 415 - Debugging With LLDB

CustomizableIntroduction

Page 37: Session 415 - Debugging With LLDB

CustomizableIntroduction

• Variable and value display■ Formats■ Summaries■ Synthetic instance variables

Page 38: Session 415 - Debugging With LLDB

CustomizableIntroduction

• Variable and value display■ Formats■ Summaries■ Synthetic instance variables

• Commands■ Aliases■ User-defined

Page 39: Session 415 - Debugging With LLDB

CustomizableIntroduction

• Variable and value display■ Formats■ Summaries■ Synthetic instance variables

• Commands■ Aliases■ User-defined

• Prompts

Page 40: Session 415 - Debugging With LLDB

Why do compiler integration?Introduction

Page 41: Session 415 - Debugging With LLDB

Why do compiler integration?Introduction

• What do debuggers do?

Page 42: Session 415 - Debugging With LLDB

Why do compiler integration?Introduction

• What do debuggers do?■ Debuggers invent their own type representation

Page 43: Session 415 - Debugging With LLDB

Why do compiler integration?Introduction

• What do debuggers do?■ Debuggers invent their own type representation■ Expression parsers use these types

Page 44: Session 415 - Debugging With LLDB

Why do compiler integration?Introduction

• What do debuggers do?■ Debuggers invent their own type representation■ Expression parsers use these types■ Strive for compiler level of accuracy

Page 45: Session 415 - Debugging With LLDB

Why do compiler integration?Introduction

• What do debuggers do?■ Debuggers invent their own type representation■ Expression parsers use these types■ Strive for compiler level of accuracy■ Expression parser needs to be updated

Page 46: Session 415 - Debugging With LLDB

Why do compiler integration?Introduction

• What do debuggers do?■ Debuggers invent their own type representation■ Expression parsers use these types■ Strive for compiler level of accuracy■ Expression parser needs to be updated

• How hard can it be to write a good C++ parser?

Page 47: Session 415 - Debugging With LLDB

Compiler integration in LLDBIntroduction

Page 48: Session 415 - Debugging With LLDB

Compiler integration in LLDBIntroduction

• Full Clang compiler built in

Page 49: Session 415 - Debugging With LLDB

Compiler integration in LLDBIntroduction

• Full Clang compiler built in• LLDB converts debugging information into native Clang types

Page 50: Session 415 - Debugging With LLDB

Compiler integration in LLDBIntroduction

• Full Clang compiler built in• LLDB converts debugging information into native Clang types

■ Use Clang AST data structures for types

Page 51: Session 415 - Debugging With LLDB

Compiler integration in LLDBIntroduction

• Full Clang compiler built in• LLDB converts debugging information into native Clang types

■ Use Clang AST data structures for types

• Use the compiler to parse expressions

Page 52: Session 415 - Debugging With LLDB

Compiler integration in LLDBIntroduction

• Full Clang compiler built in• LLDB converts debugging information into native Clang types

■ Use Clang AST data structures for types

• Use the compiler to parse expressions■ Attain what other debuggers strive for

Page 53: Session 415 - Debugging With LLDB

Compiler integration in LLDBIntroduction

• Full Clang compiler built in• LLDB converts debugging information into native Clang types

■ Use Clang AST data structures for types

• Use the compiler to parse expressions■ Attain what other debuggers strive for■ Complete language support

Page 54: Session 415 - Debugging With LLDB

Compiler integration in LLDBIntroduction

• Full Clang compiler built in• LLDB converts debugging information into native Clang types

■ Use Clang AST data structures for types

• Use the compiler to parse expressions■ Attain what other debuggers strive for■ Complete language support■ Accurate error reporting

Page 55: Session 415 - Debugging With LLDB

Compiler integration in LLDBIntroduction

• Full Clang compiler built in• LLDB converts debugging information into native Clang types

■ Use Clang AST data structures for types

• Use the compiler to parse expressions■ Attain what other debuggers strive for■ Complete language support■ Accurate error reporting■ Free compiler features

■ Objective-C Literals■ C++11

Page 56: Session 415 - Debugging With LLDB

Modern architectureIntroduction

Page 57: Session 415 - Debugging With LLDB

Modern architectureIntroduction

• Clean object-oriented design

Page 58: Session 415 - Debugging With LLDB

Modern architectureIntroduction

• Clean object-oriented design■ Encapsulation

Page 59: Session 415 - Debugging With LLDB

Modern architectureIntroduction

• Clean object-oriented design■ Encapsulation■ Plug-ins

Page 60: Session 415 - Debugging With LLDB

Modern architectureIntroduction

• Clean object-oriented design■ Encapsulation■ Plug-ins

• Designed for today’s debugging requirements

Page 61: Session 415 - Debugging With LLDB

Modern architectureIntroduction

• Clean object-oriented design■ Encapsulation■ Plug-ins

• Designed for today’s debugging requirements■ Multi-threaded programs

Page 62: Session 415 - Debugging With LLDB

Modern architectureIntroduction

• Clean object-oriented design■ Encapsulation■ Plug-ins

• Designed for today’s debugging requirements■ Multi-threaded programs■ Stay in sync with compiler

Page 63: Session 415 - Debugging With LLDB

Modern architectureIntroduction

• Clean object-oriented design■ Encapsulation■ Plug-ins

• Designed for today’s debugging requirements■ Multi-threaded programs■ Stay in sync with compiler

• LLDB is a framework

Page 64: Session 415 - Debugging With LLDB

Modern architectureIntroduction

• Clean object-oriented design■ Encapsulation■ Plug-ins

• Designed for today’s debugging requirements■ Multi-threaded programs■ Stay in sync with compiler

• LLDB is a framework ■ Provides an API to the debugger

Page 65: Session 415 - Debugging With LLDB

Modern architectureIntroduction

• Clean object-oriented design■ Encapsulation■ Plug-ins

• Designed for today’s debugging requirements■ Multi-threaded programs■ Stay in sync with compiler

• LLDB is a framework ■ Provides an API to the debugger■ Scriptable with Python

Page 66: Session 415 - Debugging With LLDB

Debugging with LLDBOverview

Introduction

LLDB in depth Examples Conclusion

Page 67: Session 415 - Debugging With LLDB

Debugging with LLDBOverview

Introduction

LLDB in depth

Examples Conclusion

Page 68: Session 415 - Debugging With LLDB

LLDBLLDB in Depth

• Getting started• Terminology• Customizing commands• Launching programs• Debug session

Page 69: Session 415 - Debugging With LLDB

LLDBLLDB in Depth

• Getting started• Terminology• Customizing commands• Launching programs• Debug session

Page 70: Session 415 - Debugging With LLDB

First commandsGetting Started

Page 71: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb

Page 72: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) file a.out

Page 73: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) file a.out(lldb) b main

Page 74: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) file a.out(lldb) b main(lldb) run

Page 75: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) file a.out(lldb) b main(lldb) run(lldb) bt

Page 76: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) file a.out(lldb) b main(lldb) run(lldb) bt(lldb) step

Page 77: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) file a.out(lldb) b main(lldb) run(lldb) bt(lldb) step(lldb) step

Page 78: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) file a.out(lldb) b main(lldb) run(lldb) bt(lldb) step(lldb) step(lldb) print argc

Page 79: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) file a.out(lldb) b main(lldb) run(lldb) bt(lldb) step(lldb) step(lldb) print argc(lldb) next

Page 80: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) file a.out(lldb) b main(lldb) run(lldb) bt(lldb) step(lldb) step(lldb) print argc(lldb) next(lldb) next

Page 81: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) file a.out(lldb) b main(lldb) run(lldb) bt(lldb) step(lldb) step(lldb) print argc(lldb) next(lldb) next(lldb) q

Page 82: Session 415 - Debugging With LLDB

First commandsGetting Started

Page 83: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb

Page 84: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) target create a.out

Page 85: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) target create a.out(lldb) breakpoint set --name main

Page 86: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) target create a.out(lldb) breakpoint set --name main(lldb) process launch

Page 87: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) target create a.out(lldb) breakpoint set --name main(lldb) process launch(lldb) thread backtrace

Page 88: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) target create a.out(lldb) breakpoint set --name main(lldb) process launch(lldb) thread backtrace(lldb) thread step-in

Page 89: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) target create a.out(lldb) breakpoint set --name main(lldb) process launch(lldb) thread backtrace(lldb) thread step-in(lldb) thread step-in

Page 90: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) target create a.out(lldb) breakpoint set --name main(lldb) process launch(lldb) thread backtrace(lldb) thread step-in(lldb) thread step-in(lldb) expression argc

Page 91: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) target create a.out(lldb) breakpoint set --name main(lldb) process launch(lldb) thread backtrace(lldb) thread step-in(lldb) thread step-in(lldb) expression argc(lldb) thread step-over

Page 92: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) target create a.out(lldb) breakpoint set --name main(lldb) process launch(lldb) thread backtrace(lldb) thread step-in(lldb) thread step-in(lldb) expression argc(lldb) thread step-over(lldb) thread step-over

Page 93: Session 415 - Debugging With LLDB

First commandsGetting Started

% xcrun lldb(lldb) target create a.out(lldb) breakpoint set --name main(lldb) process launch(lldb) thread backtrace(lldb) thread step-in(lldb) thread step-in(lldb) expression argc(lldb) thread step-over(lldb) thread step-over(lldb) quit

Page 94: Session 415 - Debugging With LLDB

Command interpreterGetting Started

Page 95: Session 415 - Debugging With LLDB

Command interpreterGetting Started

• GDB command interpreter had issues

Page 96: Session 415 - Debugging With LLDB

Command interpreterGetting Started

• GDB command interpreter had issues■ Inconsistent syntax

Page 97: Session 415 - Debugging With LLDB

Command interpreterGetting Started

• GDB command interpreter had issues■ Inconsistent syntax■ Overloaded arguments

Page 98: Session 415 - Debugging With LLDB

Command interpreterGetting Started

• GDB command interpreter had issues■ Inconsistent syntax■ Overloaded arguments

• LLDB command interpreter

Page 99: Session 415 - Debugging With LLDB

Command interpreterGetting Started

• GDB command interpreter had issues■ Inconsistent syntax■ Overloaded arguments

• LLDB command interpreter■ Consistent syntax

Page 100: Session 415 - Debugging With LLDB

Command interpreterGetting Started

• GDB command interpreter had issues■ Inconsistent syntax■ Overloaded arguments

• LLDB command interpreter■ Consistent syntax■ Use options instead of overloading

Page 101: Session 415 - Debugging With LLDB

Command interpreterGetting Started

• GDB command interpreter had issues■ Inconsistent syntax■ Overloaded arguments

• LLDB command interpreter■ Consistent syntax■ Use options instead of overloading

■ Targeted autocompletion

Page 102: Session 415 - Debugging With LLDB

Command interpreterGetting Started

• GDB command interpreter had issues■ Inconsistent syntax■ Overloaded arguments

• LLDB command interpreter■ Consistent syntax■ Use options instead of overloading

■ Targeted autocompletion■ Discoverable commands

Page 103: Session 415 - Debugging With LLDB

Command interpreterGetting Started

• GDB command interpreter had issues■ Inconsistent syntax■ Overloaded arguments

• LLDB command interpreter■ Consistent syntax■ Use options instead of overloading

■ Targeted autocompletion■ Discoverable commands■ Built-in documentation

Page 104: Session 415 - Debugging With LLDB

Noun and verbCommand Syntax

<noun> <verb>

(lldb) target create(lldb) breakpoint set(lldb) process launch(lldb) thread step-in(lldb) frame variable

Page 105: Session 415 - Debugging With LLDB

Shell style optionsCommand Syntax

<noun> <verb> [options]

(lldb) target create --arch i386(lldb) breakpoint set --name main(lldb) process launch --stop-at-entry(lldb) thread step-in(lldb) frame variable --format hex

Page 106: Session 415 - Debugging With LLDB

ArgumentsCommand Syntax

<noun> <verb> [options] [argument [argument...]]

(lldb) target create --arch i386 /bin/ls(lldb) breakpoint set --name main(lldb) process launch --stop-at-entry -- -lAF /tmp(lldb) thread step-in(lldb) frame variable --format hex argc argv[0]

Page 107: Session 415 - Debugging With LLDB

ArgumentsCommand Syntax

<noun> <verb> [options] [argument [argument...]]

(lldb) target create /bin/ls --arch i386(lldb) breakpoint set --name main(lldb) process launch --stop-at-entry -- -lAF /tmp(lldb) thread step-in(lldb) frame variable --format hex argc argv[0]

Page 108: Session 415 - Debugging With LLDB

Shortest matchCommand Syntax

<noun> <verb> [options] [argument [argument...]]

(lldb) ta c /bin/ls --arch i386(lldb) breakpoint set --name main(lldb) process launch --stop-at-entry -- -lAF /tmp(lldb) thread step-in(lldb) frame variable --format hex argc argv[0]

Page 109: Session 415 - Debugging With LLDB

Shortest matchCommand Syntax

<noun> <verb> [options] [argument [argument...]]

(lldb) ta c /bin/ls --arch i386(lldb) br s --name main(lldb) process launch --stop-at-entry -- -lAF /tmp(lldb) thread step-in(lldb) frame variable --format hex argc argv[0]

Page 110: Session 415 - Debugging With LLDB

Shortest matchCommand Syntax

<noun> <verb> [options] [argument [argument...]]

(lldb) ta c /bin/ls --arch i386(lldb) br s --name main(lldb) pro la --stop-at-entry -- -lAF /tmp(lldb) thread step-in(lldb) frame variable --format hex argc argv[0]

Page 111: Session 415 - Debugging With LLDB

Shortest matchCommand Syntax

<noun> <verb> [options] [argument [argument...]]

(lldb) ta c /bin/ls --arch i386(lldb) br s --name main(lldb) pro la --stop-at-entry -- -lAF /tmp(lldb) th step-in(lldb) frame variable --format hex argc argv[0]

Page 112: Session 415 - Debugging With LLDB

Shortest matchCommand Syntax

<noun> <verb> [options] [argument [argument...]]

(lldb) ta c /bin/ls --arch i386(lldb) br s --name main(lldb) pro la --stop-at-entry -- -lAF /tmp(lldb) th step-in(lldb) fr v --format hex argc argv[0]

Page 113: Session 415 - Debugging With LLDB

Short optionsCommand Syntax

<noun> <verb> [options] [argument [argument...]]

(lldb) ta c /bin/ls -a i386(lldb) br s -n main(lldb) pro la -s -- -lAF /tmp(lldb) th step-in(lldb) fr v -f x argc argv[0]

Page 114: Session 415 - Debugging With LLDB

LLDBLLDB in Depth

• Getting started• Terminology• Customizing commands• Launching programs• Debug session

Page 115: Session 415 - Debugging With LLDB

LLDBLLDB in Depth

• Getting started• Terminology• Customizing commands• Launching programs• Debug session

Page 116: Session 415 - Debugging With LLDB

targetTerminology

Page 117: Session 415 - Debugging With LLDB

targetTerminology

(lldb) file a.out

Page 118: Session 415 - Debugging With LLDB

targetTerminology

(lldb) file a.out(lldb) target create a.out

Page 119: Session 415 - Debugging With LLDB

targetTerminology

(lldb) file a.out(lldb) target create a.out(lldb) target

Page 120: Session 415 - Debugging With LLDB

targetTerminology

(lldb) file a.out(lldb) target create a.out(lldb) targetAvailable completions:! create! delete! list! modules! select! stop-hook! symbols! variable

Page 121: Session 415 - Debugging With LLDB

targetTerminology

Page 122: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls

Page 123: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls(lldb) breakpoint set --name malloc

Page 124: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls(lldb) breakpoint set --name malloc(lldb) process launch -- -lAF /tmp

Page 125: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls(lldb) breakpoint set --name malloc(lldb) process launch -- -lAF /tmp

(lldb) target create /bin/cat

Page 126: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls(lldb) breakpoint set --name malloc(lldb) process launch -- -lAF /tmp

(lldb) target create /bin/cat(lldb) breakpoint set --name free

Page 127: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls(lldb) breakpoint set --name malloc(lldb) process launch -- -lAF /tmp

(lldb) target create /bin/cat(lldb) breakpoint set --name free(lldb) process launch -- /tmp/test.txt

Page 128: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls(lldb) breakpoint set --name malloc(lldb) process launch -- -lAF /tmp

(lldb) target create /bin/cat(lldb) breakpoint set --name free(lldb) process launch -- /tmp/test.txt

(lldb) target list Current targets: target #0: /bin/ls (arch=x86_64,pid=18879,state=stopped* target #1: /bin/cat (arch=x86_64,pid=18885,state=stoppe

Page 129: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls(lldb) breakpoint set --name malloc(lldb) process launch -- -lAF /tmp

(lldb) target create /bin/cat(lldb) breakpoint set --name free(lldb) process launch -- /tmp/test.txt

(lldb) target list Current targets: target #0: /bin/ls (arch=x86_64,pid=18879,state=stopped* target #1: /bin/cat (arch=x86_64,pid=18885,state=stoppe(lldb) target select 0

Page 130: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls(lldb) breakpoint set --name malloc(lldb) process launch -- -lAF /tmp

(lldb) target create /bin/cat(lldb) breakpoint set --name free(lldb) process launch -- /tmp/test.txt

(lldb) target list Current targets: target #0: /bin/ls (arch=x86_64,pid=18879,state=stopped* target #1: /bin/cat (arch=x86_64,pid=18885,state=stoppe(lldb) target select 0(lldb) thread backtrace

Page 131: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls(lldb) breakpoint set --name malloc(lldb) process launch -- -lAF /tmp

(lldb) target create /bin/cat(lldb) breakpoint set --name free(lldb) process launch -- /tmp/test.txt

(lldb) target list Current targets: target #0: /bin/ls (arch=x86_64,pid=18879,state=stopped* target #1: /bin/cat (arch=x86_64,pid=18885,state=stoppe(lldb) target select 0(lldb) thread backtrace(lldb) target select 1

Page 132: Session 415 - Debugging With LLDB

targetTerminology

(lldb) target create /bin/ls(lldb) breakpoint set --name malloc(lldb) process launch -- -lAF /tmp

(lldb) target create /bin/cat(lldb) breakpoint set --name free(lldb) process launch -- /tmp/test.txt

(lldb) target list Current targets: target #0: /bin/ls (arch=x86_64,pid=18879,state=stopped* target #1: /bin/cat (arch=x86_64,pid=18885,state=stoppe(lldb) target select 0(lldb) thread backtrace(lldb) target select 1(lldb) thread backtrace

Page 133: Session 415 - Debugging With LLDB

GDBMemory Usage

LLDB GDB 2GDB 2

/bin/ls

libSystem.B.dylib

dyld

libstdc++.6.dylib

libcache.dylib

libsystem_kernel.dylib

libxpc.dylib

/bin/cat

libSystem.B.dylib

dyld

libstdc++.6.dylib

libcache.dylib

libsystem_kernel.dylib

libxpc.dylib

LLDB

Page 134: Session 415 - Debugging With LLDB

GDBLLDBMemory Usage

LLDB GDB 2GDB 1

/bin/ls

libSystem.B.dylib

dyld

libstdc++.6.dylib

libcache.dylib

libsystem_kernel.dylib

libxpc.dylib

/bin/cat

libSystem.B.dylib

dyld

libstdc++.6.dylib

libcache.dylib

libsystem_kernel.dylib

libxpc.dylib

Page 135: Session 415 - Debugging With LLDB

processTerminology

Page 136: Session 415 - Debugging With LLDB

processTerminology

(lldb) run <arg1> <arg2> ...

Page 137: Session 415 - Debugging With LLDB

processTerminology

(lldb) run <arg1> <arg2> ...(lldb) process launch -- <arg1> <arg2> ...

Page 138: Session 415 - Debugging With LLDB

processTerminology

(lldb) run <arg1> <arg2> ...(lldb) process launch -- <arg1> <arg2> ...

Page 139: Session 415 - Debugging With LLDB

processTerminology

(lldb) run <arg1> <arg2> ...(lldb) process launch -- <arg1> <arg2> ...

Page 140: Session 415 - Debugging With LLDB

processTerminology

(lldb) run <arg1> <arg2> ...(lldb) process launch -- <arg1> <arg2> ...(lldb) process

Page 141: Session 415 - Debugging With LLDB

processTerminology

(lldb) run <arg1> <arg2> ...(lldb) process launch -- <arg1> <arg2> ...(lldb) processAvailable completions:! attach! connect! continue! detach! handle! interrupt! kill

! launch! load

! signal! status! unload

Page 142: Session 415 - Debugging With LLDB

processTerminology

Page 143: Session 415 - Debugging With LLDB

processTerminology

(lldb) process attach --pid 123

Page 144: Session 415 - Debugging With LLDB

processTerminology

(lldb) process attach --pid 123(lldb) process attach --name Safari

Page 145: Session 415 - Debugging With LLDB

processTerminology

(lldb) process attach --pid 123(lldb) process attach --name Safari(lldb) target create /Applications/Safari.app

Page 146: Session 415 - Debugging With LLDB

processTerminology

(lldb) process attach --pid 123(lldb) process attach --name Safari(lldb) target create /Applications/Safari.app(lldb) process attach

Page 147: Session 415 - Debugging With LLDB

processTerminology

(lldb) process attach --pid 123(lldb) process attach --name Safari(lldb) target create /Applications/Safari.app(lldb) process attach(lldb) target create com.apple.my_xpc_service

Page 148: Session 415 - Debugging With LLDB

processTerminology

(lldb) process attach --pid 123(lldb) process attach --name Safari(lldb) target create /Applications/Safari.app(lldb) process attach(lldb) target create com.apple.my_xpc_service(lldb) process attach --waitfor

Page 149: Session 415 - Debugging With LLDB

processTerminology

(lldb) process attach --pid 123(lldb) process attach --name Safari(lldb) target create /Applications/Safari.app(lldb) process attach(lldb) target create com.apple.my_xpc_service(lldb) process attach --waitfor(lldb) process continue

Page 150: Session 415 - Debugging With LLDB

processTerminology

(lldb) process attach --pid 123(lldb) process attach --name Safari(lldb) target create /Applications/Safari.app(lldb) process attach(lldb) target create com.apple.my_xpc_service(lldb) process attach --waitfor(lldb) process continue(lldb) continue

Page 151: Session 415 - Debugging With LLDB

processTerminology

(lldb) process attach --pid 123(lldb) process attach --name Safari(lldb) target create /Applications/Safari.app(lldb) process attach(lldb) target create com.apple.my_xpc_service(lldb) process attach --waitfor(lldb) process continue(lldb) continue(lldb) c

Page 152: Session 415 - Debugging With LLDB

processTerminology

(lldb) process attach --pid 123(lldb) process attach --name Safari(lldb) target create /Applications/Safari.app(lldb) process attach(lldb) target create com.apple.my_xpc_service(lldb) process attach --waitfor(lldb) process continue(lldb) continue(lldb) c^C

Page 153: Session 415 - Debugging With LLDB

threadTerminology

Page 154: Session 415 - Debugging With LLDB

threadTerminology

(lldb) thread

Page 155: Session 415 - Debugging With LLDB

threadTerminology

(lldb) threadAvailable completions:! backtrace! continue! list! select! step-in! step-inst! step-inst-over! step-out! step-over! until

Page 156: Session 415 - Debugging With LLDB

threadTerminology

(lldb) threadAvailable completions:! backtrace! continue! list! select! step-in! step-inst! step-inst-over! step-out! step-over! until(lldb) thread list

Page 157: Session 415 - Debugging With LLDB

threadTerminology

(lldb) threadAvailable completions:! backtrace! continue! list! select! step-in! step-inst! step-inst-over! step-out! step-over! until(lldb) thread list(lldb) thread select 12

Page 158: Session 415 - Debugging With LLDB

threadTerminology

(lldb) threadAvailable completions:! backtrace! continue! list! select! step-in! step-inst! step-inst-over! step-out! step-over! until(lldb) thread list(lldb) thread select 12(lldb) thread backtrace

Page 159: Session 415 - Debugging With LLDB

threadTerminology

(lldb) threadAvailable completions:! backtrace! continue! list! select! step-in! step-inst! step-inst-over! step-out! step-over! until(lldb) thread list(lldb) thread select 12(lldb) thread backtrace(lldb) bt

Page 160: Session 415 - Debugging With LLDB

threadTerminology

(lldb) threadAvailable completions:! backtrace! continue! list! select! step-in! step-inst! step-inst-over! step-out! step-over! until(lldb) thread list(lldb) thread select 12(lldb) thread backtrace(lldb) bt(lldb) bt all

Page 161: Session 415 - Debugging With LLDB

frameTerminology

Page 162: Session 415 - Debugging With LLDB

frameTerminology

(lldb) frame

Page 163: Session 415 - Debugging With LLDB

frameTerminology

(lldb) frameAvailable completions:! info! select! variable

Page 164: Session 415 - Debugging With LLDB

frameTerminology

(lldb) frameAvailable completions:! info! select! variable(lldb) frame select 12

Page 165: Session 415 - Debugging With LLDB

frameTerminology

(lldb) frameAvailable completions:! info! select! variable(lldb) frame select 12(lldb) f 12

Page 166: Session 415 - Debugging With LLDB

frameTerminology

(lldb) frameAvailable completions:! info! select! variable(lldb) frame select 12(lldb) f 12(lldb) up

Page 167: Session 415 - Debugging With LLDB

frameTerminology

(lldb) frameAvailable completions:! info! select! variable(lldb) frame select 12(lldb) f 12(lldb) up(lldb) down

Page 168: Session 415 - Debugging With LLDB

frameTerminology

(lldb) frameAvailable completions:! info! select! variable(lldb) frame select 12(lldb) f 12(lldb) up(lldb) down(lldb) frame variable

Page 169: Session 415 - Debugging With LLDB

frameTerminology

(lldb) frameAvailable completions:! info! select! variable(lldb) frame select 12(lldb) f 12(lldb) up(lldb) down(lldb) frame variable(gdb) info locals

Page 170: Session 415 - Debugging With LLDB

frameTerminology

(lldb) frameAvailable completions:! info! select! variable(lldb) frame select 12(lldb) f 12(lldb) up(lldb) down(lldb) frame variable(gdb) info locals(gdb) info args

Page 171: Session 415 - Debugging With LLDB

modulesTerminology

Page 172: Session 415 - Debugging With LLDB

modulesTerminology

(lldb) target modules list

Page 173: Session 415 - Debugging With LLDB

modulesTerminology

(lldb) target modules list(gdb) info shared

Page 174: Session 415 - Debugging With LLDB

modulesTerminology

(lldb) target modules list(gdb) info shared(lldb) target modules list [file1 ...]

Page 175: Session 415 - Debugging With LLDB

modulesTerminology

(lldb) target modules list(gdb) info shared(lldb) target modules list [file1 ...](lldb) target modules dump symtab [file1 ...]

Page 176: Session 415 - Debugging With LLDB

modulesTerminology

(lldb) target modules list(gdb) info shared(lldb) target modules list [file1 ...](lldb) target modules dump symtab [file1 ...](lldb) target modules dump sections [file1 ...]

Page 177: Session 415 - Debugging With LLDB

modulesTerminology

(lldb) target modules list(gdb) info shared(lldb) target modules list [file1 ...](lldb) target modules dump symtab [file1 ...](lldb) target modules dump sections [file1 ...](lldb) target modules lookup --address <address>

Page 178: Session 415 - Debugging With LLDB

modulesTerminology

(lldb) target modules list(gdb) info shared(lldb) target modules list [file1 ...](lldb) target modules dump symtab [file1 ...](lldb) target modules dump sections [file1 ...](lldb) target modules lookup --address <address>(lldb) target modules lookup --type <name>

Page 179: Session 415 - Debugging With LLDB

syntax: help [command]Help

Page 180: Session 415 - Debugging With LLDB

syntax: help [command]Help

(lldb) help memory read

Page 181: Session 415 - Debugging With LLDB

syntax: help [command]Help

(lldb) help memory read Read from the memory of the process being debugged.

Syntax: memory read <cmd-options> <start-address> [<end-address>]

Command Options Usage: memory read [-A] [-f <format>] [-c <count>] [-G <gdb-format>] [-s <byte-siz memory read [-bA] [-f <format>] [-c <count>] [-s <byte-size>] [-o <path>] < memory read [-AFLORT] -t <none> [-f <format>] [-c <count>] [-G <gdb-format>

-A ( --append-outfile ) Append to the the file specified with '--outfile <path>'.

-D <count> ( --depth <count> ) Set the max recurse depth when dumping aggregate types (default

-F ( --flat ) Display results in a flat format that uses expression paths for

-f <format> ( --format <format> ) Specify a format to be used for display.

-L ( --location ) Show variable location information.

Page 182: Session 415 - Debugging With LLDB

(lldb) help memory read Read from the memory of the process being debugged.

Syntax: memory read <cmd-options> <start-address> [<end-address>]

Command Options Usage: memory read [-A] [-f <format>] [-c <count>] [-G <gdb-format>] [-s <byte-siz memory read [-bA] [-f <format>] [-c <count>] [-s <byte-size>] [-o <path>] < memory read [-AFLORT] -t <none> [-f <format>] [-c <count>] [-G <gdb-format>

-A ( --append-outfile ) Append to the the file specified with '--outfile <path>'.

-D <count> ( --depth <count> ) Set the max recurse depth when dumping aggregate types (default

-F ( --flat ) Display results in a flat format that uses expression paths for

-f <format> ( --format <format> ) Specify a format to be used for display.

-L ( --location ) Show variable location information.

Page 183: Session 415 - Debugging With LLDB

(lldb) help memory read Read from the memory of the process being debugged.

Syntax: memory read <cmd-options> <start-address> [<end-address>]

Command Options Usage: memory read [-A] [-f <format>] [-c <count>] [-G <gdb-format>] [-s <byte-siz memory read [-bA] [-f <format>] [-c <count>] [-s <byte-size>] [-o <path>] < memory read [-AFLORT] -t <none> [-f <format>] [-c <count>] [-G <gdb-format>

-A ( --append-outfile ) Append to the the file specified with '--outfile <path>'.

-D <count> ( --depth <count> ) Set the max recurse depth when dumping aggregate types (default

-F ( --flat ) Display results in a flat format that uses expression paths for

-f <format> ( --format <format> ) Specify a format to be used for display.

-L ( --location ) Show variable location information.

Page 184: Session 415 - Debugging With LLDB

syntax: help <option-type>Help

Page 185: Session 415 - Debugging With LLDB

syntax: help <option-type>Help

(lldb) help <format>

Page 186: Session 415 - Debugging With LLDB

syntax: help <option-type>Help

(lldb) help <format><format> -- One of the format names (or one-character names) that can be used to show a variable's value: "default" 'B' or "boolean" 'b' or "binary" 'y' or "bytes" 'Y' or "bytes with ASCII" 'c' or "character" 'C' or "printable character" 'F' or "complex float" 's' or "c-string" 'd' or "decimal" 'E' or "enumeration" 'x' or "hex" 'f' or "float" 'o' or "octal"

Page 187: Session 415 - Debugging With LLDB

syntax: apropos <keyword>Apropos

Page 188: Session 415 - Debugging With LLDB

syntax: apropos <keyword>Apropos

(lldb) apropos thread

Page 189: Session 415 - Debugging With LLDB

syntax: apropos <keyword>Apropos

(lldb) apropos threadThe following commands may relate to 'thread':breakpoint command add -- Add a set of commands to a breakpoint, to be executbreakpoint modify -- Modify the options on a breakpoint or set of breakpbreakpoint set -- Sets a breakpoint or set of breakpoints in the execframe -- A set of commands for operating on the current threframe info -- List information about the currently selected frame frame select -- Select a frame by index from within the current thrlog enable -- Enable logging for a single log channel.process continue -- Continue execution of all threads in the current prregister -- A set of commands to access thread registers.target stop-hook add -- Add a hook to be executed when the target stops.thread -- A set of commands for operating on one or more threthread backtrace -- Show the stack for one or more threads. If no threthread continue -- Continue execution of one or more threads in an actthread list -- Show a summary of all current threads in a process.thread select -- Select a thread as the currently active thread.

Page 190: Session 415 - Debugging With LLDB

LLDBLLDB in Depth

• Getting started• Terminology• Customizing commands• Launching programs• Debug session

Page 191: Session 415 - Debugging With LLDB

LLDBLLDB in Depth

• Getting started• Terminology• Customizing commands• Launching programs• Debug session

Page 192: Session 415 - Debugging With LLDB

Customizing commandsLLDB in Depth

• Simple aliases• Regular expression aliases• User-defined

Page 193: Session 415 - Debugging With LLDB

Aliasing

Page 194: Session 415 - Debugging With LLDB

Aliasing

(lldb) command alias <name> <command> [<arg1> <arg2> ...]

Page 195: Session 415 - Debugging With LLDB

Aliasing

(lldb) command alias <name> <command> [<arg1> <arg2> ...](lldb) command alias up frame select --relative=1

Page 196: Session 415 - Debugging With LLDB

Aliasing

(lldb) command alias <name> <command> [<arg1> <arg2> ...](lldb) command alias up frame select --relative=1(lldb) command alias down frame select -r-1

Page 197: Session 415 - Debugging With LLDB

Aliasing

(lldb) command alias <name> <command> [<arg1> <arg2> ...](lldb) command alias up frame select --relative=1(lldb) command alias down frame select -r-1(lldb) command alias disasm-range

Page 198: Session 415 - Debugging With LLDB

Aliasing

(lldb) command alias <name> <command> [<arg1> <arg2> ...](lldb) command alias up frame select --relative=1(lldb) command alias down frame select -r-1(lldb) command alias disasm-range disassemble

Page 199: Session 415 - Debugging With LLDB

Aliasing

(lldb) command alias <name> <command> [<arg1> <arg2> ...](lldb) command alias up frame select --relative=1(lldb) command alias down frame select -r-1(lldb) command alias disasm-range disassemble --start-address %1

Page 200: Session 415 - Debugging With LLDB

Aliasing

(lldb) command alias <name> <command> [<arg1> <arg2> ...](lldb) command alias up frame select --relative=1(lldb) command alias down frame select -r-1(lldb) command alias disasm-range disassemble --start-address %1 --end-address %2

Page 201: Session 415 - Debugging With LLDB

Power user featureRegular Expression Aliases

Page 202: Session 415 - Debugging With LLDB

Power user featureRegular Expression Aliases

• Specify a command alias name

Page 203: Session 415 - Debugging With LLDB

Power user featureRegular Expression Aliases

• Specify a command alias name• One or more regular expressions with substitutions

s/<regex>/<subst>/

Page 204: Session 415 - Debugging With LLDB

Power user featureRegular Expression Aliases

• Specify a command alias name• One or more regular expressions with substitutions

s/<regex>/<subst>/

• When the alias is used

Page 205: Session 415 - Debugging With LLDB

Power user featureRegular Expression Aliases

• Specify a command alias name• One or more regular expressions with substitutions

s/<regex>/<subst>/

• When the alias is used■ Arguments following alias are matched against regular expressions

Page 206: Session 415 - Debugging With LLDB

Power user featureRegular Expression Aliases

• Specify a command alias name• One or more regular expressions with substitutions

s/<regex>/<subst>/

• When the alias is used■ Arguments following alias are matched against regular expressions■ First regular expression to match wins

Page 207: Session 415 - Debugging With LLDB

Power user featureRegular Expression Aliases

• Specify a command alias name• One or more regular expressions with substitutions

s/<regex>/<subst>/

• When the alias is used■ Arguments following alias are matched against regular expressions■ First regular expression to match wins

■ Substitutions are performed

Page 208: Session 415 - Debugging With LLDB

Power user featureRegular Expression Aliases

• Specify a command alias name• One or more regular expressions with substitutions

s/<regex>/<subst>/

• When the alias is used■ Arguments following alias are matched against regular expressions■ First regular expression to match wins

■ Substitutions are performed■ New command is executed

Page 209: Session 415 - Debugging With LLDB

syntax: command regex <name> [s/<regex>/<subst>/ ...]Regular Expression Aliases

Page 210: Session 415 - Debugging With LLDB

syntax: command regex <name> [s/<regex>/<subst>/ ...]Regular Expression Aliases

(lldb) command regex f

Page 211: Session 415 - Debugging With LLDB

syntax: command regex <name> [s/<regex>/<subst>/ ...]Regular Expression Aliases

(lldb) command regex f “s/^([0-9]+)$/frame select %1/”

Page 212: Session 415 - Debugging With LLDB

syntax: command regex <name> [s/<regex>/<subst>/ ...]Regular Expression Aliases

(lldb) command regex f “s/^([0-9]+)$/frame select %1/” “s/^([+-][0-9]+)$/frame select --relative=%1/”

Page 213: Session 415 - Debugging With LLDB

syntax: command regex <name> [s/<regex>/<subst>/ ...]Regular Expression Aliases

(lldb) command regex f “s/^([0-9]+)$/frame select %1/” “s/^([+-][0-9]+)$/frame select --relative=%1/” “s/^(.*)$/frame variable %1/”

Page 214: Session 415 - Debugging With LLDB

syntax: command regex <name> [s/<regex>/<subst>/ ...]Regular Expression Aliases

(lldb) command regex f “s/^([0-9]+)$/frame select %1/” “s/^([+-][0-9]+)$/frame select --relative=%1/” “s/^(.*)$/frame variable %1/”(lldb) f 12frame select 12

Page 215: Session 415 - Debugging With LLDB

syntax: command regex <name> [s/<regex>/<subst>/ ...]Regular Expression Aliases

(lldb) command regex f “s/^([0-9]+)$/frame select %1/” “s/^([+-][0-9]+)$/frame select --relative=%1/” “s/^(.*)$/frame variable %1/”(lldb) f 12frame select 12(lldb) f +2frame select --relative=+2

Page 216: Session 415 - Debugging With LLDB

syntax: command regex <name> [s/<regex>/<subst>/ ...]Regular Expression Aliases

(lldb) command regex f “s/^([0-9]+)$/frame select %1/” “s/^([+-][0-9]+)$/frame select --relative=%1/” “s/^(.*)$/frame variable %1/”(lldb) f 12frame select 12(lldb) f +2frame select --relative=+2(lldb) f -1frame select --relative=-1

Page 217: Session 415 - Debugging With LLDB

syntax: command regex <name> [s/<regex>/<subst>/ ...]Regular Expression Aliases

(lldb) command regex f “s/^([0-9]+)$/frame select %1/” “s/^([+-][0-9]+)$/frame select --relative=%1/” “s/^(.*)$/frame variable %1/”(lldb) f 12frame select 12(lldb) f +2frame select --relative=+2(lldb) f -1frame select --relative=-1(lldb) fframe variable

Page 218: Session 415 - Debugging With LLDB

syntax: command regex <name> [s/<regex>/<subst>/ ...]Regular Expression Aliases

(lldb) command regex f “s/^([0-9]+)$/frame select %1/” “s/^([+-][0-9]+)$/frame select --relative=%1/” “s/^(.*)$/frame variable %1/”(lldb) f 12frame select 12(lldb) f +2frame select --relative=+2(lldb) f -1frame select --relative=-1(lldb) fframe variable(lldb) f argc argvframe variable argc argv

Page 219: Session 415 - Debugging With LLDB

User-Defined Commands

Page 220: Session 415 - Debugging With LLDB

User-Defined Commands

• Make it yourself with Python

Page 221: Session 415 - Debugging With LLDB

User-Defined Commands

• Make it yourself with Python• Write Python module with a command function

def <function>(debugger, command, result, dict)

Page 222: Session 415 - Debugging With LLDB

User-Defined Commands

• Make it yourself with Python• Write Python module with a command function

def <function>(debugger, command, result, dict)

• Import module into LLDB

Page 223: Session 415 - Debugging With LLDB

User-Defined Commands

• Make it yourself with Python• Write Python module with a command function

def <function>(debugger, command, result, dict)

• Import module into LLDB• Bind Python function to command

Page 224: Session 415 - Debugging With LLDB

Add “ls” commandPython Command

Page 225: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py

Add “ls” commandPython Command

Page 226: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/python

Add “ls” commandPython Command

Page 227: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldb

Add “ls” commandPython Command

Page 228: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commands

Add “ls” commandPython Command

Page 229: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict):

Add “ls” commandPython Command

Page 230: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command

Add “ls” commandPython Command

Page 231: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd)

Add “ls” commandPython Command

Page 232: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)

Add “ls” commandPython Command

Page 233: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)% xcrun lldb

Add “ls” commandPython Command

Page 234: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)% xcrun lldb(lldb) command script import /tmp/lldbshell.py

Add “ls” commandPython Command

Page 235: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)% xcrun lldb(lldb) command script import /tmp/lldbshell.py(lldb) command script add

Add “ls” commandPython Command

Page 236: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)% xcrun lldb(lldb) command script import /tmp/lldbshell.py(lldb) command script add --function lldbshell.ls_cmd

Add “ls” commandPython Command

Page 237: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)% xcrun lldb(lldb) command script import /tmp/lldbshell.py(lldb) command script add --function lldbshell.ls_cmd

Add “ls” commandPython Command

Page 238: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)% xcrun lldb(lldb) command script import /tmp/lldbshell.py(lldb) command script add --function lldbshell.ls_cmd

Add “ls” commandPython Command

Page 239: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)% xcrun lldb(lldb) command script import /tmp/lldbshell.py(lldb) command script add --function lldbshell.ls_cmd

Add “ls” commandPython Command

Page 240: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)% xcrun lldb(lldb) command script import /tmp/lldbshell.py(lldb) command script add --function lldbshell.ls_cmd ls

Add “ls” commandPython Command

Page 241: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)% xcrun lldb(lldb) command script import /tmp/lldbshell.py(lldb) command script add --function lldbshell.ls_cmd ls

Add “ls” commandPython Command

Page 242: Session 415 - Debugging With LLDB

% cat /tmp/lldbshell.py#!/usr/bin/pythonimport lldbimport commandsdef ls_cmd(debugger, command, result, dict): shell_cmd = '/bin/ls %s' % command shell_result = commands.getoutput(shell_cmd) result.PutCString(shell_result)% xcrun lldb(lldb) command script import /tmp/lldbshell.py(lldb) command script add --function lldbshell.ls_cmd ls

Add “ls” commandPython Command

Page 243: Session 415 - Debugging With LLDB

Using New Python Command

Page 244: Session 415 - Debugging With LLDB

Using New Python Command

(lldb) ls -lAF /tmp/

Page 245: Session 415 - Debugging With LLDB

Using New Python Command

(lldb) ls -lAF /tmp/total 0drwx------ 3 root wheel 102 May 11 09:40 launch-drwx------ 3 root wheel 102 May 22 15:46 launch-drwx------ 3 root wheel 102 May 13 14:34 launch-drwx------ 3 root wheel 102 May 21 19:45 launch-drwx------ 3 local wheel 102 May 21 19:31 launch-drwx------ 3 local wheel 102 May 20 20:15 launch-drwx------ 3 local wheel 102 May 11 19:37 launch-drwx------ 3 root wheel 102 May 20 11:24 launch-drwx------ 3 root wheel 102 May 11 09:40 launch-drwx------ 3 root wheel 102 May 13 14:34 launch-drwx------ 3 root wheel 102 May 12 19:17 launch-drwx------ 3 local wheel 102 May 21 19:31 launch-drwx------ 3 local wheel 102 May 22 14:03 launch-drwx------ 3 local wheel 102 May 20 10:53 launch-drwx------ 3 root wheel 102 May 13 19:26 launch-

Page 246: Session 415 - Debugging With LLDB

Python Reference

Page 247: Session 415 - Debugging With LLDB

Python Reference

Page 248: Session 415 - Debugging With LLDB

Python Reference

Page 249: Session 415 - Debugging With LLDB

~/.lldbinitInitialization Files

Page 250: Session 415 - Debugging With LLDB

~/.lldbinitInitialization Files

• Add commands to be executed just after LLDB launches

Page 251: Session 415 - Debugging With LLDB

~/.lldbinitInitialization Files

• Add commands to be executed just after LLDB launches• Common uses include

■ Aliases■ Default settings■ Type formatting■ Importing Python modules

Page 252: Session 415 - Debugging With LLDB

~/.lldbinitInitialization Files

• Add commands to be executed just after LLDB launches• Common uses include

■ Aliases■ Default settings■ Type formatting■ Importing Python modules■ Bind Python commands

Page 253: Session 415 - Debugging With LLDB

.lldbinit with “Xcode”Initialization Files Rules

Page 254: Session 415 - Debugging With LLDB

~/.lldbinit-Xcode

.lldbinit with “Xcode”Initialization Files Rules

Default initialization file1

Page 255: Session 415 - Debugging With LLDB

.lldbinit with “Xcode”Initialization Files Rules

~/.lldbinit

Default initialization file1

Page 256: Session 415 - Debugging With LLDB

.lldbinit with “Xcode”Initialization Files Rules

~/.lldbinit

Default initialization file1

Load the executable2

Page 257: Session 415 - Debugging With LLDB

.lldbinit with “lldb”Initialization Files Rules

Page 258: Session 415 - Debugging With LLDB

.lldbinit with “lldb”Initialization Files Rules

% cd /tmp

Page 259: Session 415 - Debugging With LLDB

.lldbinit with “lldb”Initialization Files Rules

% cd /tmp% xcrun lldb /bin/ls

Page 260: Session 415 - Debugging With LLDB

.lldbinit with “lldb”Initialization Files Rules

% cd /tmp% xcrun lldb /bin/ls(lldb)

~/.lldbinit-lldbDefault initialization file1

Page 261: Session 415 - Debugging With LLDB

.lldbinit with “lldb”Initialization Files Rules

% cd /tmp% xcrun lldb /bin/ls(lldb)

~/.lldbinitDefault initialization file1

Page 262: Session 415 - Debugging With LLDB

.lldbinit with “lldb”Initialization Files Rules

% cd /tmp% xcrun lldb /bin/ls(lldb)

~/.lldbinitDefault initialization file1

Page 263: Session 415 - Debugging With LLDB

.lldbinit with “lldb”Initialization Files Rules

% cd /tmp% xcrun lldb /bin/ls(lldb)

~/.lldbinitDefault initialization file1

Load the file “/bin/ls”2

Page 264: Session 415 - Debugging With LLDB

.lldbinit with “lldb”Initialization Files Rules

% cd /tmp% xcrun lldb /bin/ls(lldb)

~/.lldbinitDefault initialization file1

Load the file “/bin/ls”2

Current working directory3

Page 265: Session 415 - Debugging With LLDB

.lldbinit with “lldb”Initialization Files Rules

% cd /tmp% xcrun lldb /bin/ls(lldb)

/tmp/.lldbinit

~/.lldbinitDefault initialization file1

Load the file “/bin/ls”2

Current working directory3

Page 266: Session 415 - Debugging With LLDB

LLDBLLDB in Depth

• Getting started• Terminology• Customizing commands• Launching programs• Debug session

Page 267: Session 415 - Debugging With LLDB

LLDBLLDB in Depth

• Getting started• Terminology• Customizing commands• Launching programs• Debug session

Page 268: Session 415 - Debugging With LLDB

ArgumentsLaunching Programs

Page 269: Session 415 - Debugging With LLDB

ArgumentsLaunching Programs

% xcrun lldb print-args 1 2 3

Page 270: Session 415 - Debugging With LLDB

ArgumentsLaunching Programs

% xcrun lldb print-args 1 2 3(lldb) run

Page 271: Session 415 - Debugging With LLDB

ArgumentsLaunching Programs

% xcrun lldb print-args 1 2 3(lldb) runargv[ 0] = '/tmp/print-args'argv[ 1] = '1'argv[ 2] = '2'argv[ 3] = '3'

Page 272: Session 415 - Debugging With LLDB

ArgumentsLaunching Programs

% xcrun lldb print-args 1 2 3(lldb) runargv[ 0] = '/tmp/print-args'argv[ 1] = '1'argv[ 2] = '2'argv[ 3] = '3'(lldb) run 4 5 6

Page 273: Session 415 - Debugging With LLDB

ArgumentsLaunching Programs

% xcrun lldb print-args 1 2 3(lldb) runargv[ 0] = '/tmp/print-args'argv[ 1] = '1'argv[ 2] = '2'argv[ 3] = '3'(lldb) run 4 5 6argv[ 0] = '/tmp/print-args'argv[ 1] = '4'argv[ 2] = '5'argv[ 3] = '6'

Page 274: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

Page 275: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

% export MallocStackLogging=1

Page 276: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

% export MallocStackLogging=1% xcrun lldb /bin/cat

Page 277: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

% export MallocStackLogging=1% xcrun lldb /bin/cat(lldb) process launch

Page 278: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

% export MallocStackLogging=1% xcrun lldb /bin/cat(lldb) process launch^C

Page 279: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

% export MallocStackLogging=1% xcrun lldb /bin/cat(lldb) process launch^C(lldb) p (char *)getenv("MallocStackLogging")(const char *) $2 = 0x00007fff5fbffa21 "1"

Page 280: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

Page 281: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

% xcrun lldb /bin/cat

Page 282: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

% xcrun lldb /bin/cat(lldb) process launch --environment MallocStackLogging=1

Page 283: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

% xcrun lldb /bin/cat(lldb) process launch --environment MallocStackLogging=1(lldb) process launch -v MallocStackLogging=1

Page 284: Session 415 - Debugging With LLDB

Setting environment variablesLaunching Programs

% xcrun lldb /bin/cat(lldb) process launch --environment MallocStackLogging=1(lldb) process launch -v MallocStackLogging=1 -v MallocStackLoggingNoCompact=2

Page 285: Session 415 - Debugging With LLDB

Launch in terminalLaunching Programs

Page 286: Session 415 - Debugging With LLDB

Launch in terminalLaunching Programs

(lldb) target create /bin/cat

Page 287: Session 415 - Debugging With LLDB

Launch in terminalLaunching Programs

(lldb) target create /bin/cat(lldb) process launch --tty

Page 288: Session 415 - Debugging With LLDB

Launch in terminalLaunching Programs

(lldb) target create /bin/cat(lldb) process launch --tty

Launching: ‘/bin/cat’Working directory: ‘/Volume/work/gcclayton’1 arguments:argv[0] = ‘bin/cat’

Page 289: Session 415 - Debugging With LLDB

LLDBLLDB in Depth

• Getting started• Terminology• Customizing commands• Launching programs• Debug session

Page 290: Session 415 - Debugging With LLDB

LLDBLLDB in Depth

• Getting started• Terminology• Customizing commands• Launching programs• Debug session

Page 291: Session 415 - Debugging With LLDB

Example classDebug Session

class PointerArray { protected: uintptr_t * m_pointers; size_t m_size; };

Page 292: Session 415 - Debugging With LLDB

Bug detectedDebug Session

Page 293: Session 415 - Debugging With LLDB

Bug detectedDebug Session

Page 294: Session 415 - Debugging With LLDB

Bug detectedDebug Session

Page 295: Session 415 - Debugging With LLDB

Bug detectedDebug Session

Page 296: Session 415 - Debugging With LLDB

Bug detectedDebug Session

Page 297: Session 415 - Debugging With LLDB

Bug detectedDebug Session

Page 298: Session 415 - Debugging With LLDB

Command lineFormatting Variable Values

Page 299: Session 415 - Debugging With LLDB

Command lineFormatting Variable Values

(lldb) frame variable --format hex this->m_size

Page 300: Session 415 - Debugging With LLDB

Command lineFormatting Variable Values

(lldb) frame variable --format hex this->m_size(size_t) this->m_size = 0xffffffffffffffff

Page 301: Session 415 - Debugging With LLDB

Wrong default formatsDebug Session

Page 302: Session 415 - Debugging With LLDB

Wrong default formatsDebug Session

Page 303: Session 415 - Debugging With LLDB

Wrong default formatsDebug Session

Page 304: Session 415 - Debugging With LLDB

Setting default formatsDebug Session

Page 305: Session 415 - Debugging With LLDB

Setting default formatsDebug Session

(lldb) type format add

Page 306: Session 415 - Debugging With LLDB

Setting default formatsDebug Session

(lldb) type format add --format hex

Page 307: Session 415 - Debugging With LLDB

Setting default formatsDebug Session

(lldb) type format add --format hex uintptr_t intptr_t off_t

Page 308: Session 415 - Debugging With LLDB

Setting default formatsDebug Session

(lldb) type format add --format hex uintptr_t intptr_t off_t(lldb) print ptr(uintptr_t) ptr = 0x0000000100000000

Page 309: Session 415 - Debugging With LLDB

Setting default formatsDebug Session

(lldb) type format add --format hex uintptr_t intptr_t off_t(lldb) print ptr(uintptr_t) ptr = 0x0000000100000000(lldb) print ptrs(uintptr_t [2]) ptrs = { [0] = 0x0000000000001111 [1] = 0x0000000000002222}

Page 310: Session 415 - Debugging With LLDB

Corrected default formatsDebug Session

Page 311: Session 415 - Debugging With LLDB

Corrected default formatsDebug Session

Page 312: Session 415 - Debugging With LLDB

Adding type summariesDebug Session

Page 313: Session 415 - Debugging With LLDB

Adding type summariesDebug Session

Page 314: Session 415 - Debugging With LLDB

Adding type summariesDebug Session

Page 315: Session 415 - Debugging With LLDB

type summary addDebug Session

Page 316: Session 415 - Debugging With LLDB

type summary addDebug Session

(lldb) type summary add

Page 317: Session 415 - Debugging With LLDB

type summary addDebug Session

(lldb) type summary add -s "size=${var.m_size} ${var.m_pointers}"

Page 318: Session 415 - Debugging With LLDB

type summary addDebug Session

(lldb) type summary add -s "size=${var.m_size} ${var.m_pointers}" PointerArray

Page 319: Session 415 - Debugging With LLDB

type summary addDebug Session

(lldb) type summary add -s "size=${var.m_size} ${var.m_pointers}" PointerArray(lldb) frame variable pointer_array(PointerArray) pointer_array = size=1 0x100100990

Page 320: Session 415 - Debugging With LLDB

Summary string syntaxType Summary Strings

Page 321: Session 415 - Debugging With LLDB

Summary string syntaxType Summary Strings

• String can contain plain text and variables and formats

Page 322: Session 415 - Debugging With LLDB

Summary string syntaxType Summary Strings

• String can contain plain text and variables and formats• Variables references

${var[path][%<format>]}

Page 323: Session 415 - Debugging With LLDB

Summary string syntaxType Summary Strings

• String can contain plain text and variables and formats• Variables references

${var[path][%<format>]}

• Formats characters can be listed with:(lldb) help <format>

Page 324: Session 415 - Debugging With LLDB

Summary string syntaxType Summary Strings

• String can contain plain text and variables and formats• Variables references

${var[path][%<format>]}

• Formats characters can be listed with:(lldb) help <format>

• Example summary strings

Page 325: Session 415 - Debugging With LLDB

Summary string syntaxType Summary Strings

• String can contain plain text and variables and formats• Variables references

${var[path][%<format>]}

• Formats characters can be listed with:(lldb) help <format>

• Example summary strings“natural = ${var}, octal = ${var%o} , hex = ${var%x}”

Page 326: Session 415 - Debugging With LLDB

Summary string syntaxType Summary Strings

• String can contain plain text and variables and formats• Variables references

${var[path][%<format>]}

• Formats characters can be listed with:(lldb) help <format>

• Example summary strings“natural = ${var}, octal = ${var%o} , hex = ${var%x}”“( x = ${var.x}, y = ${var.y} )”

Page 327: Session 415 - Debugging With LLDB

Summary string syntaxType Summary Strings

• String can contain plain text and variables and formats• Variables references

${var[path][%<format>]}

• Formats characters can be listed with:(lldb) help <format>

• Example summary strings“natural = ${var}, octal = ${var%o} , hex = ${var%x}”“( x = ${var.x}, y = ${var.y} )”“string = ${var._M_dataplus._M_p%s}”

Page 328: Session 415 - Debugging With LLDB

Type summaries in XcodeDebug Session

Page 329: Session 415 - Debugging With LLDB

Type summaries in XcodeDebug Session

Page 330: Session 415 - Debugging With LLDB

Type summaries in XcodeDebug Session

Page 331: Session 415 - Debugging With LLDB

Type summaries in XcodeDebug Session

Page 332: Session 415 - Debugging With LLDB

Type summaries in XcodeDebug Session

Page 333: Session 415 - Debugging With LLDB

Type summaries in XcodeDebug Session

Page 334: Session 415 - Debugging With LLDB

Type summaries in XcodeDebug Session

Page 335: Session 415 - Debugging With LLDB

Type summaries in XcodeDebug Session

Page 336: Session 415 - Debugging With LLDB

Type summaries in XcodeDebug Session

Page 337: Session 415 - Debugging With LLDB

Variable Formatting Reference

Page 338: Session 415 - Debugging With LLDB

Variable Formatting Reference

Page 339: Session 415 - Debugging With LLDB

Variable Formatting Reference

Page 340: Session 415 - Debugging With LLDB

ExpressionsDebug Session

Page 341: Session 415 - Debugging With LLDB

ExpressionsDebug Session

{ <expression>

}

(lldb) expression <expression>

Page 342: Session 415 - Debugging With LLDB

What are expressions?Expressions

Page 343: Session 415 - Debugging With LLDB

What are expressions?Expressions

• Expressions evaluate statements as if they were code

Page 344: Session 415 - Debugging With LLDB

What are expressions?Expressions

• Expressions evaluate statements as if they were code• Results are displayed and stored in convenience variables

Page 345: Session 415 - Debugging With LLDB

What are expressions?Expressions

• Expressions evaluate statements as if they were code• Results are displayed and stored in convenience variables• Expressions can do many things

Page 346: Session 415 - Debugging With LLDB

What are expressions?Expressions

• Expressions evaluate statements as if they were code• Results are displayed and stored in convenience variables• Expressions can do many things

■ Arithmetic

Page 347: Session 415 - Debugging With LLDB

What are expressions?Expressions

• Expressions evaluate statements as if they were code• Results are displayed and stored in convenience variables• Expressions can do many things

■ Arithmetic■ Function calls

Page 348: Session 415 - Debugging With LLDB

What are expressions?Expressions

• Expressions evaluate statements as if they were code• Results are displayed and stored in convenience variables• Expressions can do many things

■ Arithmetic■ Function calls■ Casting

Page 349: Session 415 - Debugging With LLDB

What are expressions?Expressions

• Expressions evaluate statements as if they were code• Results are displayed and stored in convenience variables• Expressions can do many things

■ Arithmetic■ Function calls■ Casting■ With LLDB, much more…

Page 350: Session 415 - Debugging With LLDB

Simple expressionDebug Session

{ ptrs[1] != 0x2222

}

(lldb) expression ptrs[1] != 0x2222

Page 351: Session 415 - Debugging With LLDB

Multiple statementsDebug Session

{ ptrs[0] = 0x1234; ptrs[1] = 0x2345;}

(lldb) ptrs[0] = 0x1234; ptrs[1] = 0x2345;<no result>

Page 352: Session 415 - Debugging With LLDB

Expression local variablesDebug Session

{ uintptr_t i = 12; i + ptr}

(lldb) uintptr_t i = 12; i + ptr(float) $1 = 14.2

Page 353: Session 415 - Debugging With LLDB

Expression global variablesDebug Session

{ uintptr_t $last_ptr = ptr

}

(lldb) expression uintptr_t $last_ptr = ptr<no result>

Page 354: Session 415 - Debugging With LLDB

Flow controlDebug Session

{ if ($last_ptr != ptr) printf (“last_ptr: 0x%x”, $last_ptr)}

(lldb) expression if ($last_ptr != ptr) printf (“last_ptr: 0x%x”, $last_ptr)

Page 355: Session 415 - Debugging With LLDB

Stopping in expression codeDebug Session

Page 356: Session 415 - Debugging With LLDB

Stopping in expression codeDebug Session

(lldb) expression --unwind-on-error=0 --

Page 357: Session 415 - Debugging With LLDB

Stopping in expression codeDebug Session

{ while(pointer_array.Size() >= 0) pointer_array.Pop();}

(lldb) expression --unwind-on-error=0 --while(pointer_array.Size() >= 0) pointer_array.Pop()

Page 358: Session 415 - Debugging With LLDB

Define local typesDebug Session

{ struct test { int x; int e[0]; }; sizeof(test)}

(lldb)) expression struct test { int x; int e[0]; }; sizeof(test)

Page 359: Session 415 - Debugging With LLDB

Multiple line expressionsDebug Session

Page 360: Session 415 - Debugging With LLDB

Multiple line expressionsDebug Session

(lldb) expression

Page 361: Session 415 - Debugging With LLDB

Multiple line expressionsDebug Session

(lldb) expressionEnter expressions, then terminate with an empty line to evaluate:

Page 362: Session 415 - Debugging With LLDB

Multiple line expressionsDebug Session

(lldb) expressionEnter expressions, then terminate with an empty line to evaluate:const char *arg;

Page 363: Session 415 - Debugging With LLDB

Multiple line expressionsDebug Session

(lldb) expressionEnter expressions, then terminate with an empty line to evaluate:const char *arg; int i=0;

Page 364: Session 415 - Debugging With LLDB

Multiple line expressionsDebug Session

(lldb) expressionEnter expressions, then terminate with an empty line to evaluate:const char *arg; int i=0;while (arg = argv[i++])

Page 365: Session 415 - Debugging With LLDB

Multiple line expressionsDebug Session

(lldb) expressionEnter expressions, then terminate with an empty line to evaluate:const char *arg; int i=0;while (arg = argv[i++]) (int)puts(arg);

Page 366: Session 415 - Debugging With LLDB

Multiple line expressionsDebug Session

(lldb) expressionEnter expressions, then terminate with an empty line to evaluate:const char *arg; int i=0;while (arg = argv[i++]) (int)puts(arg);i

Page 367: Session 415 - Debugging With LLDB

Multiple line expressionsDebug Session

(lldb) expressionEnter expressions, then terminate with an empty line to evaluate:const char *arg; int i=0;while (arg = argv[i++]) (int)puts(arg);i

/tmp/prints-args456(int) $3 = 4(lldb)

Page 368: Session 415 - Debugging With LLDB

Other debuggersExpressions

(gdb) p sin(2.2 + y)(double) $0 = 0.808496

Page 369: Session 415 - Debugging With LLDB

Other debuggersExpressions

(gdb) p sin(2.2 + y)(double) $0 = 0.808496

2.2 y

+

sin

Page 370: Session 415 - Debugging With LLDB

LLDB with ClangExpressions

(lldb) expression sin(2.2 + y)(double) $0 = 0.808496

Page 371: Session 415 - Debugging With LLDB

LLDB with ClangExpressions

(lldb) expression sin(2.2 + y)(double) $0 = 0.808496

Clang

Page 372: Session 415 - Debugging With LLDB

LLDB with ClangExpressions

(lldb) expression sin(2.2 + y)(double) $0 = 0.808496

sin(2.2 + y)

Clang

AST

Page 373: Session 415 - Debugging With LLDB

LLDB with ClangExpressions

(lldb) expression sin(2.2 + y)(double) $0 = 0.808496

sin(2.2 + y)

Clang

AST

CodeGen

Page 374: Session 415 - Debugging With LLDB

LLDB with ClangExpressions

(lldb) expression sin(2.2 + y)(double) $0 = 0.808496

sin(2.2 + y)

Clang

AST

CodeGen CODE

DATA

Page 375: Session 415 - Debugging With LLDB

LLDB with ClangExpressions

(lldb) expression sin(2.2 + y)(double) $0 = 0.808496

sin(2.2 + y)

Clang

AST

CodeGen CODE

DATA

Program

Page 376: Session 415 - Debugging With LLDB

LLDB with ClangExpressions

(lldb) expression sin(2.2 + y)(double) $0 = 0.808496

sin(2.2 + y)

Clang

AST

CodeGen CODE

DATA

Program

CODE

DATA

Page 377: Session 415 - Debugging With LLDB

Compiler integrationInjecting Checks into Expressions

(lldb) p item->value + [value floatValue]

Page 378: Session 415 - Debugging With LLDB

Compiler integrationInjecting Checks into Expressions

Clang

(lldb) p item->value + [value floatValue]

Page 379: Session 415 - Debugging With LLDB

item->value + [value floatValue]

Compiler integrationInjecting Checks into Expressions

Clang

AST

(lldb) p item->value + [value floatValue]

Page 380: Session 415 - Debugging With LLDB

item->value + [value floatValue]

Compiler integrationInjecting Checks into Expressions

Checks

Clang

AST

(lldb) p item->value + [value floatValue]

Page 381: Session 415 - Debugging With LLDB

item->value + [value floatValue]

Compiler integrationInjecting Checks into Expressions

Checks item->value

Clang

AST

(lldb) p item->value + [value floatValue]

Page 382: Session 415 - Debugging With LLDB

item->value + [value floatValue]

Compiler integrationInjecting Checks into Expressions

Checks ___check_ptr(item)->value

Clang

AST

(lldb) p item->value + [value floatValue]

Page 383: Session 415 - Debugging With LLDB

item->value + [value floatValue]

Compiler integrationInjecting Checks into Expressions

Checks value

Clang

AST

(lldb) p item->value + [value floatValue]

Page 384: Session 415 - Debugging With LLDB

item->value + [value floatValue]

Compiler integrationInjecting Checks into Expressions

Checks ___check_obj(value)

Clang

AST

(lldb) p item->value + [value floatValue]

Page 385: Session 415 - Debugging With LLDB

item->value + [value floatValue]

Compiler integrationInjecting Checks into Expressions

Checks ___check_obj(value)

Clang

AST

AST___check_ptr(item)->value + [___check_obj(value) floatValue]

(lldb) p item->value + [value floatValue]

Page 386: Session 415 - Debugging With LLDB

Debugging with LLDBOverview

Introduction

LLDB in depth

Examples Conclusion

Page 387: Session 415 - Debugging With LLDB

Debugging with LLDBOverview

Introduction LLDB in depth

Examples

Conclusion

Page 388: Session 415 - Debugging With LLDB

Symbolicating a crash logSymbolication

• Manually• Using built-in Python module

Page 389: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

ManualSymbolication

Page 390: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

ManualSymbolication

Page 391: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target create a.out

ManualSymbolication

Page 392: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target create a.out

ManualSymbolication

Page 393: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target create a.out

ManualSymbolication

Page 394: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target create a.out(lldb) target modules add /usr/lib/dyld

ManualSymbolication

Page 395: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target create a.out(lldb) target modules add /usr/lib/dyld

ManualSymbolication

Page 396: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target create a.out(lldb) target modules add /usr/lib/dyld

ManualSymbolication

Page 397: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target modules load --file a.out __TEXT 0x104cc0000(lldb) target modules load --file dyld __TEXT 0x7fff648c0000

ManualSymbolication

Page 398: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target modules load --file a.out __TEXT 0x104cc0000(lldb) target modules load --file dyld __TEXT 0x7fff648c0000

ManualSymbolication

Page 399: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target modules load --file a.out __TEXT 0x104cc0000(lldb) target modules load --file dyld __TEXT 0x7fff648c0000

ManualSymbolication

Page 400: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target modules lookup --address 0x0000000104cc146a

ManualSymbolication

Page 401: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target modules lookup --address 0x0000000104cc146a

ManualSymbolication

Page 402: Session 415 - Debugging With LLDB

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread0 libsystem_c.dylib 0x00007fff8ad164f0 strlen + 161 a.out 0x0000000104cc146a main + 34 (char_traits.h:257)2 a.out 0x0000000104cc1440 start + 52

Binary Images: 0x104cc0000 - 0x104cc1fff a.out (??? - ???) <626A790D-54 0x7fff648c0000 - 0x7fff648f4baf dyld (195.6 - ???) <0CD1B35B- 0x7fff87f5e000 - 0x7fff87f68ff7 liblaunch.dylib (392.38.0 - 0x7fff8800c000 - 0x7fff8800dff7 libsystem_sandbox.dylib (??? 0x7fff88426000 - 0x7fff8842efff libsystem_dnssd.dylib (??? 0x7fff886d2000 - 0x7fff886e0fff libdispatch.dylib (187.9.0 - 0x7fff88708000 - 0x7fff88709fff libunc.dylib (24.0.0 - compati

(lldb) target modules lookup --address 0x0000000104cc146a

ManualSymbolication

Page 403: Session 415 - Debugging With LLDB

ManualSymbolication

(lldb) target modules lookup -a 0x0000000104cc146aAddress: a.out[0x000000010000146a] (a.out.__TEXT.__text + 94)Summary: a.out`main + 34 [inlined] char_traits<char>::length(char const*) + 5 a.out`main + 29 [inlined] string::assign(char const*) at main.cpp:11 a.out`main + 29 at main.cpp:11

Page 404: Session 415 - Debugging With LLDB

ManualSymbolication

(lldb) target modules lookup -a 0x0000000104cc146aAddress: a.out[0x000000010000146a] (a.out.__TEXT.__text + 94)Summary: a.out`main + 34 [inlined] char_traits<char>::length(char const*) + 5 a.out`main + 29 [inlined] string::assign(char const*) at main.cpp:11 a.out`main + 29 at main.cpp:11

Page 405: Session 415 - Debugging With LLDB

Using with Python moduleSymbolication

Page 406: Session 415 - Debugging With LLDB

Using with Python moduleSymbolication

(lldb) script import lldb.macosx.crashlog

Page 407: Session 415 - Debugging With LLDB

Using with Python moduleSymbolication

(lldb) script import lldb.macosx.crashlog"crashlog" command installed, type "crashlog --help" for detailed help

Page 408: Session 415 - Debugging With LLDB

Using with Python moduleSymbolication

(lldb) script import lldb.macosx.crashlog"crashlog" command installed, type "crashlog --help" for detailed help(lldb) crashlog /tmp/a.crash

Page 409: Session 415 - Debugging With LLDB

Using with Python moduleSymbolication

(lldb) script import lldb.macosx.crashlog"crashlog" command installed, type "crashlog --help" for detailed help(lldb) crashlog /tmp/a.crashGetting symbols for 626A790D-54BA-3B1F-9689-095C4A5B35FC /tmp/a.out... okThread[0] EXC_BAD_ACCESS (SIGSEGV) (KERN_INVALID_ADDRESS at 0x0000000000000000)[ 0] 0x00007fff8ad164f0 libsystem_c.dylib`strlen + 16

0x00007fff8ad164e4: movl %edi, %ecx 0x00007fff8ad164e6: movq %rdi, %rdx 0x00007fff8ad164e9: andq $-16, %rdi 0x00007fff8ad164ed: orl $-1, %eax -> 0x00007fff8ad164f0: pcmpeqb (%rdi), %xmm0 0x00007fff8ad164f4: andl $15, %ecx 0x00007fff8ad164f7: shll %cl, %eax 0x00007fff8ad164f9: pmovmskb %xmm0, %ecx 0x00007fff8ad164fd: andl %eax, %ecx

Page 410: Session 415 - Debugging With LLDB

Using with Python moduleSymbolication

[ 1] 0x0000000104cc1469 a.out`main [inlined] std::char_traits<char>::length([ 1] 0x0000000104cc1465 a.out`main [inlined] std::string::assign(char const*[ 1] 0x0000000104cc1465 a.out`main + 29 at main.cpp:11[ 2] 0x0000000104cc143f a.out`start + 51

Page 411: Session 415 - Debugging With LLDB

Using with Python moduleSymbolication

[ 1] 0x0000000104cc1469 a.out`main [inlined] std::char_traits<char>::length([ 1] 0x0000000104cc1465 a.out`main [inlined] std::string::assign(char const*[ 1] 0x0000000104cc1465 a.out`main + 29 at main.cpp:11[ 2] 0x0000000104cc143f a.out`start + 51

Page 412: Session 415 - Debugging With LLDB

Take a look at the built-in modulesLLDB Python Package

Page 413: Session 415 - Debugging With LLDB

Take a look at the built-in modulesLLDB Python Package

• Xcode.app/Contents/SharedFrameworks/LLDB.framework

Page 414: Session 415 - Debugging With LLDB

Take a look at the built-in modulesLLDB Python Package

• Xcode.app/Contents/SharedFrameworks/LLDB.framework■ Resources/Python/lldb

Page 415: Session 415 - Debugging With LLDB

Take a look at the built-in modulesLLDB Python Package

• Xcode.app/Contents/SharedFrameworks/LLDB.framework■ Resources/Python/lldb

■ lldb/formatters/cpp

Page 416: Session 415 - Debugging With LLDB

Take a look at the built-in modulesLLDB Python Package

• Xcode.app/Contents/SharedFrameworks/LLDB.framework■ Resources/Python/lldb

■ lldb/formatters/cpp■ lldb/formatters/objc

Page 417: Session 415 - Debugging With LLDB

Take a look at the built-in modulesLLDB Python Package

• Xcode.app/Contents/SharedFrameworks/LLDB.framework■ Resources/Python/lldb

■ lldb/formatters/cpp■ lldb/formatters/objc■ lldb/utils/symbolication.py

Page 418: Session 415 - Debugging With LLDB

Take a look at the built-in modulesLLDB Python Package

• Xcode.app/Contents/SharedFrameworks/LLDB.framework■ Resources/Python/lldb

■ lldb/formatters/cpp■ lldb/formatters/objc■ lldb/utils/symbolication.py■ lldb/macosx/crashlog.py

Page 419: Session 415 - Debugging With LLDB

Take a look at the built-in modulesLLDB Python Package

• Xcode.app/Contents/SharedFrameworks/LLDB.framework■ Resources/Python/lldb

■ lldb/formatters/cpp■ lldb/formatters/objc■ lldb/utils/symbolication.py■ lldb/macosx/crashlog.py■ lldb/macosx/heap.py

Page 420: Session 415 - Debugging With LLDB

Debugging with LLDBOverview

Introduction LLDB in depth

Examples

Conclusion

Page 421: Session 415 - Debugging With LLDB

Debugging with LLDBOverview

Introduction LLDB in depth Examples

Conclusion

Page 422: Session 415 - Debugging With LLDB

Wrapping things upConclusion

Page 423: Session 415 - Debugging With LLDB

Wrapping things upConclusion

• Customizable

Page 424: Session 415 - Debugging With LLDB

Wrapping things upConclusion

• Customizable■ Type formats

Page 425: Session 415 - Debugging With LLDB

Wrapping things upConclusion

• Customizable■ Type formats■ Type summaries

Page 426: Session 415 - Debugging With LLDB

Wrapping things upConclusion

• Customizable■ Type formats■ Type summaries

• Improved multi-threaded debugging

Page 427: Session 415 - Debugging With LLDB

Wrapping things upConclusion

• Customizable■ Type formats■ Type summaries

• Improved multi-threaded debugging• Compiler integration

Page 428: Session 415 - Debugging With LLDB

Wrapping things upConclusion

• Customizable■ Type formats■ Type summaries

• Improved multi-threaded debugging• Compiler integration

■ Rethink what you can do with expressions

Page 429: Session 415 - Debugging With LLDB

Wrapping things upConclusion

• Customizable■ Type formats■ Type summaries

• Improved multi-threaded debugging• Compiler integration

■ Rethink what you can do with expressions

• LLDB.framework

Page 430: Session 415 - Debugging With LLDB

Wrapping things upConclusion

• Customizable■ Type formats■ Type summaries

• Improved multi-threaded debugging• Compiler integration

■ Rethink what you can do with expressions

• LLDB.framework• Python integration

Page 431: Session 415 - Debugging With LLDB

More Information

Michael JurewitzDeveloper Tools [email protected]

DocumentationLLDB Websitehttp://lldb.llvm.org

Python Referencehttp://lldb.llvm.org/python-reference.html

Variable Formats and Summarieshttp://lldb.llvm.org/varformats.html

Apple Developer Forumshttp://devforums.apple.com

Page 432: Session 415 - Debugging With LLDB

Labs

LLDB Lab Developer Tools Lab CFriday 11:30AM

Page 433: Session 415 - Debugging With LLDB
Page 434: Session 415 - Debugging With LLDB
Page 435: Session 415 - Debugging With LLDB
Page 436: Session 415 - Debugging With LLDB