THE DEBUGGABLE INTERPRETER DESIGN PATTERN

合集下载

优化与防止被优化

优化与防止被优化

注册登录•论坛•搜索•帮助•导航SoC Vista -- IC/FPGA设计家园» 30分钟必答 - 无限制提问专区» 设计未完成阶段进行面积评估如何防止被优化12下一页返回列表回复发帖mentor00超级通吃版主1#打印字体大小: t T发表于 2009-11-8 09:48 | 只看该作者设计未完成阶段进行面积评估如何防止被优化(本文来自anthonyyi的来信。

请大家一起来解答。

)为了对整个设计进行性能和面积的评估在模块尚未全部完成的阶段进入FPGA综合阶段在顶层设计中instance了所有已完成的模块但这些模块中有的由于后续模块没有完成,其输出悬空,即没有load在Synplify下使用Syn_noprune属性发现在compile阶段能保留上述模块,其RTL view显示模块存在在map之后观测Technology view发现上述模块已经被优化掉只剩下输入端口,且无drive故综合报告无实际意义和参考价值想请教在如何不改变顶层模块的输出管脚而使综合保留上述无输出的模块个人想到一种,用syn_probe将输出net probe出来,但这样会有风险因为综合工具似乎只会保留这些与该输出有关的逻辑而优化掉其他的部分而且该步骤没有进行实战确认:(本主题由 admin 于 2009-12-2 07:56 加入精华收藏分享评分回复引用订阅 TOPmentor00超级通吃版主2#发表于 2009-11-8 10:04 | 只看该作者我想可以参考一下下面的转载内容提问:我使用的是synplify pro综合verilog语言,例化了一个BUF,在综合结果里也看到了这个BUF,但是在MAP是这个BUF还是被优化掉了,请问用什么方法将这个BUF保留下来?解答:在这个BUF两端的信号线上加上下面的属性——wire bufin /* synthesis syn_keep=1 xc_props="X" */;wire bufout /* synthesis syn_keep=1 xc_props="X" */;解释下:1、syn_keep=1就是保留这个信号线,是它成为一个instance(synplify的),然后就可以对它添加XILINX的约束属性;2、xc_props=“”是synplify为XILINX保留留的约束属性,可以透传到ISE的实现中去,从而约束实现过程。

AD9783中文资料

AD9783中文资料
3. Programmable current outputs and dual auxiliary DACs provide flexibility and system enhancements.
CLKP CLKN
LVDS INTERFAቤተ መጻሕፍቲ ባይዱE
D[15:0] VIA, VIB
DEINTERLEAVING LOGIC
Full programmability is provided through a serial peripheral interface (SPI) port. Some pin-programmable features are also offered for those applications without a controller.
Dual 12-/14-/16-Bit,
LVDS Interface, 500 MSPS DACs
AD9780/AD9781/AD9783
GENERAL DESCRIPTION
The AD9780/AD9781/AD9783 include pin-compatible, high dynamic range, dual digital-to-analog converters (DACs) with 12-/14-/16-bit resolutions, and sample rates of up to 500 MSPS. The devices include specific features for direct conversion transmit applications, including gain and offset compensation, and they interface seamlessly with analog quadrature modulators such as the ADL5370.

debug怎么解决方案

debug怎么解决方案

debug怎么解决方案
《debug》
在软件开发过程中,debug是一个非常重要的环节,它可以帮
助开发者找到和解决程序中的bug或错误。

然而,要正确地进行debug并不是一件容易的事情,因此需要一些解决方案来帮
助开发者更高效地进行debug。

首先,要正确地进行debug,开发者需要使用合适的工具。


常来说,集成开发环境(IDE)提供了许多有用的debug工具,比如断点、变量查看、堆栈跟踪等。

当程序出现bug时,开发者可以利用这些工具来逐步跟踪程序的执行过程,从而发现bug所在的位置和原因。

其次,要正确地进行debug,开发者需要良好的程序设计和编
码习惯。

比如,遵循面向对象的设计原则、编写清晰易懂的代码、使用合理的命名规范等,都可以帮助开发者更容易地找到bug并解决它们。

另外,要正确地进行debug,开发者还需要善于利用日志和调
试信息。

在程序中添加适当的日志和调试信息,可以帮助开发者更直观地了解程序的执行过程,从而更容易地找到bug并解决它们。

总而言之,要正确地进行debug,开发者需要使用合适的工具、遵循良好的编码习惯,并善于利用日志和调试信息。

只有这样,开发者才能更高效地进行debug,找到并解决程序中的bug。

惠普彩色激光打印机 Pro M454 和惠普彩色激光多功能一体机 Pro M479 维修手册说明书

惠普彩色激光打印机 Pro M454 和惠普彩色激光多功能一体机 Pro M479 维修手册说明书

Table -1 Revision history Revision number 1
Revision date 6/2019
Revision notes HP LaserJet Pro M454 HP LaserJet Pro MFP M479 Repair manual initial release
Additional service and support for HP internal personnel HP internal personnel, go to one of the following Web-based Interactive Search Engine (WISE) sites: Americas (AMS) – https:///wise/home/ams-enWISE - English – https:///wise/home/ams-esWISE - Spanish – https:///wise/home/ams-ptWISE - Portuguese – https:///wise/home/ams-frWISE - French Asia Pacific / Japan (APJ) ○ https:///wise/home/apj-enWISE - English ○ https:///wise/home/apj-jaWISE - Japanese ○ https:///wise/home/apj-koWISE - Korean ○ https:///wise/home/apj-zh-HansWISE - Chinese (simplified)
Find information about the following topics ● Service manuals ● Service advisories ● Up-to-date control panel message (CPMD) troubleshooting ● Install and configure ● Printer specifications ● Solutions for printer issues and emerging issues ● Remove and replace part instructions and videos ● Warranty and regulatory information

设计模式.解释器模式(Interpreter

设计模式.解释器模式(Interpreter
通过对解释器的性能进行分析和调优,提高解释器 的执行效率,减少资源消耗。
维护文法规则
随着业务需求的变化,可能需要调整或扩展 文法规则,因此需要对解释器进行相应的维 护和更新。
THANKS
感谢观看
与访问者模式比较
访问者模式可以在不修改已有 类的情况下增加新的操作,而 解释器模式则关注于如何解析 和执行特定的语言或脚本。两 者都涉及对对象结构的操作, 但关注点不同。
解释器模式在软件开发中应
06
用实践
需求分析阶段应用
01
确定语言文法
在需求分析阶段,通过对业务领域进行深入分析, 可以明确需要解释的语言的文法规则。
的代码,符合开闭原则。
灵活性高
解释器模式可以动态地改变解释逻辑, 从而灵活地处理各种复杂的语言或脚
本。
缺点与不足
性能问题
01
解释器模式通常比编译执行的语言慢,因为解释器需要动态解
析和执行代码。
错误处理困难
02
由于解释器模式通常涉及动态执行代码,因此错误处理和调试
可能更加困难。
语法复杂度高
03
对于复杂的语法结构,解释器模式可能需要实现复杂的解析逻
03
设计模式使代码编制真正工程化,是软件工程的基石脉络。
解释器模式定义
解释器模式(Interpreter Pattern)是一种行为 设计模式,它提供了一种解释语言的语法或表达 式的方式,并定义了一个解释器接口,用于解释 这些语法或表达式。
解释器模式通常用于实现一个简单的语言解释器 或编译器,或者用于解析和执行复杂的数学表达 式等。
解释器模式使得规则引擎具有高度的灵活性和可扩展性。业务规则可以独立于应用程序进行修改和扩展, 而无需修改应用程序代码。

SIEMENS ET200SP 西门子 ET200SP 分布式 IO 系统手册

SIEMENS ET200SP 西门子 ET200SP 分布式 IO 系统手册
(https:///cs/ww/zh/ps/13828) • SIMATIC WinAC RTX (F) (https:///cs/ww/zh/ps/13915) • SIMATIC S7-1500/SIMATIC S7-1500F
合格的专业人员
本文件所属的产品/系统只允许由符合各项工作要求的合格人员进行操作。其操作必须遵照各自附带的文件说 明,特别是其中的安全及警告提示。 由于具备相关培训及经验,合格人员可以察觉本产品/系统的风险,并避 免可能的危险。
按规定使用 Siemens 产品
请注意下列说明:
商标 责任免除
警告 Siemens 产品只允许用于目录和相关技术文件中规定的使用情况。如果要使用其他公司的产品和组件,必须 得到 Siemens 推荐和允许。正确的运输、储存、组装、装配、安装、调试、操作和维护是产品安全、正常 运行的前提。必须保证允许的环境条件。必须注意相关文件中的提示。
Siemens AG Digital Industries Postfach 48 48 90026 NÜRNBERG 德国
A5E03576855-AK Ⓟ 05/2021 本公司保留更改的权利
Copyright © Siemens AG 2012 - 2021. 保留所有权利
前言
前言
本文档的用途
(https:///cs/ww/zh/ps/13716) • SIMATIC S7-1200/SIMATIC S7-1200F
(https:///cs/ww/zh/ps/13683) • 分布式 I/O (https:///cs/ww/zh/ps/14029) • STEP 7 (TIA Portal) (https:///cs/ww/zh/ps/14667)

code interpreter 的功能介绍

code interpreter 的功能介绍

code interpreter 的功能介绍Code interpreter 是一种能够解释和执行编程语言的计算机程序。

它的主要功能是将编程语言代码翻译成计算机可以理解的指令,并执行这些指令以实现程序的功能。

以下是 Code interpreter 的主要功能介绍:1.词法分析:Code interpreter 首先对输入的代码进行词法分析,将代码拆分成一个个的单词或符号,识别出其中的关键字、变量名、运算符等元素。

这一步是代码解释器能够正确理解代码的基础。

2.语法分析:接下来,Code interpreter 会根据编程语言的语法规则对代码进行语法分析,将词法分析的结果转化为语法树或抽象语法树。

语法树是一种表示代码结构的树形结构,有助于解释器理解和执行代码。

3.语义分析:Code interpreter 会对语法树进行语义分析,检查代码是否符合编程语言的语义规则。

这包括类型检查、函数和变量的定义和使用等。

如果代码存在语义错误,解释器会报错并停止执行。

4.解释执行:如果代码没有语法和语义错误,Code interpreter 就会开始解释和执行代码。

解释器会按照语法树或抽象语法树的顺序逐条执行指令。

对于一些需要计算的指令,解释器会进行相应的计算;对于需要调用函数的指令,解释器会查找并执行相应的函数。

5.错误处理:在解释执行过程中,Code interpreter 会进行错误处理,当遇到错误或异常情况时及时报错并停止执行。

错误处理的方式可以因解释器的设计和实现而异,但通常会提供有用的错误信息以帮助程序员进行调试。

6.调试支持:一些 Code interpreter 还提供调试支持,允许程序员在解释器中单步执行代码、查看变量值、设置断点等。

这有助于程序员更好地理解和调试代码。

7.运行时环境:Code interpreter 通常提供一个运行时环境,这个环境为正在执行的程序提供必要的支持和服务,例如内存管理、输入输出、线程调度等。

Adobe Acrobat SDK 开发者指南说明书

Adobe Acrobat SDK 开发者指南说明书
Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law. The unauthorized incorporation of such material into your new work could be a violation of the rights of the copyright owner. Please be sure to obtain any permission required from the copyright owner.
This guide is governed by the Adobe Acrobat SDK License Agreement and may be used or copied only in accordance with the terms of this agreement. Except as permitted by any such agreement, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe. Please note that the content in this guide is protected under copyright law.
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

THE DEBUGGABLE INTERPRETER DESIGN PATTERNJan Vran´yDepartment of Computer ScienceFaculty of Electrical EngineeringTechnical University in Prague,Czechvranyj1@fel.cvut.czAlexandre BergelSoftware Architecture GroupHasso Plattner Institut,University of Potsdam&LERO&Distributed Systems GroupTrinity College Dublin,IrelandAlexandre.Bergel@hpi.uni-potsdam.deKeywords:program interpretation,debugger,design pattern,programming environmentAbstract:The use of Interpreter and Visitor design patterns has been widely adopted to implement programming lan-guage interpreters due to their expressive and simple design.However,no general approach to conceive adebugger is commonly adopted.This paper presents the debuggable interpreter design pattern as a general approach to extend a languageinterpreter with debugging facilities such as step-over and step-into.Moreover,it enables multiple debuggerscoexisting and extends the Interpreter and Visitor design patterns with a few hooks and a debugging service.SmallJS,an interpreter for Javascript-like language,serves as an illustration.1INTRODUCTIONA design pattern is a general repeatable solution to a commonly occurring problem in software design. It is a description or template for how to solve a prob-lem that can be used in many different situations.De-sign patterns gained popularity after Gamma,Helm, Johnson,and Vlissides compiled and classified what were recognised as common patterns[Gamma et al., 1993,Gamma et al.,1995].The interpreter and visitor design patterns are usually described in terms of interpreting grammars. Given a language,they define a representation for its grammar along with an interpreter sentences in the language[Gamma et al.,1995].Whereas the abil-ity of the visitor and interpreter patterns to define programming language interpreters is widely recog-nised[Cheong and Jarzabek,1999,Acebal et al., 2002,Lorenz,1997],no approaches to facilitate the realisation of a debugger are currently available,to our knowledge.The Debuggable Interpreter Design Pattern de-scribes a programming language interpreter that of-fers debugging facilities.It augments the Interpreter pattern[Gamma et al.,1995]with some hooks in the “visiting”methods and employs a debugging service to model operations(i.e.,step-in,step-over,etc...).The contributions of this paper are the follow-ing:(i)description of the debuggable interpreter pat-tern,and(ii)illustration with SmallJS,a subset of Javascript.Section2illustrates the challenges in implement-ing a debugger.Section3presents the debuggable interpreter pattern and its illustration with SmallJS, a minimal procedural language.Section4discusses several points and shows some properties of the pat-tern.Section5provides a brief overview of related work.Finally,Section6concludes by summarising the presented work.2INTERPRETING ANDDEBUGGING LANGUAGES2.1The SmallJS InterpreterSmallJS is a JavaScript-subset interpreter written in ST/X,a dynamically-typed object-oriented program-ming language1.SmallJS contains the usual language constructions to define variables and functions.As an 1www.exept.de/exept/english/Smalltalk/-frame uebersicht.htmlillustration,the following code describes the factorial function:function fact(i){if(i>0){return i*fact(i-1);}else{return1;};}var a;a=6;fact(a);VisitorvisitAssignmentNode(Node)visitFunctionCallNode(Node)visitFunctionNode(Node)visitMultiplicationNode(Node)...Interpreter context visitAdditionNode: node visitFunctionCallNode: node visitFunctionNode: node visitMultiplicationNode: node visitAssignmentNode: node ...| left right |left := node leftOperandacceptVisitor: self. right := node rightOperand acceptVisitor: self. ^ left + right| value |value := node valueacceptVisitor: self ^ contextat: node variableput: valueFigure1:The SmallJS interpreter.Figure1provides an excerpt of a visitor-based in-terpreter for SmallJS and presents the body of the vis-itAdditionNode:aNode and visitAssignmentNode:aN-ode methods2.An addition is realized by running the visitor on the left operand,then on the right operand,and tofinally return the sum of these two values.Anassignment is realized by running the visitor on thevalue of the assignment,and then storing the value inthe context of the interpreter.The interpretation of the SmallJS programminglanguage is realized through a direct application of theInterpreter and Visitor design patterns[Gamma et al.,1995].2.2Realizing a DebuggerA debugger is a tool that is used to test and debugprograms.Typically,debuggers offer sophisticatedfunctionalities such as running a program step by step,stopping(pausing the program to examine the current 2We adopted the ST/X syntax in UML diagrams to present a homogeneous notation.state)at some kind ofevent by means of a break-point,and tracking the values of defined variables. The interpreter maintains several registers such as the program counter(instruction pointer)and the stack pointer.Figure2:A graphical user interface of a debugger.Figure2shows a debugging session involving the piece of code given above.Advanced debugging environments(e.g.,ST/X, VisualWorks3,Dolphin Smalltalk4)enable several de-buggers and interpreters for the same program code to coexist.Operations such as opening a new debug-ger from a debugger,debugging two different pieces of the same program,or debugging a multi-threaded program may be performed.Whereas the state of instruction-based interpreters is contained in a set of registers,recursive function invocations define the state of a visitor-based inter-preter.The state of the interpreter is determined by the set of function activation records which are con-tained in the method call stacks.Local context visual-isation is achieved by sophisticated reflective features, such as stack reification,which might result in a lack of performances or raise technical issues difficult to address.A visitor-based interpreter allows for breakpoints to be set and offers a mechanism to perform de-bugging operations such as step by step instruction execution.3THE DEBUGGABLEINTERPRETER PATTERNThis section describes a general approach to real-ize and implement a debugger for a visitor-based in-terpreter.It augments the visitor interpreter with a set of hooks inserted in the visit*methods.As part of the Interpreter design pattern,the dynamic infor-mation needed for a program interpretation is stored in a context.Debugging operations such as step-into, step-by,and continue are offered by a debugging ser-vice.3.1Debugging operationsBefore describing the Debuggable Interpreter design pattern,it is important to outline the different oper-ations we will use as debuggers traditionally come with their own set of definitions.Setting breakpoints.A breakpoint is a signal that tells the debugger to temporarily suspend the execu-tion of a program.A breakpoint is associated with a node in the abstract syntax tree.The same program may contains several breakpoints.When the interpretation of an abstract syntax tree (AST)reaches a breakpoint,an interactive session begins during which the operations described below may be invoked.The state of the debugger is mod-elled by a context and a reference to a particular node in the AST,which we call the current node.Breakpoints are set by a user through an interface. For example,right clicking on the interface presented in Figure2displays a menu which offers a’set breakpoint’entry.Step-over.A step-over operation consists of moving to the following node in the AST after having inter-preted the current node.The current node is then po-sitioned on this new node.a = 6;print(fact(a));Node being interpreted a = 6;print(fact(a));Figure3:A step-over operation does not go into recursion.Figure3illustrates a step-over operation.The current node is fact(a).By performing a step-over operation,the current node is then print(fact(a)). Step-into.A step-into operation consists of moving to the next node in the AST according to the appli-cation controlflow.This operation differs from step-over by entering recursion.a = 6;print(fact(a));Node being interpretedfunction fact(i) {if ( i > 0 ) {return i * fact(i - 1);} else {Figure4:A step-into operation goes into recursion.A step-into operation is illustrated in Figure4.In this situation,the interpreter halts at thefirst node in the recursion which is i>0.Continue.The execution of an application may be resumed by continuing it.Terminate.The program execution might be prema-turely ended with the terminate operation.As a con-sequence,no subsequent nodes are evaluated and al-located resources such as context stack and the inter-preter are freed.3.2Hooks in the VisitorTheflow of a program interpretation stems from the invocation order of the visiting methods.Suspending and resuming the interpretationflow and capturing re-cursion are the basis for the debugging operations.For the remainder of this paper,the interpreter class is called Interpreter.As described in Figure1, it implements the visiting methods.Hooks need to be inserted in the Interpreter class to enable step-over and step-in operations.These hooks inform a debugger service as to which part of code is being executed.As explained in Section3.5, a service is a placeholder for debugging operations. The method Interpreter.onTracepoint:aNode enables interpretation of an AST to be driven by a service: Interpreter.onTracepoint:aNode{ debuggerService onT racepoint:aNode}Both methods have to be invoked when visitingnodes.A visit:method maintains the current nodereference in a context:Interpreter.visit:aNode{|value previousNode|”A reference of the current node istemporarily stored”previousNode:=context currentNode.”The node is set as current”context currentNode:aNode.”Visit the node”value:=aNode acceptVisitor:self.”The previous node is restored”context currentNode:previousNode.ˆvalue}First,visit:aNode gets a reference of the previousnode from the current activation context.This refer-ence is used to set the current node back when visit: aNode has completed.Then the interpreter notifies the new current node to the context.This new currentnode is the node being traversed.The interpreter runsover this node using a double dispatch.The reference of the current node acts as an in-struction pointer.It clearly identifies the current exe-cution location.However,instead of directly performing a doubledispatch,the visit:aNode has to be used.For example,in the method visitAdditionNode:aNode the recursionis obtained from invoking visit:aNode: Interpreter.visitAdditionNode:aNode{|left right|left:=self visit:aNode left.right:=self visit:aNode right.self onTracepoint:aNode.ˆleft+right}Each visit*method must perform a call to onTrace-point:aNode after traversing all branches and before synthesising the result.Compared with the code shown in Figure1,thisnew version of visitAdditionNode:aNode makes theinterpreter aware of breakpoints.When a breakpointis reached,the execution of the interpreter is sus-pended.Subsequent subsections illustrate how break-points and debugging modes are modelled.3.3Context definitionAssociations between variables and values are storedwithin a context object[Gamma et al.,1995].Thedebuggable interpreter pattern augments this context with dynamic information related to the parent con-text and the current node under execution.Each func-tion invocation creates a new context.The class InterpreterContext contains three vari-ables:sender which refers to the parent context,cur-rentNode for the node in the abstract syntax tree, and returnReached indicating if return node has beenreached or not.The interpreter should not evalu-ate subsequent nodes when a return node has beenreached.Typically,this occurs when a return state-ment is interpreter.The method visitReturnNode:aN-ode is therefore defined as follows:Interpreter.visitReturnNode:aNode{|value|value:=self visit:expression.self onT racepoint:aNode.self returnReached:true.context returnReached:true.ˆvalue}3.4Separate Control FlowAn interpreter has to be embedded in a thread.This isnecessary for several reasons:•Multiple execution of the same program enablesa debugger to launch another debugger.Althoughnot essential,this feature leads to a better comfortwhen debugging.•If the executed program fails,it should not impact the enclosing application environment.The inter-preter cannot run in the same controlflow as the programming environment.The program under execution and the debugger cannot be executed in the same thread.The Interpreter class defines a variable process and an evaluate:aNode method to trigger an execu-tion:Interpreter.evaluate:aNode{|value semaphore|semaphore:=Semaphore new:0.context:=Context new.process:=([value:=self visit:aNode]newProcess) addExitAction:[semaphore signal];resume.semaphore wait.ˆvalue}The evaluate:aNode method creates a semaphore.This is necessary to block the execution of the inter-preter.A new context is created,followed by the cre-ation of a new thread(called process in the ST/X ter-minology)that is intended to execute the code value :=self visit:aNode.Independently,regardless ofwhether an exception is raised or not,once com-pleted,the exit action is triggered which releases the semaphore.3.5Debugging ServiceIn addition to keep a reference to a context,an in-terpreter must also refer to a debugger service .This service implements the debugging operations such as step-into,step-over and continue.Figure 5provides an overview.mode:onTracepoint:stepInto stepOver terminate runInterpreter continueaddBreakpointOn: tracepointReachedFor:interpreter breakpoints mode DebuggerService onTracepoint:continue stepInto stepOverdebuggerService modeDebuggerMode 11continueonTracepoint:ContinueMode stepIntoonTracepoint:StepIntoMode stepOveronTracepoint:context StepOverMode Figure 5:Debugger services definitions.The control flow of an application is halted when it reaches a breakpoint,which identifies a location in the program 5.With the debuggable interpreter pat-tern,a breakpoint is identified as a node in the abstract syntax tree.When a breakpoint is reached,the interpreter en-ters an interaction mode,which allow the user to per-form further operations.The mode in which the ser-vice is set reflects the operation that is currently per-formed.Each mode represents a debugging operation.To keep this paper concise,we consider only 3modes:continue,step-into,and step-over.A service maintains a list of breakpoints,accessi-ble by the modes.A breakpoint is added to a service by the user through a user interface.The methods continue ,stepInto ,and stepOver de-fined on DebuggerService are delegated to the current mode:DebuggerService.continue {mode continue }DebuggerService.stepInto {mode stepInto }5Note that advanced definitions of breakpoints such as conditional are outside the scope of this paper.DebuggerService.stepOver {mode stepOver }The tracepointReachedFor:and run methods are used to steer the process associated with an inter-preter.tracepointReachedFor:is invoked by the mode when a breakpoint is reached.This method simply suspends the process associated with the interpreter:DebuggerService.runInterpreter {interpreter run }Interpreter.run {process resume }Setting breakpoints.A debugger service maintains a list of nodes that represent breakpoints in the pro-gram.DebuggerService.addBreakpointOn:aNode {breakpoints ifNil:[breakpoints :=OrderedCollection new ].breakpoints add:aNode.}The method addBreakpointOn:is invoked by the debugger user interface.The aNode parameter corresponds to the node in the abstract syntax tree that should halt the program interpretation.Continue mode.The continue mode is the initial mode of the debugger service.When the debugger service is in the continue mode the program is exe-cuted until a breakpoint is reached.When that occurs,the interpreter thread is suspended and a debugger is opened.The service can either switch to a step-into or step-over mode,or a continue mode.The two meth-ods that define this mode are:ContinueMode.onT racePoint:aNode {(debuggerService isBreakpoint:aNode)ifT rue:[debuggerService tracepointReachedFor:aNode ].}ContinueMode.continue {debuggerService runInterpreter }Step-into mode.When the debugger service is in the step-into mode the program interpretation is stopped (and a debugger is opened)when onTracepoint:is in-voked.StepIntoMode.onTracePoint:aNode {debuggerService tracepointReachedFor:aNode }StepIntoMode.stepInto {debuggerService runInterpreter }Step-over mode.When the debugger service is in the step-over mode stepping does not follow recursionsand method calls.The StepOverMode has a contextvariable.This variable captures the state of the cur-rent interpretation and is initialised when the debug-ger service switches to this mode.The two methods that define this mode are: StepOverMode.onT racePoint:aNode{((context=debuggerService context)ifTrue:[debuggerService tracepointReachedFor:aNode] }StepOverMode.stepOver{debuggerService runInterpreter}If the current context and the current node matchthe ones referenced by the step-mode,then the debug-ger switches for a step-into mode,so that the execu-tion will be halted on the node that follows the onethat was stepped over.4DISCUSSIONCoexisting debuggers.Since multiple interpreters can interpret the same program,several debuggersmay be active at the same time.Although this featuredoes notfigure as a priority for the Java debugger6,itgreatly enhances the debugging activity. Breakpoints.The debuggable interpreter pattern emits a breakpoint signal when the controlflowreaches a particular node in the abstract syntax tree.Note that this definition of breakpoint might slightlydiverge from a widely known debugger such as Gdb7where a breakpoint signal may be triggered when thecontrolflow reaches a particular line of the sourcecode.New operations.New debugging operations can easily be added by subclassing DebuggerMode andadding the corresponding methods in DebuggerSer-vice.For example,a mode that holds a condition to enable the interpretation can be implementedin a class ConditionalInterpretationMode in whichthe method onT racePoint:aNode checks for theconditional expression.Speed and memory overhead.A natural question to be raised is the cost in terms of speed and mem-ory consumption.The table below shows the time /j2se/1.4.2/docs/jguide/jpda/-jarchitecture.html./gdb/in millisecond taken to execute the factorial function with the debuggable interpreter design pattern(DIDP) and the classical visitor pattern(VDP).Thesefigures are obtained while disabling the just-in-time compiler (JIT).Iteration DIDP(ms)VDP(ms)ratio fac(100) 5.0 2.02.50fac(200)8.0 5.0 1.60fac(400)17.012.0 1.41fac(900)38.020.0 1.90fac(10000)973.0540.01.80fac(70000)22774.019722.01.151003005007009003000100004000070000FactorialSlowdownratio..51.1.52.2.5Figure6:Ratio between a non-debuggable and a debug-gable e of a just-in-time compiler(JIT)is denoted in black.Figure6shows the overhead of the DIDP with the VDP for each factorial expression.It also measures the benefit of having a JIT.The black bar indicates a measurements obtained with the JIT enabled,whereas the value denoted by the white bars are obtained with the JIT disabled.As a result,we see that the ratio is asymptotic to 1.This means that the cost of the debuggable inter-preter design pattern compared to the classical visitor is negligible for deep recursion.The table below compares the memory consump-tion of DIDP with VDP.The total number of created objects is shown for each factorial expression.Iteration DIDP VDP ratiofac(100)1021021fac(200)2022021fac(400)4024021fac(900)9029021fac(10000)10002100021fac(70000)70002700021During the evaluation of factorial expression,con-texts are created for each recursion,as well as a mode and a service.This table shows that the DIDP does not incur any memory overhead.The computer used for this experiment is an Intel Pentium M1,6GHz,Linux(kernel2.6.20.1),512MB RAM,ST/X5.2.8.5RELATED WORKScripting debugging.Marceau et al.[Marceau et al., 2006]designed a language for a scriptable debug-ger.The purpose of this debugger is to automatise se-quences of debugging operations that might be labori-ous to repeat manually.A classical sequence could be setting a breakpoint,examining values of some vari-ables,or resuming execution.Debugging an appli-cation generally may necessitate repeat this sequence many times in order tofind a single bug.Scripting a debugger helps in automating such a task.Similar to the debuggable interpreter pattern,the scriptable debugger provides primitives to capture the essential functionality of a debugger:observing a program’s state,monitoring its control path,and controlling its execution.This is achieved by explicit commands embedded in the program.In order to be debugged,a program must contain explicit trace points.This is a major difference with the debuggable interpreter pattern for which program do not need to be annotated.Trace library.Hofer et al.[Hofer et al.,2006]pro-pose a backward-in-time debugger.The Unstuck de-bugger allows one to navigate the history of the ap-plication.Their implementation uses a trace library to collect the events and reconstruct the states.To generate events(method invocation,variable access and method return),the methods are instrumented us-ing ByteSurgeon[Denker et al.,2006],a high-level library to manipulate method bytecode.Unstuck assumes that a program is interpreted by a virtual machine,whereas the debuggable interpreter design pattern relies on an interpretation driven by a visitor.AST instrumentation.The Relational Meta-Language(RML)[Pop and Fritzson,2005]is a lan-guage for writing executable Natural Semantics spec-ifications.It is used to formally specify program-ming languages such as Java,Pascal,and MiniML. The RML debugger is based on an abstract syntax tree instrumentation that captures and records partic-ular events.A post-mortem analysis tool is then pro-vided to walk back and forth in time,display variable values,and execution points.The AST is instrumented with debugging anno-tation related to trace generation.From its design, the programming environment of RML is limited to one single debugger per session.On the contrary,our approach allows several debuggers to coexist. Grammar weaving.Wu et al.[Wu et al.,2005] claims that debugging is a concern that crosscuts a do-main specific language specification.They propose to use AspectJ8to weave the debugging semantics into the code created by a parser generator.Their work is restricted to programming lan-guages that are translated into a general purpose lan-guage.Our approach is different since it assumes a program interpretation through a visitor and inter-preter design pattern.6CONCLUSION AND FUTURE WORKThis paper presents a general approach for imple-menting and realizing a debugger for a visitor-like in-terpreter.It extends a visitor with a set of hooks em-bedded in the visiting methods.The context,primar-ily used to hold variables bindings,has been extended with a reference to a parent context,and keeps a refer-ence to the node currently being interpreted.A debug-ger service models the different operations available by means of a set of modes.To conclude,the Debuggable Interpreter design pattern offers the benefits of the coexistence of mul-tiple debuggers,a capacity to accept new debugging operations,while being easy to implement.For future work,we plan to assess the scalability of the debuggable interpreter design pattern by implementing a larger language such as Java,which involves dozens of nodes.Acknowledgement.We gratefully thank thefi-nancial support of Science Foundation Ireland and /aspectj/Lero–the Irish Software Engineering Research Centre.We also would like to thank Marcus Denker and Erin Shoemaker for their valuable comments and re-views.REFERENCESAcebal,C.F.,Castanedo,R.I.,and Lovelle,J.M.C.(2002).Good design principles in a compiler university course.SIGPLAN Not.,37(4):62–73. AspectJ.AspectJ home page./aspectj/.Cheong,Y.C.and Jarzabek,S.(1999).Frame-based method for customizing generic software archi-tectures.In SSR’99:Proceedings of the1999 symposium on Software reusability,pages103–112,New York,NY,USA.ACM Press. Denker,M.,Ducasse,S.,and Tanter,´E.(2006).Runtime bytecode transformation for Smalltalk.Journal of Computer Languages,Systems and Structures,32(2-3):125–139.Gamma,E.,Helm,R.,Johnson,R.,and Vlissides,J.(1995).Design Patterns:Elements of Reusable Object-Oriented Software.Addison Wesley, Reading,Mass.Gamma,E.,Helm,R.,Vlissides,J.,and Johnson, R.E.(1993).Design patterns:Abstraction and reuse of object-oriented design.In Nierstrasz, O.,editor,Proceedings ECOOP’93,volume707 of LNCS,pages406–431,Kaiserslautern,Ger-many.Springer-Verlag.Hofer,C.,Denker,M.,and Ducasse,S.(2006).De-sign and implementation of a backward-in-time debugger.In Proceedings of NODE’06,volume P-88of Lecture Notes in Informatics,pages17–32.Gesellschaft f¨u r Informatik(GI).JDI.Java debug interface(jdi)./-j2se/1.4.2/docs/jguide/jpda/jarchitecture.html. Lorenz,D.H.(1997).Tiling design patterns a case study using the interpreter pattern.In OOP-SLA’97:Proceedings of the12th ACM SIG-PLAN conference on Object-oriented program-ming,systems,languages,and applications, pages206–217,New York,NY,USA.ACM Press.Marceau,G.,Cooper,G.H.,Spiro,J.P.,Krishna-murthi,S.,and Reiss,S.P.(2006).The design and implementation of a dataflow language for scriptable debugging.Automated Software En-gineering Journal.Pop,A.and Fritzson,P.(2005).Debugging natural se-mantics specifications.In AADEBUG’05:Pro-ceedings of the sixth international symposium on Automated analysis-driven debugging,pages 77–82,New York,NY,USA.ACM Press. Wu,H.,Gray,J.,Roychoudhury,S.,and Mernik, M.(2005).Weaving a debugging aspect into domain-specific language grammars.In SAC ’05:Proceedings of the2005ACM symposium on Applied computing,pages1370–1374,New York,NY,USA.ACM Press.。

相关文档
最新文档