AGnosis debugger
This page contains information about the internals of the AGnosis Silver debugger. This tool is unfinished and has not been merged into the main branch of Silver; it can be found at https://github.com/melt-umn/silver/tree/feature/agnosis.
- For the theoretical details of debugging contextualization, see Matthew Feraru’s honors thesis “Abstract Syntax Contextualization Framework for Debugging Attribute Grammar Specifications.” [TODO: insert link to thesis in UMN conservatory once uploaded within a couple of months].
- The key idea of contextualization is to represent the location of the currently navigated-to node within an abstract syntax tree (AST) textually. This is mainly done through concrete syntax representations of nodes, concrete syntax highlighting, and a set of labels that describe the applications of Silver forwarding or higher-order attributes that generate AST subtrees. (Note that the “is-new” label cannot be implemented in Silver due to the current limitations of origin tracking).
The thesis abstract:
In this thesis, we explore an aspect of debugging attribute grammar (AG) specifications. AG frameworks in themselves are high-level languages that allow a programmer to specify the syntax rules and semantics of a new programming language. The debugging of AG specifications is often done by interactively traversing abstract syntax trees (ASTs) that represent a parsed program in a meta-program. The goal of such debugging is to find AG specifications with semantic rules that observe correct inputs but incorrect outputs—the possible bugs of AG specifications.
For large programs, ASTs may be difficult to understand by a programmer; graphically rendering ASTs in a debugging interface is challenging and still does not make it straightforwardly easy to understand ASTs relative to source code. Resultantly, we propose a textual way to use source and source-like syntax to represent the location of a navigated-to AST node relative to its position in an entire AST and highlight any notable features of the tree, such as the application of reduction grammars. This contextualization framework of abstract syntax tree nodes has been prototyped to work on Silver [1] specifications, but it is applicable to any AG framework since it only relies on the core features of the AG paradigm itself.
- All necessary contextualization information for an AST “node” visited comes from
DecoratedNodein the Silver Javacoreruntime. - Information extracted from an instance of a
DecoratedNodeis captured in aNodeContextMessageobject. They are records of contextualization for a node that is part of the path from the unique (we ignore reference attributes) root to the current navigated-to node. This is because we naturally do a DFS tree traversal while debugging, and hold visited nodes in a stack. - During tree navigation, we maintain a stack of
NodeContextMessageobjects implicitly representing the path from AST root to the current node. - This stack is an instance of
ContextStack(this is the “full” context stack from the thesis). DecoratedNodeobjects are pushed while following edges into the tree and popped when traversing back up into aContextStack. It is theContextStackitself that makes/generates newNodeContextMessageobjects when new nodes are pushed.- A
ContextStackcan generate its own verbose contextualization. This is useful for debugging the contextualization classes themselves. - To yield a final or “simplified” contextualization, a
SimplifiedContextStackis employed. It is a heavy-weight wrapper around a (full)ContextStackinstance. TheSimplifiedContextStackcompresses the stack ofNodeContextMessageobjects within itsContextStackinto a smaller stack ofSimplifiedContextBoxobjects. - It is this stack of
SimplifiedContextBoxobjects within aSimplifiedContextStackinstance that is then rendered to give our contextualization. SimplifiedContextStacksupports basic text file and HTML representations currently.
- Interactive debugging is all handled by the
Debugclass.
- Before the main debugging loop is entered, a
ContextStack cStackis created/made. (There are different decorating classes around aContextStackif different intermediate contextualization representations are required, such asFileContextVisualization. These decorators need to return back theContextStackobject they are wrapping). - A
SimplifiedContextStack sStackis also initialized withcStackas its parameter. - Currently, there are two methods to generate final simplified contextualization from
sStack:show()andgenerateHTMLFile(). They, respectively, generate a text or HTML file to a path that can be specified in the constructor ofSimplifiedContextStack.
- Whenever a command that traverses deeper into an AST is called (e.g., down or forwards),
cStack.push(currentNode);is called. - Following this line,
sStack.show()orsStack.generateHTMLFile()can be called to update the contextualization. - Recall that
sStackmaintains a reference tocStack; whenevercStackis updated, thensStackwill update itself based on itscStackwhen invoked to regenerate its contextualization file.
- All files are currently located in the Silver Java runtime in the
corepacket. - TODO: create new debugging package (not just contextualization issue).
- Concrete syntax representations will either be the parsed source syntax associated with a
DecoratedNodeor its pretty print representation. - The former is to be used only if no horizontal edges were crossed to get to this node. horizontal edges refer to either forwarding edges (entering rewrite-rules) or “into” higher-order attribute edges because these constructs may introduce nodes that are not associated with parsed syntax.
getPrettyPrint(). Returnsppattribute orUtil.genericShow()if it is not present.getFilename(). Returns via origin tracking the file name parsed that generated this node.getStartCoordiantes()andgetEndCoordiantes(). ReturnFileCoordinateobjects. These objects just store a row and column position.- The combination of a filename, start coordinate, and an end coordiante denote the parsed concrete syntax that generated this node.
- These labels are used to represent applications of rewrite rules (forwardings) or higher-order attributes, the two constructs we consider that can generate horizontal edges.
- A
redexis a forwarding node; acontractumis a forwarded-to node. getIsRedex()andgetIsContractum()represent if a node is involved with a forwarding based on theforwardParentfield.getRedex()andgetContractum()return the first ancestor of a node that has either respective property or null if none.getIsAttributeRoot(). Returns whether or not this node is the root of a higher-order attribute subtree. This is true if this node is an attribute of its parent node.- To represent the nesting of forwarding edges,
getIsTranslation()returns the number of forwarding edges encountered from root to this node (0 if none). - To represent the nesting of higher-order attributes for this node,
getIsAttribute()returns the number of higher-order attribute entry edges encountered from root to this node (0 if none). - These implement the “labels” and “headers” further described in Matthew Feraru’s thesis [TODO: insert link to thesis in UMN conservatory once uploaded within a couple of months]. for the
NodeContextMessagerecord.
- While these additions are implemented efficiently in
DecoratedNode, we want to move all of these functionalities to a contextualization utility class to keepDecoratedNodeas minimal as possible (OK to recompute redexes and contractums on parents each time, etc.). - Find a way to track reference attributes.
- Higher-order attributes have not been navigated-into yet, so higher-order attribute-related functionality has only been tested to work in the absence of them.
- Very straightforward container of a row and column index into a file.
- Create another wrapping class to represent <FileName, StartFileCoord, EndFileCoord>, a complete concrete syntax file location.
- Wrap extracted information from
DecoratedNodeabout an individual node part of a path from the current node to the abstract syntax tree root–a record of a node for contextualization purposes. - They are the elements of the “full”/intermediate stack maintained in a
ContextStack. This info is then compressed inSimplifiedContextStack. - 4 sections of information are maintained about a node (given as parameter in
NodeConextMessageconstructor.)
-
Section 1. (HEADERS). Headers are either TRANSLATION-X (for rewrite rules) or HIGHER-ORDER (for higher-order attributes). They represent the cumulative nesting of these constructs a current node has relative to the program root. Headers are dependent on a node’s labels and its ancestors' labels.
-
Section 2. (CONCRETE SYNTAX). Concrete syntax representation of the current node. Should hold parsed concrete syntax from the source file if headers are empty (no rewrite rules or higher-order attributes traversed yet), or the node’s pretty print attribute otherwise.
-
Section 3. (PRODUCTION). Store the production name (we currently keep file lines as well. But they are not needed for the current version of the SimplifiedContextStack).
-
SECTION 4. (labels). Labels represent whether the current node is involved with horizontal edges. Current possible labels are is-contractum and is-redex (for forwarding relationship) and is-attribute-root (for higher-order attribute subtree roots). Labels are currently extracted from DecoratedNode itself.
- The
GetSection_()functions are to intermediately generate a file representation of such a node within a fullContextStack. - To extract information for a
SimplifiedContextStack’sSimplifiedContextBoxes, use the simple getter functions for respective properties, e.g.isRedex()orgetProdName().
- Add contextualization labels/any info needed to support reference attributes.
- Once remove
ContextStackand store an intermediate stack ofNodeContextMessageobjects directly inSimplifiedContextStack, remove allGetSection_()methods.
- Maintain a stack of
NodeContextMessageobjects. Whenever tree navigation occurs, update this stack with the traversal (DFS). - I.e., if heading deeper into the tree (or across a forwarding edge),
push()the new current node, and if going up a parent link,pop()from the stack. - This is ultimately an intermediate store of information to generate the final
SimplifiedContextStackcontextualization representation. - Currently, use
get()to access individualNodeContextMessageobjects. - Can define child classes that inherit from
ContextVisualization(a wrapper aroundContextStack) to add extra methods to visualize an intermediate full stack (e.g.,FileContextVisualizationgenerates a text file)
- Move the stack of
NodeContextMessageobjects directly intoSimplifiedContextStack; i.e., get rid ofContextStackentirely and only ever render a final simplified contextualization.
- Core of contextualization for debugging: the ‘SimplifiedContextStack’ is basically a heavyweight decorator over a ContextStack to generate a simplified (one node per tree order/horizontal-edge encountered) stack.
- Its
ContextStackmemberfull_stackis dynamically updated while debugging occurs. Then, extracting a contextualization from a SimplifiedContextStack requires calling ‘updateSimplifiedStack()’ to create an updatedSimplifiedContextStack(ofSimplifiedConextBoxobjects) based on the current state of the ContextStackfull_stack. - It currently can print some primitive text representations to a text file, or generate a better HTML file. (Filenames can be specified upon SimplifiedContextStack construction).
- THIS IS THE FINAL RESULT OF CONTEXTUALIZATION: RENDERING THIS FILE.
- Move
full_stack(the wrappedContextStack) updating directly into here; i.e., push/pop nodes into the simplified stack directly and get rid ofContextStackentirely. - Would then maintain a stack of
NodeContextMessageobjects and another stack ofSimplifiedContextBoxobjects. The former would be used to update the latter stack. - Avoid having to rebuild the entire stack each time as a result of this internal updating (instead of relying on
ContextStackto update). - Find better than O(n^2) time complexity for production name assignment
-
The
SimplifiedContextBoxmaintains all information needed for an individual element as part of simplified debugging contextualization. -
Objects of this class are the elements of a SimplifiedContextStack.
-
One fully represents a path in an abstract syntax tree that has no horizontal edges (edges created by forwarding/translation or higher-order attribute entry links)
-
The
SimplifiedContextStackcreates one of these boxes each time it encounters a horizontal edge (plus the original started at the program root). -
Tree Order represents how many horizontal edges have been navigated across (by type separately).
-
Text Syntax represents the current path through concrete syntax.
-
text_syntaxshould store parsed concrete syntax when (x, y) from tree order are both 0. Otherwise, it will be the pretty print representation. This is for the first production associated with a SimplifiedContextBox (widest-spanning) -
syntax_to_highlightshould be highlighted withintext_syntax. It represents the deepest (least-spanning) navigated-to node within the path of productions such a box represents. -
Productions Visited. Just a list of production names this box’s abstract syntax tree path represents. They should be added with increasing tree depth.
-
Interesting Features. Records which nodes are associated with horizontal edges themselves. This info comes from
NodeContextMessageobjects stored in the basic ContextStack from which a SimplifiedContextStack is built from. -
There are currently HTML and toString representations of an individual box. When adding/generating HTML, the headers are added within SimplifiedContextStack.
- POTENTIAL FUTURE RESEARCH PROJECT: some extra information while doing tree traversal will be needed to make highlighting unique if there are multiple instances of
syntax_to_highlightwithintext_syntax.
- Simple container for a production name paired with an index.
- Implement an HTML-specific toString() with highlighting.
- Container for a contextualization label (i.e., is-redex, is-contractum, is-attribute-root).
- Maintains the production name (
baseProd) it is associated with. - Also maintains, where applicable, the “
target” production associated with a label (e.g., the target of a redex is the forwarded-to contractum if visited).
- Implement an HTML-specific toString() with highlighting.