Skip to content

Commit

Permalink
Make alternate_thread_diversion work on LLDB
Browse files Browse the repository at this point in the history
  • Loading branch information
rocallahan committed May 30, 2024
1 parent b8eeb57 commit 8d3c236
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
25 changes: 10 additions & 15 deletions src/test/alternate_thread_diversion.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
from util import *

send_gdb('b break_here')
expect_gdb('Breakpoint 1')
send_gdb('c')
expect_gdb('Breakpoint 1')
bp = breakpoint_at_function('break_here')
cont()
expect_breakpoint_stop(bp)

send_gdb('info threads')
expect_gdb(' 1 Thread')
expect_gdb('\\* 2 Thread')
expect_threads(num_threads=2, selected_thread=2)

send_gdb('thread 1')
expect_gdb('Switching to thread 1')
send_gdb('set scheduler-locking on')
send_gdb('call get_value()')
expect_gdb('1')
send_gdb('set scheduler-locking off')
send_gdb('c')
expect_gdb('SIGKILL')
select_thread(1)
scheduler_locking_on()
expect_expression('get_value()', 1)
scheduler_locking_off()
cont()
expect_signal_stop('SIGKILL')

ok()
2 changes: 1 addition & 1 deletion src/test/alternate_thread_diversion.run
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source `dirname $0`/util.sh
debug_test_gdb_only
debug_test
43 changes: 42 additions & 1 deletion src/test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
'get_gdb_version', 'breakpoint_at_function',
'watchpoint_at_address', 'cont', 'backtrace', 'up',
'expect_breakpoint_stop', 'expect_watchpoint_stop',
'delete_watchpoint', 'set_breakpoint_commands' ]
'delete_watchpoint', 'expect_signal_stop',
'set_breakpoint_commands', 'select_thread',
'scheduler_locking_on', 'scheduler_locking_off',
'expect_expression', 'expect_threads', ]

# Don't use python timeout. Use test-monitor timeout instead.
TIMEOUT_SEC = 10000
Expand Down Expand Up @@ -113,6 +116,12 @@ def expect_watchpoint_stop(number):
else:
expect_debugger("stop reason = watchpoint %d"%number)

def expect_signal_stop(signal_name):
if debugger_type == 'GDB':
expect_debugger(f"received signal {signal_name}")
else:
expect_debugger(f"received signal: {signal_name}")

def set_breakpoint_commands(number, commands):
if debugger_type == 'GDB':
send_gdb(f'commands {number}')
Expand All @@ -127,6 +136,38 @@ def set_breakpoint_commands(number, commands):
send_lldb('DONE')
expect_debugger('(rr)')

def expect_expression(expression, value):
send_debugger(f'print {expression}', f'print {expression}')
if debugger_type == 'GDB':
expect_debugger(f' = {value}')
else:
expect_debugger(fr'\) {value}')

def expect_threads(num_threads, selected_thread):
send_debugger('info threads', 'thread list')
for i in range(1, num_threads + 1):
selected = r'\*' if i == selected_thread else ''
if debugger_type == 'GDB':
expect_debugger(f'{selected} +{i} ')
else:
expect_debugger(f'{selected} +thread #{i}:')

def select_thread(index):
if debugger_type == 'GDB':
send_gdb(f"thread {index}")
expect_debugger(f'Switching to thread {index} ')
else:
send_lldb(f"thread select {index}")
expect_debugger(f'thread #{index}')

def scheduler_locking_on():
if debugger_type == 'GDB':
send_gdb('set scheduler-locking on')

def scheduler_locking_off():
if debugger_type == 'GDB':
send_gdb('set scheduler-locking off')

def send_debugger(gdb_cmd, lldb_cmd):
if debugger_type == 'GDB':
send_gdb(gdb_cmd)
Expand Down

0 comments on commit 8d3c236

Please sign in to comment.