Exemplo n.º 1
0
    def handle_exception(self, res):
        if res is None:
            return

        if isinstance(res, DebugBreakpointSoft):
            print "Breakpoint reached @0x%08x" % res.addr
        elif isinstance(res, ExceptionHandle):
            if res == ExceptionHandle.memoryBreakpoint():
                print "Memory breakpoint reached!"

                # Remove flag
                except_flag = self.myjit.vm.get_exception()
                self.myjit.vm.set_exception(except_flag ^ res.except_flag)

            else:
                raise NotImplementedError("Unknown Except")
        else:
            raise NotImplementedError("type res")
Exemplo n.º 2
0
    def handle_exception(self, res):
        if res is None:
            return

        if isinstance(res, DebugBreakpointSoft):
            print "Breakpoint reached @0x%08x" % res.addr
        elif isinstance(res, ExceptionHandle):
            if res == ExceptionHandle.memoryBreakpoint():
                print "Memory breakpoint reached!"

                # Remove flag
                except_flag = self.myjit.vm.get_exception()
                self.myjit.vm.set_exception(except_flag ^ res.except_flag)

            else:
                raise NotImplementedError("Unknown Except")
        else:
            raise NotImplementedError("type res")
Exemplo n.º 3
0
    def handle_exception(self, res):
        if not res:
            # A breakpoint has stopped the execution
            return DebugBreakpointTerminate(res)

        if isinstance(res, DebugBreakpointSoft):
            print "Breakpoint reached @0x%08x" % res.addr
        elif isinstance(res, ExceptionHandle):
            if res == ExceptionHandle.memoryBreakpoint():
                print "Memory breakpoint reached!"

                # Remove flag
                except_flag = self.myjit.vm.get_exception()
                self.myjit.vm.set_exception(except_flag ^ res.except_flag)

            else:
                raise NotImplementedError("Unknown Except")
        else:
            raise NotImplementedError("type res")

        # Repropagate res
        return res
Exemplo n.º 4
0
    def handle_exception(self, res):
        if not res:
            # A breakpoint has stopped the execution
            return DebugBreakpointTerminate(res)

        if isinstance(res, DebugBreakpointSoft):
            print "Breakpoint reached @0x%08x" % res.addr
        elif isinstance(res, ExceptionHandle):
            if res == ExceptionHandle.memoryBreakpoint():
                print "Memory breakpoint reached!"

                # Remove flag
                except_flag = self.myjit.vm.get_exception()
                self.myjit.vm.set_exception(except_flag ^ res.except_flag)

            else:
                raise NotImplementedError("Unknown Except")
        else:
            raise NotImplementedError("type res")

        # Repropagate res
        return res
Exemplo n.º 5
0
    def process_messages(self):

        while self.recv_queue:
            msg = self.recv_queue.pop(0)
            buf = StringIO(msg)
            msg_type = buf.read(1)

            self.send_queue.append("+")

            if msg_type == "q":
                if msg.startswith("qSupported"):
                    self.send_queue.append("PacketSize=3fff")
                elif msg.startswith("qC"):
                    # Current thread
                    self.send_queue.append("")
                elif msg.startswith("qAttached"):
                    # Not supported
                    self.send_queue.append("")
                elif msg.startswith("qTStatus"):
                    # Not supported
                    self.send_queue.append("")
                elif msg.startswith("qfThreadInfo"):
                    # Not supported
                    self.send_queue.append("")
                else:
                    raise NotImplementedError()

            elif msg_type == "H":
                # Set current thread
                self.send_queue.append("OK")

            elif msg_type == "?":
                # Report why the target halted
                self.send_queue.append(self.status)  # TRAP signal

            elif msg_type == "g":
                # Report all general register values
                self.send_queue.append(self.report_general_register_values())

            elif msg_type == "p":
                # Read a specific register
                reg_num = int(buf.read(), 16)
                self.send_queue.append(self.read_register(reg_num))

            elif msg_type == "P":
                # Set a specific register
                reg_num, value = buf.read().split("=")
                reg_num = int(reg_num, 16)
                value = int(value.decode("hex")[::-1].encode("hex"), 16)
                self.set_register(reg_num, value)
                self.send_queue.append("OK")

            elif msg_type == "m":
                # Read memory
                addr, size = map(lambda x: int(x, 16), buf.read().split(","))
                self.send_queue.append(self.read_memory(addr, size))

            elif msg_type == "k":
                # Kill
                self.sock.close()
                self.send_queue = []
                self.sock = None

            elif msg_type == "!":
                # Extending debugging will be used
                self.send_queue.append("OK")

            elif msg_type == "v":
                if msg == "vCont?":
                    # Is vCont supported ?
                    self.send_queue.append("")

            elif msg_type == "s":
                # Step
                self.dbg.step()
                self.send_queue.append("S05")  # TRAP signal

            elif msg_type == "Z":
                # Add breakpoint or watchpoint
                bp_type = buf.read(1)
                if bp_type == "0":
                    # Exec breakpoint
                    assert(buf.read(1) == ",")
                    addr, size = map(
                        lambda x: int(x, 16), buf.read().split(","))

                    if size != 1:
                        raise NotImplementedError("Bigger size")
                    self.dbg.add_breakpoint(addr)
                    self.send_queue.append("OK")

                elif bp_type == "1":
                    # Hardware BP
                    assert(buf.read(1) == ",")
                    addr, size = map(
                        lambda x: int(x, 16), buf.read().split(","))

                    self.dbg.add_memory_breakpoint(addr, size,
                                                   read=True,
                                                   write=True)
                    self.send_queue.append("OK")

                elif bp_type in ["2", "3", "4"]:
                    # Memory breakpoint
                    assert(buf.read(1) == ",")
                    read = bp_type in ["3", "4"]
                    write = bp_type in ["2", "4"]
                    addr, size = map(
                        lambda x: int(x, 16), buf.read().split(","))

                    self.dbg.add_memory_breakpoint(addr, size,
                                                   read=read,
                                                   write=write)
                    self.send_queue.append("OK")

                else:
                    raise ValueError("Impossible value")

            elif msg_type == "z":
                # Remove breakpoint or watchpoint
                bp_type = buf.read(1)
                if bp_type == "0":
                    # Exec breakpoint
                    assert(buf.read(1) == ",")
                    addr, size = map(
                        lambda x: int(x, 16), buf.read().split(","))

                    if size != 1:
                        raise NotImplementedError("Bigger size")
                    dbgsoft = self.dbg.get_breakpoint_by_addr(addr)
                    assert(len(dbgsoft) == 1)
                    self.dbg.remove_breakpoint(dbgsoft[0])
                    self.send_queue.append("OK")

                elif bp_type == "1":
                    # Hardware BP
                    assert(buf.read(1) == ",")
                    addr, size = map(
                        lambda x: int(x, 16), buf.read().split(","))
                    self.dbg.remove_memory_breakpoint_by_addr_access(
                        addr, read=True, write=True)
                    self.send_queue.append("OK")

                elif bp_type in ["2", "3", "4"]:
                    # Memory breakpoint
                    assert(buf.read(1) == ",")
                    read = bp_type in ["3", "4"]
                    write = bp_type in ["2", "4"]
                    addr, size = map(
                        lambda x: int(x, 16), buf.read().split(","))

                    self.dbg.remove_memory_breakpoint_by_addr_access(
                        addr, read=read, write=write)
                    self.send_queue.append("OK")

                else:
                    raise ValueError("Impossible value")

            elif msg_type == "c":
                # Continue
                self.status = ""
                self.send_messages()
                ret = self.dbg.run()
                if isinstance(ret, debugging.DebugBreakpointSoft):
                    self.status = "S05"
                    self.send_queue.append("S05")  # TRAP signal
                elif isinstance(ret, ExceptionHandle):
                    if ret == ExceptionHandle.memoryBreakpoint():
                        self.status = "S05"
                        self.send_queue.append("S05")
                    else:
                        raise NotImplementedError("Unknown Except")
                elif isinstance(ret, debugging.DebugBreakpointTerminate):
                    # Connexion should close, but keep it running as a TRAP
                    # The connexion will be close on instance destruction
                    print ret
                    self.status = "S05"
                    self.send_queue.append("S05")
                else:
                    raise NotImplementedError()

            else:
                raise NotImplementedError(
                    "Not implemented: message type '%s'" % msg_type)