Skip to content

Commit 75a57f6

Browse files
[TOOLS] Allow (re)symbolication of all symbols
This allows resymbolication for already symbolicated crash entries (possibly with proper demangling). This allows resymbolication of non-system libraries/binaries (e.g. the app itself).
1 parent 23f0454 commit 75a57f6

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

tools/symbol_extractor/symbol_extractor.cpp

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,6 @@ static pid_t swift_demangler_pid = 0;
104104
static FILE* swift_demangler_stdin = nullptr;
105105
static FILE* swift_demangler_stdout = nullptr;
106106

107-
// Escape JSON strings (minimal escaping)
108-
std::string escape_json_string(const std::string& input) {
109-
std::string output;
110-
output.reserve(input.size() * 2);
111-
for (char c : input) {
112-
switch (c) {
113-
case '\"': output += "\\\""; break;
114-
case '\\': output += "\\\\"; break;
115-
case '\b': output += "\\b"; break;
116-
case '\f': output += "\\f"; break;
117-
case '\n': output += "\\n"; break;
118-
case '\r': output += "\\r"; break;
119-
case '\t': output += "\\t"; break;
120-
default:
121-
if (static_cast<unsigned char>(c) < 0x20) {
122-
char buf[7];
123-
snprintf(buf, sizeof(buf), "\\u%04x", c);
124-
output += buf;
125-
} else {
126-
output += c;
127-
}
128-
}
129-
}
130-
return output;
131-
}
132-
133107
std::string read_string(FILE* fp) {
134108
char buffer[65536];
135109
std::string result;
@@ -165,11 +139,11 @@ std::string demangle_swift_symbol(const std::string& mangled) {
165139
}
166140
if (WIFEXITED(status)) {
167141
if (WEXITSTATUS(status) != 0) {
168-
std::cerr << "swift-demangle exited with code " << WEXITSTATUS(status) << std::endl;
142+
std::cerr << "swift-demangle exited with code " << WEXITSTATUS(status) << " while demangling" << std::endl;
169143
exit(2);
170144
}
171145
} else {
172-
std::cerr << "swift-demangle terminated abnormally" << std::endl;
146+
std::cerr << "swift-demangle terminated abnormally while demangling" << std::endl;
173147
exit(2);
174148
}
175149
}
@@ -274,13 +248,15 @@ bool extract_symbols(const std::string& filepath, std::vector<SymbolEntry>& symb
274248
char* demangled = abi::__cxa_demangle(symNameRaw, nullptr, nullptr, &status);
275249
std::string symName = (status == 0 && demangled) ? demangled : symNameRaw;
276250
//don't try swift demangle, if c++ could already demangle it and only try to demangle stuff that's marked as swift
277-
if ((status != 0 || !demangled) && symName.starts_with("_$s"))
251+
if ((status != 0 || !demangled) && (symName.starts_with("$s") || symName.starts_with("_$s")))
278252
{
279253
std::string newSymName = demangle_swift_symbol(symName);
280254
if (newSymName != symName) {
281-
// std::cout << "'" << symName << "' => '" << newSymName << "'" << std::endl;
255+
//std::cout << "\t'" << symName << "' => '" << newSymName << "'" << std::endl;
282256
symName = newSymName;
283257
}
258+
} else if (symName.starts_with("_R")) {
259+
std::cout << "\tRUST NAME: '" << symName << "'" << std::endl;
284260
}
285261
free(demangled);
286262
if(!symName.empty())
@@ -612,10 +588,10 @@ int main(int argc, char* argv[]) {
612588
waitpid(swift_demangler_pid, &status, 0);
613589
if (WIFEXITED(status)) {
614590
if (WEXITSTATUS(status) != 0) {
615-
std::cerr << "swift-demangle exited with code " << WEXITSTATUS(status) << std::endl;
591+
std::cerr << "swift-demangle exited with code " << WEXITSTATUS(status) << " while shutting down" << std::endl;
616592
}
617593
} else {
618-
std::cerr << "swift-demangle terminated abnormally" << std::endl;
594+
std::cerr << "swift-demangle terminated abnormally while shutting down" << std::endl;
619595
}
620596
}
621597

tools/symbol_extractor/symbolicator.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ def extract_crash_metadata(crash: str) -> dict:
1111
for line in crash.splitlines():
1212
line = line.strip()
1313

14+
# Example: "Version: 1046 (6.4.13)"
15+
if line.startswith("Version:"):
16+
match = re.match(r"Version:\s+(\d+)\s+\(([\d\.]+)\)", line)
17+
if match:
18+
app_build_number, app_version = match.groups()
1419
# Example: "OS Version: iOS 18.6.2 (22G100)"
15-
if line.startswith("OS Version:"):
20+
elif line.startswith("OS Version:"):
1621
match = re.match(r"OS Version:\s+(\w+)\s+([\d\.]+)\s+\(([^)]+)\)", line)
1722
if match:
1823
os_type, os_version, build_number = match.groups()
@@ -34,6 +39,8 @@ def extract_crash_metadata(crash: str) -> dict:
3439
"osVersion": os_version,
3540
"buildNumber": build_number,
3641
"cpuArch": cpu_arch,
42+
"appBuildNumber": app_build_number,
43+
"appVersion": app_version,
3744
}
3845

3946
def replace_redacted_in_crash_log(crash: str, sqlite_db_path: str) -> str:
@@ -48,7 +55,7 @@ def replace_redacted_in_crash_log(crash: str, sqlite_db_path: str) -> str:
4855
(?P<lib>\S+)\s+ # library name
4956
0x(?P<absaddr>[0-9a-fA-F]+)\s+ # absolute address
5057
0x(?P<baseaddr>[0-9a-fA-F]+)\s+\+\s+(?P<offset>\d+)\s+ # base + offset
51-
\(<redacted>\s+\+\s+(?P<delta>\d+)\) # (<redacted> + N)
58+
\((?P<symbol>.+)\s+\+\s+(?P<delta>\d+)\)$ # (symbol + N)
5259
""",
5360
re.VERBOSE | re.MULTILINE
5461
)
@@ -68,10 +75,15 @@ def replacer(match):
6875
LIMIT 1;
6976
"""
7077
# print("Searching for %s, %s, %s, %s" % (offset, lib, metadata["buildNumber"], metadata["cpuArch"]))
71-
cursor.execute(query, (offset, lib, metadata["buildNumber"], metadata["cpuArch"]))
78+
cursor.execute(query, (offset, lib, metadata["appBuildNumber"], metadata["cpuArch"]))
7279
result = cursor.fetchone()
7380
if result:
74-
return match.group(0).replace("<redacted>", result[0])
81+
return match.group(0).replace(match.group("symbol"), result[0])
82+
else:
83+
cursor.execute(query, (offset, lib, metadata["buildNumber"], metadata["cpuArch"]))
84+
result = cursor.fetchone()
85+
if result:
86+
return match.group(0).replace(match.group("symbol"), result[0])
7587
return match.group(0)
7688

7789
retval = frame_regex.sub(replacer, crash)

0 commit comments

Comments
 (0)