Closed ivan-mogilko closed 1 week ago
For the reference, I started working on a cleaner branch: https://github.com/ivan-mogilko/ags-refactoring/tree/ags4--memwatch
will open a new PR when it will be at least usable.
Closed in favor of a cleaner variant #2430
WARNING: a dirty draft, contains ugly code and non-final data serialization, NOT FOR MERGING. UPDATE: started a cleaner branch here: https://github.com/ivan-mogilko/ags-refactoring/tree/ags4--memwatch
This implements an mechanism for retrieving contents of engine memory via a debugger communication interface. Adds the "Watch variables" panel in the Editor, which lets user type in variable names, and receive current values.
A tall screenshot under the spoiler: **CLICK HERE**
![ags4-memorywatch-draft4](https://github.com/adventuregamestudio/ags/assets/1833754/20b6007b-a1a3-4fb6-825a-683faa22334f)What works:
[n]
notation.What does not work:
How is it done
x[N]:offset[,type[:offset,type[:...]]
, wherex
is a script's memory designation (e.g.g
for global script,r
for current room script,m2
for script module under index 2, and so on),offset
tells relative memory address in bytes, and type explains how to resolve this address (e.g.i1
for int8,i2
for int16,i4
for int32,h
for managed handle, etc). I implemented this command first, because it allows to get memory without even knowing variable names. But of course it's quite inconvenient for common users.mystruct.member_field.internal_field
etc. In order to process this command and correctly resolve all memory addresses engine requires "table of contents" from the current script and RTTI. If these are not available, then it will fail. If they are present, then engine builds a memory access instruction similar to "GETMEM" command, for itself, and then carries on with its processing.Other notes...
Remaining questions
Besides the code written in a dirty way, and quickly mashed serialization format for "table of contents" (I will be rewriting this as soon as I get more spare time), the big question I have is whether we want to have this "toc" persistent in the game scripts.
With RTTI the situation was simpler, because RTTI was required to make nested pointers work.
This TOC is so far only for debugging. An alternate use that I might think of is for improving the save system, because knowing a list of variables may let us actually know what we are saving or reading. But this is only an idea.
I see two options here, if we don't want this to be always present in compiled scripts:
There's also a question of separating tasks. I wrote this so that engine does most of the work, but that's because it was faster for me to do. I thought that Editor, or another debugger (whoever sends commands), could be resolving variable names to memory instruction as well. But I'm not entirely certain about that now, because there are imported variables which address cannot be known without linking, and local variables with their tricky processing.
Finally, the "watch" GUI may be better, but that's a completely separate problem that may be dealt with on its own.
Backporting to ags 3
If there's a wish to backport this watch feature to ags3, the RTTI generation must also be backported. Any RTTI-based features (in scripting) may be omitted, but RTTI table itself has to be present to be able to access nested fields and recognize types.