# Path: debugger/enums.py
# class ProcessState(Enum):
#     """
#     Represents the debugged process' state.
#     """
#     Attaching = 3
#     Connected = 2
#     Crashed = 8
#     Detached = 9
#     Exited = 10
#     Invalid = 0
#     Launching = 4
#     Running = 6
#     Stepping = 7
#     Stopped = 5
#     Suspended = 11
#     Unloaded = 1
# 
# Path: debugger/util.py
# class EventBroadcaster(object):
#     """
#     Object that broadcasts event to it's listeners.
# 
#     Evety broadcaster represents a single event type.
#     """
#     def __init__(self):
#         self.listeners = []
# 
#     def notify(self, *args, **kwargs):
#         """
#         Notifies all listeners that an event has occured.
#         @param args: arbitraty arguments that will be passed to the listeners
#         """
#         map(lambda listener: listener(*args, **kwargs), self.listeners)
# 
#     def subscribe(self, listener):
#         """
#         Subscribes an event listener, who will receive events from the
#         broadcaster.
#         @type listener: function
#         """
#         self.listeners.append(listener)
# 
#     def unsubscribe(self, listener):
#         """
#         Unsubscribes an event listener.
#         It will no longer receive events after he unsubscribes.
#         @param listener: function
#         """
#         self.listeners.remove(listener)
# 
#     def clear(self):
#         """
#         Removes all event listeners.
#         """
#         self.listeners = []
# 
#     def redirect(self, broadcaster):
#         """
#         Redirects this broadcaster to the given broadcaster.
# 
#         All events fired by this broadcaster will be also delivered to the
#         given broadcaster.
#         @type broadcaster: EventBroadcaster
#         """
#         self.subscribe(broadcaster.notify)
# 
#     def __call__(self, *args, **kwargs):
#         self.notify(*args, **kwargs)


import os
import ptrace
import Queue
import signal
import threading
import traceback
from debugger.enums import ProcessState
from debugger.util import EventBroadcaster

        if child_pid:
            self.child_pid = child_pid
            self._parent()
        else:
            self._child()

    def _child(self):
        if ptrace.ptrace(ptrace.PTRACE_TRACEME) < 0:
            raise Exception()

        os.execl(self.file, self.file, *self.args)
        exit(0)

    def _parent(self):
        try:
            while True:
                pid, status = os.waitpid(self.child_pid, os.WNOHANG)

                if pid != 0:
                    self._handle_child_status(status)

                try:
                    command = self.msg_queue.get(True, 0.1)
                    self._handle_command(self.child_pid, status, command)
                except Queue.Empty:
                    pass
                except:
                    traceback.print_exc()
        except OSError:

# Path: debugger/enums.py
# class ProcessState(Enum):
#     """
#     Represents the debugged process' state.
#     """
#     Attaching = 3
#     Connected = 2
#     Crashed = 8
#     Detached = 9
#     Exited = 10
#     Invalid = 0
#     Launching = 4
#     Running = 6
#     Stepping = 7
#     Stopped = 5
#     Suspended = 11
#     Unloaded = 1
# 
# Path: debugger/util.py
# class EventBroadcaster(object):
#     """
#     Object that broadcasts event to it's listeners.
# 
#     Evety broadcaster represents a single event type.
#     """
#     def __init__(self):
#         self.listeners = []
# 
#     def notify(self, *args, **kwargs):
#         """
#         Notifies all listeners that an event has occured.
#         @param args: arbitraty arguments that will be passed to the listeners
#         """
#         map(lambda listener: listener(*args, **kwargs), self.listeners)
# 
#     def subscribe(self, listener):
#         """
#         Subscribes an event listener, who will receive events from the
#         broadcaster.
#         @type listener: function
#         """
#         self.listeners.append(listener)
# 
#     def unsubscribe(self, listener):
#         """
#         Unsubscribes an event listener.
#         It will no longer receive events after he unsubscribes.
#         @param listener: function
#         """
#         self.listeners.remove(listener)
# 
#     def clear(self):
#         """
#         Removes all event listeners.
#         """
#         self.listeners = []
# 
#     def redirect(self, broadcaster):
#         """
#         Redirects this broadcaster to the given broadcaster.
# 
#         All events fired by this broadcaster will be also delivered to the
#         given broadcaster.
#         @type broadcaster: EventBroadcaster
#         """
#         self.subscribe(broadcaster.notify)
# 
#     def __call__(self, *args, **kwargs):
#         self.notify(*args, **kwargs)


# Path: debugger/pycgdb/programrunner.py
import os
import ptrace
import Queue
import signal
import threading
import traceback
from debugger.enums import ProcessState
from debugger.util import EventBroadcaster


        if child_pid:
            self.child_pid = child_pid
            self._parent()
        else:
            self._child()

    def _child(self):
        if ptrace.ptrace(ptrace.PTRACE_TRACEME) < 0:
            raise Exception()

        os.execl(self.file, self.file, *self.args)
        exit(0)

    def _parent(self):
        try:
            while True:
                pid, status = os.waitpid(self.child_pid, os.WNOHANG)

                if pid != 0:
                    self._handle_child_status(status)

                try:
                    command = self.msg_queue.get(True, 0.1)
                    self._handle_command(self.child_pid, status, command)
                except Queue.Empty:
                    pass
                except:
                    traceback.print_exc()
        except OSError:

            self.on_signal.notify(ProcessState.Exited)