Skip to content

Commit db61a69

Browse files
authored
Fixes/improvements to crash call stacks. (#12355)
* Fixes/improvements to crash call stacks.
1 parent 9a5f24f commit db61a69

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

Extension/src/LanguageServer/extension.ts

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,11 @@ function handleMacCrashFileRead(err: NodeJS.ErrnoException | undefined | null, d
10661066
const dynamicLoadErrorEnd: string = "\n\n";
10671067
const endDynamicLoadError: number = data.indexOf(dynamicLoadErrorEnd, startDynamicLoadError);
10681068
if (endDynamicLoadError >= 0) {
1069-
dynamicLoadError = data.substring(startDynamicLoadError, endDynamicLoadError) + "\n\n";
1069+
dynamicLoadError = data.substring(startDynamicLoadError, endDynamicLoadError);
1070+
if (dynamicLoadError.includes("/")) {
1071+
dynamicLoadError = "<dyld error>";
1072+
}
1073+
dynamicLoadError += "\n\n";
10701074
}
10711075
}
10721076

@@ -1117,7 +1121,11 @@ function handleMacCrashFileRead(err: NodeJS.ErrnoException | undefined | null, d
11171121
if (!line.includes(".dylib") && !line.includes("???")) {
11181122
line = line.replace(/^\d+\s+/, ""); // Remove <numbers><spaces> from the start of the line.
11191123
line = line.replace(/std::__1::/g, "std::"); // __1:: is not helpful.
1120-
data += line + "\n";
1124+
if (line.includes("/")) {
1125+
data += "<path>\n";
1126+
} else {
1127+
data += line + "\n";
1128+
}
11211129
}
11221130
});
11231131
data = data.trimRight();
@@ -1149,18 +1157,27 @@ async function handleCrashFileRead(crashDirectory: string, crashFile: string, cr
11491157
const startStr: string = isMac ? " _" : "<";
11501158
const offsetStr: string = isMac ? " + " : "+";
11511159
const endOffsetStr: string = isMac ? " " : " <";
1152-
const dotStr: string = "…";
1153-
const signalType: string = lines[0];
1160+
const dotStr: string = "\n…";
1161+
let signalType: string;
1162+
if (lines[0].startsWith("SIG")) {
1163+
signalType = lines[0];
1164+
} else {
1165+
// The signal type may fail to be written.
1166+
signalType = "SIG-??\n"; // Intentionally different from SIG-? from cpptools.
1167+
}
11541168
let crashCallStack: string = "";
1155-
for (let lineNum: number = 2; lineNum < lines.length - 3; ++lineNum) { // skip first/last lines
1156-
crashCallStack += "\n";
1157-
addressData += "\n";
1169+
let validFrameFound: boolean = false;
1170+
for (let lineNum: number = 0; lineNum < lines.length - 3; ++lineNum) { // skip last lines
11581171
const line: string = lines[lineNum];
11591172
const startPos: number = line.indexOf(startStr);
11601173
if (startPos === -1 || line[startPos + (isMac ? 1 : 4)] === "+") {
1174+
if (!validFrameFound) {
1175+
continue; // Skip extra … at the start.
1176+
}
11611177
crashCallStack += dotStr;
11621178
const startAddressPos: number = line.indexOf("0x");
11631179
const endAddressPos: number = line.indexOf(endOffsetStr, startAddressPos + 2);
1180+
addressData += "\n";
11641181
if (startAddressPos === -1 || endAddressPos === -1 || startAddressPos >= endAddressPos) {
11651182
addressData += "Unexpected offset";
11661183
} else {
@@ -1170,17 +1187,18 @@ async function handleCrashFileRead(crashDirectory: string, crashFile: string, cr
11701187
}
11711188
const offsetPos: number = line.indexOf(offsetStr, startPos + startStr.length);
11721189
if (offsetPos === -1) {
1173-
crashCallStack += "Missing offsetStr";
1190+
crashCallStack += "\nMissing offsetStr";
1191+
addressData += "\n";
11741192
continue; // unexpected
11751193
}
11761194
const startPos2: number = startPos + 1;
11771195
let funcStr: string = line.substring(startPos2, offsetPos);
1178-
if (filtPath) {
1196+
if (filtPath && filtPath.length !== 0) {
11791197
let ret: util.ProcessReturnType | undefined = await util.spawnChildProcess(filtPath, ["--no-strip-underscore", funcStr], undefined, true).catch(logAndReturn.undefined);
11801198
if (ret?.output === funcStr) {
11811199
ret = await util.spawnChildProcess(filtPath, [funcStr], undefined, true).catch(logAndReturn.undefined);
11821200
}
1183-
if (ret !== undefined) {
1201+
if (ret !== undefined && ret.succeeded) {
11841202
funcStr = ret.output;
11851203
funcStr = funcStr.replace(/std::(?:__1|__cxx11)/g, "std"); // simplify std namespaces.
11861204
funcStr = funcStr.replace(/std::basic_/g, "std::");
@@ -1190,10 +1208,21 @@ async function handleCrashFileRead(crashDirectory: string, crashFile: string, cr
11901208
funcStr = funcStr.replace(/, std::allocator<std::string>/g, "");
11911209
}
11921210
}
1211+
if (funcStr.includes("/")) {
1212+
funcStr = "<func>";
1213+
} else if (!validFrameFound && (funcStr.startsWith("crash_handler(") || funcStr.startsWith("_sigtramp"))) {
1214+
continue; // Skip these on early frames.
1215+
}
1216+
validFrameFound = true;
1217+
crashCallStack += "\n";
1218+
addressData += "\n";
11931219
crashCallStack += funcStr + offsetStr;
11941220
const offsetPos2: number = offsetPos + offsetStr.length;
11951221
if (isMac) {
1196-
crashCallStack += line.substring(offsetPos2);
1222+
const pendingOffset: string = line.substring(offsetPos2);
1223+
if (!pendingOffset.includes("/")) {
1224+
crashCallStack += pendingOffset;
1225+
}
11971226
const startAddressPos: number = line.indexOf("0x");
11981227
if (startAddressPos === -1 || startAddressPos >= startPos) {
11991228
// unexpected
@@ -1207,7 +1236,10 @@ async function handleCrashFileRead(crashDirectory: string, crashFile: string, cr
12071236
crashCallStack += "<Missing > >";
12081237
continue; // unexpected
12091238
}
1210-
crashCallStack += line.substring(offsetPos2, endPos);
1239+
const pendingOffset: string = line.substring(offsetPos2, endPos);
1240+
if (!pendingOffset.includes("/")) {
1241+
crashCallStack += pendingOffset;
1242+
}
12111243
}
12121244
}
12131245

0 commit comments

Comments
 (0)