Skip to content

Commit

Permalink
solve the problem of failed parsing of std containers
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryRiley0 committed Sep 18, 2024
1 parent d840528 commit 5c1fbd9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Versioning].
- New `frameFilters` option for GDB that allows using custom frame filters,
enabled by default ([@JacquesLucke])
- Suppress error for hover as the user may just play with the mouse ([@oltolm]).
- solve the problem of failed parsing of containers ([@henryriley0])

## [0.27.0] - 2024-02-07

Expand Down
33 changes: 29 additions & 4 deletions src/backend/gdb_expansion.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { VariableObject } from "./backend";
import { MINode } from "./mi_parse";

const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-]*|\[\d+\])\s*=\s*/;
const variableRegex = /^[a-zA-Z_\-][a-zA-Z0-9_\-]*/;
const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-<> :(),]*|\[\d+\])\s*=\s*/;
const variableRegex = /^[a-zA-Z_\-\'\(][a-zA-Z0-9_\-\>\ \\\'\)\:]*/;
const errorRegex = /^\<.+?\>/;
const referenceStringRegex = /^(0x[0-9a-fA-F]+\s*)"/;
const referenceRegex = /^0x[0-9a-fA-F]+/;
Expand Down Expand Up @@ -105,14 +105,18 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio
const eqPos = value.indexOf("=");
const newValPos1 = value.indexOf("{");
const newValPos2 = value.indexOf(",");
const newValPos3 = value.indexOf("}");
let newValPos = newValPos1;
if (newValPos2 != -1 && newValPos2 < newValPos1)
newValPos = newValPos2;
if (newValPos != -1 && eqPos > newValPos || eqPos == -1) { // is value list
if (newValPos != -1 && eqPos > newValPos || eqPos == -1 || eqPos > newValPos3 || value.startsWith("std::")) { // is value list
const values = [];
stack.push("[0]");
let val = parseValue();
stack.pop();
if(typeof val == "string" && val.endsWith('>')){
val = val.substring(0, val.length - 2);
}
values.push(createValue("[0]", val));
const remaining = value;
let i = 0;
Expand Down Expand Up @@ -191,18 +195,30 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio
return parseCString();
else if (value[0] == '{')
return parseTupleOrList();
else if(value.startsWith("std::")){
const eqPos = value.indexOf("=");
value = value.substring(eqPos + 2);
return parseValue();
}
else
return parsePrimitive();
};

parseResult = (pushToStack: boolean = false) => {
if (value[0] == '<') {
value = value.substring(1).trim();
}
value = value.trim();
value = value.replace(/^static /, "");
const variableMatch = resultRegex.exec(value);
if (!variableMatch)
return undefined;
value = value.substring(variableMatch[0].length).trim();
const name = variable = variableMatch[1];
let name = variable = variableMatch[1].trim();
const tmpName = name.split(" ");
if(tmpName.length > 1 && !name.includes("anonymous union") && !name.includes(',')){
name = tmpName[tmpName.length - 1];
}
if (pushToStack)
stack.push(variable);
const val = parseValue();
Expand Down Expand Up @@ -231,6 +247,15 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio
ref = variableCreate(getNamespace(name));
val = "...";
}
value = value.trim();
if (value[0] == ','){
let tmp = value;
tmp = tmp.substring(1).trim();
if(tmp.startsWith("<No data fields>")){
value = tmp = tmp.substring("<No data fields>".length);
}
}

return {
name: name,
value: val,
Expand Down
16 changes: 9 additions & 7 deletions src/mibase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,14 @@ export class MI2DebugSession extends DebugSession {
// TODO: this evaluates on an (effectively) unknown thread for multithreaded programs.
variable = await this.miDebugger.evalExpression(JSON.stringify(id), 0, 0);
try {
let expanded = expandValue(createVariable, variable.result("value"), id, variable);
let variableValue = variable.result("value");
const pattern = /'([^']*)' <repeats (\d+) times>/g;
variableValue = variableValue.replace(pattern, (_: any, char: string, count: string) => {
const repeatCount = parseInt(count, 10) + 1;
const repeatedArray = Array(repeatCount).fill(char);
return `{${repeatedArray.map(item => `'${item}'`).join(', ')}}`;
});
let expanded = expandValue(createVariable, variableValue, id, variable);
if (!expanded) {
this.sendErrorResponse(response, 2, `Could not expand variable`);
} else {
Expand Down Expand Up @@ -715,12 +722,7 @@ export class MI2DebugSession extends DebugSession {
};
this.sendResponse(response);
}, msg => {
if (args.context == "hover") {
// suppress error for hover as the user may just play with the mouse
this.sendResponse(response);
} else {
this.sendErrorResponse(response, 7, msg.toString());
}
this.sendErrorResponse(response, 7, msg.toString());
});
} else {
this.miDebugger.sendUserInput(args.expression, threadId, level).then(output => {
Expand Down

0 comments on commit 5c1fbd9

Please sign in to comment.