Help needed on trace() to locate user var reference and contents #1402
Replies: 8 comments
-
Posted at 2020-04-20 by @gfwilliams
It's because Espruino uses fixed-size blocks - it's the block number: http://www.espruino.com/Internals#variable-storage
Espruino's vars are reference counted for quick garbage collection. R = number of references (from other JS vars), L = number of locks (eg. bits of Espruino internal code that have a pointer to it).
The name of the field inside the object you just inspected.
However
Look down the hierarchy of the trace (eg, the lines above) to figure out what the function was, then you can write the code to reference it. If you paste the whole trace up I could show you. But the issue here is you've got a very large function that's been uploaded. As above just searching your code for |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-04-22 by Robin Tue 2020.04.21 In three parts as each too large for one forum post. Thank you @gfwilliams for the identification of References and Locks. After looking up several web pages, I thought I'd surprise myself, with a solution on successful traversing the trace object with code. Well it did indeed become a surprise, but also a big disappointment. This code file is an attempt to generate the errors under my control and is not the code file that has issues. It reproduces close enough, that I am able to create working functions that I hope are small enough to paste into the other module to locate it's issues.
I would expect that each name be different, should the attribute be specific to a function. In the attached trace, there is #110 #74 #437 #358 #328 etc. which so far point to both strings and flat strings, so as I see it, isn't specific as in one to one with a particular function, specific to Strings or to FlatStrings or an object type. While I understand the gist of your response indicated to use the information gathered and then peruse the source code file to see the original source. I get that, but what is needed is to inspect the block as referenced by the block number, such as #531 while in memory. I'm attempting to build small functions to perform that task inside the WebIDE during run time, and not by human visual means. re: Q1: Why does the refrence value change and what is that value exactly? I understood that, what I should have clarified is how do I get to #531 when I am able to locate in the trace block #348 using text: '\xFFcod' which I have now identified isn't a good technique either as there are many instances of '\xFFcod'
But that only works on completion of first upload, as performing a subsequent trace on that block by name results in a unique new block number. Such as:
My guess is that the act of typing in the command is assigned a new block as it is uploaded such that Espruino is then knows what to do, e.g. modify the linked list after parsing and deciding if in fact it is a valid block. Still searching for a better example, but couldn't find one in the haste to post this. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-04-22 by Robin Part 2 But therein lies the problem. How to get at the block (#438) that contains what we are after when we only have reference to the String name (#428) that is the actual text identifying it's function.
In our cleaned up version, it is block #438 after locating #428
Using:
I learned that the global variable is just a Javascript Object after:
then creating an array that I can manipulate and assigning the contents of the global variable to the array object just created:
Using properties of that object, I am able to extract the data for a var I defined:
That checks out and as expected. > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries Attempting to iterate using the entries method is fraught with errors:
Although I was able to iterate over the history array using just indexers into the array, the rest has become the big surprise, and not what I thought I could get done. For the curious onlookers: Please heed the code file internal Warning and read everything before uploading
Better yet, beginners please don't upload at all!Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-04-22 by Robin Part 3 Just noticed this, that wasn't apparent as I typed the posts. Traversing backwards, I see the large code chunk is part of a known function named 'dl()' In the history, which I believe is what is uploaded before parsing as block #440 and then again as the string identifier in memory at block #428 that points to the function configured in memory as block #438, made of other linked blocks, it's ID of #437 and the function as a FlatString object at #637
What I would like to do is be able to traverse the trace results and get at block #637 but not knowing the actual function by name. Maybe a traverse the results and list the blocks containing more than 'x' (?ten?) blocks might be a good start. As typeof trace() returns ="undefined" I'm starting to wonder if it is in fact just a function that prints to the console, values that are extracted under some rules, as I expected "object" to be returned. > 'If you paste the whole trace up I could show you' So, yes please, a small sample to get going would be appreciated.
Also, found this unproven snippet: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-04-22 by @gfwilliams
I don't think you're understanding -
Again, I don't think you really took in what I said previously. You just defined a String with contents If you want history, you look at:
And go back down the trace output, using the name in the lines above:
Espruino doesn't support that syntax.
A few lines earlier you did
Yes, it prints.
Ok, so there's what I mentioned above with So let's say you're after
So now, you just work back. You can see
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-04-23 by Robin Wed 2020.04.22 Thanks for the answers above, still working through that. Would you please provide the link to garbage collecting entry point source, specifically seeking the rules determining when GC should occur, and what governs the order that history is reduced. I should then be able to use VSCode to navigate the internal functions. Thank you. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-04-23 by @gfwilliams Looks like GitHub is down right now so I can't point you to the exact points, but it's easy enough to search for Specifically:
History is cleared line-by-line, oldest first, when memory actually completely runs out. I think it may also be removed completely if a Flat String allocation is required and then fails. I really think you're going down a rabbit hole here when I don't think there's any need though. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-04-23 by Robin Thr 2020.04.23 Thank you for the function name, that should suffice.
I'd like to see what should be going on and when, before I ask a ton of unnecessary questions. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2020-04-19 by Robin
Sun 2020.04.19
I need to monitor the number of blocks a user var requires in memory. I need to extract or view
the contents of that var, using the reference that trace provides.
Using trace,
I'm able to view it's ID and space utilized:
#348
and#531
What I am after is how to get the value
#531
and it's contents. It takes up 137 blocks.Pairing down, now that I know the ID
\xFFcod
of the varBut a curious response emerges, the reference value changes from
#348
to#990
, but it is the same location in memory?Q1: Why does the refrence value change and what is that value exactly? Q2: Wht is the meaning of 'r0' and 'l1' and compared to 'r1' and 'l2' ?
Using getSizeOf()
Q3: What is the 'name' attribute refereing to? Q4: What are the return values here as they don't seem to be the actual blocks as returned in a trace request? Q5: How to get the value
#531
and it's contents using trace() ?Thank you in advance. . . .
Beta Was this translation helpful? Give feedback.
All reactions