From 5883e16b57fbb9db615fac0042eae497f375ddb8 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Tue, 28 May 2019 17:25:36 +0300 Subject: [PATCH] Remove `symbolication` sample --- samples/settings.gradle | 1 - samples/symbolication/README.md | 4 - samples/symbolication/build.gradle | 20 ----- samples/symbolication/gradle.properties | 2 - .../cinterop/coreSymbolication.def | 69 ---------------- .../src/symbolicationMain/kotlin/main.kt | 78 ------------------- samples/symbolication/test.kt | 22 ------ 7 files changed, 196 deletions(-) delete mode 100644 samples/symbolication/README.md delete mode 100644 samples/symbolication/build.gradle delete mode 100644 samples/symbolication/gradle.properties delete mode 100644 samples/symbolication/src/nativeInterop/cinterop/coreSymbolication.def delete mode 100644 samples/symbolication/src/symbolicationMain/kotlin/main.kt delete mode 100644 samples/symbolication/test.kt diff --git a/samples/settings.gradle b/samples/settings.gradle index 038e12183a5..c2940ca16c2 100644 --- a/samples/settings.gradle +++ b/samples/settings.gradle @@ -45,7 +45,6 @@ if (MPPTools.isMacos() || MPPTools.isLinux()) { if (MPPTools.isMacos()) { include ':objc' include ':opengl' - include ':symbolication' include ':uikit' include ':coverage' } diff --git a/samples/symbolication/README.md b/samples/symbolication/README.md deleted file mode 100644 index b9c54fb5917..00000000000 --- a/samples/symbolication/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Backtrace symbolication tool - -Produces more verbose backtrace symbolication with file name and line number. -Only works on debug .dSYM binaries on macOS at the moment. diff --git a/samples/symbolication/build.gradle b/samples/symbolication/build.gradle deleted file mode 100644 index fe42efec6d4..00000000000 --- a/samples/symbolication/build.gradle +++ /dev/null @@ -1,20 +0,0 @@ -plugins { - id 'kotlin-multiplatform' -} - -// Determine host preset. -def hostPreset = MPPTools.defaultHostPreset(project) - -kotlin { - targetFromPreset(hostPreset, 'symbolication') { - binaries { - executable() { - entryPoint = 'symbolication.main' - } - } - compilations.main.cinterops { - coreSymbolication { - } - } - } -} \ No newline at end of file diff --git a/samples/symbolication/gradle.properties b/samples/symbolication/gradle.properties deleted file mode 100644 index 790a07d5124..00000000000 --- a/samples/symbolication/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -kotlin.code.style=official -kotlin.import.noCommonSourceSets=true diff --git a/samples/symbolication/src/nativeInterop/cinterop/coreSymbolication.def b/samples/symbolication/src/nativeInterop/cinterop/coreSymbolication.def deleted file mode 100644 index 7ffc02a12aa..00000000000 --- a/samples/symbolication/src/nativeInterop/cinterop/coreSymbolication.def +++ /dev/null @@ -1,69 +0,0 @@ -package = CoreSymbolication -linkerOpts.osx = -F /System/Library/PrivateFrameworks -framework CoreSymbolication -headerFilter = ** -language=Objective-C ---- -#include -#include - -typedef struct { - unsigned long type; - void* contents; -} CSTypeRef; - -typedef CSTypeRef CSSymbolicatorRef; -typedef CSTypeRef CSSymbolOwnerRef; -typedef CSTypeRef CSSymbolRef; -typedef CSTypeRef CSSourceInfoRef; - -typedef struct { - unsigned long long location; - unsigned long long length; -} CSRange; - -typedef unsigned long long CSArchitecture; - -#define kCSNow LONG_MAX - -cpu_type_t CSArchitectureGetCurrent(); - -CSSymbolicatorRef CSSymbolicatorCreateWithPid(pid_t pid); - -CSSymbolicatorRef CSSymbolicatorCreateWithPathAndArchitecture(const char* path, cpu_type_t type); - -CSArchitecture CSSymbolicatorGetArchitecture(CSSymbolicatorRef symbolicator); - -CSSymbolOwnerRef CSSymbolicatorGetSymbolOwnerWithNameAtTime( - CSSymbolicatorRef symbolicator, const char* name, long time); - -CSSymbolOwnerRef CSSymbolicatorGetSymbolOwnerWithAddressAtTime( - CSSymbolicatorRef symbolicator, unsigned long long address, long time); - -CSSymbolOwnerRef CSSymbolicatorGetSymbolOwner(CSSymbolicatorRef cs); - -CSSymbolRef CSSymbolicatorGetSymbolWithNameAtTime( - CSSymbolicatorRef symbolicator, const char* name, long time); - -const char* CSSymbolOwnerGetName(CSSymbolOwnerRef owner); - -unsigned long long CSSymbolOwnerGetBaseAddress(CSSymbolOwnerRef owner); - -CSSourceInfoRef CSSymbolOwnerGetSourceInfoWithAddress( - CSSymbolOwnerRef owner, unsigned long long address); - -const char* CSSymbolGetName(CSSymbolRef symbol); - -CSRange CSSymbolGetRange(CSSymbolRef symbol); - -const char* CSSourceInfoGetPath(CSSourceInfoRef info); - -const char* CSSourceInfoGetFilename(CSSourceInfoRef info); - -uint32_t CSSourceInfoGetLineNumber(CSSourceInfoRef info); -uint32_t CSSourceInfoGetColumn(CSSourceInfoRef info); - -CSTypeRef CSRetain(CSTypeRef); - -void CSRelease(CSTypeRef); - -bool CSIsNull(CSTypeRef); diff --git a/samples/symbolication/src/symbolicationMain/kotlin/main.kt b/samples/symbolication/src/symbolicationMain/kotlin/main.kt deleted file mode 100644 index 9414f5d4339..00000000000 --- a/samples/symbolication/src/symbolicationMain/kotlin/main.kt +++ /dev/null @@ -1,78 +0,0 @@ -package symbolication - -import platform.darwin.* - -import kotlinx.cinterop.* -import CoreSymbolication.* - -fun main(args: Array) { - val program = if (args.size > 0 && args[0].isNotEmpty()) - args[0] else throw Error("please specify .dSYM path as the first argument") - val arch = if (args.size > 1 && args[1].isNotEmpty()) args[1] else "current" - val input = generateSequence { readLine() } - analyzeTrace(program, arch, input) -} - -fun archToCpuName(arch: String): cpu_type_t = when (arch) { - "x64", "x86_64" -> CPU_TYPE_X86_64 - "arm32" -> CPU_TYPE_ARM - "arm64" -> CPU_TYPE_ARM64 - "current" -> CSArchitectureGetCurrent() - else -> TODO("unsupported $arch") -} - -fun sourceInfoString(owner: CValue, address: ULong): String? { - var sourceInfo: CValue? = CSSymbolOwnerGetSourceInfoWithAddress(owner, address) - if (CSIsNull(sourceInfo!!)) return null - var lineNumber = CSSourceInfoGetLineNumber(sourceInfo) - var maybe = false - if (lineNumber == 0u) { - // Workaround compiler bug. - sourceInfo = null - for (maybeAddress in address - 10u .. address + 10u) { - val maybeSourceInfo = CSSymbolOwnerGetSourceInfoWithAddress(owner, maybeAddress) - if (CSIsNull(maybeSourceInfo)) continue - var maybeLineNumber = CSSourceInfoGetLineNumber(maybeSourceInfo) - if (maybeLineNumber != 0u) { - lineNumber = maybeLineNumber - sourceInfo = maybeSourceInfo - maybe = true - break - } - } - } - if (sourceInfo == null) return null - val filePath = CSSourceInfoGetPath(sourceInfo)?.toKString() ?: return null - val columnNumber = CSSourceInfoGetColumn(sourceInfo) - return "$filePath:${if (lineNumber == 0u) "" else "${if (maybe) "~" else ""}$lineNumber:$columnNumber"}" -} - -fun analyzeTrace(program: String, arch: String, input: Sequence) { - val symbolicator = CSSymbolicatorCreateWithPathAndArchitecture(program, archToCpuName(arch)) - if (CSIsNull(symbolicator)) throw Error("Cannot create \"$arch\" symbolicator for $program") - val owner = CSSymbolicatorGetSymbolOwner(symbolicator) - // Format is like - // at 14 test.kexe 0x0000000106a2e071 Konan_run_start + 113 - val matcher = "(at \\d+\\s+\\S+\\s+0x[0-9a-f]+\\s+)([^+]+)\\+\\s(\\d+)".toRegex() - for (line in input) { - val match = matcher.find(line) - var result = line - if (match != null) { - val atPart = match.groupValues[1] - val functionName = match.groupValues[2].trim() - val offsetInFunction = match.groupValues[3].toUInt() - val symbol = CSSymbolicatorGetSymbolWithNameAtTime(symbolicator, functionName, kCSNow) - if (!CSIsNull(symbol)) { - CSSymbolGetRange(symbol).useContents { - val address = this.location + offsetInFunction - val sourceInfo = sourceInfoString(owner, address) - if (sourceInfo != null) { - result = matcher.replaceFirst(line, "$atPart$functionName + $offsetInFunction ($sourceInfo)") - } - } - } - } - println(result) - } - CSRelease(symbolicator) -} diff --git a/samples/symbolication/test.kt b/samples/symbolication/test.kt deleted file mode 100644 index 826d5303408..00000000000 --- a/samples/symbolication/test.kt +++ /dev/null @@ -1,22 +0,0 @@ -fun f(p: Int) { - if (p == 0) throw Error() - f(p - 1) -} - -fun g1(p: Int) { - if (p == 0) throw Error() - g2(p - 1) -} - -fun g2(p: Int) { - g1(p - 1) -} - -fun main() { - try { - f(10) - } catch (e: Throwable) { - e.printStackTrace() - } - g1(10) -}