如何创建“局部变量”使用 DWScript 及其调试器显示
我正在为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将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)
对于阅读此问题的任何其他人,我将展示一些与获取符号值有关的补充信息。该符号是按照 Eric 上面的描述找到的,但很难弄清楚如何获取该符号的实际值。下面的代码是每次调用时用局部变量填充 TMemo (memLocalVariables) 的过程。缺少一些功能,例如变量值的整洁格式和对调用参数的访问。我从调试器“dsDebugSuspished”状态调用此方法。不太直观的一点是对堆栈上符号数据的访问以及堆栈基址指针的使用。了解编译器如何工作的好方法!但是,也许在某个地方我还没有找到一个实用函数......?埃里克?
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?