1616
1717
1818class PugdebugDebugger (QObject ):
19+
1920 server = None
2021
2122 connections = deque ()
@@ -42,15 +43,20 @@ class PugdebugDebugger(QObject):
4243 def __init__ (self ):
4344 """Init the debugger object
4445
45- Create a PugdebugServer object used to communicate with xdebug client
46- through TCP .
46+ Create a PugdebugServer objects that listens to new connections
47+ from xdebug .
4748
48- Connect signals to slots.
49+ Connect server signals to slots.
4950 """
5051 super (PugdebugDebugger , self ).__init__ ()
5152
5253 self .server = PugdebugServer ()
5354
55+ self .connect_server_signals ()
56+
57+ def connect_server_signals (self ):
58+ """Connect server signals to slots
59+ """
5460 self .server .server_connected_signal .connect (
5561 self .handle_server_connected
5662 )
@@ -59,25 +65,38 @@ def __init__(self):
5965 )
6066
6167 def connect_connection_signals (self , connection ):
68+ """Connect signals for a new connection
69+
70+ Connect signals that gets emitted when a connection is stopped
71+ or detached, when a step command is done, when variables are read,
72+ when stacktraces are read, when breakpoints are set or removed,
73+ when breakpoints are read, when expressions are evaluated.
74+ """
75+
76+ # Stop/detach signals
6277 connection .server_stopped_signal .connect (
6378 self .handle_server_stopped
6479 )
6580 connection .server_detached_signal .connect (
6681 self .handle_server_stopped
6782 )
6883
84+ # Step command signals
6985 connection .server_stepped_signal .connect (
7086 self .handle_server_stepped
7187 )
7288
89+ # Variables signals
7390 connection .server_got_variables_signal .connect (
7491 self .handle_server_got_variables
7592 )
7693
94+ # Stacktraces signals
7795 connection .server_got_stacktraces_signal .connect (
7896 self .handle_server_got_stacktraces
7997 )
8098
99+ # Breakpoints signals
81100 connection .server_set_init_breakpoints_signal .connect (
82101 self .handle_server_set_breakpoint
83102 )
@@ -91,6 +110,7 @@ def connect_connection_signals(self, connection):
91110 self .handle_server_listed_breakpoints
92111 )
93112
113+ # Expressions signals
94114 connection .server_expression_evaluated_signal .connect (
95115 self .handle_server_expression_evaluated
96116 )
@@ -100,6 +120,13 @@ def connect_connection_signals(self, connection):
100120
101121 def cleanup (self ):
102122 """Cleanup debugger when it's done
123+
124+ If there is an active connection, disconnect from it and clear
125+ all the remaining connections.
126+
127+ Stop the server from listening.
128+
129+ Clean up attributes.
103130 """
104131 if self .is_connected ():
105132 self .current_connection .disconnect ()
@@ -113,9 +140,13 @@ def cleanup(self):
113140 self .current_line = 0
114141
115142 def is_connected (self ):
143+ """Is there an active connection
144+ """
116145 return self .current_connection is not None
117146
118147 def has_pending_connections (self ):
148+ """Are there any pending connections?
149+ """
119150 return len (self .connections ) > 0
120151
121152 def start_debug (self ):
@@ -126,9 +157,13 @@ def start_debug(self):
126157 self .server .connect ()
127158
128159 def handle_server_connected (self , connection ):
129- """Handle when server gets connected
160+ """Handle when the server establishes a new connection
161+
162+ Connect the signals for the new connection.
163+
164+ Add it to the queue of connections.
130165
131- Emit a debugging started signal .
166+ If there is no active connection, start the new connection .
132167 """
133168 self .connect_connection_signals (connection )
134169
@@ -138,6 +173,12 @@ def handle_server_connected(self, connection):
138173 self .start_new_connection ()
139174
140175 def start_new_connection (self ):
176+ """Start a new connection
177+
178+ Get the first (oldest) connection from the queue, set it's init
179+ message as the init message for the session, set it as the current
180+ connection and emit the debugging started signal.
181+ """
141182 connection = self .connections .popleft ()
142183 self .init_message = connection .init_message
143184 self .current_connection = connection
@@ -146,22 +187,27 @@ def start_new_connection(self):
146187
147188 def stop_debug (self ):
148189 """Stop a debugging session
190+
191+ If there is an active connection, stop only that one, otherwise
192+ stop the server from listening to new connections.
149193 """
150194 if self .is_connected ():
151195 self .current_connection .stop ()
152196 else :
153197 self .server .stop ()
154198
155199 def detach_debug (self ):
156- """Detach a debugging session
200+ """Detach the current connection
157201 """
158202 if self .is_connected ():
159203 self .current_connection .detach ()
160204
161205 def handle_server_stopped (self ):
162- """Handle when server gets disconnected
206+ """Handle when a server stopped signal is received
207+
208+ If there are pending connections, start a new one.
163209
164- Emit a debugging stopped signal.
210+ Otherwise clean up and emit a server stopped signal.
165211 """
166212 if self .has_pending_connections ():
167213 self .start_new_connection ()
0 commit comments