Repository: jerryscript-project/jerryscript
File: jerry-debugger/jerry_client_main.py (Python)

Code before:
                    result += "Exception throw detected (to disable automatic stop type exception 0)\n"
                    if self.exception_string:
                        result += "Exception hint: %s\n" % (self.exception_string)
                        self.exception_string = ""

                if breakpoint[1]:
                    breakpoint_info = "at"
                else:
                    breakpoint_info = "around"

                if breakpoint[0].active_index >= 0:
                    breakpoint_info += " breakpoint:%s%d%s" % (self.red, breakpoint[0].active_index, self.nocolor)

                result += "Stopped %s %s\n" % (breakpoint_info, breakpoint[0])

                if self.display > 0:
                    result += self.print_source(self.display, self.src_offset)

                self.prompt = True
                return DebuggerAction(DebuggerAction.TEXT, result)

            elif buffer_type == JERRY_DEBUGGER_EXCEPTION_STR:
                self.exception_string += data[1:].decode('latin1')

            elif buffer_type == JERRY_DEBUGGER_EXCEPTION_STR_END:
                self.exception_string += data[1:].decode('latin1')

            elif buffer_type == JERRY_DEBUGGER_BACKTRACE_TOTAL:
                total = struct.unpack(self.byte_order + self.idx_format, data[1:])[0]
                result += "Total number of frames: %d\n" % (total)
                return DebuggerAction(DebuggerAction.TEXT, result)

            elif buffer_type in [JERRY_DEBUGGER_BACKTRACE, JERRY_DEBUGGER_BACKTRACE_END]:
                frame_index = self.frame_index

                buffer_pos = 1
                while buffer_size > 0:
                    breakpoint_data = struct.unpack(self.byte_order + self.cp_format + self.idx_format,
                                                    data[buffer_pos: buffer_pos + self.cp_size + 4])

                    breakpoint = self._get_breakpoint(breakpoint_data)

                    result += "Frame %d: %s\n" % (frame_index, breakpoint[0])

                    frame_index += 1
                    buffer_pos += self.cp_size + 4
                    buffer_size -= self.cp_size + 4

                if buffer_type == JERRY_DEBUGGER_BACKTRACE_END:
                    self.prompt = True
                else:

Review comment (bug):
Is Latin-1 encoding OK for exception strings? Cannot they contain arbitrary Unicode characters?

Btw, this could be simplified to `elif buffer_type in [JERRY_DEBUGGER_EXCEPTION_STR, JERRY_DEBUGGER_EXCEPTION_STR_END]:`, just like elsewhere in the code.

Code after:
                    result += "Exception throw detected (to disable automatic stop type exception 0)\n"
                    if self.exception_string:
                        result += "Exception hint: %s\n" % (self.exception_string)
                        self.exception_string = ""

                if breakpoint[1]:
                    breakpoint_info = "at"
                else:
                    breakpoint_info = "around"

                if breakpoint[0].active_index >= 0:
                    breakpoint_info += " breakpoint:%s%d%s" % (self.red, breakpoint[0].active_index, self.nocolor)

                result += "Stopped %s %s\n" % (breakpoint_info, breakpoint[0])

                if self.display > 0:
                    result += self.print_source(self.display, self.src_offset)

                self.prompt = True
                return DebuggerAction(DebuggerAction.TEXT, result)

            elif buffer_type in [JERRY_DEBUGGER_EXCEPTION_STR, JERRY_DEBUGGER_EXCEPTION_STR_END]:
                self.exception_string += data[1:].decode('utf8')

            elif buffer_type == JERRY_DEBUGGER_BACKTRACE_TOTAL:
                total = struct.unpack(self.byte_order + self.idx_format, data[1:])[0]
                result += "Total number of frames: %d\n" % (total)
                return DebuggerAction(DebuggerAction.TEXT, result)

            elif buffer_type in [JERRY_DEBUGGER_BACKTRACE, JERRY_DEBUGGER_BACKTRACE_END]:
                frame_index = self.frame_index

                buffer_pos = 1
                while buffer_size > 0:
                    breakpoint_data = struct.unpack(self.byte_order + self.cp_format + self.idx_format,
                                                    data[buffer_pos: buffer_pos + self.cp_size + 4])

                    breakpoint = self._get_breakpoint(breakpoint_data)

                    result += "Frame %d: %s\n" % (frame_index, breakpoint[0])

                    frame_index += 1
                    buffer_pos += self.cp_size + 4
                    buffer_size -= self.cp_size + 4

                if buffer_type == JERRY_DEBUGGER_BACKTRACE_END:
                    self.prompt = True
                else:
                    self.frame_index = frame_index

                return DebuggerAction(DebuggerAction.TEXT, result)