Esempio n. 1
0
    def __handle_event(self, event: dict) -> None:
        ev = event['event']
        if ev == 'at bp':
            dbgprint(
                f"reached breakpoint {self.module.addr(event['breakpoint'])}")
            self.__reachedbp = True
            self.debug_session()
            if 'single-stop' in self.policies:
                infoprint(f"enforcing `single-stop' to `{self.device.name}`")
                for bp in self.breakpoints:
                    self.remove_breakpoint(bp)
                self.run()
            elif 'remove-and-proceed' in self.policies:
                dbgprint(
                    f"applying `remove-and-proceed` policy to `{self.device.name}`"
                )
                expr = self.module.addr(event['breakpoint'])
                dbgprint(f"the expr {expr}")
                self.remove_breakpoint(expr)
                self.run()

        elif ev == 'disconnection':
            dbgprint(f'device {self.device.name} disconnected')

        elif ev == 'error':
            infoprint(f"error occured a device `{self.device.name}")
            _sess = DebugSession.from_json(event['execution_state'],
                                           self.module, self.device)
            _sess.exception = event['msg']
            # end = event['time'].monotonic()
            # self.register_measure(event['start_time'], end, _sess)
            self.changes_handler.add(_sess)
        else:
            errprint('not understood event occurred')
Esempio n. 2
0
 def pause(self) -> None:
     #TODO ask for debug session
     if not self.device.connected:
         dbgprint(f'First connect to {self.device.name}')
         return
     if self.device.pause():
         infoprint(f'`{self.device.name}` is paused')
     else:
         dbgprint(f'device {self.device.name} failed to pause')
Esempio n. 3
0
 def run(self) -> None:
     if not self.device.connected:
         dbgprint(f'First connect to {self.device.name}')
         return
     # self.__update_session() #TODO uncomment
     if self.device.run():
         infoprint(f'`{self.device.name}` is running')
     else:
         dbgprint(f'device {self.device.name} failed to run')
Esempio n. 4
0
    def step(self, amount: int = 1) -> DebugSession:
        if not self.device.connected:
            dbgprint(f'First connect to {self.device.name}')
            return

        self.__update_session()
        if self.device.step(amount):
            _json = self.device.get_execution_state()
            _sess = DebugSession.from_json(_json, self.module, self.device)
            self.changes_handler.add(_sess)
            infoprint("stepped")
            return _sess
Esempio n. 5
0
    def remove_breakpoint(self, inst: Union[Expr, int]) -> None:
        if not self.device.connected:
            dbgprint(f'First connect to {self.device.name}')
            return
        if isinstance(inst, int):
            [inst] = self.module.linenr(inst)

        if self.device.remove_breakpoint(inst.addr):
            infoprint(f'breakpoint {inst} removed')
            self.breakpoints = list(
                filter(lambda i: i.addr != inst.addr, self.breakpoints))
        else:
            infoprint(f"could not remove breakpoint {inst}")
Esempio n. 6
0
    def add_breakpoint(self, expr: Union[Expr, int]) -> None:
        if not self.device.connected:
            dbgprint(f'First connect to {self.device.name}')
            return

        if isinstance(expr, int):
            [expr] = self.module.linenr(expr)
        if self.device.add_breakpoint(expr.addr):
            # infoprint(f"added breakpoint at {expr}")
            infoprint(f"added breakpoint")
            self.breakpoints.append(expr.copy())
        else:
            dbgprint(f'failed to add breakpoint {expr}')
Esempio n. 7
0
    def connect(self, upload_proxies=False):
        c = self.device.connect(self.__handle_event)
        if not c:
            infoprint(f"connection failed to `{self.device.name}`")
        else:
            infoprint(f'connected to `{self.device.name}`')

        pc = self.__proxy_config
        if pc is not None and len(pc.get('proxy', [])) > 0:
            if upload_proxies:
                self.device.send_proxies(pc)

        if self.device.is_local:
            pass
Esempio n. 8
0
    def commit(self, mod: Union[WAModule, None] = None):
        if not self.device.connected:
            dbgprint(f'First connect to {self.device.name}')
            return

        wasm = None
        if mod is not None:
            wasm = mod.compile()
            self.module = mod
            self.__changeshandler.module = mod
        else:
            wasm = self.__changeshandler.commit()
        if self.device.commit(wasm):
            infoprint('Module Updated')
Esempio n. 9
0
    def receive_session(self, debugsess: DebugSession) -> None:
        if not self.device.connected:
            dbgprint(f'First connect to {self.device.name}')
            return

        if debugsess.modified:
            infoprint("Debug Session Modified")
            upd = debugsess.get_update()
            if not upd.valid:
                dbgprint("invalid change")
                return
            self.changes_handler.add(upd)
            debugsess = upd

        _json = debugsess.to_json()
        # _json['breakpoints'] = [ hex(bp.addr) for bp in self.breakpoints]
        dbgprint(f"sending breakpoints {_json['breakpoints']}")
        if self.device.receive_session(_json):
            infoprint(f"`{self.device.name}` received debug session")
            self.debug_session()