Skip to content

Commit f87ff76

Browse files
committed
rollup merge of #18654 : michaelwoerister/lldb-test-timeout
2 parents 3c81f33 + 36088ab commit f87ff76

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

mk/tests.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
677677
CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
678678
CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
679679
CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
680-
CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS)
680+
CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
681+
$(S)src/etc/lldb_batchmode.py \
682+
$(S)src/etc/lldb_rust_formatters.py
681683
CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
682684

683685
endef

src/etc/lldb_batchmode.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
import os
2929
import sys
3030
import threading
31+
import thread
3132
import re
3233
import atexit
34+
import time
3335

3436
# Set this to True for additional output
3537
DEBUG_OUTPUT = False
@@ -130,6 +132,22 @@ def listen():
130132
target.GetBroadcaster().AddListener(listener, lldb.SBTarget.eBroadcastBitBreakpointChanged)
131133

132134

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+
133151
####################################################################################################
134152
# ~main
135153
####################################################################################################
@@ -147,6 +165,9 @@ def listen():
147165
print("Target executable is '%s'." % target_path)
148166
print("Current working directory is '%s'" % os.getcwd())
149167

168+
# Start the timeout watchdog
169+
start_watchdog()
170+
150171
# Create a new debugger instance
151172
debugger = lldb.SBDebugger.Create()
152173

@@ -175,6 +196,10 @@ def listen():
175196

176197
for line in script_file:
177198
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)
178203
if command != '':
179204
execute_command(command_interpreter, command)
180205

0 commit comments

Comments
 (0)