Skip to content

Commit 5e73b93

Browse files
committed
Avoid maxBuffer by using spawnSync
1 parent 238626a commit 5e73b93

File tree

2 files changed

+53
-48
lines changed

2 files changed

+53
-48
lines changed

src/cmsis-debug-session.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,12 @@ export class CmsisDebugSession extends GDBDebugSession {
208208
throw message;
209209
});
210210

211-
this.symbolTable = new SymbolTable(args.program, args.objdump);
212-
await this.symbolTable.loadSymbols();
211+
try {
212+
this.symbolTable = new SymbolTable(args.program, args.objdump);
213+
await this.symbolTable.loadSymbols();
214+
} catch (error) {
215+
this.sendEvent(new OutputEvent(`Unable to load debug symbols: ${error.message}`));
216+
}
213217

214218
const port = await this.portScanner.findFreePort();
215219
if (!port) {

src/symbols.ts

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* SOFTWARE.
2525
*/
2626

27-
import { exec } from 'child_process';
27+
import { spawnSync } from 'child_process';
2828
import { platform, EOL } from 'os';
2929
import { dirname, normalize, basename } from 'path';
3030

@@ -78,42 +78,39 @@ export class SymbolTable {
7878
}
7979

8080
public async loadSymbols(): Promise<void> {
81-
try {
82-
const results = await this.execute();
83-
const output = results.toString();
84-
const lines = output.split(EOL);
85-
let currentFile: string | undefined = undefined;
86-
87-
for (const line of lines) {
88-
const match = line.match(SYMBOL_REGEX);
89-
if (match) {
90-
if (match[7] === 'd' && match[8] === 'f') {
91-
currentFile = match[11].trim();
92-
}
93-
const type = TYPE_MAP[match[8]];
94-
const scope = SCOPE_MAP[match[2]];
95-
let name = match[11].trim();
96-
let hidden = false;
97-
98-
if (name.startsWith('.hidden')) {
99-
name = name.substring(7).trim();
100-
hidden = true;
101-
}
102-
103-
this.symbols.push({
104-
address: parseInt(match[1], 16),
105-
type: type,
106-
scope: scope,
107-
section: match[9].trim(),
108-
length: parseInt(match[10], 16),
109-
name: name,
110-
file: scope === SymbolScope.Local ? currentFile : undefined,
111-
hidden: hidden
112-
});
81+
const results = await this.execute();
82+
const output = results.toString();
83+
const lines = output.split(EOL);
84+
let currentFile: string | undefined;
85+
86+
for (const line of lines) {
87+
const match = line.match(SYMBOL_REGEX);
88+
if (match) {
89+
if (match[7] === 'd' && match[8] === 'f') {
90+
currentFile = match[11].trim();
11391
}
92+
const type = TYPE_MAP[match[8]];
93+
const scope = SCOPE_MAP[match[2]];
94+
let name = match[11].trim();
95+
let hidden = false;
96+
97+
if (name.startsWith('.hidden')) {
98+
name = name.substring(7).trim();
99+
hidden = true;
100+
}
101+
102+
this.symbols.push({
103+
address: parseInt(match[1], 16),
104+
type: type,
105+
scope: scope,
106+
section: match[9].trim(),
107+
length: parseInt(match[10], 16),
108+
name: name,
109+
file: scope === SymbolScope.Local ? currentFile : undefined,
110+
hidden: hidden
111+
});
114112
}
115-
// tslint:disable-next-line: no-empty
116-
} catch (e) {}
113+
}
117114
}
118115

119116
public getGlobalVariables(): SymbolInformation[] {
@@ -131,20 +128,24 @@ export class SymbolTable {
131128

132129
private execute(): Promise<string> {
133130
return new Promise((resolve, reject) => {
134-
exec([
135-
this.objdump,
136-
'--syms',
137-
`"${this.program}"`
138-
].join(' '), {
139-
cwd: dirname(this.objdump),
140-
windowsHide: true
141-
}, (error: Error | null, stdout: string) => {
131+
try {
132+
const { stdout, stderr } = spawnSync(this.objdump, [
133+
'--syms',
134+
this.program
135+
], {
136+
cwd: dirname(this.objdump),
137+
windowsHide: true
138+
});
139+
140+
const error = stderr.toString('utf8');
142141
if (error) {
143-
return reject(error);
142+
return reject(new Error(error));
144143
}
145144

146-
return resolve(stdout);
147-
});
145+
resolve(stdout.toString('utf8'));
146+
} catch (error) {
147+
return reject(new Error(error));
148+
}
148149
});
149150
}
150151
}

0 commit comments

Comments
 (0)