Skip to content

Commit

Permalink
fix: sym file lookup (#107)
Browse files Browse the repository at this point in the history
* fix: sym file lookup

* fix: shared object matching bug
  • Loading branch information
bobbyg603 authored Apr 16, 2024
1 parent 04148ee commit e4995a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
11 changes: 9 additions & 2 deletions bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ import { CommandLineDefinition, argDefinitions, usageDefinitions } from './comma
const nodeDumpSyms = (await import('node-dump-syms')).dumpSyms;
symbolFilePaths = symbolFilePaths.map(file => {
console.log(`Dumping syms for ${file}...`);
const fileNoExt = file.split('.')[0]; // Handle macos .app.dSYM etc.
const symFile = join(tmpDir, `${basename(fileNoExt)}.sym`);
const symFile = join(tmpDir, `${getSymFileBaseName(file)}.sym`);
nodeDumpSyms(file, symFile);
return symFile;
});
Expand Down Expand Up @@ -179,6 +178,14 @@ async function getCommandLineOptions(argDefinitions: Array<CommandLineDefinition
version
}
}
// The rust-minidump-stackwalker symbol lookup implementation removes some extensions from the sym file name for symbol lookups.
// This is a bit of a mystery and is subject to change when we learn more about how it works.
// For now, remove any non .so extension in the sym file's base name to satisfy the minidump-stackwalker symbol lookup.
function getSymFileBaseName(file: string): string {
const linuxSoExtensionPattern = /\.so\.?.*$/gm;
const fileNoExt = file.split('.')[0];
return linuxSoExtensionPattern.test(file) ? basename(file) : basename(fileNoExt);
}

function logHelpAndExit() {
const help = commandLineUsage(usageDefinitions);
Expand Down
2 changes: 1 addition & 1 deletion spec/sym.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('getSymFileInfo', () => {
});

it('should get module name for file with line feeds', async () => {
const expected = 'libc++_shared';
const expected = 'libc++_shared.so';

const { moduleName } = await getSymFileInfo('./spec/support/android.sym');

Expand Down
14 changes: 9 additions & 5 deletions src/sym.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function getSymFileInfo(path: string): Promise<{ dbgId: string, mod
const matches = Array.from(firstLine?.matchAll(/([0-9a-fA-F]{33,34})\s+(.*)$/gm));
const dbgId = matches?.at(0)?.at(1) || '';
const moduleNameWithExt = matches?.at(0)?.at(2) || '';
const moduleName = removeNonWindowsExtensions(moduleNameWithExt);
const moduleName = removeIgnoredExtensions(moduleNameWithExt);
return {
dbgId,
moduleName
Expand All @@ -20,12 +20,16 @@ export async function getSymFileInfo(path: string): Promise<{ dbgId: string, mod
}
}

function removeNonWindowsExtensions(moduleName: string): string {
const windowsExtensions = ['.dll', '.pdb', '.exe'];
// The rust-minidump-stackwalker symbol lookup implementation removes some extensions from the module name for symbol lookups.
// This is a bit of a mystery and is subject to change when we learn more about how it works.
// For now, remove some module name extensions to satisfy the minidump-stackwalker symbol lookup.
function removeIgnoredExtensions(moduleName: string): string {
// We've seen .pdb, .so, .so.0, and .so.6 in the module lookup
const ignoredExtensions = [/\.pdb$/gm, /\.so\.?.*$/gm];

if (windowsExtensions.some(ext => moduleName.endsWith(ext))) {
if (ignoredExtensions.some((regex) => regex.test(moduleName))) {
return moduleName;
}

return moduleName.split('.')[0];
}

0 comments on commit e4995a4

Please sign in to comment.