[Lldb-commits] [PATCH] D70050: [lldb] [test] Add a test for watchpoint set error handling on NetBSD

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Nov 10 02:51:02 PST 2019


mgorny created this revision.
mgorny added reviewers: labath, krytarowski.
Herald added a subscriber: jfb.
mgorny added a parent revision: D70025: [lldb] [Process/NetBSD] Fix handling concurrent watchpoint events.

Add a test that verifies that when the user does not have permissions
to set watchpoints on NetBSD, the 'watchpoint set' errors out gracefully
and thread monitoring does not crash on being unable to copy watchpoints
to new threads.


https://reviews.llvm.org/D70050

Files:
  lldb/test/Shell/Watchpoint/Inputs/thread-dbreg.c
  lldb/test/Shell/Watchpoint/netbsd-nouserdbregs.test
  lldb/test/Shell/lit.cfg.py


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')
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/Watchpoint/Inputs/thread-dbreg.c
===================================================================
--- /dev/null
+++ lldb/test/Shell/Watchpoint/Inputs/thread-dbreg.c
@@ -0,0 +1,23 @@
+#include <pthread.h>
+
+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;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70050.228597.patch
Type: text/x-patch
Size: 2620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191110/08217e45/attachment.bin>


More information about the lldb-commits mailing list