How to use the gilgamesh.subroutine.Subroutine function in gilgamesh

To help you get started, we’ve selected a few gilgamesh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AndreaOrru / gilgamesh / gilgamesh / log.py View on Github external
if self.rom.is_ram(pc):
            return
        if stack_trace is None:
            stack_trace = []

        # Assign a label to the subroutine (or retrieve the existing one).
        preserved_label = self.preserved_labels.get(pc)
        if preserved_label:
            label = preserved_label
        elif not label:
            label = "sub_{:06X}".format(pc)

        # Create and register subroutine (unless it exists already).
        subroutine = self.subroutines.get(pc)
        if subroutine is None:
            subroutine = Subroutine(self, pc, label)
            self.subroutines[pc] = subroutine
            self.subroutines_by_label[label] = subroutine
        subroutine.stack_traces.add(tuple(stack_trace) if stack_trace else ())

        # Apply existing state change assertions.
        state_changes = self.subroutine_assertions.get(pc, {})
        for state_change in state_changes.items():
            subroutine.assert_state_change(*state_change)
github AndreaOrru / gilgamesh / gilgamesh / log.py View on Github external
def _clear(self, preserve_labels=True) -> None:
        # Preserve currently assigned labels.
        if preserve_labels:
            self._preserve_labels()

        # Invalidate Subroutine and Instruction objects.
        if hasattr(self, "subroutines"):
            bulk_invalidate(self.subroutines.values())

        # Clear all data structures.
        self.local_labels: DefaultDict[int, Dict[str, int]] = defaultdict(bidict)
        self.instructions: DefaultDict[int, Set[InstructionID]] = defaultdict(set)
        self.subroutines: Dict[int, Subroutine] = SortedDict()
        self.subroutines_by_label: Dict[str, Subroutine] = {}
        self.references: DefaultDict[int, Set[Tuple[int, int]]] = defaultdict(set)
        gc.collect()

        # Add entry points.
        for pc, entry in self.entry_points.items():
            self.add_subroutine(pc, label=entry.name)

        self.dirty = False