Example #1
0
 def close(self):
     cui.get_variable(constants.ST_BREAKPOINTS).remove_session(self)
     for thread in self.threads.values():
         thread.close()
     cui.kill_buffer(buffers.ThreadBuffer, self)
     cui.run_hook(constants.ST_ON_KILL_SESSION)
     super(Session, self).close()
Example #2
0
    def __init__(self, socket):
        super(Session, self).__init__(socket)
        self.threads = collections.OrderedDict()
        self._sequence_no = 1
        self._file_mapping = cui.get_variable(constants.ST_FILE_MAPPING).copy()

        cui.get_variable(constants.ST_BREAKPOINTS).add_session(self)

        # Initialize debugger, load threads, start process
        self.send_command(constants.CMD_VERSION, 'cui\tWINDOWS\tLINE')
        self.send_command(constants.CMD_LIST_THREADS)
        self.send_command(constants.CMD_RUN)
Example #3
0
    def start(self):
        host = cui.get_variable(self.host_var)
        port = cui.get_variable(self.port_var)

        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.server.bind((host, port))
        self.server.listen(5)
        cui.message('Listening on %s:%s' % self.server.getsockname())

        cui.register_waitable(self.server, self.read)
        cui.add_exit_handler(self.shutdown)
Example #4
0
def evaluate(string, handle_result=True):
    log_calls = cui.get_variable(['logging', 'emacs-calls'])
    if log_calls:
        cui.message('emacs-call: %s' % string)

    proc = subprocess.run(
        [cui.get_variable(['emacs', 'emacsclient']), "-e", string],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)
    if (proc.returncode != 0):
        raise LispException(proc.stderr.decode('utf-8'))
    result = proc.stdout.decode('utf-8').strip()
    if log_calls:
        cui.message('emacs-result: %s' % result)
    return parse(result) if handle_result else None
Example #5
0
 def _write_breakpoints(self):
     if cui.get_variable(constants.ST_SERIALIZE_BREAKPOINTS):
         with open(cui.user_directory('pydevd_breaks.json'), 'w') as f:
             json.dump([{
                 'path': path,
                 'lines': lines
             } for path, lines in self._breakpoints.items()], f)
Example #6
0
 def send_command(self, command, argument=''):
     sequence_no = self._sequence_no
     payload = ('%s\t%s\t%s\n' % (command, sequence_no, argument))
     if cui.get_variable(constants.ST_DEBUG_LOG):
         cui.message('=== Sending command: \n%s' % (payload, ))
     self.send_all(payload.encode('utf-8'))
     self._sequence_no += 2
     return sequence_no
Example #7
0
 def render_item(self, window, item, index):
     tree_tab = cui.get_variable(['tree-tab'])
     rendered_node = self.render_node(
         window, item['item'], item['depth'],
         window.dimensions[1] - tree_tab * item['depth'])
     return [[
         self.render_tree_tab(window, item, line, tree_tab,
                              line == rendered_node[0]), line
     ] for line in rendered_node]
Example #8
0
 def _read_breakpoints(self):
     if cui.get_variable(constants.ST_SERIALIZE_BREAKPOINTS):
         try:
             with open(cui.user_directory('pydevd_breaks.json'), 'r') as f:
                 for entry in json.load(f):
                     path = entry['path']
                     for line in entry['lines']:
                         self.add_breakpoint(path, line)
         except IOError:
             pass
Example #9
0
 def toggle_breakpoint(self, path, line, activate=True):
     active_map = cui.get_variable(constants.ST_BREAKPOINTS) \
                     ._active_map[_Breakpoints.breakpoint_id(path, line)]
     is_active = active_map.get(str(self), False)
     if is_active:
         self.send_command(
             constants.CMD_REMOVE_BREAK, '\t'.join([
                 'python-line',
                 self._file_mapping.to_other(path),
                 str(line + 1)
             ]))
         active_map[str(self)] = False
     elif not is_active and activate:
         self.send_command(
             constants.CMD_SET_BREAK, '\t'.join([
                 'python-line',
                 self._file_mapping.to_other(path),
                 str(line + 1), 'None', 'THREAD', 'None', 'None'
             ]))
         active_map[str(self)] = True
     else:
         active_map[str(self)] = is_active
Example #10
0
def initialize():
    proc = subprocess.run(
        [cui.get_variable(['emacs', 'emacsclient']), '--version'],
        universal_newlines=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)
    if (proc.returncode != 0):
        raise LispException(proc.stderr)
    cui.message(proc.stdout)
    # define functions from python
    while len(FUNCTION_LIST):
        evaluate(FUNCTION_LIST.pop(0))

    while len(PACKAGE_LIST):
        PACKAGE_LIST.pop(0).load()

    # retrieve doc for declared functions
    global DEFERRED_FN_INFO
    while DEFERRED_FN_INFO:
        fns = DEFERRED_FN_INFO[:10]
        for fn, info in zip((fn for _, fn in fns),
                            _retrieve_function_infos((sym for sym, _ in fns))):
            _set_function_info(fn, info)
        DEFERRED_FN_INFO = DEFERRED_FN_INFO[10:]
Example #11
0
def pydevd_session(session_id):
    return cui.get_variable(constants.ST_SERVER).clients_by_name[session_id]
Example #12
0
def pydevd_sessions():
    return list(cui.get_variable(constants.ST_SERVER).clients.values())
Example #13
0
 def __init__(self, session, *args, **kwargs):
     super(BreakpointLineHandler, self).__init__(session, *args, **kwargs)
     self._session = session
     self._breakpoints = cui.get_variable(constants.ST_BREAKPOINTS)
Example #14
0
def remove_breakpoints(path):
    breakpoints = cui.get_variable(constants.ST_BREAKPOINTS)
    for line in list(breakpoints.breakpoints(path)):
        breakpoints.remove_breakpoint(path, line)
Example #15
0
 def load(self):
     path = _convert_arg(
         cui.get_variable(['emacs', 'file-mapping']).to_other(self.path))
     evaluate("(if (not (member '%s features)) (load %s))" %
              (self.name, path))
Example #16
0
def toggle_breakpoint(session, path, line):
    cui.get_variable(constants.ST_BREAKPOINTS) \
       .add_breakpoint(path, line, activate=(session is None))
    if session:
        return session.toggle_breakpoint(path, line)
Example #17
0
def remove_breakpoint(path, line):
    return cui.get_variable(constants.ST_BREAKPOINTS) \
              .remove_breakpoint(path, line)
Example #18
0
 def handle_line(self, line):
     if cui.get_variable(constants.ST_DEBUG_LOG):
         cui.message('=== Received response: \n%s' % (line, ))
     self._dispatch(Command.from_string(self._file_mapping, line))
Example #19
0
def pydevd_id(path, line):
    return cui.get_variable(constants.ST_BREAKPOINTS).pydevd_id(path, line)
Example #20
0
 def __init__(self, session):
     super(BreakpointBuffer, self).__init__(session)
     self._session = session
     self._breakpoints = cui.get_variable(constants.ST_BREAKPOINTS)