>"The routine could maintain a path from root pointer to object (easily done on the recursion stack) so that it's reported along with matches."
Yes, it definitely could!
For extra points (if the additional functionality is desired!), also create an API interface for this functionality for coding AI's, present and future, such that they can also perform this form of grepping automatically when needed, for example, when running/debugging a program they wrote, or are assisting a programmer with making changes to...
(Observation: There seem to emerge two different main patterns with respect to variable inspection... One is to set a watchpoint on a variable and stop the program when the variable changes.
Another would be to globally scan all variables (i.e. grep) at specific intervals (a form of a batch pattern) for specific strings/values, and all of that would be/could be -- settable by the programmer and/or an AI...)
Objects in heaps can be reached in more than one way. We don't want to traverse any object twice, because we will loop, so we must use the GC marked bit.
Yet! There is a way to report all the paths by which an grepped-out object is reachable.
Say we encounter an interesting object O for the first time, at path A B C. So we have A.B.C.O.
We keep objects A, B and C in a hash table. The hash table represents nodes we have visited, which are on the path to a hit.
Then say we encounter object B again, at path X Y Z B. B is a hit in our hash table, and so we report X.Y.Z.B.C.O as another hit for object O, without descending into B again.
>"The routine could maintain a path from root pointer to object (easily done on the recursion stack) so that it's reported along with matches."
Yes, it definitely could!
For extra points (if the additional functionality is desired!), also create an API interface for this functionality for coding AI's, present and future, such that they can also perform this form of grepping automatically when needed, for example, when running/debugging a program they wrote, or are assisting a programmer with making changes to...
(Observation: There seem to emerge two different main patterns with respect to variable inspection... One is to set a watchpoint on a variable and stop the program when the variable changes.
Another would be to globally scan all variables (i.e. grep) at specific intervals (a form of a batch pattern) for specific strings/values, and all of that would be/could be -- settable by the programmer and/or an AI...)
Anyway, your idea is a good one!