Closed ivan-mogilko closed 5 months ago
I believe that this feature now works for the most part. What remains are looking for nuances and edge cases, and usability improvements.
The biggest next change which I have in todo here is to move return value formatting to the Editor side, and make engine return plain array of bytes, accompanied by a type hint. Possibly encoded in base64?
EDIT: Another thing that could be supported here is having "nested expression" (variable reference) as an array index in []
, which means multiple variables have to be resolved in a sequence (or recursively etc). I believe that this is already doable with the existing code.
I can't figure it out how to test this, do I have to do something to make the watch variable panel not be empty? Edit: uhm... I tried to manually add a variable in my project but got and error...
An exception 0xC0000005 occurred in ACWIN.EXE at EIP = 0x004AD2FA; program pointer is +1004, engine version 4.0.0.5, gtags (0,0)
OK, trying to attach a read in different places always gives me this error...
Trying in a much simpler project in my String Split test I get a crash with exception but it's a different one
An exception 0xC0000005 occurred in ACWIN.EXE at EIP = 0x004AD2FA; program pointer is +6, engine version 4.0.0.5, gtags (0,0)
function room_AfterFadeIn()
{
String str = "this is a string";
String spl[] = str.Split(" ");
Label1.Text = "";
for(int i=0; i<spl.Length; i++)
{
System.Log(eLogInfo, "'%s'", spl[i]);
Label1.Text = Label1.Text.Append(String.Format("'%s' , ", spl[i]));
}
String a[];
String joined = String.Join(a, ",");
System.Log(eLogInfo, "'%s'", joined);
Label1.Text = Label1.Text.Append(String.Format("\nJoined: '%s'", joined));
}
OK, figured if I comment any GUI stuff I don't get crashes
What about making the local variables dynamically watcheable and having global variables require explicitly being watched? Plus some right click watch selection in the script editor.
And perhaps an array could show the first three or five elements and a ellipsis to signal it goes longer.
Edit: uhm... I tried to manually add a variable in my project but got and error...
Please elaborate, what do you mean by "manually add a variable in project"? There's a context menu that add/remove variables for now, I mentioned this in the ticket. Did you add these variables using a context menu, or some other way? EDIT: added a more clear explanation in the ticket.
What about making the local variables dynamically watcheable and having global variables require explicitly being watched? Plus some right click watch selection in the script editor.
I am not going to do any of these in the first stage. Any automation may be added later if there's a wish for that, and showing all variables should be optional, as I imagine not everyone will like that. There's a number of things to be figured out for this. For instance, at the moment Editor does not know which variables are there, because it does not read this gathered data. So either this data should be available for the Editor too, or it should receive their list from the engine first, using another command.
And perhaps an array could show the first three or five elements and a ellipsis to signal it goes longer.
Whole array contents are not sent at the moment. This may be done though, but I need to figure out how to limit the size of tranferred memory (and also for strings).
I tried testing the code you posted above, not commenting anything, and I do not get any exceptions. There are few result formatting mistakes, I will try to fix these soon.
If you are still getting these crashes, could you send me your full test project?
In the ags4distfx.zip project, you can add a breakpoint in the _distorter
function and try to add any of the local variables and it will crash.
After your changes I don't get crashes anymore in my String Split program (which is simpler), but I still do get crashes in the Sandwalker. In the title room (1) try to throw a breakpoint in init_button_logo
function and read any variable there. It should crash right away.
I noticed my Ags4VideoHD.zip project can't hit breakpoints, but I don't know if this was a change here or breakpoints were broken during video playback...
I noticed my Ags4VideoHD.zip project can't hit breakpoints, but I don't know if this was a change here or breakpoints were broken during video playback...
Could you also test the latest ags4 branch? I noticed that breakpoints do not work in room scripts with the new compiler, but they work with old compiler, but I don't know since when.
Could you also test the latest ags4 branch? I noticed that breakpoints do not work in room scripts with the new compiler, but they work with old compiler, but I don't know since when.
I tested and it doesn't work in the latest ags4 branch too. The compiler doesn't make a difference. Edit: I also think I caught a new issue that the new video api is ignoring the eRepeat
and not repeating the video.
Alright, should look into these separately...
So, I fixed couple of more mistakes. Because of these variables did not show up correctly when one script called another. Unfortunately, I was not able to reproduce any crashes... in my case the panel simply refuse to show any values.
There's something else that I forgot; I probably should make it so that if you switch to another level of a call stack (in the Editor), the context of memory inspection also change. I will try implementing this tomorrow.
@ericoporto I fixed a mistake in the old compiler that caused breakpoints to not work in room scripts. But from my tests, there's no problem with the new compiler. I think there could be a confusion if you don't order "Rebuild all files" then the room scripts are not rebuilt when you switch compilers, so it looks like the problem repeats with another compiler. Switching compiler property must force Editor to rebuild all scripts...
Hey, I tried this and now all my test games are running correctly and both the breakpoints are being hit as trying to read a variable do not crash AGS anymore. I tried a few of my games and it appears they are all working correctly as is now.
If you want to merge as is and fix further issues later the way it is looks alright - I think one fix I will do after this is merged is to make the right click context menu of the watch panel to not have the "Remove" enabled if nothing is selected or you right click on blank space .
Like logging with the Log Panel the first time I used, this feature is also one thing that I will miss now everytime I try to test something in AGS after having used it, when using a version that doesn't have it. xD
So... unless I introduced more new mistakes with the recent changes, the feature is mostly working in its current state.
The following are the remaining concerns and known issues:
arrayname[ integervarname ]
. I did not do that yet, being busy with fixing mistakes. May be addressed separately; but I think that would require simply a recursive call to "resolve memory" for each nested item.I fear that I've lost much of a "steam" I had when starting this, so would rather make a "checkpoint" here, and leave the above for the future.
I think these remaining issues could be moved to a new ticket to keep track and this PR merged. Then later once each thing is tackled they could be split in their own issues - I think writing the issues down will require thinking/studying this so I don't think properly writing already would be easy, this is why I would suggest to just copy a paste to a new issue.
One other thing I noticed is if a variable that is a struct (not a managed struct), it's value will be "unknown data", instead of something like "(struct)". Its fields can still be accessed fine, I think it's just that there is nothing to say on the value of a struct itself (not its fields).
This implements an mechanism for retrieving contents of a script 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.
The list of variables currently is worked with using a context menu that has Add/Remove/Clear commands. You may also edit variable's name by single clicking on a existing item in the list.
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 this is achieved
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, and then processes this instruction as a separate operation. This is when it gets to the final memory address, reads a value of certain size, and then ~formats it into a string, depending on its type.~ encodes value's bytes into a base64 string, except when value is already a string, and sends back to debugger.Other notes...
Design issues
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.
Known problems and TODOs
[]
; this means that multiple variables have to be resolved in a sequence (or recursively).Char
variables should perhaps have both numeric value and char value shown in a result string.~