Skip to content

Commit f0a9e24

Browse files
committed
Remove charset detection and utf8 decoding, extend octal transform to sequences
Signed-off-by: Jens Reinecke <[email protected]>
1 parent a5eca80 commit f0a9e24

File tree

2 files changed

+7
-65
lines changed

2 files changed

+7
-65
lines changed

src/MIParser.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*********************************************************************/
1010
import { Readable } from 'stream';
1111
import { IGDBBackend } from './types/gdb';
12-
import * as utf8 from 'utf8';
1312
import { NamedLogger } from './namedLogger';
1413

1514
interface Command {
@@ -144,12 +143,17 @@ export class MIParser {
144143

145144
let cstring = '';
146145
let octal = '';
146+
let octalSequence: number[] = [];
147147
mainloop: for (c = this.next(); c; c = this.next()) {
148148
if (octal) {
149149
octal += c;
150150
if (octal.length == 3) {
151-
cstring += String.fromCodePoint(parseInt(octal, 8));
151+
octalSequence.push(parseInt(octal, 8));
152152
octal = '';
153+
if (this.peek() !== '\\') {
154+
cstring += String.fromCodePoint(...octalSequence);
155+
octalSequence = [];
156+
}
153157
}
154158
continue;
155159
}
@@ -190,19 +194,7 @@ export class MIParser {
190194
}
191195
}
192196

193-
// Return received string without decoding if turned off.
194-
if (!this.decodeUtf8) {
195-
return cstring;
196-
}
197-
198-
try {
199-
return utf8.decode(cstring);
200-
} catch (err) {
201-
this.logger.error(
202-
`Failed to decode cstring '${cstring}'. ${JSON.stringify(err)}`
203-
);
204-
return cstring;
205-
}
197+
return cstring;
206198
}
207199

208200
protected handleString() {

src/gdb/GDBBackend.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ import { compareVersions } from '../util/compareVersions';
2828
import { isProcessActive } from '../util/processes';
2929
import { NamedLogger } from '../namedLogger';
3030

31-
// Error as returned by GDB when calling 'set charset' without argument
32-
const CHARSETS_ERROR_REGEXP =
33-
/Requires an argument. Valid arguments are (.+)\./;
34-
3531
type WriteCallback = (error: Error | null | undefined) => void;
3632

3733
export class GDBBackend extends events.EventEmitter implements IGDBBackend {
@@ -61,49 +57,6 @@ export class GDBBackend extends events.EventEmitter implements IGDBBackend {
6157
return this.varMgr;
6258
}
6359

64-
/**
65-
* Detect list of supported charsets by provoking error from GDB
66-
* which returns the list.
67-
*/
68-
private async getSupportedCharsets(): Promise<string[]> {
69-
let charsetString: string | undefined;
70-
try {
71-
// Provoke error by missing argument
72-
await this.sendGDBSet('charset');
73-
} catch (error) {
74-
const errMessage = (error as Error)?.message;
75-
if (errMessage) {
76-
const matches = CHARSETS_ERROR_REGEXP.exec(errMessage);
77-
charsetString = matches ? matches[1] : undefined;
78-
}
79-
}
80-
if (!charsetString) {
81-
return [];
82-
}
83-
const charsets = charsetString
84-
.split(',')
85-
.map((charset) => charset.trim());
86-
return charsets;
87-
}
88-
89-
/**
90-
* Detect if to apply UTF-8 decoding based on detecting available
91-
* charsets in GDB.
92-
*
93-
* Return 'false' if only CP1252 (ASCII) and 'auto' like for some
94-
* GDB variants for embedded on Windows.
95-
* Note: Strictly speaking Windows-only, but keep this method OS
96-
* agnostic to avoid potential trouble with web use-case.
97-
*/
98-
private async shouldDecodeUTF8(): Promise<boolean> {
99-
const supportedCharsets = await this.getSupportedCharsets();
100-
return !(
101-
supportedCharsets.length === 2 &&
102-
supportedCharsets.includes('CP1252') &&
103-
supportedCharsets.includes('auto')
104-
);
105-
}
106-
10760
public async spawn(
10861
requestArgs: LaunchRequestArguments | AttachRequestArguments
10962
) {
@@ -139,9 +92,6 @@ export class GDBBackend extends events.EventEmitter implements IGDBBackend {
13992
this.asyncRequestedExplicitly = !!(
14093
requestArgs.gdbAsync || requestArgs.gdbNonStop
14194
);
142-
if (!(await this.shouldDecodeUTF8())) {
143-
this.parser.decodeUtf8 = false;
144-
}
14595
await this.setNonStopMode(requestArgs.gdbNonStop);
14696
await this.setAsyncMode(requestArgs.gdbAsync);
14797
}

0 commit comments

Comments
 (0)