How to create a display of "local variables" using DWScript and its debugger

I am writing an IDE for DWScript and got the code using the debugger. Now I want to add a mapping of "local variables" (i.e. those that are in scope). Can someone give me a pointer to a way to do this? I can get a list of all the characters, but I don’t understand how to get the current scope. Thanks.

+6
source share
2 answers

Passing IdwsProgramExecution to TdwsProgramExecution, you will get access to the CurrentProg property, TdwsProgram, which is either TdwsMainProgram (if you are mostly) or TdwsProcedure (if you are in the proc / FUNC / method). They will have the Table property, which lists the local characters that are the most direct. This table will have one or more parent elements that reference the parent areas (hierarchically, in terms of the amount of source code).

If in TdwsProcedure you can also see its FuncSymbol property, which will have a parameter table (useful if you want to isolate parameters directly from the rest of the local area)

+9
source

For others who are reading this question, I will show additional information regarding getting the value of a character. The symbol is found as described above by Eric, but it is difficult to determine how to obtain the actual value of the symbol. The code below is a procedure that fills TMemo (memLocalVariables) with local variables each time it is called. There are some features that are missing, like neatly formatting a variable's value and accessing call parameters. I call this from the debugger state "dsDebugSuspended". A less intuitive bit is accessing character data on the stack and using the stack base pointer. A great way to find out how the compiler works! But maybe there is a utility function somewhere I did not find ...? Eric?

procedure DrawLocalVariables; var ProgramExecution : TdwsProgramExecution; I : integer; Sym : TSymbol; V : variant; Adr : integer; SymbolTable : TSymbolTable; begin memLocalVariables.Lines.Clear; ProgramExecution := TdwsProgramExecution( dwsDebugger1.Execution ); SymbolTable := ProgramExecution.CurrentProg.Table; For I := 0 to SymbolTable.Count-1 do begin Sym := SymbolTable[I]; if Sym is TDataSymbol then begin Adr := TDataSymbol( Sym).StackAddr + ProgramExecution.Stack.BasePointer; ProgramExecution.Stack.ReadValue( Adr, V ); memLocalVariables.Lines.Add( Format( '%s = %s', [ Sym.Name, VarToStr(V) ] )); end; end; end; 
+2
source

Source: https://habr.com/ru/post/896951/


All Articles