没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Section I: Beginning LLDB
Commands
This section will cover the basics of using LLDB, Apple’s software debugger. You’ll
explore an application named Signals, an Objective-C/Swift application that illustrates
how Unix signals can be processed within an application. You’ll learn some strategies to
find and create Swift syntax-style breakpoints as well as Objective-C style breakpoints.
By the end of this section, you’ll be able to wield the debugger to perform most of the
basic tasks needed for debugging, as well as create your own simple custom commands.
Chapter 1: Getting Started
Chapter 2: Help & Apropos
Chapter 3: Attaching with LLDB
Chapter 4: Stopping in Code
Chapter 5: Expression
Chapter 6: Thread, Frame and Stepping Around
Chapter 7: Image
Chapter 8: Persisting & Customizing Commands
Chapter 9: Regex Commands
raywenderlich.com
20
1
Chapter 1: Getting Started
In this chapter, you’re going to get acquainted with LLDB and investigate the process of
introspecting and debugging a program. You’ll start off by introspecting a program you
didn’t even write — Xcode!
You’ll take a whirlwind tour of a debugging session using LLDB and discover the
amazing changes you can make to a program you’ve absolutely zero source code for.
This first chapter heavily favors doing over learning, so a lot of the concepts and deep
dives into certain LLDB functionality will be saved for later chapters.
Let’s get started.
raywenderlich.com
21
Getting around Rootless
Before you can start working with LLDB, you need to learn about a feature introduced
by Apple to thwart malware. Unfortunately, this feature will also thwart your attempts
to introspect and debug using LLDB and other tools like DTrace. Never fear though,
because Apple included a way to turn this feature off — for those who know what
they’re doing. And you’re going to become one of these people who knows what they’re
doing!
The feature blocking your introspection and debugging attempts is System Integrity
Protection, also known as Rootless. This system restricts what programs can do —
even if they have root access — to stop malware from planting itself deep inside your
system.
Although Rootless is a substantial leap forward in security, it introduces some
annoyances as it makes programs harder to debug. Specifically, it prevents other
processes from attaching a debugger to programs Apple signs.
Since this book involves debugging not only your own applications, but any application
you’re curious about, it’s important that you to remove this feature while you learn
about debugging so you can inspect any application of your choosing.
If you currently have Rootless enabled, you’ll be unable to attach to the majority of
Apple’s programs. There are exceptions however, such as any apps shipped on the iOS
Simulator.
For example, try attaching LLDB to the Finder application.
Open up a Terminal window and look for the Finder process, like so:
lldb -n Finder
You’ll notice the following error:
error: attach failed: cannot attach to process due to System Integrity
Protection
Note: There are many ways to attach to a process, as well as specific
configurations when LLDB attaches successfully. To learn more about attaching to
a process, check out Chapter 3, “Attaching with LLDB”.
Advanced Apple Debugging Chapter 1: Getting Started
raywenderlich.com
22
Disabling Rootless
To disable Rootless, perform the following steps:
1. Restart your macOS machine.
2. When the screen turns blank, hold down Command + R until the Apple boot logo
appears. This will put your computer into Recovery Mode.
3. Now, find the Utilities menu from the top and then select Terminal.
4. With the Terminal window open, type:
csrutil disable; reboot
5. Your computer will restart with Rootless disabled.
Note: A safer way to follow along with this book would be to create a dedicated
virtual machine using VMWare or VirtualBox and only disable Rootless on this.
You can verify if you’ve successfully disabled Rootless by trying the same command in
Terminal again once you log into your account.
lldb -n Finder
LLDB should now attach itself to the current Finder process. The output of a successful
attach should look like this:
After verifying a successful attach, detach LLDB by either killing the Terminal window,
or typing quit and confirming in the LLDB console.
Advanced Apple Debugging Chapter 1: Getting Started
raywenderlich.com
23
Attaching LLDB to Xcode
Now that you’ve disabled Rootless, you can attach LLDB to any process on your macOS
machine (some hurdles may apply, such as with ptrace, but we’ll get to that later).
You’re first going to look into an application you frequently use in your day-to-day
development: Xcode! Make sure you have the latest version of Xcode 9 installed on
your computer before continuing.
Open a new Terminal window. Next, edit the Terminal tab’s title by pressing ⌘ + Shift +
I. A new popup window will appear. Edit the Tab Title to be LLDB.
Next, make sure Xcode isn’t running, or you’ll end up with multiple running instances
of Xcode, which could cause confusion.
In Terminal, type the following:
lldb
This launches LLDB.
Create a new Terminal tab by pressing ⌘ + T. Edit the tab’s title again using ⌘ + Shift +
I and name the tab Xcode stderr. This Terminal tab will contain all output when you
print content from the debugger.
Make sure you are on the Xcode stderr Terminal tab and type the following:
~ $ tty
Advanced Apple Debugging Chapter 1: Getting Started
raywenderlich.com
24
剩余98页未读,继续阅读
资源评论
love_2016
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功