iOS essay-xcode use-document translation

Source: Internet
Author: User
Tags dashed line print object

This article is a personal translation record ~ is not a technical sharing ~ Want to read Chinese documents, you can view the ~

About debugging with Xcode

About Xcode Regulators

Finding and eliminating problems in your code is a key part of the development process. The Xcode debugger presets common debugging useful features that automatically run when your application starts. The debugger can help you:

1. Identifying and locating problems
2. Check the control flow and data structure of the running code to find the cause
3. Develop a solution and edit the appropriate code
4. Run the modified application and confirm that the patch

You should be familiar with the concepts of application design and programming. With some familiarity with Xcode also recommended; see the overview of Xcode.

Each year, Apple's meetings at the Global Developers Conference are dedicated to debugging the materials in this guide and adding them to useful technologies. These sessions are available from the Apple Developer Library on the Apple Developer website, and it's easy to find the "debug" filter

The following new WWDC lectures focus on using the Xcode debugger:
WWDC 2014:xcode 6 Debugging: Learn how to work with application queues, explore and resolve user interfaces, and add custom Quick Find support.
WWDC 2013: Debugging with Xcode: detecting and repairing performance issues using Xcode's graphical debugger.
WWDC 2013: Advanced Debugging: Debug LLDB using the terminal and Xcode graphics debugger.

A good Enlightenment book was written by David J.agans called the9 indispensable Rules for finding even the most elusive software and Hardware problems /c3>

Quick Start

Quick Start

Imagine: You have a successful application and you are adding a new feature. Click the Run button to run your application and start the Xcode debugging session after the toolbar in the workspace and your application are successfully built.
When the application runs, the Xcode window adjusts to open the debug area at the bottom and debug the left side of the debugging navigation. In the Debug Navigator, debugging a gauge helps monitor your program's use of system resources. You start practicing your app and use some new code that you only add to the display picture or diagram ... There's nothing to show.

What should you do now?

Start Preparing for commissioning!

The most important thing in debugging is to analyze the logic of the Code, or control the process, and ensure that the application provides the correct data. The logic problem of the application shows unexpected behavior: it does not happen (as in the hypothetical case, as described above), the wrong thing happens, or the application crashes. Code that performs incorrect operations often renders the wrong data to the user; Imagine a button button on a calculator, add 1 and 1, and get the result 20. When you see a problem to ensure that the application behaves in a plan and shows the correct results presented to the user.
In your hypothetical case, your new code doesn't seem to be executing. You do not know whether this password is not hit, or did not produce an output. But you know what's wrong with you, you have a mistake.
Other problems are more difficult to spot. Using an application in the debugger gives you the opportunity to monitor the use of system resources using a debugger. Note the shape of the graphic, and consider what you should expect to see the application run and the various parts of the code run. For example, if you see unexpected spikes in the CPU or memory table, for example, these may show more subtle problems.

Click a specification to open a more detailed report for a higher resolution view.

In both cases, your new code, not within your expectations, and in the unexpected signs of debugging instrumentation, you may not immediately know the cause of the problem. However, you already have some information:
The behavior of the application is correct before you start adding new features.
The application behaves correctly at the point where you use the application's user interface to run the new code.
You know what new code you have added to the source code.
To further isolate this cause, you can set breakpoints in your code.

Using breakpoints

Breakpoints are a versatile solution for checking a running application.
Breakpoints interrupt normal execution so that you can use the Debug bar control to run your application to examine the control flow and state variables for each line of code. When your program encounters a breakpoint, the debugger pauses the application's main window, switches to Xcode with the source positioned for you to check, and fills in the variable view and the process view and the navigation of the Debug tool in the state of the paused application. Breakpoints have several features that you can use to modify their behavior, making it easier for you to gather information. You can add breakpoints to your source code before you run the application, and you can add them to your code at run time.
To insert a breakpoint:
1. Locate the source in the source editor.
2. Click the line next to the resource editor slot where you want to pause.
Creates a file and a line breakpoint, which is available by default.

In the debug bar, you can use various methods, such as controls that you see in the debugger. It can also be time-consuming to check your code with a manual piece of code. Once you place a breakpoint in your code, you can set it to operate in a different way to improve your debugging efficiency. Control, click Breakpoints to display a context-sensitive menu, and then choose Edit Breakpoint.

You can configure a breakpoint on a condition basis to abort the program. Because the breakpoint is active when your application is running, you can use any code or variable in your application, at which point the source point is activated to test the range of a condition.

Breakpoint conditions are useful in many ways. For example, say that your new functionality depends on the state of a variable. You notice that when a problem occurs, the application that you check for a variable pauses at a breakpoint, which always has a special exception state or other unusual value. Once you know, you can set a breakpoint condition to monitor the variable and pause the application only if the variable has that value.
Another useful feature of a breakpoint is the ability to trigger an action.

In view of the above, the loop increment and the variable need to reach a specific state, perhaps you are interested to know that each loop execution is the value of the variable. You can set the breakpoint action to print to the console variable description at every pass using the LLDB command Po (PO is to provide the lldb abbreviation for the "Print Object" command).
Breakpoints in your code are managed with the Breakpoint navigator.

Using the breakpoint Navigator, you can see your code, all breakpoints edit breakpoints, enable and disable them, and business scope changes in Xcode. To enable or disable breakpoints, click Indicators in the Breakpoint Navigator or source editor, and a gray indicates that the breakpoint is disabled.
To remove a breakpoint when you are finished using it, do one of the following:
1. Drag it into the source code Editor.
2. Select the Breakpoing navigator and press DELETE.
3. Control click on it (in the source editor or the Breakpoint Navigator) and select Delete Breakpoint.

You can enable or disable multiple breakpoints at the same time. For example, what you might want to do is, for example, you identify several issues in different parts of the code.
Click the breakpoint line in the breakpoint row to move the source program to the source editor in the breakpoint location.
Sometimes, when you have placed a set of breakpoints, debug an issue, but temporarily need to run your application without pausing so that you can reach this problem and you are likely to have problems. To deactivate or activate all breakpoints, click the Activate button in the breakpoint Debug bar.
Note
The breakpoint Activation button does not change the Enable/disable setting for a breakpoint. All breakpoints remain in place when activated, enabled or disabled, as they are before being activated.

Controls in the debugger
The Debug navigator can help you check the control flow of your application. When an application is stopped by a breakpoint, the debugger displays the last value produced by the execution of the application. The following debug meter is a process view that can be set to show the running state of your application, organized by a thread or queue.

The Debug area contains three panes at the bottom of the main window of Xcode: The Debug bar, the variable view, and the console.


Distribution control in the debug bar

The debug bar contains controls that hide and show the debug area, the breakpoint Activation button, and the Resume/pause button. When the application is paused for a breakpoint, click the Continue button to restore the program.
The next Continue/pause button is a set of three buttons to get your app. Their basic operations are step-by-step instructions, step-by-step instructions, and get out of an instruction. If you put the mouse on these buttons, the alternate step mode will appear when you click on the modifier keys:

You set a breakpoint before the code line code, which is the problem that is causing the problem. This pauses the application so that you can check the variables. Then, you step-by-step the application to see how the variable's state changes, enters, enters, and in the desired line of code. Once you have completed the check, you click on the Continue/pause button to resume the application's normal operation.
Note
The step control of the debug bar is also available in the Debug menu, and has the keyboard to make their use efficient and convenient. The default key bindings can be used with Xcode preference>key Bindings.
Other buttons in the debug bar are more specialized. Debug the buttons discussed in the view hierarchy. On the right side of these 2 buttons, the process/thread/stack frame jump bar allows you to move directly into the stack frame in the suspended application, a useful alternative to moving with the Debug Navigator view display.
In the next section, you'll see how a mutable view of the debug zone allows you to examine variables, but the best way to frequently debug a problem is to see as much of the source code around the problem area as possible. This is when you use the Hide/Show button to hide the debug area, leaving only the debug bar available for the stepping source editor. You can open the debug area again, and then press the Hide/show button.


Variable View Check variables

Use the variable view in the debug area to examine the variable and determine its state.

As you can see, the Variables View pane lists the availability of each variable at the breakpoint where the application is paused. The next disclosure triangle is a set of icons that represent the kind of variable and then the variable name. The variable summary after the name represents the current value. When you use the step control in the debug bar to execute your application, you can see the value of the variable caused by each operation in the source code.
In the Variables view pane, the lower-left corner is a filter pop-up menu, which is set to automatic by default. This setting restricts variables in viewing those that are usually considered to be most debugging interesting, but you can set the variable view to show all variables (including global variables, static, and registers) or just local variables.
For complex variable structures and objects, you can drill into all components of a variable by clicking the Disclosure Triangle. This allows you to see every detail of the variables at once, and how they change your application.

The pop-up menu next to the filter is the Quick Find button, and the description of the print , you select a variable in the list, click these buttons to show up in the popup window. The Quick Find button produces a graphical rendering with dimensions and/or value information, depending on the type of variable selected. Fast graphical rendering is especially useful when you are trying to see a complex object and how it is drawn or rendered. The following is a Quick Find button that is used to display an instance of an Uibezierpath object in a variable view:

Note:
Quick Find Displays the type of object that the system provides and your object type. See Quick Find data types for more information.
The Print Description button provides textual information about the variable, equivalent to commands in the console using commands. When you click the Print Description button, it emits the PO output to the console and displays it in a popup window.
For many developers, the best way to do this is to view the source code as much as possible while pausing in the debugger. You can hide the debug area and work directly in the source editor, using the Quick Find and print description buttons to check the variables. Holding down the mouse in the instant source editor a variable and a popup window, the variable will appear in the variable to see the same information appearing. You can open the "disclosure" triangle, and then, at the angle of the variable, see the components of a complex variable, and so on. Pop-up Windows also have Quick View and print descriptions of available buttons just fine: Click on them with the same effect and click on the variable view.
For example, this diagram shows a Print button that describes a Cgpoint variable:

As you might expect, the print Description button output is displayed in a pop-up window in the console.
Most of the time, you use the variable view, quick Find, and print Description tool to check the variable values when you debug, to ensure that they are expected. However, sometimes you may want to try to change the value of a variable, as seen in fly, correcting a problem without having to go through a full construction cycle. This is easy to do with pop-ups in the source editor: hover your mouse over a variable until the pop-up window appears, drill down to the variable using the triangle you want, and then double-click the value. Remember, changing the value of a variable is often a bit risky in fly because you're changing the state of the running application, which can have side effects, but for some types of debugging it can provide the information you're looking for.
Understanding the Console
The Xcode debugger area includes the console view. The console view is a terminal, such as a command-line environment, that records output from the application and the debugger when the debugging session is running. When you run, break, and check variables, you can use the console to collect printed variable values. While the values in console view always persist throughout the debugging session, you can see the list of outputs generated during the entire session. When you complete a session and rerun another session of the application, the console is cleared, so it always starts empty at the beginning of a debugging session. However, you can review the contents of the console in past debugging sessions by going to the report navigator and examining the contents of the debugging session that is stored there.
The Xcode debugger uses LLDB, a low-level debug engine, to play its function. The console can use the LLDB command line interface directly, and you can use any of the LLDB commands in the console view to supplement or extend the Xcode debugging experience.

LLDB is a powerful debugging environment with many features. Learn the basics of using LLDB by reading the LLDB Quick Start Guide. In the Debug Navigator study backtracking general situation as described earlier in this chapter, you launch the application Run button. You tried to invoke the new code you added, and nothing happened. Now that you have added a breakpoint, the new code should be from and try calling the code again. The Xcode debugger has stopped your application at that location and the population variable view in the current state of the Debug and Debug Navigator application. You'll probably look at the variables and their values first. The variable view, quick Find, and print Description tool gives you the status of the application for the first time you see it. The next question that needs to be addressed is "How is the code here?" To answer this question, you can use the Debug Navigator view pane. When the program stops at the breakpoint, the debugger "turns" in the debug navigation process in the View pane of the program flow that is introduced to you. Some definitions will make this clear: the stack frame is an instance of the calling method. "Close" means "view the method that contains your breakpoint, and then trace the stack frame pointer and the method that called the site." ”。 The stack frame unlocks this fashionable sequence called backtracking. By default, this view is organized by threads of the current stack frame, where the position of the program counter is highlighted at the breakpoint in the source code Editor. (The debugger has been hidden in this example, the Debug Navigator uses the highlighted buttons to let you focus on the process view to show backtracking.) )

Backtracking allows you to understand the flow of control in your application. Displays the icon identification for each stack frame in the Debug Navigator view pane. The icon tells you where the stack frame of the compiled code came from. There are user code icons, base frames, it or uikit frames, graphics frames, and so on. The debugger retrieves and is no longer remembered in this full history execution connector, even including stack frames.
This view of the backtracking, you can see your application to the current state, paused at the breakpoint. Look at the illustrations above:
The app is stuck in your source code in _plotaccel, this thread 5 executes.
This code is called by a system function, which is part of a scheduled asynchronous callback.
Some system stack frames omit view dashed lines to represent them. You can display these stack frames at the bottom of the Debug navigator by selecting the leftmost button.
The stack frame below the dashed line shows the start of a worker thread called code.
Below, you can see the backtracking that is logged in the block async queue.
The record shows that this piece is backtracking awakefromnib when the queue may start in the application.
When you click on the back of the stack frame in the source editor, jump in the source or decompile the binary executable, point. For the stack frame of the code, you can see the source code. If the frame is in memory, you can see the value of the variable; if the stack frame is no longer in memory, it is a variable value that records the stack frame is not available.
Note
In the Debug navigator view, if the icon for a stack frame is color, the stack frame is in memory. The stack frame next to the gray icon indicates that the stack frame is no longer in memory, and the debug navigation has retrieved the stack frame by analyzing the recorded call history; The debugger cannot recreate the value of the variable from the recorded call history.

Using debug navigation and backtracking, you can see that the code of the program has moved along the desired path to the breakpoint or whether it deviates from what you expected. Jump to user code in backtracking when you have a problem, you can set a new breakpoint, stop the application at the front point and look at it by checking the variable along the road to go awry.
If your new code does not run or appears because the condition does not implement the correct backtracking, find the correct point, set a breakpoint, explain the problem, click Run/Pause recovery to run normally, and then execute, the new code should rerun the role. This time stop in the program flow and check the variables and then step-by-step the application until you find the cause of the problem, check the variables along the way.
Cyclic debugging process
Debugging is a repeated effort. You find a problem where you set breakpoints to help you locate the source it occurs in, you check the backtracking and variables to assess their status and the cause of the problem, and you come up with a solution or repair. With a potential solution, you have made a change to the source and rerun the application to see if the issue is resolved. If the test shows that the problem persists, you repeat the cycle until you put the correct fix in place.
When the problem is resolved, you can disable or remove the breakpoints that you used in their survey. You don't want them to move forward in the direction you continue the next question.

iOS essay-xcode use-document translation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.