如何创建“局部变量”使用 DWScript 及其调试器显示

发布于 2024-12-04 06:18:54 字数 190 浏览 2 评论 0原文

我正在为 DWScript 编写一个 IDE,并使用调试器让它逐步执行代码。我现在希望添加“局部变量”的显示(即范围内的变量)。有人可以给我指点一下执行此操作的方法吗?我可以获得所有符号的列表,但不明白如何获取事物的当前范围部分。 谢谢。

I'm writing an IDE for DWScript and have got it stepping through code using the debugger. I now wish to add a display of 'local variables' (i.e those in scope). Can someone give me a pointer to the means of doing this? I can get a list of all symbols but do not understand how to get the current scope part of things.
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半边脸i 2024-12-11 06:18:54

IdwsProgramExecution转换为TdwsProgramExecution,您将获得对“CurrentProg”属性的访问权限,这是一个TdwsProgram,是TdwsMainProgram(如果您在主程序中)或TdwsProcedure(如果您在过程/函数/方法)。这些将有一个 Table 属性,其中列出了本地符号,这是最直接的范围。
将有一个或多个父级,它引用父级范围(按源代码范围分层)。

如果在 TdwsProcedure 中,您可能还想查看其 FuncSymbol 属性,该属性将有一个参数表(如果您想直接将参数与其余参数隔离,这很有用)本地范围)

Cast the IdwsProgramExecution to TdwsProgramExecution, you'll gain access to a "CurrentProg", property, a TdwsProgram which is either a TdwsMainProgram (if you're in the main) or a TdwsProcedure (if you're in a proc/func/method). Those will have a Table property, which lists the local symbols, that's the most direct scope.
That Table will have one or more Parents, which refers the parent scopes (hierarchically, in terms of source code scope).

If in a TdwsProcedure, you may also want to look at its FuncSymbol property, which will have a table of parameters (useful if you want to directly isolate the parameters from the rest of the local scope)

獨角戲 2024-12-11 06:18:54

对于阅读此问题的任何其他人,我将展示一些与获取符号值有关的补充信息。该符号是按照 Eric 上面的描述找到的,但很难弄清楚如何获取该符号的实际值。下面的代码是每次调用时用局部变量填充 TMemo (memLocalVariables) 的过程。缺少一些功能,例如变量值的整洁格式和对调用参数的访问。我从调试器“dsDebugSuspished”状态调用此方法。不太直观的一点是对堆栈上符号数据的访问以及堆栈基址指针的使用。了解编译器如何工作的好方法!但是,也许在某个地方我还没有找到一个实用函数......?埃里克?

  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;

For any others reading this question, I will show some supplementary info concerned with getting the value of a symbol. The symbol is found as described by Eric above but it is hard to work out how to get the actual value of the symbol. The code below is a procedure that populates a TMemo (memLocalVariables) with local variables each time it is called. There are some features missing like neat formatting of the variable value and access to calling parameters. I call this from the debugger 'dsDebugSuspended' state. The less intuitive bit is the access to the symbol data on the stack and the use of the stack base pointer. A great way to learn how the compiler works! But, maybe there is a utility function somewhere I've not found...? 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文