Index: lldb/test/Shell/Watchpoint/Inputs/thread-dbreg.c =================================================================== --- /dev/null +++ lldb/test/Shell/Watchpoint/Inputs/thread-dbreg.c @@ -0,0 +1,23 @@ +#include + +int g_watchme = 0; + +void *thread_func(void *arg) { + /* watchpoint trigger from subthread */ + g_watchme = 2; + return 0; +} + +int main() { + pthread_t thread; + if (pthread_create(&thread, 0, thread_func, 0)) + return 1; + + /* watchpoint trigger from main thread */ + g_watchme = 1; + + if (pthread_join(thread, 0)) + return 2; + + return 0; +} Index: lldb/test/Shell/Watchpoint/netbsd-nouserdbregs.test =================================================================== --- /dev/null +++ lldb/test/Shell/Watchpoint/netbsd-nouserdbregs.test @@ -0,0 +1,22 @@ +# Check that 'watchpoint set' errors out gracefully when we can't set dbregs +# and that new threads are monitored correctly even though we can't copy dbregs. + +# REQUIRES: native && system-netbsd && (target-x86 || target-x86_64) && !dbregs-set +# RUN: %clang %p/Inputs/thread-dbreg.c -pthread -g -o %t.out +# RUN: %lldb -b -o 'settings set interpreter.stop-command-source-on-error false' -s %s %t.out 2>&1 | FileCheck %s + +settings show interpreter.stop-command-source-on-error +# CHECK: interpreter.stop-command-source-on-error (boolean) = false + +b main +# CHECK: Breakpoint {{[0-9]+}}: where = {{.*}}`main +b thread_func +# CHECK: Breakpoint {{[0-9]+}}: where = {{.*}}`thread_func +run +# CHECK: stop reason = breakpoint +watchpoint set variable g_watchme +# CHECK: error: Watchpoint creation failed +cont +# CHECK: stop reason = breakpoint +cont +# CHECK: Process {{[0-9]+}} exited with status = 0 Index: lldb/test/Shell/lit.cfg.py =================================================================== --- lldb/test/Shell/lit.cfg.py +++ lldb/test/Shell/lit.cfg.py @@ -5,6 +5,7 @@ import re import shutil import site +import subprocess import sys import lit.formats @@ -103,3 +104,17 @@ if find_executable('xz') != None: config.available_features.add('xz') + +# NetBSD permits setting dbregs either if one is root +# or if user_set_dbregs is enabled +can_set_dbregs = True +if platform.system() == 'NetBSD' and os.geteuid() != 0: + try: + output = subprocess.check_output(["/sbin/sysctl", "-n", + "security.models.extensions.user_set_dbregs"]).decode().strip() + if output != "1": + can_set_dbregs = False + except subprocess.CalledProcessError: + can_set_dbregs = False +if can_set_dbregs: + config.available_features.add('dbregs-set')