Menu

#78 Debugging does not work with references

v1.0_(example)
closed
nobody
None
5
2024-04-03
2024-03-23
No
  1. If a referenced variable is updated inside a function, the watch window will display the old value during and after executing the function. Example in screenshot.
  2. There is an error during debugging if any array is passed by reference into a function. "Variable unknown is not an array" is displayed in the output window.

Both issues are caused by not handling references in the logic that adds variables to the watch window from inside the interpreter. I made a fix to handle walking the references in the interpreter and adding the correct variable to the watch window. The references themselves are also correctly displayed as function variables.

This is the patch:

Index: Interpreter.cpp
===================================================================
--- Interpreter.cpp (revision 957)
+++ Interpreter.cpp (working copy)
@@ -588,19 +588,46 @@
 void Interpreter::watchvariable(bool doit, int i) {
    // send an event to the variable watch window to display a variable/array content
    if (doit) {
-       emit(varWinAssign(&variables, i, variables->getrecurse()));
+       int level = variables->getrecurse();
+       int varnum = i;
+       Variable* v = variables->getAt(i, level);
+       while (DataElement::getType(v->data) == T_REF) {
+           emit(varWinAssign(&variables, varnum, level));
+           varnum = v->data->intval;
+           level = v->data->level;
+           v = variables->getAt(i, level);
+       }
+       emit(varWinAssign(&variables, varnum, level));
    }
 }
 void Interpreter::watchvariable(bool doit, int i, int x, int y) {
    // send an event to the variable watch window to display aan array element's value
    if (doit) {
-       emit(varWinAssign(&variables, i, variables->getrecurse(), x ,y));
+       int level = variables->getrecurse();
+       int varnum = i;
+       Variable* v = variables->getAt(i, level);
+       while (DataElement::getType(v->data) == T_REF) {
+           emit(varWinAssign(&variables, varnum, level));
+           varnum = v->data->intval;
+           level = v->data->level;
+           v = variables->getAt(i, level);
+       }
+       emit(varWinAssign(&variables, varnum, level, x ,y));
    }
 }
 void Interpreter::watchvariable(bool doit, int i, QString k) {
    // send an event to the variable watch window to display a map element's value
    if (doit) {
-       emit(varWinAssign(&variables, i, variables->getrecurse(), k));
+       int level = variables->getrecurse();
+       int varnum = i;
+       Variable* v = variables->getAt(i, level);
+       while (DataElement::getType(v->data) == T_REF) {
+           emit(varWinAssign(&variables, varnum, level));
+           varnum = v->data->intval;
+           level = v->data->level;
+           v = variables->getAt(i, level);
+       }
+       emit(varWinAssign(&variables, varnum, level, k));
    }
 }

Discussion

  • Jim Reneau

    Jim Reneau - 2024-04-03

    Updated to source 2.0.99.9 (959)

     
  • Jim Reneau

    Jim Reneau - 2024-04-03
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.