Skip to content

Commit 5c1fbd9

Browse files
committed
solve the problem of failed parsing of std containers
1 parent d840528 commit 5c1fbd9

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Versioning].
2121
- New `frameFilters` option for GDB that allows using custom frame filters,
2222
enabled by default ([@JacquesLucke])
2323
- Suppress error for hover as the user may just play with the mouse ([@oltolm]).
24+
- solve the problem of failed parsing of containers ([@henryriley0])
2425

2526
## [0.27.0] - 2024-02-07
2627

src/backend/gdb_expansion.ts

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { VariableObject } from "./backend";
22
import { MINode } from "./mi_parse";
33

4-
const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-]*|\[\d+\])\s*=\s*/;
5-
const variableRegex = /^[a-zA-Z_\-][a-zA-Z0-9_\-]*/;
4+
const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-<> :(),]*|\[\d+\])\s*=\s*/;
5+
const variableRegex = /^[a-zA-Z_\-\'\(][a-zA-Z0-9_\-\>\ \\\'\)\:]*/;
66
const errorRegex = /^\<.+?\>/;
77
const referenceStringRegex = /^(0x[0-9a-fA-F]+\s*)"/;
88
const referenceRegex = /^0x[0-9a-fA-F]+/;
@@ -105,14 +105,18 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio
105105
const eqPos = value.indexOf("=");
106106
const newValPos1 = value.indexOf("{");
107107
const newValPos2 = value.indexOf(",");
108+
const newValPos3 = value.indexOf("}");
108109
let newValPos = newValPos1;
109110
if (newValPos2 != -1 && newValPos2 < newValPos1)
110111
newValPos = newValPos2;
111-
if (newValPos != -1 && eqPos > newValPos || eqPos == -1) { // is value list
112+
if (newValPos != -1 && eqPos > newValPos || eqPos == -1 || eqPos > newValPos3 || value.startsWith("std::")) { // is value list
112113
const values = [];
113114
stack.push("[0]");
114115
let val = parseValue();
115116
stack.pop();
117+
if(typeof val == "string" && val.endsWith('>')){
118+
val = val.substring(0, val.length - 2);
119+
}
116120
values.push(createValue("[0]", val));
117121
const remaining = value;
118122
let i = 0;
@@ -191,18 +195,30 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio
191195
return parseCString();
192196
else if (value[0] == '{')
193197
return parseTupleOrList();
198+
else if(value.startsWith("std::")){
199+
const eqPos = value.indexOf("=");
200+
value = value.substring(eqPos + 2);
201+
return parseValue();
202+
}
194203
else
195204
return parsePrimitive();
196205
};
197206

198207
parseResult = (pushToStack: boolean = false) => {
208+
if (value[0] == '<') {
209+
value = value.substring(1).trim();
210+
}
199211
value = value.trim();
200212
value = value.replace(/^static /, "");
201213
const variableMatch = resultRegex.exec(value);
202214
if (!variableMatch)
203215
return undefined;
204216
value = value.substring(variableMatch[0].length).trim();
205-
const name = variable = variableMatch[1];
217+
let name = variable = variableMatch[1].trim();
218+
const tmpName = name.split(" ");
219+
if(tmpName.length > 1 && !name.includes("anonymous union") && !name.includes(',')){
220+
name = tmpName[tmpName.length - 1];
221+
}
206222
if (pushToStack)
207223
stack.push(variable);
208224
const val = parseValue();
@@ -231,6 +247,15 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio
231247
ref = variableCreate(getNamespace(name));
232248
val = "...";
233249
}
250+
value = value.trim();
251+
if (value[0] == ','){
252+
let tmp = value;
253+
tmp = tmp.substring(1).trim();
254+
if(tmp.startsWith("<No data fields>")){
255+
value = tmp = tmp.substring("<No data fields>".length);
256+
}
257+
}
258+
234259
return {
235260
name: name,
236261
value: val,

src/mibase.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,14 @@ export class MI2DebugSession extends DebugSession {
537537
// TODO: this evaluates on an (effectively) unknown thread for multithreaded programs.
538538
variable = await this.miDebugger.evalExpression(JSON.stringify(id), 0, 0);
539539
try {
540-
let expanded = expandValue(createVariable, variable.result("value"), id, variable);
540+
let variableValue = variable.result("value");
541+
const pattern = /'([^']*)' <repeats (\d+) times>/g;
542+
variableValue = variableValue.replace(pattern, (_: any, char: string, count: string) => {
543+
const repeatCount = parseInt(count, 10) + 1;
544+
const repeatedArray = Array(repeatCount).fill(char);
545+
return `{${repeatedArray.map(item => `'${item}'`).join(', ')}}`;
546+
});
547+
let expanded = expandValue(createVariable, variableValue, id, variable);
541548
if (!expanded) {
542549
this.sendErrorResponse(response, 2, `Could not expand variable`);
543550
} else {
@@ -715,12 +722,7 @@ export class MI2DebugSession extends DebugSession {
715722
};
716723
this.sendResponse(response);
717724
}, msg => {
718-
if (args.context == "hover") {
719-
// suppress error for hover as the user may just play with the mouse
720-
this.sendResponse(response);
721-
} else {
722-
this.sendErrorResponse(response, 7, msg.toString());
723-
}
725+
this.sendErrorResponse(response, 7, msg.toString());
724726
});
725727
} else {
726728
this.miDebugger.sendUserInput(args.expression, threadId, level).then(output => {

0 commit comments

Comments
 (0)