Ejemplo n.º 1
0
def read_json_arguments_if_needed(arguments):
    '''If arguments_in_json is enabled we parse all the
    arguments from a separate input pipe.
    '''
    if arguments.arguments_in_json:
        ARGUMENT_INPUT_FD = 3
        buffering = 1  # 1 means line-buffered.
        file = os.fdopen(ARGUMENT_INPUT_FD, 'r+', buffering)
        init_line = file.readline()
        if init_line.startswith('init'):
            file.write('ready\n')  # Tell parent channel is ready.
            arguments_input = file.readline()
            log_debug('Received json arguments: %s' % arguments_input)
            # Parse JSON into python object.
            arguments = json.loads(
                arguments_input,
                object_hook=lambda d: namedtuple('arguments', d.keys())
                (*d.values()))
            log_debug('Parsed arguments: %s' %
                      json.dumps(arguments, ensure_ascii=False))
            file.close()
        else:
            # Fail: did not receive proper initialization sequence.
            log_error('LLDB got unknown init line: %s' % init_line)
            sys.exit(2)
    return arguments
Ejemplo n.º 2
0
    def __init__(self, debugger_store, app):
        Thread.__init__(self)
        self.daemon = True
        self._debugger_store = debugger_store
        self._app = app
        self._listener = debugger_store.debugger.GetListener()
        lldb = get_lldb()
        self.breakpoint_event_type_to_name_map = {
            lldb.eBreakpointEventTypeAdded: 'Added',
            lldb.eBreakpointEventTypeCommandChanged: 'Command Changed',
            lldb.eBreakpointEventTypeConditionChanged: 'Condition Changed',
            lldb.eBreakpointEventTypeDisabled: 'Disabled',
            lldb.eBreakpointEventTypeEnabled: 'Enabled',
            lldb.eBreakpointEventTypeIgnoreChanged: 'Ignore Changed',
            lldb.eBreakpointEventTypeInvalidType: 'Invalid Type',
            lldb.eBreakpointEventTypeLocationsAdded: 'Location Added',
            lldb.eBreakpointEventTypeLocationsRemoved: 'Location Removed',
            lldb.eBreakpointEventTypeLocationsResolved: 'Location Resolved',
            lldb.eBreakpointEventTypeRemoved: 'Removed',
            lldb.eBreakpointEventTypeThreadChanged: 'Thread Changed',
        }

        process = debugger_store.debugger.GetSelectedTarget().process
        self._add_listener_to_process(process)

        # LLDB will not emit any stopping event during attach.
        # Linux lldb has a bug of not emitting stopping event during launch.
        if self._debugger_store.is_attach or sys.platform.startswith('linux'):
            if process.state != lldb.eStateStopped:
                # Instead of using assert() which will crash debugger log an error message
                # and tolerate this non-fatal situation.
                log_error(
                    'Inferior should be stopped after attach or linux launch')
            self._send_paused_notification(process)
        self._add_listener_to_target(process.target)
Ejemplo n.º 3
0
    def send_output_message_sync(self, level, text):
        self._send_output_message(level, text, is_sync=True)

        # Wait from response from client.
        response = self._file.readline()
        log_debug('Ipc response: %s' % response)
        response_object = json.loads(response)
        if int(response_object['message_id']) != self._message_id:
            log_error('Get wrong ipc response: %s' % response)
Ejemplo n.º 4
0
    def send_output_message_sync(self, level, text):
        self._send_output_message(level, text, is_sync=True)

        # Wait from response from client.
        response = self._file.readline()
        log_debug('Ipc response: %s' % response)
        response_object = json.loads(response)
        if int(response_object['message_id']) != self._message_id:
            log_error('Get wrong ipc response: %s' % response)
Ejemplo n.º 5
0
    def received_message(self, message):
        log_debug('received_message: %s' % message.data)
        parsed = None
        try:
            parsed = json.loads(message.data)
        except Exception:
            # Print invalid JSON requests to stderr.
            log_error('Invalid JSON: %s' % message)

        response = self._generate_response(parsed)
        response_in_json = json.dumps(response)
        log_debug('response: %s' % response_in_json)
        self.send(response_in_json)
Ejemplo n.º 6
0
    def received_message(self, message):
        log_debug('received_message: %s' % message.data);
        parsed = None
        try:
            parsed = json.loads(message.data)
        except Exception:
            # Print invalid JSON requests to stderr.
            log_error('Invalid JSON: %s' % message)

        response = self._generate_response(parsed)
        response_in_json = json.dumps(response);
        log_debug('response: %s' % response_in_json);
        self.send(response_in_json)
Ejemplo n.º 7
0
def _get_default_lldb_python_path():
    if sys.platform == 'darwin':
        try:
            # Update pythonpath with likely location in the active Xcode app bundle.
            developer_dir = subprocess.check_output(['xcode-select', '--print-path'])
            return os.path.join(
                developer_dir.strip(),
                '../SharedFrameworks/LLDB.framework/Resources/Python/lldb')
        except:
            log_error('Cannot find lldb: make sure you have Xcode installed or lldb in the path.')
            os._exit(2)
    elif sys.platform.startswith('linux'):
        # Assume to be Facebook linux devserver.
        return '/mnt/gvfs/third-party2/lldb/d51c341932343d3657b9fa997f3ed7d72775d98d/3.8.0.rc3/' \
            'centos6-native/ff04b3a/lib/python2.7/site-packages/lldb'
    else:
        raise Exception('Failure to find lldb python binding: unknown platform.')
Ejemplo n.º 8
0
def _get_default_lldb_python_path():
    if sys.platform == 'darwin':
        try:
            # Update pythonpath with likely location in the active Xcode app bundle.
            developer_dir = subprocess.check_output(['xcode-select', '--print-path'])
            return os.path.join(
                developer_dir.strip(),
                '../SharedFrameworks/LLDB.framework/Resources/Python')
        except:
            log_error('Cannot find lldb: make sure you have Xcode installed or lldb in the path.')
            os._exit(2)
    elif sys.platform.startswith('linux'):
        # Assume to be Facebook linux devserver.
        # TODO: make this configurable.
        return '/mnt/gvfs/third-party2/lldb/d51c341932343d3657b9fa997f3ed7d72775d98d/3.8.0.rc3/' \
            'centos6-native/ff04b3a/lib/python2.7/site-packages'
    else:
        raise Exception('Failure to find lldb python binding: unknown platform.')
Ejemplo n.º 9
0
def _get_lldb_python_path():
    if sys.platform == "darwin":
        try:
            # Update pythonpath with likely location in the active Xcode app bundle.
            developer_dir = subprocess.check_output(["xcode-select", "--print-path"])
            return os.path.join(developer_dir.strip(), "../SharedFrameworks/LLDB.framework/Resources/Python")
        except:
            log_error("Cannot find lldb: make sure you have Xcode installed or lldb in the path.")
            os._exit(2)
    elif sys.platform.startswith("linux"):
        # Assume to be Facebook linux devserver.
        # TODO: make this configurable.
        return (
            "/mnt/gvfs/third-party2/lldb/d51c341932343d3657b9fa997f3ed7d72775d98d/"
            "3.8.0.rc3/centos6-native/ff04b3a/lib/python2.7/site-packages"
        )
    else:
        raise Exception("Failure to find lldb python binding: unknown platform.")
Ejemplo n.º 10
0
    def received_message(self, message):

        parsed = None
        try:
            parsed = json.loads(message.data)
        except Exception:
            # Print invalid JSON requests to stderr.
            log_error('Invalid JSON: %s' % message)

        should_log = self._is_debugger_protocol(parsed)
        if should_log:
            log_debug('received_message: %s' % message.data)

        response = self._generate_response(parsed)
        response_in_json = json.dumps(response, ensure_ascii=False)
        if should_log:
            log_debug('response: %s' % response_in_json)
        self.send(response_in_json)
Ejemplo n.º 11
0
def get_lldb():
    global _lldb
    if _lldb:
        return _lldb

    try:
        _add_default_lldb_python_path()
        # _add_custom_lldb_python_path() must be called after
        # _add_default_lldb_python_path() to take precedence.
        _add_custom_lldb_python_path()

        import lldb
        _lldb = lldb
        log_debug('find_lldb: %s' % str(lldb))
        return _lldb
    except ImportError, error:
        log_error(_get_lldb_import_error_message())
        os._exit(2)
Ejemplo n.º 12
0
    def received_message(self, message):

        parsed = None
        try:
            parsed = json.loads(message.data)
        except Exception:
            # Print invalid JSON requests to stderr.
            log_error('Invalid JSON: %s' % message)

        should_log = self._is_debugger_protocol(parsed)
        if should_log:
            log_debug('received_message: %s' % message.data)

        response = self._generate_response(parsed)
        response_in_json = json.dumps(response, ensure_ascii=False)
        if should_log:
            log_debug('response: %s' % response_in_json)
        self.send(response_in_json)
Ejemplo n.º 13
0
    def __init__(self, debugger_store, app):
      Thread.__init__(self)
      self.daemon = True
      self._debugger_store = debugger_store
      self._app = app
      self._listener = debugger_store.debugger.GetListener()

      process = debugger_store.debugger.GetSelectedTarget().process
      self._add_listener_to_process(process)

      # LLDB will not emit any stopping event during attach.
      # Linux lldb has a bug of not emitting stopping event during launch.
      if self._debugger_store.is_attach or sys.platform.startswith('linux'):
          if process.state != lldb.eStateStopped:
              # Instead of using assert() which will crash debugger log an error message
              # and tolerate this non-fatal situation.
              log_error('Inferior should be stopped after attach or linux launch')
          self._send_paused_notification(process)
      self._add_listener_to_target(process.target)
Ejemplo n.º 14
0
    def __init__(self, debugger_store, app):
      Thread.__init__(self)
      self.daemon = True
      self._debugger_store = debugger_store
      self._app = app
      self._listener = debugger_store.debugger.GetListener()

      process = debugger_store.debugger.GetSelectedTarget().process
      self._add_listener_to_process(process)

      # LLDB will not emit any stopping event during attach.
      # Linux lldb has a bug of not emitting stopping event during launch.
      if self._debugger_store.is_attach or sys.platform.startswith('linux'):
          if process.state != lldb.eStateStopped:
              # Instead of using assert() which will crash debugger log an error message
              # and tolerate this non-fatal situation.
              log_error('Inferior should be stopped after attach or linux launch')
          self._send_paused_notification(process)
      self._add_listener_to_target(process.target)
Ejemplo n.º 15
0
def read_json_arguments_if_needed(arguments):
    '''If arguments_in_json is enabled we parse all the
    arguments from a separate input pipe.
    '''
    if arguments.arguments_in_json:
        ARGUMENT_INPUT_FD = 3
        buffering = 1  # 1 means line-buffered.
        file = os.fdopen(ARGUMENT_INPUT_FD, 'r+', buffering)
        init_line = file.readline()
        if init_line.startswith('init'):
            file.write('ready\n')  # Tell parent channel is ready.
            arguments_input = file.readline()
            log_debug('Received json arguments: %s' % arguments_input)
            # Parse JSON into python object.
            arguments = json.loads(
                arguments_input,
                object_hook=lambda d: namedtuple('arguments', d.keys())(*d.values()))
            log_debug('Parsed arguments: %s' % json.dumps(arguments, ensure_ascii=False))
            file.close()
        else:
            # Fail: did not receive proper initialization sequence.
            log_error('LLDB got unknown init line: %s' % init_line)
            sys.exit(2)
    return arguments
Ejemplo n.º 16
0
    def __init__(self, debugger_store, app):
        Thread.__init__(self)
        self.daemon = True
        self._debugger_store = debugger_store
        self._app = app
        self._listener = debugger_store.debugger.GetListener()
        lldb = get_lldb()
        self.breakpoint_event_type_to_name_map = {
            lldb.eBreakpointEventTypeAdded: 'Added',
            lldb.eBreakpointEventTypeCommandChanged: 'Command Changed',
            lldb.eBreakpointEventTypeConditionChanged: 'Condition Changed',
            lldb.eBreakpointEventTypeDisabled: 'Disabled',
            lldb.eBreakpointEventTypeEnabled: 'Enabled',
            lldb.eBreakpointEventTypeIgnoreChanged: 'Ignore Changed',
            lldb.eBreakpointEventTypeInvalidType: 'Invalid Type',
            lldb.eBreakpointEventTypeLocationsAdded: 'Location Added',
            lldb.eBreakpointEventTypeLocationsRemoved: 'Location Removed',
            lldb.eBreakpointEventTypeLocationsResolved: 'Location Resolved',
            lldb.eBreakpointEventTypeRemoved: 'Removed',
            lldb.eBreakpointEventTypeThreadChanged: 'Thread Changed',
        }



        process = debugger_store.debugger.GetSelectedTarget().process
        self._add_listener_to_process(process)

        # LLDB will not emit any stopping event during attach.
        # Linux lldb has a bug of not emitting stopping event during launch.
        if self._debugger_store.is_attach or sys.platform.startswith('linux'):
            if process.state != lldb.eStateStopped:
                # Instead of using assert() which will crash debugger log an error message
                # and tolerate this non-fatal situation.
                log_error('Inferior should be stopped after attach or linux launch')
            self._send_paused_notification(process)
        self._add_listener_to_target(process.target)
Ejemplo n.º 17
0
 def _handle_unknown_event(self, event):
     log_error('Unknown event: %d %s %s' % (
         event.GetType(),
         lldb.SBEvent.GetCStringFromEvent(event),
         self._get_description_from_object(event)))
Ejemplo n.º 18
0
 def _handle_unknown_event(self, event):
     log_error('Unknown event: %d %s %s' %
               (event.GetType(), lldb.SBEvent.GetCStringFromEvent(event),
                self._get_description_from_object(event)))