|
Post by (X) on Jul 12, 2023 14:49:22 GMT 1
Do you get the same errors for trying to access the value of 'v': 'v.Value'... "Type Mismatch"?
Local c As Int = 1, d = 2 Dim a = 10, b = 20 Global f, g
Show_Vars
Proc Show_Vars Dim v As Gfa_Var Dim vs As Gfa_Vars Set vs = Gfa_Vars("-") Debug "Locals:" For Each v In vs Debug v.Name;".Addr = ";Hex(v.Addr) Debug v.Name;".IsArray = ";Iif(IsNothing(v.IsArray), " Nothing", v.IsArray) Debug v.Name;".IsTyped = ";v.IsTyped Debug v.Name;".PName = ";v.PName Debug v.Name;".Size = ";v.Size Debug v.Name;".Type = ";v.Type Debug v.Name;".TypeName= ";v.TypeName Debug v.Name;".TypeObj = ";Iif(IsNothing(v.TypeObj), " Nothing", v.TypeObj) Debug v.Name;".VarPtr = ";Iif(IsNothing(v.VarPtr), " Nothing", Hex(v.VarPtr)) Debug v.Name & ".Value = " & v.Value // Type Mismatch Debug v.Name & ".Value = " & CStr(v.Value) // Type Mismatch 'Debug v.Name;".Value = ";LPeek(v.VarPtr) 'Debug v.Name;".Value = ";'Iif(IsNothing(v.VarPtr), " Nothing", LPeek(v.VarPtr)) °Debug v.Name;".Value = ";Iif(IsNothing(v.Value), " Nothing", v.Value) Next v Debug Debug "Globals:" Set vs = Gfa_Vars("") For Each v In vs Debug v.Name Next v EndProc
|
|
webu
Full Member
Posts: 149
|
Post by webu on Jul 12, 2023 23:08:15 GMT 1
I had no idea at all that the variable types 'Gfa_Var' and 'Gfa_Vars' exist and what they do
|
|
|
Post by dragonjim on Jul 12, 2023 23:13:08 GMT 1
Yes. For some reason, the value is Null.
Have you tried this as a GLL?
|
|
|
Post by (X) on Jul 13, 2023 2:11:48 GMT 1
Yes, I've tried accessing the Local vars in Main code from a GLL.
As far as I know, if if we try to list the Local vars in the main code from a GLL, the collection count will be 0, even if we execute a DoCompile before trying to list the Local vars.
I have only been able to list Local vars in the main code from the main program. N.B.: You must compile the code before updates/changes to the Local vars are taken into account.
I have not tried from a library yet.
Generating a Global var collection seems to work fine from either GLL or G32 files.
|
|
|
Post by dragonjim on Jul 13, 2023 10:16:43 GMT 1
It looks like the problem you are having is not necessarily with Gfa_Var but with Debug: it can not print a Null variable and that is causing the error.
If you load the Variants library and use VarPrint to print the value then all works OK.
Why the value is being returned as Null I can not tell you.
|
|
|
Post by (X) on Jul 13, 2023 13:55:19 GMT 1
It looks like the problem you are having is not necessarily with Gfa_Var but with Debug: it can not print a Null variable and that is causing the error. If you load the Variants library and use VarPrint to print the value then all works OK. Why the value is being returned as Null I can not tell you.
'Trace' seems to work better than 'Debug'...
Now, I am trying to get to the '<some Gfa_Var>.Value' via VarPtr, Addr or any other means I can think of, so far, nothing...
|
|
|
Post by scalion on Jul 13, 2023 15:06:11 GMT 1
Hi,
Try this : If v.Type = basInt Debug v.Name;".Value = ";LPeek(V:v + 40) Foundation 2 its TOMORRIW !!! YIPI !!!
|
|
|
Post by (X) on Jul 13, 2023 17:37:58 GMT 1
Hi, Try this : If v.Type = basInt Debug v.Name;".Value = ";LPeek(V:v + 40) Foundation 2 its TOMORRIW !!! YIPI !!!
Ohhh! Merci pour ceci!
Very promissing! I can see the values of the Local variables in this memory area!
I am trying to work out the different variable types.
Will publish as soon as I can work it out...
Yessssss!
|
|
|
Post by (X) on Jul 14, 2023 22:52:08 GMT 1
Hier: LPeek(V:v + 40) fonctionnait a merveille... Depuis, j'ai changé quelquechose et je n'arrives plus!
As-tu un demo qui fonctionne par hazard?
|
|
|
Post by (X) on Jul 15, 2023 21:34:40 GMT 1
This project is kicking my butt and forcing me to develop my own tools...
|
|
|
Post by dragonjim on Jul 16, 2023 12:29:51 GMT 1
A workaround to the problem you are facing is to use the Addr property of the Gfa_Var object something like this:
Dim v As Gfa_Var, GlobVars As Gfa_Vars, gv_addr%, c% = 5, d# = 10
Set GlobVars = Gfa_Vars("")
For Each v In GlobVars If v.Type = 3 Debug v.Name & " = "; LPeek(v.Addr) ElseIf v.Type = 5 Debug v.Name & " = "; DblPeek(v.Addr) ElseIf v.Type = 9 Debug v.Name & " = " & v.TypeName & "(" & Hex(v.Addr) & ")" EndIf Next
This produces a report like this:
WM_ACTIVATEINST = 0 v = Gfa_Var(19C0840) GlobVars = Gfa_Vars(19C0844) gv_addr% = 0 c% = 5 d# = 10
|
|
|
Post by (X) on Jul 16, 2023 19:15:38 GMT 1
I finally got some promissing results related to getting the value of a Local variable as listed by the Gfa_Vars collection!
As you may recall, the value returned for a Local main variable listed by a Gfa_Vars collection was for some reason always unexpectedly: 'null'. (While a Debug check fails and generates an error: 'Type mismatch', a Trace succeeds in verifying this.)
GLOBALS... "Easy as pie!"
I have always been able to get the value of the Global vars using the pointers in the Gfa_Vars item's 'v.Addr' or 'v.VarPtr' properties (which seem to be the same) where v, when declared as a Gfa_Var typed variable and is either set to an item of the Gfa_Vars collection or implicitly set as part of a For Each..Next loop.
Dim vs as Gfa_Vars vs = Gfa_Vars("") // for populating 'vs' with a collection of the main code's Global variables
Dim v as Gfa_Var Set v = vs.Item(1) Trace v.Addr Trace v.VarPtr Trace v.Value // If we pass this address to a function that takes the var type into account we can easily return a variant containing the value of the same data type.
LOCALS... “Tougher than overcooked steak!”
The problem with the Local Gfa_Var item's .Addr property is that it returns an relative address offset instead of an absolute address, for example -4, -8 etc for each Local variable in the Gfa_Vars collection: Gfa_Vars("-").
But, relative to what? I guessed that it might be relative the the absolute memory address of the first Local variable in the list: 'vs.Item(1).Name'.
In short, this 'guess' turned out to be correct as far as I can tell. (I had to offset the initial address by the Size: 'vs.Item(1).Size' of the first local variable and all was 'hunky dory'!)
This means I'll need use a different method to get the Local variable values compared to Global.
I still have not verified if this applies to the variables inside Procs, Subs and Funcs.
More code demos to follow...
|
|
|
Post by (X) on Jul 20, 2023 0:17:50 GMT 1
Here is the Memory Explorer utility program that helped me probe the variable memory in my search for answers in regards to the Local variable Gfa_Vars collection.
You can select or double click on an address in the blue screen to make the hexdump appear below, and you can scroll the memory address by pressing up/down on the offset label.
I used a couple fonts that you may not have: dymo.zip (37.19 KB) and Ac437 IBM VGA 9x16 which you can find online or you can use whatever font you choose.
Attachments:Demo XMEM.G32 (131.33 KB)
|
|
|
Post by (X) on Jul 20, 2023 14:14:05 GMT 1
I've been searching for a way to get the pointer address of the first Local variable in the Local Gfa_Vars collection by name. In other words, if I give GFA-BASIC 32 for Windows a string containing the name of a variable, can I get the starting memory address of that variable? I know I can use the V:<some_var> or *<some_var> statements but I can not pass a string to these commands. For example: Local a as int = 1
Trace *a Trace V:a Returns: But how could I create a function that takes a string "a" and returns the pointer?
Function GetAddrFromVarNameString(s$) as Long Return <some code that takes a variable name as a string and returns the address> EndFunc
Trace GetAddrFromVarNameString("a")
|
|
|
Post by dragonjim on Jul 20, 2023 22:31:06 GMT 1
I thought that was stored in the Addr property of the Gfa_Var object...
...but as the following shows, maybe not...
test Procedure test Local a As Int32 = 15 Trace V:a Trace *a Local v As Gfa_Var, LocVars As Gfa_Vars Set LocVars = Gfa_Vars("test") For Each v In LocVars If v.Name = "a" Then Debug v.Name & ": " v.Addr Next EndProcedure
On my system, v.Addr returns -4, which is odd as this would be the case if it was uninitiated...
|
|
|
Post by dragonjim on Jul 20, 2023 22:40:08 GMT 1
My guess is that Gfa_Vars is broken when it comes to local variables...
|
|