I’ve been trying to debug some quite complicated code I wrote, featuring calls to procedures stored in variables a.o. One of these procedures is apparently sometimes called with an unexpected parameter value, but I haven’t succeeded in discovering which other part of the software is actually calling it, and what the caller’s variable settings are. Ideally I would like to reverse the order of evaluation from where I encountered the issue, but I’m afraid that’s impossible.
What I suspect to be doable is having the caller’s variable names and values reported, perhaps the caller’s block label, or even similar data about the caller’s caller (etc.). Does anyone have tools for this kind of thing? And / or any other generally useful debugging tools? Thx!
By the way, here are mine. (not all blocks are debugging tools, but several are).
You can actually stick a pause block before the block in question, then right click the pause block, and you'll see a list of variable names that you can click on to show the watcher on stage (and to hide temporary variable watchers, just run hide variable [] with the slot empty).
Of course you can also use visible stepping to see the results of reporters, and step through the code.
What I have not figured out yet, is whether one can find the label of the current block, or its caller. Does anyone know?
How can I distinguish between local variables and variables from an outer scope, especially if a local variable bears the same name as an outer variable? (granted, I could invent tricks to find out, like changing the value of a variable and then read the values; but that may be more complicated than necessary).
Finally (for now) I would like to know if (and how) one can get to the caller of a given environment. What I tried that doesn’t work is:
Yes, this works for me - thanks! What I’ve been trying to do (and achieved now, using your suggestion) is write a block that will report the name (or label) of the procedure it’s embedded in (e.g. for debugging purposes):
Yeah, I catch your drift. What I’m ultimately trying to achieve is to write a procedure logging all variables associated with any procedures within the call stack, plus their values. I’m going to try to build that now.
Explanation and demo
Within this demo, the inner a is a separate variable from the outer a, whereas there’s only one b.
The block will detect this difference by temporarily changing the value of one variable, testing whether the “other” variable contains the same (unique) value, and finally restoring the original value(s). The warp will protect the critical section, making sure no other process is changing (any of) the variable(s).