class Value(TreeAddressable): """A leaf node of the meta tree""" def __init__(self, name, *args): self._name = name self._properties = Properties(*args) self._parent: Node = None def getPath(self) -> str: return "%s.%s" % (self._parent.getPath(), self._name) def configureProperties(self) -> None: self._properties.configure(self._parent._properties)
def __init__(self): super().__init__( "similar_symbols", DisplayInfo(), RelatedSymbols(), Value("id", Doc("The id of the symbol pair"), Type(int)), Multiple( ("old", "new"), Node( None, Value( "signature_tagged", Doc("A tagged version of the symbol signature. Taggs '%s' and '%s' must be replaced accordingly, e.g. for highlighting." % ( string_diff.HIGHLIGHT_START_TAG, string_diff.HIGHLIGHT_END_TAG, )), Type(str), ), ), ), Node( "similarities", Properties(Doc("Symbol similarity ratios"), Type(float)), Value("signature", Doc("The percentage of symbol signature similarity")), Value( "instruction", Doc("The percentage of symbol instruction similarity"), ), ), ) self.connectNodes()
def connectNodes(self) -> None: """Connect the tree nodes: Register parent with children and pass on properties. """ if self._properties is None: self._properties = Properties() if self._parent is None: self._properties.configure(None) else: self._properties.configure(self._parent._properties) for child in self._children.values(): child._parent = self # Recurse child.connectNodes() for value in self._values.values(): value._parent = self value.configureProperties()
def __init__(self): super().__init__( "related_symbols", Properties(Doc("A relation between two symbols")), Value( "size_delta", Doc("Difference in bytes between the resource occupation of the two symbols" ), Type(int), ), Value("old", Doc("The old symbol"), Type(ValueTreeNode), AliasType(Symbol)), Value("new", Doc("The new symbol"), Type(ValueTreeNode), AliasType(Symbol)), )
def __init__(self): super().__init__( "display_info", Properties( Doc("Information that configures how things are displayed")), Value( "symbol_class", Doc("The class of symbol old/new/appeared/disappeared/persisting/similar" ), Type(str), ), Value( "anchor_id", Doc("Unique string identifier token that can be used to generate a HTML anchor for cross references" ), Type(str), ), Value( "display_symbol_details", Doc("True if symbol details are supposed to be displayed"), Type(bool), ), )
class Node(TreeAddressable): """A common base class for all meta tree node types""" def __init__(self, name: str, *args): self._name: str = name self._properties: Optional[Properties] = None self._values = {} # type: Dict[str, Value] self._children = {} # type: Dict[str, Node] self._parent = None # type: Optional[Node] self.parseOptionalArgs(*args) def parseOptionalArgs(self, *args: Any) -> None: """Parse any optional arguments""" for opt_arg in args: if isinstance(opt_arg, Properties): if self._properties is not None: raise TreeException(self, "Properties ambiguously defined") self._properties = opt_arg self._properties.validate(self) elif issubclass(type(opt_arg), Node): node: Node = opt_arg self._children[node._name] = node elif isinstance(opt_arg, Value): value: Value = opt_arg self._values[value._name] = value value._parent = self elif isinstance(opt_arg, Multiple): multi_node: Multiple = opt_arg spawned = multi_node.spawn() # Pass the spawned nodes and values as if they would have been added # to this node's constructor self.parseOptionalArgs(*spawned) def getPath(self) -> str: """Return the formatted tree path of the node""" if self._parent is not None: return "%s.%s" % (self._parent.getPath(), self._name) if self._name is None: raise TreeException(self, "Encountered an unnamed node") return self._name def connectNodes(self) -> None: """Connect the tree nodes: Register parent with children and pass on properties. """ if self._properties is None: self._properties = Properties() if self._parent is None: self._properties.configure(None) else: self._properties.configure(self._parent._properties) for child in self._children.values(): child._parent = self # Recurse child.connectNodes() for value in self._values.values(): value._parent = self value.configureProperties() def forEachChild(self, callable_: Callable) -> None: """Apply a callable to all children""" for key in sorted(self._children): child: Node = self._children[key] callable_(self, child) @abc.abstractmethod def configureValueTree(self, value_tree_node: Any, **kwargs: Any) -> None: pass
def __init__(self, name, *args): self._name = name self._properties = Properties(*args) self._parent: Node = None
def __init__(self): super().__init__( "document", Properties(Doc(None)), Node( "general", Properties(Doc("General information about the document")), Value( "document_version", Doc("The document version of this document"), Type(int), ), Value("page_title", Doc("The title of the document page"), Type(str)), Value("doc_title", Doc("Document title"), Type(str)), Value( "elf_diff_repo_root", Doc("Path to the root of the elf_diff git repo"), Type(str), ), Value("generation_date", Doc("The document generation date"), Type(str)), Value( "elf_diff_version", Doc("The elf_diff version that generated the page"), Type(str), ), ), Node( "configuration", Properties( Doc("Boolean flags that configure what is supposed to be displayed and how" ), Type(bool), ), Value( "instructions_available", Doc("True if instructions could be read from both binary files" ), ), Value( "display_old_binary_info", Doc("True if old binary info is supposed to be displayed"), ), Value( "display_new_binary_info", Doc("True if new binary info is supposed to be displayed"), ), Value( "display_details", Doc("True if symbol detail information is supposed to be displayed" ), ), Value( "display_binary_details", Doc("True if details about binaries are supposed to be displayed" ), ), Value( "display_build_info", Doc("True if build information is supposed to be displayed" ), ), Value( "display_persisting_symbols_overview", Doc("True if an overview about persisting symbols is supposed to be displayed" ), ), Value( "display_disappeared_symbols_overview", Doc("True if an overview about disappeared symbols is supposed to be displayed" ), ), Value( "display_appeared_symbols_overview", Doc("True if an overview about appeared symbols is supposed to be displayed" ), ), Value( "display_similar_symbols_overview", Doc("True if an overview about similar symbols is supposed to be displayed" ), ), Value( "display_similar_symbols", Doc("True if similar symbols are supposed to be displayed" ), ), Value( "display_migrated_symbols_overview", Doc("True if an overview about migrated symbols is supposed to be displayed" ), ), Value( "display_migrated_symbols", Doc("True if migrated symbols are supposed to be displayed" ), ), Value( "debug_info_available", Doc("True if Dwarf debugging information was found in both binaries" ), ), ), Value("old_binary_info", Doc("Info about the old binary"), Type(str)), Value("new_binary_info", Doc("Info about the new binary"), Type(str)), Value("build_info", Doc("Information about the build"), Type(str)), Node( "files", Properties(Doc("Information about relevant files")), Node( "input", Properties(Doc("Information about relevant input files")), Multiple( ("old", "new"), Node( None, Value( "binary_path", Doc("The path to the binary file"), Type(str), ), Value( "debug_info_available", Doc("True if Dwarf debug info avaiable in the elf binary" ), Type(bool), ), Value( "source_files", Doc("Source file by file id (dict values of type SourceFile)" ), ), ), ), ), ), Node( "statistics", Node( "overall", Properties(Doc("Overall statistics")), Multiple( ("old", "new", "delta"), Node( None, Properties(Doc(None)), Node( "resource_consumption", Properties( Doc("Information about resource consumption" ), Type(int), ), Value("code", Doc("Memory required to store code")), Value("static_ram", Doc("Static RAM consumption")), Value("text", Doc("text section memory consumption")), Value("data", Doc("data section memory consumption")), Value("bss", Doc("bss section memory consumption")), ), ), ), ), Node( "symbols", Properties(Doc("Statistics of symbols")), Multiple( ("old", "new"), Node( None, Properties( Doc("Overall statistics about symbols considered" )), Node( "count", Properties(Doc("Number of symbols"), Type(int)), Value("selected", Doc("Number of symbols selected")), Value("dropped", Doc("Number of symbols dropped")), Value( "total", Doc("Number of total symbols in binary")), ), Node( "regex", Properties(Type(str)), Value( "selection", Doc("Regular expression used to select symbols found in binary" ), ), Value( "exclusion", Doc("Regular expression used to exclude symbols found in binary" ), ), ), ), ), Multiple( ("appeared", "disappeared"), Node( None, Properties(Type(int), Doc(None)), Value("count", Doc("Number of symbols")), ), ), Node( "persisting", Properties(Doc(None)), Value("count", Doc("Number of symbols"), Type(int)), Node( "resource_consumption", Properties( Doc("Total resource consumption of considered symbols of given class" ), Type(int), ), Value( "old", Doc("Overall number of bytes consumed in the old version" ), ), Value( "new", Doc("Overall number of bytes consumed in the old version" ), ), Value( "delta", Doc("Change to number of bytes consumed (only for persisting and similar)" ), ), ), ), Node( "similar", Properties(Doc(None)), Value("count", Doc("Number of symbols"), Type(int)), ), ), ), Node( "symbols", Properties(Doc("Symbols by id/table id ")), Type(dict), Value( "old", Doc("Dict of selected symbols of the old binary by symbol id (dict values of type Symbol)" ), ), Value( "new", Doc("Dict of selected symbols of the new binary by symbol id (dict values of type Symbol)" ), ), Value( "appeared", Doc("Dict of appeared symbols by symbol id (dict values of type AppearedSymbol)" ), ), Value( "disappeared", Doc("Disappeared symbols by symbol id (dict values of type DisappearedSymbol)" ), ), Value( "persisting", Doc("Persisting symbols by symbol id (dict values of type PersistingSymbol)" ), ), Value( "similar", Doc("Similar symbols by symbol id (dict values of type SimilarSymbols)" ), ), Value( "migrated", Doc("Migrated symbols by symbol id (dict values of type MigratedSymbol)" ), ), ), ) self.connectNodes()