diff --git a/src/backend/gdb_expansion.ts b/src/backend/gdb_expansion.ts index bdd22dc..f383a19 100644 --- a/src/backend/gdb_expansion.ts +++ b/src/backend/gdb_expansion.ts @@ -9,7 +9,7 @@ const referenceRegexQt = /^(0x[0-9a-fA-F]+)([\])/ const cppReferenceRegex = /^@0x[0-9a-fA-F]+/; const nullpointerRegex = /^0x0+\b/; const charRegex = /^(\d+) ['"]/; -const numberRegex = /^\d+(\.\d+)?(e-\d+)?/; +const numberRegex = /^(-)?\d+(\.\d+)?(e-\d+)?/; const pointerCombineChar = "."; const nullTupleRegex = /^(0x[0-9a-fA-F]+)}/; @@ -96,10 +96,15 @@ function writeLogToFile(log, filePath) { } } -export function expandValue(variableCreate: Function, value: string, root: string = "", extra: any = undefined): any { - addToLogQueue("xh++++++++++++++:expandValue=====xxxx1", filePath); - // addToLogQueue(`xh++++++++++++++:expandValue=====xxxx2 ${value}: ${JSON.stringify(extra)}`, filePath); +export function expandValue(variableCreate: Function, value: string, root: string = "", extra: any = undefined): any { + addToLogQueue("debug.output::expandValue=====xxxx1", filePath); + addToLogQueue(`debug.output::expandValue=====xxxx2 ${value}: ${JSON.stringify(extra)}`, filePath); + + let jsonVar = false; + if(value.indexOf("=")!=-1){ + jsonVar = true; + } const parseCString = () => { value = value.trim(); if (value[0] != '"' && value[0] != '\'') @@ -160,6 +165,9 @@ export function expandValue(variableCreate: Function, value: string, root: strin //解析字典,json const parseTupleOrList = () => { + + addToLogQueue(`debug.output::parseTupleOrList=====xxxx10 ${value}`, filePath); + value = value.trim(); if (value[0] != '{') return undefined; @@ -184,6 +192,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin const newValPos1 = value.indexOf("{"); const newValPos2 = value.indexOf(","); let newValPos = newValPos1; + addToLogQueue(`debug.output::parseTupleOrList=====xxxx10 ${value}:${eqPos}: ${newValPos}: ${newValPos2}`, filePath); if (newValPos2 != -1 && newValPos2 < newValPos1){ newValPos = newValPos2; @@ -237,6 +246,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin }; const parsePrimitive = () => { + addToLogQueue(`debug.output::parsePrimitive=====xxxx20 ${value}`, filePath); let primitive: any; let match; @@ -286,18 +296,29 @@ export function expandValue(variableCreate: Function, value: string, root: strin parseValue = () => { value = value.trim(); + addToLogQueue(`debug.output::parseValue=====xxxx3 ${value}`, filePath); + if (value[0] == '"'){ //解析字符串 return parseCString(); } else if (value[0] == '{'){ //解析字典 return parseTupleOrList(); } + else if(value.startsWith("std::vector of length")){ + addToLogQueue(`debug.output::parseValue=====xxxx4 ${value}`, filePath); + const eqPos = value.indexOf("="); + value = value.substr(eqPos).trim(); + addToLogQueue(`debug.output::parseValue=====xxxx5 ${value}`, filePath); + return parseValue(); + } else{ return parsePrimitive(); } }; parseResult = (pushToStack: boolean = false) => { + addToLogQueue(`debug.output::parseResult=====xxxx30 ${value}`, filePath); + value = value.trim(); const variableMatch = resultRegex.exec(value); if (!variableMatch) @@ -325,6 +346,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin createValue = (name, val) => { let ref = 0; let evaluateName; + addToLogQueue(`debug.output::parseResult=====xxxx40 ${value}`, filePath); if (typeof val == "object") { ref = variableCreate(val); @@ -358,7 +380,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin var tmp = value tmp = tmp.substr(1).trim(); tmp = tmp.trim(); - if(tmp[0] == '{'){ + if(tmp[0] == '{' && jsonVar == true){ tmp = ",anonymous union = " + tmp; value = tmp; }