Skip to content

Commit f571ce4

Browse files
committed
fix ENOBUF when dump symbol table
1 parent 43afe3c commit f571ce4

1 file changed

Lines changed: 21 additions & 58 deletions

File tree

src/EIDEProjectExplorer.ts

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
18421842
dispType = 'show_all';
18431843
}
18441844

1845-
return new Promise((resolve) => {
1845+
return new Promise(async (resolve) => {
18461846

18471847
const uid = new File(uri.fsPath).noSuffixName;
18481848
const prj = this.getProjectByUid(uid);
@@ -1958,7 +1958,26 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
19581958
throw new Error(`Not found elf tool: '${elftool}' !`);
19591959
}
19601960

1961-
let textLines = child_process.execFileSync(elftool, elfcmds).toString().split(/\r\n|\n/);
1961+
// Don't use 'child_process.execFileSync' because a huge file
1962+
// will cause an ENOBUF Error.
1963+
const doReadSymbolLines = (toolpath: string, cmds: string[]): Promise<string[]> => {
1964+
return new Promise((resolve) => {
1965+
const executable = new ExeFile();
1966+
const results: string[] = [];
1967+
executable.on('line', (line) => {
1968+
results.push(line);
1969+
});
1970+
executable.on('close', () => {
1971+
resolve(results);
1972+
});
1973+
executable.on('error', (err) => {
1974+
GlobalEvent.log_warn(err);
1975+
});
1976+
executable.Run(toolpath, cmds);
1977+
});
1978+
};
1979+
1980+
let textLines = await doReadSymbolLines(elftool, elfcmds);
19621981

19631982
// filter lines
19641983
// notes:
@@ -2160,62 +2179,6 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
21602179

21612180
resolve(outputLines.join(os.EOL));
21622181

2163-
//
2164-
// @deprecated Because this lib is too slow
2165-
//
2166-
2167-
// let maxLen = 0;
2168-
// for (const l of headerLines) {
2169-
// if (l.length > maxLen) maxLen = l.length;
2170-
// }
2171-
2172-
// for (let i = 1; i < headerLines.length; i++) {
2173-
// headerLines[i] = headerLines[i].padEnd(maxLen);
2174-
// }
2175-
2176-
// const tableCfg: TxtTable.TableUserConfig = {
2177-
2178-
// header: {
2179-
// alignment: 'center',
2180-
// content: headerLines.join('\n')
2181-
// },
2182-
2183-
// drawHorizontalLine: (idx, rowCount) => idx <= 2 || idx === rowCount,
2184-
2185-
// columns: {
2186-
// 0: { width: col_addr_maxLen },
2187-
// 1: { width: col_size_maxLen },
2188-
// 2: { width: col_type_maxLen },
2189-
// 3: { width: col_name_maxLen },
2190-
// 4: { width: col_loca_maxLen }
2191-
// },
2192-
2193-
// border: {
2194-
// topBody: `─`,
2195-
// topJoin: `┬`,
2196-
// topLeft: `┌`,
2197-
// topRight: `┐`,
2198-
2199-
// bottomBody: `─`,
2200-
// bottomJoin: `┴`,
2201-
// bottomLeft: `└`,
2202-
// bottomRight: `┘`,
2203-
2204-
// bodyLeft: `│`,
2205-
// bodyRight: `│`,
2206-
// bodyJoin: `│`,
2207-
2208-
// joinBody: `─`,
2209-
// joinLeft: `├`,
2210-
// joinRight: `┤`,
2211-
// joinJoin: `┼`
2212-
// }
2213-
// };
2214-
2215-
// const result = TxtTable.table(resultLines, tableCfg);
2216-
2217-
// resolve(result);
2218-
22192182
} catch (error) {
22202183
resolve('Error: ' + (<Error>error).message);
22212184
}

0 commit comments

Comments
 (0)