Skip to content
This repository was archived by the owner on Aug 28, 2020. It is now read-only.

Commit 27dc96e

Browse files
committed
Introduce a post start command
Having a post start command makes it easier to run several commands at once after debugging starts, thus avoiding any race conditions between commands. See comments on #116 for examples.
1 parent 5a9a7fc commit 27dc96e

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

pugdebug/debugger.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class PugdebugDebugger(QObject):
2929
current_line = 0
3030

3131
debugging_started_signal = pyqtSignal()
32+
debugging_post_start_signal = pyqtSignal()
3233
debugging_stopped_signal = pyqtSignal()
3334
step_command_signal = pyqtSignal()
3435
got_all_variables_signal = pyqtSignal(object)
@@ -78,6 +79,9 @@ def connect_connection_signals(self, connection):
7879
"""
7980

8081
# Stop/detach signals
82+
connection.post_start_signal.connect(
83+
self.handle_post_start
84+
)
8185
connection.stopped_signal.connect(
8286
self.handle_stopped
8387
)
@@ -194,6 +198,12 @@ def start_new_connection(self):
194198

195199
self.debugging_started_signal.emit()
196200

201+
def post_start_command(self, post_start_data):
202+
self.current_connection.post_start_command(post_start_data)
203+
204+
def handle_post_start(self):
205+
self.debugging_post_start_signal.emit()
206+
197207
def handle_server_stopped(self):
198208
if not self.is_connected():
199209
self.cleanup()

pugdebug/pugdebug.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ def connect_debugger_signals(self):
169169
self.debugger.debugging_started_signal.connect(
170170
self.handle_debugging_started
171171
)
172+
self.debugger.debugging_post_start_signal.connect(
173+
self.handle_debugging_post_start
174+
)
172175
self.debugger.debugging_stopped_signal.connect(
173176
self.handle_debugging_stopped
174177
)
@@ -454,9 +457,21 @@ def handle_debugging_started(self):
454457

455458
self.main_window.toggle_actions(True)
456459

457-
self.set_init_breakpoints(self.init_breakpoints)
460+
post_start_data = {
461+
'init_breakpoints': self.init_breakpoints
462+
}
463+
self.debugger.post_start_command(post_start_data)
464+
465+
def handle_debugging_post_start(self):
466+
"""Handle post start debugging
458467
459-
self.open_document(self.debugger.get_index_file())
468+
If the code should not break at first line, run the debugger.
469+
"""
470+
break_at_first_line = int(get_setting('debugger/break_at_first_line'))
471+
if break_at_first_line == 0:
472+
self.run_debug()
473+
else:
474+
self.step_into()
460475

461476
def stop_debug(self):
462477
"""Stop a debugging session

pugdebug/server.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class PugdebugServerConnection(QThread):
107107

108108
xdebug_encoding = 'iso-8859-1'
109109

110+
post_start_signal = pyqtSignal()
110111
stopped_signal = pyqtSignal()
111112
detached_signal = pyqtSignal()
112113
stepped_signal = pyqtSignal(dict)
@@ -182,7 +183,14 @@ def run(self):
182183
action = self.action
183184

184185
try:
185-
if action == 'stop':
186+
if action == 'post_start':
187+
response = self.__post_start(data)
188+
189+
self.listed_breakpoints_signal.emit(
190+
response['breakpoints']
191+
)
192+
self.post_start_signal.emit()
193+
elif action == 'stop':
186194
response = self.__stop()
187195
self.stopped_signal.emit()
188196
elif action == 'detach':
@@ -234,6 +242,11 @@ def disconnect(self):
234242
if self.socket is not None:
235243
self.socket.close()
236244

245+
def post_start_command(self, post_start_data):
246+
self.data = post_start_data
247+
self.action = 'post_start'
248+
self.start()
249+
237250
def stop(self):
238251
self.action = 'stop'
239252
self.start()
@@ -287,6 +300,16 @@ def evaluate_expression(self, index, expression):
287300
self.data = (index, expression)
288301
self.start()
289302

303+
def __post_start(self, data):
304+
post_start_response = {
305+
'init_breakpoints': self.__set_init_breakpoints(
306+
data['init_breakpoints']
307+
),
308+
'breakpoints': self.__list_breakpoints()
309+
}
310+
311+
return post_start_response
312+
290313
def __stop(self):
291314
command = 'stop -i %d' % self.__get_transaction_id()
292315
self.__send_command(command)

0 commit comments

Comments
 (0)