IOS development often needs to contact the concept of symbol table, this article mainly shares the symbol table related knowledge, including what is a symbol table, symbol table function, symbol table generation process, how to find symbol table file, how to find symbol table file UUID.
IOS symbol table (dSYM) knowledge summary
What is a symbol table and why is it needed
The symbol table generated when iOS is built. It is a mapping table of memory addresses and function names, file names, and line numbers. The symbol table elements look like this:
< start address > < end address > < function > [< file name: line number >]Copy the code
Similar to the Mapping file when Android builds the Release package, we can use the mapping file to restore the existing stack information of APP runtime after confusion to the stack information before confusion (using the retrace tool). Therefore, when crash is applied, we can use the stack information during crash to get the stack information corresponding to the source code and see how many lines of the code are in error. Therefore, we can quickly locate the error code and solve the problem quickly.
For iOS applications, there is also a stack when crash occurs. For release applications, the stack information when crash occurs is all binary address information.
Android at least sees the function names, albeit obfuscated, and the system function names, so it’s a bit better.)
It is impossible to locate the problem by using the binary address information, so we need to restore the binary address information to the source code functions and line numbers, and then we need a symbol table. Here’s an example:
In the debug version of the application, sometimes you can see the function name in the stack information during crash, but you can’t see the line number of the corresponding source code file, so you can’t locate the problem. The debug version crash stack looks like this:
Therefore, if we provide the product to project members for experience, both the Debug version and the release version need symbol table to help us restore the stack information of crash to the corresponding information of the source code file, so as to quickly locate the problem
If We use Bugly to manage crash reporting, we only need to upload the symbol table during construction to Bugly. When crash is applied, Bugly will report crash information to Bugly, and then it will automatically restore the original binary stack information of crash into the source code file information including line number for us. We can quickly locate the problem
How is a symbol table generated
Take a look at the archive build process for ios projects:
-
Ready to build the environment, build the directory
-
BUILD a static library or Framework for the Pods PROJECT that the main PROJECT depends on (=== BUILD TARGET Aspects OF PROJECT Pods WITH CONFIGURATION Debug ===)
-
Compile main project source code file (CompileC)
-
Link to generate executable file corresponding to main project (Ld)
-
Copy images, Columns and other resources (CpResource)
-
CompileStoryboard files to CompileStoryboard
-
CompileAssetCatalog
-
Process the pinfo.list file (ProcessInfoPlistFile)
-
Generate symbol table file
-
Link to the StoryBoard (LinkStoryboards)
-
Execute the configuration script file (PhaseScriptExecution)
-
Package generated APP file, not IPA file (ProcessProductPackaging)
-
The signature (CodeSign)
-
Check (Validate)
For example, Bugly asked us to add its script to Build Phases in the project configuration to upload the generated symbol table to Bugly. According to the archive construction process, we know that the symbol table generation step is after the pinfo. PLST file, so the bugly execution script we configured must be placed after the link step, otherwise the symbol table file will not be found. In addition, the initially generated symbol table is not in the archive file we see, but in a temporary directory built, and finally copied to the archive directory. The directory for storing the initially generated symbol table files is similar to the following:
/Users/cloud/Library/Developer/Xcode/DerivedData/Xxx-ajmvyrkvoxmeqecuyqlnxbgtlaoy/Build/Intermediates.noindex/ArchiveInt ermediates/Here/BuildProductsPath/Debug-iphoneos/Xxx.app.dSYMCopy the code
In fact, steps 1 to 11 are the construction steps of the main Target configuration of the main project, as follows:
Note:
-
Debug configuration Does not generate symbol tables by default
If you want to generate a symbol table, see :XCode does not generate dSYM files after compiling?
-
Each build generates a different symbol table, which is very different from the Android mapping file in that each symbol table has a unique UUID that corresponds to each build
The xArchive file is obtained through the archive construction process. To generate an IPA file, you must export the IPA file through the archive command line
xcodebuild -workspace CardPlayer.xcworkspace -scheme CardPlayer -destination generic/platform=iOS -configuration Debug archive -archivePath ~/Desktop/CardPlayer
Copy the code
The command for exporting ipA files is as follows:
xcodebuild -exportArchive -archivePath ~/Desktop/CardPlayer -exportPath ~/Desktop/CardPlayer2017 -exportOptionsPlist expportOption.plist
Copy the code
How do I locate dSYM files
See how to locate a dSYM file
A dSYM file is actually a file in the form of a folder with a suffix that looks like this:
CardPlayer. App. DSYM / └ ─ ─ Contents ├ ─ ─ the Info. The plist └ ─ ─ Resources └ ─ ─ DWARF └ ─ ─ CardPlayerCopy the code
The actual symbol table file is actually a binary file. Bugly provides a script to convert this binary file into a text file. The contents of the file are the binary address pairs and the corresponding relationship between the source file, line number, and function name
How do I view the UUID of a dSYM file
When iOS App crashes, there will be the uUID information of this build. If you want to restore the crash stack to the corresponding source code file information, you need to find the UUID of the corresponding symbol table according to this UUID, so as to restore correctly
See how to check the UUID of a dSYM file
There are two ways to sum it up:
-
Viewing by Command
Xcrun dwarfdump --uuid <dSYM file >Copy the code
-
Use the Bugly script to export the symbol table file to view the UUID
How to retrieve the dSYM file of an App that has been published to the App Store?
See how to retrieve dSYM files for apps that have been published to the App Store
The resources
- IOS symbol table
note
To summarize how to restore a development-time crash stack, theoretically there should be two steps:
-
Listen for ios app crashes and print crash stack information to file
-
Restore crash stack information to the corresponding information in the source file
¥50 yuan