diff --git a/uppsrc/ide/Debuggers/Gdb_MI2.cpp b/uppsrc/ide/Debuggers/Gdb_MI2.cpp index 69379c414..a2dd694f0 100644 --- a/uppsrc/ide/Debuggers/Gdb_MI2.cpp +++ b/uppsrc/ide/Debuggers/Gdb_MI2.cpp @@ -992,10 +992,11 @@ void Gdb_MI2::SyncLocals() // simplify batch for(int iLoc = 0; iLoc < localVars.GetCount(); iLoc++) { - while(localVars[iLoc].Simplify()) + VarItem &v = localVars[iLoc]; + while(v.Simplify()) RaiseIfStop(); - VarItem &v = localVars[iLoc]; + localExpressions.Set(iLoc, v.evaluableExpression); localValues[iLoc] = v.value; { GuiLock __; @@ -1070,7 +1071,10 @@ void Gdb_MI2::SyncLocals(Vector localVars) { if(localVars[iLoc].Simplify()) { - locals.Set(iLoc, 1, localVars[iLoc].value); + VarItem &v = localVars[iLoc]; + localExpressions.Set(iLoc, v.evaluableExpression); + localValues[iLoc] = v.value; + locals.Set(iLoc, 1, v.value); SyncAutos(); timeCallback.Set(100, THISBACK1(SyncLocals, localVars)); return; @@ -1078,7 +1082,12 @@ void Gdb_MI2::SyncLocals(Vector localVars) } for(int iLoc = 0; iLoc < localVars.GetCount(); iLoc++) - locals.Set(iLoc, 1, localVars[iLoc].value); + { + VarItem &v = localVars[iLoc]; + localExpressions.Set(iLoc, v.evaluableExpression); + localValues[iLoc] = v.value; + locals.Set(iLoc, 1, v.value); + } // when finished, mark changed values MarkChanged(prev, locals); @@ -1136,11 +1145,12 @@ void Gdb_MI2::SyncThis() for(int iVar = 0; iVar < children.GetCount(); iVar++) { RaiseIfStop(); - while(children[iVar].Simplify()) - RaiseIfStop(); VarItem &v = children[iVar]; + while(v.Simplify()) + RaiseIfStop(); + thisExpressions.Set(iVar, v.evaluableExpression); thisValues[iVar] = v.value; { GuiLock __; @@ -1203,9 +1213,12 @@ void Gdb_MI2::SyncThis(Vector children) // simplify batch for(int iVar = 0; iVar < children.GetCount(); iVar++) { - if(children[iVar].Simplify()) + VarItem &v = children[iVar]; + if(v.Simplify()) { - members.Set(iVar, 1, children[iVar].value); + thisExpressions.Set(iVar, v.evaluableExpression); + thisValues[iVar] = v.value; + members.Set(iVar, 1, v.value); SyncAutos(); timeCallback.Set(100, THISBACK1(SyncThis, children)); return; @@ -1306,11 +1319,12 @@ void Gdb_MI2::SyncWatches() for(int iWatch = 0; iWatch < watchesVars.GetCount(); iWatch++) { RaiseIfStop(); - while(watchesVars[iWatch].Simplify()) + + VarItem &v = watchesVars[iWatch]; + while(v.Simplify()) RaiseIfStop(); - VarItem &v = watchesVars[iWatch]; - + watchesExpressions.Set(iWatch, v.evaluableExpression); watchesValues[iWatch] = v.value; { GuiLock __; @@ -1360,14 +1374,22 @@ void Gdb_MI2::SyncWatches(Vector watchesVars) { if(watchesVars[iWatch].Simplify()) { - watches.Set(iWatch, 1, watchesVars[iWatch].value); + VarItem &v = watchesVars[iWatch]; + watchesExpressions.Set(iWatch, v.evaluableExpression); + watchesValues[iWatch] = v.value; + watches.Set(iWatch, 1, v.value); timeCallback.Set(100, THISBACK1(SyncWatches, watchesVars)); return; } } for(int iWatch = 0; iWatch < watchesVars.GetCount(); iWatch++) - watches.Set(iWatch, 1, watchesVars[iWatch].value); + { + VarItem &v = watchesVars[iWatch]; + watchesExpressions.Set(iWatch, v.evaluableExpression); + watchesValues[iWatch] = v.value; + watches.Set(iWatch, 1, v.value); + } // when finished, mark changed values MarkChanged(prev, watches); diff --git a/uppsrc/ide/Debuggers/UppSimplifiers.icpp b/uppsrc/ide/Debuggers/UppSimplifiers.icpp index 449d73f67..40d4f0a3a 100644 --- a/uppsrc/ide/Debuggers/UppSimplifiers.icpp +++ b/uppsrc/ide/Debuggers/UppSimplifiers.icpp @@ -33,7 +33,7 @@ static int UppStringSimplify(VarItem &varItem, int step) } u; // see Upp::String code for how it works.... - MIValue val = varItem.EvaluateExpression(varItem.evaluableExpression + "." + "chr"); + MIValue val = varItem.EvaluateExpression("(" + varItem.evaluableExpression + ")." + "chr"); if(!val.IsString()) return 0; String chrs = val.ToString(); @@ -49,7 +49,7 @@ static int UppStringSimplify(VarItem &varItem, int step) else { dword len = u.w[LLEN]; - MIValue val = varItem.EvaluateExpression(varItem.evaluableExpression + "." + "ptr[0]@" + FormatInt(len)); + MIValue val = varItem.EvaluateExpression("(" + varItem.evaluableExpression + ").ptr[0]@" + FormatInt(len)); if(!val.IsString()) return 0; s = val.ToString(); @@ -433,6 +433,42 @@ static int UppIndexSimplify(VarItem &varItem, int step) return step + 2; } +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +static int UppOneSimplify(VarItem &varItem, int step) +{ + // setup item type + varItem.kind = VarItem::COMPLEX; + + // if we're just doing first scan phase, signal that we need further evaluation later +#ifdef EVALDEEP + if(!step) + // next step is 1 + return 1; +#else + varItem.value = placeHolder; + return 0; +#endif + + // de-reference and forward simplify + MIValue val = varItem.EvaluateExpression(varItem.evaluableExpression + "." + "ptr"); + if(val.IsError() || !val.IsString()) + { + varItem.value = "Upp::One<> = "; + return 0; + } + String ptr = val.ToString(); + if(ptr == "0x0") + { + varItem.value = "Upp::One<> = "; + return 0; + } + + // replace variable with de-referenced one + VarItem vItem(&varItem.Debugger(), "*" + varItem.evaluableExpression + "." + "ptr"); + varItem = vItem; + return varItem.GetSimplifyStep(); +} + // Register the simplifiers REGISTERSIMPLIFIER("Upp::String" , UppStringSimplify); REGISTERSIMPLIFIER("Upp::Vector<" , UppVectorSimplify); @@ -440,3 +476,4 @@ REGISTERSIMPLIFIER("Upp::VectorMap<" , UppVectorMapSimplify); REGISTERSIMPLIFIER("Upp::Array<" , UppArraySimplify); REGISTERSIMPLIFIER("Upp::ArrayMap<" , UppArrayMapSimplify); REGISTERSIMPLIFIER("Upp::Index<" , UppIndexSimplify); +REGISTERSIMPLIFIER("Upp::One<" , UppOneSimplify); diff --git a/uppsrc/ide/Debuggers/VarItem.h b/uppsrc/ide/Debuggers/VarItem.h index e210f044a..73b5d5728 100644 --- a/uppsrc/ide/Debuggers/VarItem.h +++ b/uppsrc/ide/Debuggers/VarItem.h @@ -51,7 +51,7 @@ class VarItem : Moveable // number of items for array and maps int items; - + // check if value contains an error bool IsEmpty(void) const { return empty; } bool operator!(void) const { return IsEmpty(); } @@ -68,6 +68,9 @@ class VarItem : Moveable // deep simplify known types bool Simplify(void); + + // get next simplify step + int GetSimplifyStep(void) { return simplifyStep; } // constructors VarItem(Gdb_MI2 *dbg);