Пример #1
0
 def run_gdb(self):  # type: () -> None
     with self:  # disable console control
         normal_print('')
         try:
             cmd = [
                 '%sgdb' % self.toolchain_prefix,
                 '-ex',
                 'set serial baud %d' % self.serial.baudrate,
                 '-ex',
                 'target remote %s' % self.serial.port,
                 '-ex',
                 'interrupt',  # monitor has already parsed the first 'reason' command, need a second
                 self.elf_file
             ]
             process = subprocess.Popen(cmd, cwd='.')
             process.wait()
         except OSError as e:
             red_print('%s: %s' % (' '.join(cmd), e))
         except KeyboardInterrupt:
             pass  # happens on Windows, maybe other OSes
         finally:
             try:
                 # on Linux, maybe other OSes, gdb sometimes seems to be alive even after wait() returns...
                 process.terminate()
             except Exception:
                 pass
             try:
                 # also on Linux, maybe other OSes, gdb sometimes exits uncleanly and breaks the tty mode
                 subprocess.call(['stty', 'sane'])
             except Exception:
                 pass  # don't care if there's no stty, we tried...
         self.prompt_next_action('gdb exited')
Пример #2
0
    def main_loop(self) -> None:
        self._pre_start()

        try:
            while self.console_reader.alive and self.serial_reader.alive:
                try:
                    self._main_loop()
                except KeyboardInterrupt:
                    yellow_print(
                        'To exit from IDF monitor please use \"Ctrl+]\"')
                    self.serial_write(codecs.encode(CTRL_C))
        except SerialStopException:
            normal_print('Stopping condition has been received\n')
        except KeyboardInterrupt:
            pass
        finally:
            try:
                self.console_reader.stop()
                self.serial_reader.stop()
                self.logger.stop_logging()
                # Cancelling _invoke_processing_last_line_timer is not
                # important here because receiving empty data doesn't matter.
                self._invoke_processing_last_line_timer = None
            except Exception:  # noqa
                pass
            normal_print('\n')
Пример #3
0
    def main_loop(self):
        # type: () -> None
        self.console_reader.start()
        self.serial_reader.start()
        try:
            while self.console_reader.alive and self.serial_reader.alive:
                try:
                    item = self.cmd_queue.get_nowait()
                except queue.Empty:
                    try:
                        item = self.event_queue.get(True, 0.03)
                    except queue.Empty:
                        continue

                event_tag, data = item
                if event_tag == TAG_CMD:
                    self.handle_commands(data, self.target)
                elif event_tag == TAG_KEY:
                    try:
                        self.serial.write(codecs.encode(data))
                    except serial.SerialException:
                        pass  # this shouldn't happen, but sometimes port has closed in serial thread
                    except UnicodeEncodeError:
                        pass  # this can happen if a non-ascii character was passed, ignoring
                elif event_tag == TAG_SERIAL:
                    self.handle_serial_input(data)
                    if self._invoke_processing_last_line_timer is not None:
                        self._invoke_processing_last_line_timer.cancel()
                    self._invoke_processing_last_line_timer = threading.Timer(
                        0.1, self.invoke_processing_last_line)
                    self._invoke_processing_last_line_timer.start()
                    # If no further data is received in the next short period
                    # of time then the _invoke_processing_last_line_timer
                    # generates an event which will result in the finishing of
                    # the last line. This is fix for handling lines sent
                    # without EOL.
                elif event_tag == TAG_SERIAL_FLUSH:
                    self.handle_serial_input(data, finalize_line=True)
                else:
                    raise RuntimeError('Bad event data %r' %
                                       ((event_tag, data), ))
        except SerialStopException:
            normal_print('Stopping condition has been received\n')
        finally:
            try:
                self.console_reader.stop()
                self.serial_reader.stop()
                self.stop_logging()
                # Cancelling _invoke_processing_last_line_timer is not
                # important here because receiving empty data doesn't matter.
                self._invoke_processing_last_line_timer = None
            except Exception:
                pass
            normal_print('\n')
Пример #4
0
    def run_gdb(self):  # type: () -> None
        with self:  # disable console control
            normal_print('')
            try:
                cmd = [
                    '%sgdb' % self.toolchain_prefix, '-ex',
                    'set serial baud %d' % self.serial.baudrate, '-ex',
                    'target remote %s' % self.serial.port, self.elf_file
                ]

                # Here we handling GDB as a process
                # Open GDB process
                try:
                    process = subprocess.Popen(cmd, cwd='.')
                except KeyboardInterrupt:
                    pass

                # We ignore Ctrl+C interrupt form external process abd wait responce util GDB will be finished.
                while True:
                    try:
                        process.wait()
                        break
                    except KeyboardInterrupt:
                        pass  # We ignore the Ctrl+C
                self.gdb_exit = True

            except OSError as e:
                red_print('%s: %s' % (' '.join(cmd), e))
            except KeyboardInterrupt:
                pass  # happens on Windows, maybe other OSes
            finally:
                try:
                    # on Linux, maybe other OSes, gdb sometimes seems to be alive even after wait() returns...
                    process.terminate()
                except Exception:
                    pass
                try:
                    # also on Linux, maybe other OSes, gdb sometimes exits uncleanly and breaks the tty mode
                    subprocess.call(['stty', 'sane'])
                except Exception:
                    pass  # don't care if there's no stty, we tried...
Пример #5
0
    def main_loop(self):
        # type: () -> None
        self.console_reader.start()
        self.serial_reader.start()
        self.gdb_helper.gdb_exit = False
        self.serial_handler.start_cmd_sent = False
        try:
            while self.console_reader.alive and self.serial_reader.alive:
                try:
                    if self.gdb_helper.gdb_exit:
                        self.gdb_helper.gdb_exit = False
                        time.sleep(GDB_EXIT_TIMEOUT)
                        try:
                            # Continue the program after exit from the GDB
                            self.serial.write(
                                codecs.encode(GDB_UART_CONTINUE_COMMAND))
                            self.serial_handler.start_cmd_sent = True
                        except serial.SerialException:
                            pass  # this shouldn't happen, but sometimes port has closed in serial thread
                        except UnicodeEncodeError:
                            pass  # this can happen if a non-ascii character was passed, ignoring

                    try:
                        item = self.cmd_queue.get_nowait()
                    except queue.Empty:
                        try:
                            item = self.event_queue.get(
                                timeout=EVENT_QUEUE_TIMEOUT)
                        except queue.Empty:
                            continue

                    event_tag, data = item
                    if event_tag == TAG_CMD:
                        self.serial_handler.handle_commands(
                            data, self.target, self.run_make,
                            self.console_reader, self.serial_reader)
                    elif event_tag == TAG_KEY:
                        try:
                            self.serial.write(codecs.encode(data))
                        except serial.SerialException:
                            pass  # this shouldn't happen, but sometimes port has closed in serial thread
                        except UnicodeEncodeError:
                            pass  # this can happen if a non-ascii character was passed, ignoring
                    elif event_tag == TAG_SERIAL:
                        self.serial_handler.handle_serial_input(
                            data, self.console_parser, self.coredump,
                            self.gdb_helper, self._line_matcher,
                            self.check_gdb_stub_and_run)
                        if self._invoke_processing_last_line_timer is not None:
                            self._invoke_processing_last_line_timer.cancel()
                        self._invoke_processing_last_line_timer = threading.Timer(
                            LAST_LINE_THREAD_INTERVAL,
                            self.invoke_processing_last_line)
                        self._invoke_processing_last_line_timer.start()
                        # If no further data is received in the next short period
                        # of time then the _invoke_processing_last_line_timer
                        # generates an event which will result in the finishing of
                        # the last line. This is fix for handling lines sent
                        # without EOL.
                    elif event_tag == TAG_SERIAL_FLUSH:
                        self.serial_handler.handle_serial_input(
                            data,
                            self.console_parser,
                            self.coredump,
                            self.gdb_helper,
                            self._line_matcher,
                            self.check_gdb_stub_and_run,
                            finalize_line=True)
                    else:
                        raise RuntimeError('Bad event data %r' %
                                           ((event_tag, data), ))
                except KeyboardInterrupt:
                    try:
                        yellow_print(
                            'To exit from IDF monitor please use \"Ctrl+]\"')
                        self.serial.write(codecs.encode(CTRL_C))
                    except serial.SerialException:
                        pass  # this shouldn't happen, but sometimes port has closed in serial thread
                    except UnicodeEncodeError:
                        pass  # this can happen if a non-ascii character was passed, ignoring
        except SerialStopException:
            normal_print('Stopping condition has been received\n')
        except KeyboardInterrupt:
            pass
        finally:
            try:
                self.console_reader.stop()
                self.serial_reader.stop()
                self.logger.stop_logging()
                # Cancelling _invoke_processing_last_line_timer is not
                # important here because receiving empty data doesn't matter.
                self._invoke_processing_last_line_timer = None
            except Exception:  # noqa
                pass
            normal_print('\n')