Skip to content

Commit 72c8b34

Browse files
committed
Resolve the issue of parsing failure with "std::mutex repeats N times"
1 parent 4c51a66 commit 72c8b34

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/backend/gdb_expansion.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { VariableObject } from "./backend";
22
import { MINode } from "./mi_parse";
3-
const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-:\ \<\>\(\)]*|\[\d+\])\s*=\s*/;
4-
const variableRegex = /^[a-zA-Z_\-][a-zA-Z0-9_\-]*/;
3+
const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-<> :(),]*|\[\d+\])\s*=\s*/;
4+
const variableRegex = /^[a-zA-Z_\-\'\(][a-zA-Z0-9_\-\>\ \\\'\)\:]*/;
55
const errorRegex = /^\<.+?\>/;
66
const referenceStringRegex = /^(0x[0-9a-fA-F]+\s*)"/;
77
const referenceRegex = /^0x[0-9a-fA-F]+/;
@@ -104,10 +104,11 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio
104104
const eqPos = value.indexOf("=");
105105
const newValPos1 = value.indexOf("{");
106106
const newValPos2 = value.indexOf(",");
107+
const newValPos3 = value.indexOf("}");
107108
let newValPos = newValPos1;
108109
if (newValPos2 != -1 && newValPos2 < newValPos1)
109110
newValPos = newValPos2;
110-
if (newValPos != -1 && eqPos > newValPos || eqPos == -1 || value.startsWith("std::")) { // is value list
111+
if (newValPos != -1 && eqPos > newValPos || eqPos == -1 || eqPos > newValPos3 || value.startsWith("std::")) { // is value list
111112
const values = [];
112113
stack.push("[0]");
113114
let val = parseValue();
@@ -209,18 +210,20 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio
209210
value = value.trim();
210211
value = value.replace(/^static /, "");
211212
const variableMatch = resultRegex.exec(value);
212-
if (!variableMatch)
213+
if (!variableMatch){
213214
return undefined;
215+
}
214216
value = value.substring(variableMatch[0].length).trim();
215217
let name = variable = variableMatch[1].trim();
216218

217219
const tmpName = name.split(" ");
218-
if(tmpName.length > 1 && !name.includes("anonymous union")){
220+
if(tmpName.length > 1 && !name.includes("anonymous union") && !name.includes(',')){
219221
name = tmpName[tmpName.length - 1];
220222
}
221223

222224
if (pushToStack)
223225
stack.push(variable);
226+
224227
const val = parseValue();
225228
if (pushToStack)
226229
stack.pop();

src/mibase.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,15 @@ 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+
548+
let expanded = expandValue(createVariable, variableValue, id, variable);
541549
if (!expanded) {
542550
this.sendErrorResponse(response, 2, `Could not expand variable`);
543551
} else {

0 commit comments

Comments
 (0)