Skip to content

Commit

Permalink
添加工程
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlintie committed Aug 19, 2021
1 parent 21d9713 commit 5b91276
Show file tree
Hide file tree
Showing 10 changed files with 637 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# symbolicatecrash
iOS crash 文件符号解析工具

## 前提

* 安装好 Xcode
* 将需要被解析的崩溃文件以 '.crash' 作为后缀进行保存
* 将同名的 dSYM 文件,放在同一文件夹下

如:

```
/path/to/
├── mycrash.crash
├── mycrash.dSYM
```
## 使用方法

`$ ./symbolicatecrash path/to/mycrash.crash`

解析成功后,将在同一文件夹下生成 `mycrash-symbolicated.crash` 文件

## 提示

本工具使用了 Xcode 自带工具 `symbolicatecrash`,目录为:

> /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash
若后续该工具路径发生变化,使用下方命令进行查找:

`$ find /Applications/Xcode.app -name symbolicatecrash -type f`

然后在源码中替换新的路径,重新编译即可
123 changes: 123 additions & 0 deletions symbolicatecrash/core/Shell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
//
// Shell.swift
// BinaryBuild
//
// Created by Zhen,Lintie on 2020/4/17.
//

import Foundation

struct ShellResult {
var status: Int
var output: String
var error: String
}

enum ShellCommand {

case symbolicatecrash
case ls
case cp
case rm
case mkdir

var path: String {
switch self {
case .symbolicatecrash:
return "/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash"
case .ls:
return "/bin/ls"
case .cp:
return "/bin/cp"
case .rm:
return "/bin/rm"
case .mkdir:
return "/bin/mkdir"
}
}

func isValid() -> Bool {
return false
}

}

private func getOutputString(_ pipe: Pipe) -> String {
var output = ""
var outputData: Data?
if #available(OSX 10.15.4, *) {
outputData = try? pipe.fileHandleForReading.readToEnd()
} else {
outputData = pipe.fileHandleForReading.readDataToEndOfFile()
}
if let data = outputData, let string = String(data: data, encoding: .utf8) {
output = string.trimmingCharacters(in: .whitespacesAndNewlines)
}
return output
}

@discardableResult
func run(_ cmd: String, _ args: [String] = [], environment: [String: String]? = nil, printError: Bool = true) -> ShellResult {
let task = Process()
task.launchPath = cmd
if !args.isEmpty {
task.arguments = args
}
if let environment = environment {
task.environment = env.merging(environment) {
$1
}
}
// print("Process launch")

let outputPipe = Pipe()
task.standardOutput = outputPipe

let errorPipe = Pipe()
task.standardError = errorPipe

task.launch()

let output = getOutputString(outputPipe)
let error = getOutputString(errorPipe)

task.waitUntilExit()

let status = Int(task.terminationStatus)

if status != 0, error.count > 0 {
if printError {
print(error)
}
} else {
print(output)
}


// print("Process end \(cmd)")

return ShellResult(status: status, output: output, error: error)
}

@discardableResult
func run(_ cmd: ShellCommand, _ arguments: [String] = [], environment: [String: String]? = nil, printError: Bool = true) -> ShellResult {
return run(cmd.path, arguments, environment: environment, printError: printError)
}

@discardableResult
func ls(_ arguments: [String] = []) -> ShellResult {
run(.ls, arguments)
}

@discardableResult
func cpDir(_ fromPath: String, _ toPath: String) -> ShellResult {
run(.cp, ["-r", fromPath, toPath])
}

@discardableResult
func rmDir(_ path: String) -> ShellResult {
run(.rm, ["-rf", path], printError: false)
}



Loading

0 comments on commit 5b91276

Please sign in to comment.