All about Debugging with Xcode (P1)

Tram Ho

Written by: Hoang Hai

In this article, I will summarize the basic skills that everyone needs to know and accompanying the tips, tricks that I can pick up to debug with Xcode effectively.

Part 1: Xcode Debugging uses breakpoints.

This article will focus on introducing the breakpoint Xcode debug technique – a Xcode debugging tool.

Một breakpoint là một công cụ gỡ gỡ để cho phép bạn xử lý thực hiện của chương trình này được tạo để một số nguyên.

We can understand that breakpoints are an integrated support tool in Xcode to help us stop processing of the program at a time. Temporarily stopping processing can help us evaluate, check, make sure our code is running properly, and help investigate Bug’s traces when an unexpected error occurs.

Đang tạo “pause” điểm trong mã không thể thực hiện bạn xử lý các mã để xem các lỗi occur.

How to create and use breakpoints?

Easy. Decide trên địa chỉ bạn muốn xử lý thực hiện của mã này và khi mở trong gutter left để tạo một sự phân tách blue.

Any line of Xcode code can set breakpoints by simply clicking on the line number on the left side of the code area.

  • Note:
  1. Debug Navigator: displays all threads and breakpoints.
  2. The time when the thread was created and processed.
  3. You can easily set breakpoint by clicking on the serial number of the code line on the left side of the code area
  4. Debug area.
  5. Active and Active Breakpoints.
  6. Continue or stop processing (shortcut keyboard: ⌃ + ⌘ + Y).
  7. Step Over: execute the next line of code (keyboard shortcut F6).
  8. Step Into: Going inside the function is called to consider (F7 keyboard shortcut).
  9. Step Out: jump out of the function (keyboard shortcut F8).
  10. “Lldb” means “low level debugger”

Maybe you are interested

Tips for naming conventions for CSS help you shorten 2/3 time when debugging!

JavaScript Tip: Set function names to debugging more easily

In the image above I have placed the debug at the beginning of the line of the function ViewDidLoad (). Here Xcode will stop processing BEFORE executing the ViewDidLoad () function. I added another breakpoint at line 24.

Here if I click on the allow icon to continue or stop processing (keyboard shortcut: ⌃ + ⌘ + Y) then Xcode will stop at the time before the code at line 24 is executed. Then if I click this icon again, the code will run as usual.

However, if I do not let Xcode continue to run as usual but click on Step over: execute the next code line (keyboard shortcut F6) then Xcode will stop before the next line of code must execute.

Previously I chose the Quicksort tab, so within the line switch the Quicksort function will be added.

Here we can click on Step Into: go inside the called function to review (keyboard shortcut F7) to see the details of the code executed in this called function.

Also, if you want to stop the inspect inside the function but don’t want to finish tracking after that function, we can click on Step Out: jump out of the function (keyboard shortcut F8).

If you want to remove the set breakpoint, we can right-click the breakpoint to display the options, we can also drag the breakpoint drop out to remove it, and right-click will disable breakpoint. (make it blur, not disappear).

The message line (lldb) appears when we set the breakpoint with the idea of ​​”low level debugger”, Xcode provides us with a debug environment for iOS applications through the console.

LLDB stands for “low level debugger” which cung cấp cơ sở dữ liệu Debugging để tạo cho iOS applications. It can be used to find and eliminate issues in your Swift and Objective-C code.

So what does Breakpoint and LLDB have to do with each other? LLDB allows us to use commands to debug on the console of Xcode: set breakpoint, listing all breakpoints as well as disabling breakpoints.

Bạn không thể loại bỏ những lệnh shortcut vào LLDB để giúp thiết lập câu lệnh breakpoints ở các dòng này, đặt breakpoints ở nhiều điểm trong mã của bạn, list all your breakpoints, and disable breakpoints.

In the console, I used the breakpoint set --selector viewDidLoad to set breakpoint at all existent keywords “viewDidLoad”. The breakpoint list command breakpoint list all current breakpoints that are being set. We can see in detail the information of each breakpoint, maybe even understanding the number of times Xcode has run to that breakpoint via hit count. The breakpoint disable command is used to disable all current breakpoints, if I add a number n as Int immediately, xcode will understand that I want to disable the breakpoint at n.

Above is a summary of how to use breakpoint to debug in Xcode, I will continue to introduce debugging methods in the next article. Hopefully this article is useful for everyone in the “bug” killing later. Thanks for your interest in my article.

Viblo

Share the news now

Source : Viblo