28
28
import os
29
29
import sys
30
30
import threading
31
+ import thread
31
32
import re
32
33
import atexit
34
+ import time
33
35
34
36
# Set this to True for additional output
35
37
DEBUG_OUTPUT = False
@@ -130,6 +132,22 @@ def listen():
130
132
target .GetBroadcaster ().AddListener (listener , lldb .SBTarget .eBroadcastBitBreakpointChanged )
131
133
132
134
135
+ def start_watchdog ():
136
+ "Starts a watchdog thread that will terminate the process after a certain period of time"
137
+ watchdog_start_time = time .clock ()
138
+ watchdog_max_time = watchdog_start_time + 30
139
+
140
+ def watchdog ():
141
+ while time .clock () < watchdog_max_time :
142
+ time .sleep (1 )
143
+ print ("TIMEOUT: lldb_batchmode.py has been running for too long. Aborting!" )
144
+ thread .interrupt_main ()
145
+
146
+ # Start the listener and let it run as a daemon
147
+ watchdog_thread = threading .Thread (target = watchdog )
148
+ watchdog_thread .daemon = True
149
+ watchdog_thread .start ()
150
+
133
151
####################################################################################################
134
152
# ~main
135
153
####################################################################################################
@@ -147,6 +165,9 @@ def listen():
147
165
print ("Target executable is '%s'." % target_path )
148
166
print ("Current working directory is '%s'" % os .getcwd ())
149
167
168
+ # Start the timeout watchdog
169
+ start_watchdog ()
170
+
150
171
# Create a new debugger instance
151
172
debugger = lldb .SBDebugger .Create ()
152
173
@@ -175,6 +196,10 @@ def listen():
175
196
176
197
for line in script_file :
177
198
command = line .strip ()
199
+ if command == "run" or command == "r" or re .match ("^process\s+launch.*" , command ):
200
+ # Before starting to run the program, let the thread sleep a bit, so all
201
+ # breakpoint added events can be processed
202
+ time .sleep (0.5 )
178
203
if command != '' :
179
204
execute_command (command_interpreter , command )
180
205
0 commit comments