diff --git a/CHANGELOG.md b/CHANGELOG.md index 6112a98..9320aca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/backend/gdb_expansion.ts b/src/backend/gdb_expansion.ts index 0b10e6d..5ae2d96 100644 --- a/src/backend/gdb_expansion.ts +++ b/src/backend/gdb_expansion.ts @@ -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]+/; @@ -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; @@ -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(); @@ -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("")){ + value = tmp = tmp.substring("".length); + } + } + return { name: name, value: val, diff --git a/src/mibase.ts b/src/mibase.ts index 1aa859a..7ad6bd6 100644 --- a/src/mibase.ts +++ b/src/mibase.ts @@ -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 = /'([^']*)' /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 { @@ -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 => {