aboutsummaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/macosx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Python/lldbsuite/test/macosx')
-rw-r--r--packages/Python/lldbsuite/test/macosx/add-dsym/Makefile11
-rw-r--r--packages/Python/lldbsuite/test/macosx/add-dsym/TestAddDsymMidExecutionCommand.py45
-rw-r--r--packages/Python/lldbsuite/test/macosx/add-dsym/main.c7
-rw-r--r--packages/Python/lldbsuite/test/macosx/debug-info/apple_types/Makefile6
-rw-r--r--packages/Python/lldbsuite/test/macosx/debug-info/apple_types/TestAppleTypesIsProduced.py67
-rw-r--r--packages/Python/lldbsuite/test/macosx/debug-info/apple_types/main.c27
-rw-r--r--packages/Python/lldbsuite/test/macosx/indirect_symbol/Makefile48
-rw-r--r--packages/Python/lldbsuite/test/macosx/indirect_symbol/TestIndirectSymbols.py88
-rw-r--r--packages/Python/lldbsuite/test/macosx/indirect_symbol/alias.list1
-rw-r--r--packages/Python/lldbsuite/test/macosx/indirect_symbol/indirect.c14
-rw-r--r--packages/Python/lldbsuite/test/macosx/indirect_symbol/main.c14
-rw-r--r--packages/Python/lldbsuite/test/macosx/indirect_symbol/reexport.c7
-rw-r--r--packages/Python/lldbsuite/test/macosx/order/Makefile7
-rw-r--r--packages/Python/lldbsuite/test/macosx/order/TestOrderFile.py36
-rw-r--r--packages/Python/lldbsuite/test/macosx/order/cmds.txt3
-rw-r--r--packages/Python/lldbsuite/test/macosx/order/main.c54
-rw-r--r--packages/Python/lldbsuite/test/macosx/order/order-file4
-rw-r--r--packages/Python/lldbsuite/test/macosx/queues/Makefile28
-rw-r--r--packages/Python/lldbsuite/test/macosx/queues/TestQueues.py243
-rw-r--r--packages/Python/lldbsuite/test/macosx/queues/main.c133
-rw-r--r--packages/Python/lldbsuite/test/macosx/safe-to-func-call/Makefile28
-rw-r--r--packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py63
-rw-r--r--packages/Python/lldbsuite/test/macosx/safe-to-func-call/main.c30
-rw-r--r--packages/Python/lldbsuite/test/macosx/universal/Makefile19
-rw-r--r--packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py107
-rw-r--r--packages/Python/lldbsuite/test/macosx/universal/main.c7
26 files changed, 1097 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/macosx/add-dsym/Makefile b/packages/Python/lldbsuite/test/macosx/add-dsym/Makefile
new file mode 100644
index 000000000000..4e4aa71de2a2
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/add-dsym/Makefile
@@ -0,0 +1,11 @@
+CC ?= clang
+
+all: clean
+ mkdir hide.app
+ mkdir hide.app/Contents
+ $(CC) -g main.c
+ mv a.out.dSYM hide.app/Contents
+ strip -x a.out
+
+clean:
+ rm -rf a.out a.out.dSYM hide.app
diff --git a/packages/Python/lldbsuite/test/macosx/add-dsym/TestAddDsymMidExecutionCommand.py b/packages/Python/lldbsuite/test/macosx/add-dsym/TestAddDsymMidExecutionCommand.py
new file mode 100644
index 000000000000..497f695d7cc7
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/add-dsym/TestAddDsymMidExecutionCommand.py
@@ -0,0 +1,45 @@
+"""Test that the 'add-dsym', aka 'target symbols add', succeeds in the middle of debug session."""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+import sys
+from lldbsuite.test.lldbtest import *
+
+@skipUnlessDarwin
+class AddDsymMidExecutionCommandCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ self.source = 'main.c'
+
+ @no_debug_info_test # Prevent the genaration of the dwarf version of this test
+ def test_add_dsym_mid_execution(self):
+ """Test that add-dsym mid-execution loads the symbols at the right place for a slid binary."""
+ self.buildDsym(clean=True)
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ self.target = self.dbg.CreateTarget(exe)
+ self.assertTrue(self.target, VALID_TARGET)
+
+ main_bp = self.target.BreakpointCreateByName ("main", "a.out")
+ self.assertTrue(main_bp, VALID_BREAKPOINT)
+
+ self.runCmd("settings set target.disable-aslr false")
+ self.process = self.target.LaunchSimple (None, None, self.get_process_working_directory())
+ self.assertTrue(self.process, PROCESS_IS_VALID)
+
+ # The stop reason of the thread should be breakpoint.
+ self.assertTrue(self.process.GetState() == lldb.eStateStopped,
+ STOPPED_DUE_TO_BREAKPOINT)
+
+ self.runCmd("add-dsym hide.app/Contents/a.out.dSYM")
+
+ self.expect("frame select",
+ substrs = ['a.out`main at main.c'])
diff --git a/packages/Python/lldbsuite/test/macosx/add-dsym/main.c b/packages/Python/lldbsuite/test/macosx/add-dsym/main.c
new file mode 100644
index 000000000000..da9e09f07389
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/add-dsym/main.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+static int var = 5;
+int main ()
+{
+ printf ("%p is %d\n", &var, var); // break on this line
+ return ++var;
+}
diff --git a/packages/Python/lldbsuite/test/macosx/debug-info/apple_types/Makefile b/packages/Python/lldbsuite/test/macosx/debug-info/apple_types/Makefile
new file mode 100644
index 000000000000..aa3a0fcdcea4
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/debug-info/apple_types/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c
+MAKE_DSYM := NO
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/macosx/debug-info/apple_types/TestAppleTypesIsProduced.py b/packages/Python/lldbsuite/test/macosx/debug-info/apple_types/TestAppleTypesIsProduced.py
new file mode 100644
index 000000000000..fad14db41003
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/debug-info/apple_types/TestAppleTypesIsProduced.py
@@ -0,0 +1,67 @@
+"""
+Test that clang produces the __apple accelerator tables, for example, __apple_types, correctly.
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.lldbutil import symbol_type_to_str
+
+class AppleTypesTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ #rdar://problem/11166975
+ @skipUnlessDarwin
+ def test_debug_info_for_apple_types(self):
+ """Test that __apple_types section does get produced by clang."""
+
+ if not self.getCompiler().endswith('clang'):
+ self.skipTest("clang compiler only test")
+
+ self.build()
+ if self.debug_info == "dsym":
+ exe = os.path.join(os.getcwd(), "a.out.dSYM/Contents/Resources/DWARF/a.out")
+ else:
+ exe = os.path.join(os.getcwd(), "main.o")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+ self.assertTrue(target.GetNumModules() > 0)
+
+ # Hide stdout if not running with '-t' option.
+ if not self.TraceOn():
+ self.HideStdout()
+
+ print("Number of modules for the target: %d" % target.GetNumModules())
+ for module in target.module_iter():
+ print(module)
+
+ # Get the executable module at index 0.
+ exe_module = target.GetModuleAtIndex(0)
+
+ dwarf_section = exe_module.FindSection("__DWARF")
+ self.assertTrue(dwarf_section)
+ print("__DWARF section:", dwarf_section)
+ print("Number of sub-sections: %d" % dwarf_section.GetNumSubSections())
+ INDENT = ' ' * 4
+ for subsec in dwarf_section:
+ print(INDENT + str(subsec))
+
+ debug_str_sub_section = dwarf_section.FindSubSection("__debug_str")
+ self.assertTrue(debug_str_sub_section)
+ print("__debug_str sub-section:", debug_str_sub_section)
+
+ # Find our __apple_types section by name.
+ apple_types_sub_section = dwarf_section.FindSubSection("__apple_types")
+ self.assertTrue(apple_types_sub_section)
+ print("__apple_types sub-section:", apple_types_sub_section)
+
+ # These other three all important subsections should also be present.
+ self.assertTrue(dwarf_section.FindSubSection("__apple_names") and
+ dwarf_section.FindSubSection("__apple_namespac") and
+ dwarf_section.FindSubSection("__apple_objc"))
diff --git a/packages/Python/lldbsuite/test/macosx/debug-info/apple_types/main.c b/packages/Python/lldbsuite/test/macosx/debug-info/apple_types/main.c
new file mode 100644
index 000000000000..cb4bdb9c16b4
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/debug-info/apple_types/main.c
@@ -0,0 +1,27 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+int main (int argc, char const *argv[])
+{
+ struct point_tag {
+ int x;
+ int y;
+ }; // Set break point at this line.
+
+ struct rect_tag {
+ struct point_tag bottom_left;
+ struct point_tag top_right;
+ };
+ struct point_tag pt = { 2, 3 }; // This is the first executable statement.
+ struct rect_tag rect = {{1,2}, {3,4}};
+ pt.x = argc;
+ pt.y = argc * argc;
+ rect.top_right.x = rect.top_right.x + argc;
+ rect.top_right.y = rect.top_right.y + argc;
+ return 0;
+}
diff --git a/packages/Python/lldbsuite/test/macosx/indirect_symbol/Makefile b/packages/Python/lldbsuite/test/macosx/indirect_symbol/Makefile
new file mode 100644
index 000000000000..07aa39eac3be
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/indirect_symbol/Makefile
@@ -0,0 +1,48 @@
+CC ?= clang
+ifeq "$(ARCH)" ""
+ ARCH = x86_64
+endif
+
+ifeq "$(OS)" ""
+ OS = $(shell uname -s)
+endif
+
+CFLAGS ?= -g -O0
+CWD := $(shell pwd)
+
+LIB_PREFIX := lib
+
+ifeq "$(OS)" "Darwin"
+ CFLAGS += -arch $(ARCH)
+ DS := dsymutil
+ LD_FLAGS := -dynamiclib
+ LIB_INDIRECT := $(LIB_PREFIX)indirect.dylib
+ LIB_REEXPORT := $(LIB_PREFIX)reexport.dylib
+ EXEC_PATH := "@executable_path"
+ EXEC_PATH_INDIRECT := -install_name $(EXEC_PATH)/$(LIB_INDIRECT)
+ EXEC_PATH_REEXPORT := -install_name $(EXEC_PATH)/$(LIB_REEXPORT)
+endif
+
+all: a.out $(LIB_INDIRECT) $(LIB_REEXPORT)
+
+a.out: main.o $(LIB_INDIRECT) $(LIB_REEXPORT)
+ $(CC) $(CFLAGS) -o a.out main.o -L. $(LIB_INDIRECT) $(LIB_REEXPORT)
+
+main.o: main.c
+ $(CC) $(CFLAGS) -c main.c
+
+$(LIB_INDIRECT): indirect.o
+ $(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_INDIRECT) -o $(LIB_INDIRECT) indirect.o
+ if [ "$(OS)" = "Darwin" ]; then dsymutil $(LIB_INDIRECT); fi
+
+indirect.o: indirect.c
+ $(CC) $(CFLAGS) -c indirect.c
+
+$(LIB_REEXPORT): reexport.o $(LIB_INDIRECT)
+ $(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_REEXPORT) -o $(LIB_REEXPORT) reexport.o -L. -lindirect -Wl,-alias_list,$(CWD)/alias.list
+ if [ "$(OS)" = "Darwin" ]; then dsymutil $(LIB_REEXPORT); fi
+
+reexport.o: reexport.c
+ $(CC) $(CFLAGS) -c reexport.c
+clean:
+ rm -rf $(wildcard *.o *~ *.dylib *.so a.out *.dSYM)
diff --git a/packages/Python/lldbsuite/test/macosx/indirect_symbol/TestIndirectSymbols.py b/packages/Python/lldbsuite/test/macosx/indirect_symbol/TestIndirectSymbols.py
new file mode 100644
index 000000000000..4f98865ca5a2
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/indirect_symbol/TestIndirectSymbols.py
@@ -0,0 +1,88 @@
+"""Test stepping and setting breakpoints in indirect and re-exported symbols."""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+class TestIndirectFunctions(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line numbers that we will step to in main:
+ self.main_source = "main.c"
+
+ @skipUnlessDarwin
+ @add_test_categories(['pyapi'])
+ def test_with_python_api(self):
+ """Test stepping and setting breakpoints in indirect and re-exported symbols."""
+ self.build()
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ self.main_source_spec = lldb.SBFileSpec (self.main_source)
+
+ break1 = target.BreakpointCreateBySourceRegex ("Set breakpoint here to step in indirect.", self.main_source_spec)
+ self.assertTrue(break1, VALID_BREAKPOINT)
+
+ break2 = target.BreakpointCreateBySourceRegex ("Set breakpoint here to step in reexported.", self.main_source_spec)
+ self.assertTrue(break2, VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at entry point.
+ process = target.LaunchSimple (None, None, self.get_process_working_directory())
+
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # The stop reason of the thread should be breakpoint.
+ threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1)
+ if len(threads) != 1:
+ self.fail ("Failed to stop at breakpoint 1.")
+
+ thread = threads[0]
+
+ # Now do a step-into, and we should end up in the hidden target of this indirect function.
+ thread.StepInto()
+ curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
+ self.assertTrue (curr_function == "call_through_indirect_hidden", "Stepped into indirect symbols.")
+
+ # Now set a breakpoint using the indirect symbol name, and make sure we get to that:
+ break_indirect = target.BreakpointCreateByName ("call_through_indirect");
+ self.assertTrue (break_indirect, VALID_BREAKPOINT)
+
+ # Now continue should take us to the second call through the indirect symbol:
+
+ threads = lldbutil.continue_to_breakpoint (process, break_indirect)
+ self.assertTrue (len(threads) == 1, "Stopped at breakpoint in indirect function.")
+ curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
+ self.assertTrue (curr_function == "call_through_indirect_hidden", "Stepped into indirect symbols.")
+
+ # Delete this breakpoint so it won't get in the way:
+ target.BreakpointDelete (break_indirect.GetID())
+
+ # Now continue to the site of the first re-exported function call in main:
+ threads = lldbutil.continue_to_breakpoint (process, break2)
+
+ # This is stepping Into through a re-exported symbol to an indirect symbol:
+ thread.StepInto()
+ curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
+ self.assertTrue (curr_function == "call_through_indirect_hidden", "Stepped into indirect symbols.")
+
+ # And the last bit is to set a breakpoint on the re-exported symbol and make sure we are again in out target function.
+ break_reexported = target.BreakpointCreateByName ("reexport_to_indirect");
+ self.assertTrue (break_reexported, VALID_BREAKPOINT)
+
+ # Now continue should take us to the second call through the indirect symbol:
+
+ threads = lldbutil.continue_to_breakpoint (process, break_reexported)
+ self.assertTrue (len(threads) == 1, "Stopped at breakpoint in reexported function target.")
+ curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
+ self.assertTrue (curr_function == "call_through_indirect_hidden", "Stepped into indirect symbols.")
diff --git a/packages/Python/lldbsuite/test/macosx/indirect_symbol/alias.list b/packages/Python/lldbsuite/test/macosx/indirect_symbol/alias.list
new file mode 100644
index 000000000000..3232c5888379
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/indirect_symbol/alias.list
@@ -0,0 +1 @@
+_call_through_indirect _reexport_to_indirect \ No newline at end of file
diff --git a/packages/Python/lldbsuite/test/macosx/indirect_symbol/indirect.c b/packages/Python/lldbsuite/test/macosx/indirect_symbol/indirect.c
new file mode 100644
index 000000000000..48e1459bb59b
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/indirect_symbol/indirect.c
@@ -0,0 +1,14 @@
+#define MakeResolver(name) \
+ void * name ## Resolver(void) __asm__("_" #name); \
+ void * name ## Resolver(void) { \
+ __asm__(".symbol_resolver _" #name); \
+ return name ## _hidden; \
+ }
+
+int
+call_through_indirect_hidden(int arg)
+{
+ return arg + 5;
+}
+
+MakeResolver(call_through_indirect)
diff --git a/packages/Python/lldbsuite/test/macosx/indirect_symbol/main.c b/packages/Python/lldbsuite/test/macosx/indirect_symbol/main.c
new file mode 100644
index 000000000000..b5af058d00b1
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/indirect_symbol/main.c
@@ -0,0 +1,14 @@
+extern int call_through_indirect(int);
+extern int reexport_to_indirect(int);
+
+int
+main ()
+{
+ int indirect_result = call_through_indirect(20); // Set breakpoint here to step in indirect.
+ indirect_result = call_through_indirect(30);
+
+ int reexport_result = reexport_to_indirect (20); // Set breakpoint here to step in reexported.
+ reexport_result = reexport_to_indirect (30);
+
+ return 0;
+}
diff --git a/packages/Python/lldbsuite/test/macosx/indirect_symbol/reexport.c b/packages/Python/lldbsuite/test/macosx/indirect_symbol/reexport.c
new file mode 100644
index 000000000000..096a463b3a47
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/indirect_symbol/reexport.c
@@ -0,0 +1,7 @@
+extern int call_through_indirect(int);
+
+int
+fake_call_through_reexport(int value)
+{
+ return value + 10;
+}
diff --git a/packages/Python/lldbsuite/test/macosx/order/Makefile b/packages/Python/lldbsuite/test/macosx/order/Makefile
new file mode 100644
index 000000000000..52fae2d2ca34
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/order/Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+LDFLAGS = $(CFLAGS) -Xlinker -order_file -Xlinker ./order-file
+MAKE_DSYM := NO
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/macosx/order/TestOrderFile.py b/packages/Python/lldbsuite/test/macosx/order/TestOrderFile.py
new file mode 100644
index 000000000000..6541169798ae
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/order/TestOrderFile.py
@@ -0,0 +1,36 @@
+"""
+Test that debug symbols have the correct order as specified by the order file.
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+import re
+import lldb
+from lldbsuite.test.lldbtest import *
+
+class OrderFileTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @skipUnlessDarwin
+ def test(self):
+ """Test debug symbols follow the correct order by the order file."""
+ self.build()
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Test that the debug symbols have Function f3 before Function f1.
+ # Use "-s address" option to sort by address.
+ self.runCmd("image dump symtab -s address a.out")
+ output = self.res.GetOutput()
+ mo_f3 = re.search("Code +.+f3", output)
+ mo_f1 = re.search("Code +.+f1", output)
+
+ # Match objects for f3 and f1 must exist and f3 must come before f1.
+ self.assertTrue(mo_f3 and mo_f1 and mo_f3.start() < mo_f1.start(),
+ "Symbols have correct order by the order file")
+
+ self.runCmd("run", RUN_COMPLETED)
diff --git a/packages/Python/lldbsuite/test/macosx/order/cmds.txt b/packages/Python/lldbsuite/test/macosx/order/cmds.txt
new file mode 100644
index 000000000000..8c51dd763bf4
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/order/cmds.txt
@@ -0,0 +1,3 @@
+b main.c:41
+c
+lines -shlib a.out main.c
diff --git a/packages/Python/lldbsuite/test/macosx/order/main.c b/packages/Python/lldbsuite/test/macosx/order/main.c
new file mode 100644
index 000000000000..cd1ea581876f
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/order/main.c
@@ -0,0 +1,54 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+
+
+int f1 (char *s);
+int f2 (char *s);
+int f3 (char *s);
+
+
+// We want f1 to start on line 20
+int f1 (char *s)
+{
+ return printf("f1: %s\n", s);
+}
+
+
+
+
+
+// We want f2 to start on line 30
+int f2 (char *s)
+{
+ return printf("f2: %s\n", s);
+}
+
+
+
+
+
+// We want f3 to start on line 40
+int f3 (char *s)
+{
+ return printf("f3: %s\n", s);
+}
+
+
+
+
+
+// We want main to start on line 50
+int main (int argc, const char * argv[])
+{
+ f1("carp");
+ f2("ding");
+ f3("dong");
+ return 0;
+}
diff --git a/packages/Python/lldbsuite/test/macosx/order/order-file b/packages/Python/lldbsuite/test/macosx/order/order-file
new file mode 100644
index 000000000000..0cf8ecd2a639
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/order/order-file
@@ -0,0 +1,4 @@
+main.o:_f3
+main.o:_main
+main.o:_f2
+main.o:_f1
diff --git a/packages/Python/lldbsuite/test/macosx/queues/Makefile b/packages/Python/lldbsuite/test/macosx/queues/Makefile
new file mode 100644
index 000000000000..93f2f7b2f340
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/queues/Makefile
@@ -0,0 +1,28 @@
+CC ?= clang
+ifeq "$(ARCH)" ""
+ ARCH = x86_64
+endif
+
+ifeq "$(OS)" ""
+ OS = $(shell uname -s)
+endif
+
+CFLAGS ?= -g -O0
+CWD := $(shell pwd)
+
+LIB_PREFIX := lib
+
+ifeq "$(OS)" "Darwin"
+ CFLAGS += -arch $(ARCH)
+endif
+
+all: a.out
+
+a.out: main.o
+ $(CC) $(CFLAGS) -o a.out main.o
+
+main.o: main.c
+ $(CC) $(CFLAGS) -c main.c
+
+clean:
+ rm -rf $(wildcard *.o *~ *.dylib *.so a.out *.dSYM)
diff --git a/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py b/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py
new file mode 100644
index 000000000000..492d1d3bda3a
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py
@@ -0,0 +1,243 @@
+"""Test queues inspection SB APIs."""
+
+from __future__ import print_function
+
+
+
+import unittest2
+import os, time
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+class TestQueues(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @skipUnlessDarwin
+ @add_test_categories(['pyapi'])
+ @unittest2.expectedFailure("rdar://22531180")
+ def test_with_python_api(self):
+ """Test queues inspection SB APIs."""
+ self.build()
+ self.queues()
+ self.queues_with_libBacktraceRecording()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line numbers that we will step to in main:
+ self.main_source = "main.c"
+
+ def check_queue_for_valid_queue_id(self, queue):
+ self.assertTrue(queue.GetQueueID() != 0, "Check queue %s for valid QueueID (got 0x%x)" % (queue.GetName(), queue.GetQueueID()))
+
+ def check_running_and_pending_items_on_queue(self, queue, expected_running, expected_pending):
+ self.assertTrue(queue.GetNumPendingItems() == expected_pending, "queue %s should have %d pending items, instead has %d pending items" % (queue.GetName(), expected_pending, (queue.GetNumPendingItems())))
+ self.assertTrue(queue.GetNumRunningItems() == expected_running, "queue %s should have %d running items, instead has %d running items" % (queue.GetName(), expected_running, (queue.GetNumRunningItems())))
+
+ def check_number_of_threads_owned_by_queue(self, queue, number_threads):
+ self.assertTrue(queue.GetNumThreads() == number_threads, "queue %s should have %d thread executing, but has %d" % (queue.GetName(), number_threads, queue.GetNumThreads()))
+
+ def check_queue_kind (self, queue, kind):
+ expected_kind_string = "Unknown"
+ if kind == lldb.eQueueKindSerial:
+ expected_kind_string = "Serial queue"
+ if kind == lldb.eQueueKindConcurrent:
+ expected_kind_string = "Concurrent queue"
+ actual_kind_string = "Unknown"
+ if queue.GetKind() == lldb.eQueueKindSerial:
+ actual_kind_string = "Serial queue"
+ if queue.GetKind() == lldb.eQueueKindConcurrent:
+ actual_kind_string = "Concurrent queue"
+ self.assertTrue(queue.GetKind() == kind, "queue %s is expected to be a %s but it is actually a %s" % (queue.GetName(), expected_kind_string, actual_kind_string))
+
+ def check_queues_threads_match_queue(self, queue):
+ for idx in range(0, queue.GetNumThreads()):
+ t = queue.GetThreadAtIndex(idx)
+ self.assertTrue(t.IsValid(), "Queue %s's thread #%d must be valid" % (queue.GetName(), idx))
+ self.assertTrue(t.GetQueueID() == queue.GetQueueID(), "Queue %s has a QueueID of %d but its thread #%d has a QueueID of %d" % (queue.GetName(), queue.GetQueueID(), idx, t.GetQueueID()))
+ self.assertTrue(t.GetQueueName() == queue.GetName(), "Queue %s has a QueueName of %s but its thread #%d has a QueueName of %s" % (queue.GetName(), queue.GetName(), idx, t.GetQueueName()))
+ self.assertTrue(t.GetQueue().GetQueueID() == queue.GetQueueID(), "Thread #%d's Queue's QueueID of %d is not the same as the QueueID of its owning queue %d" % (idx, t.GetQueue().GetQueueID(), queue.GetQueueID()))
+
+ def queues(self):
+ """Test queues inspection SB APIs without libBacktraceRecording."""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+ self.main_source_spec = lldb.SBFileSpec (self.main_source)
+ break1 = target.BreakpointCreateByName ("stopper", 'a.out')
+ self.assertTrue(break1, VALID_BREAKPOINT)
+ process = target.LaunchSimple (None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+ threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1)
+ if len(threads) != 1:
+ self.fail ("Failed to stop at breakpoint 1.")
+
+ queue_submittor_1 = lldb.SBQueue()
+ queue_performer_1 = lldb.SBQueue()
+ queue_performer_2 = lldb.SBQueue()
+ queue_performer_3 = lldb.SBQueue()
+ for idx in range (0, process.GetNumQueues()):
+ q = process.GetQueueAtIndex(idx)
+ if q.GetName() == "com.apple.work_submittor_1":
+ queue_submittor_1 = q
+ if q.GetName() == "com.apple.work_performer_1":
+ queue_performer_1 = q
+ if q.GetName() == "com.apple.work_performer_2":
+ queue_performer_2 = q
+ if q.GetName() == "com.apple.work_performer_3":
+ queue_performer_3 = q
+
+ self.assertTrue(queue_submittor_1.IsValid() and queue_performer_1.IsValid() and queue_performer_2.IsValid() and queue_performer_3.IsValid(), "Got all four expected queues: %s %s %s %s" % (queue_submittor_1.IsValid(), queue_performer_1.IsValid(), queue_performer_2.IsValid(), queue_performer_3.IsValid()))
+
+ self.check_queue_for_valid_queue_id (queue_submittor_1)
+ self.check_queue_for_valid_queue_id (queue_performer_1)
+ self.check_queue_for_valid_queue_id (queue_performer_2)
+ self.check_queue_for_valid_queue_id (queue_performer_3)
+
+ self.check_number_of_threads_owned_by_queue (queue_submittor_1, 1)
+ self.check_number_of_threads_owned_by_queue (queue_performer_1, 1)
+ self.check_number_of_threads_owned_by_queue (queue_performer_2, 1)
+ self.check_number_of_threads_owned_by_queue (queue_performer_3, 4)
+
+ self.check_queue_kind (queue_submittor_1, lldb.eQueueKindSerial)
+ self.check_queue_kind (queue_performer_1, lldb.eQueueKindSerial)
+ self.check_queue_kind (queue_performer_2, lldb.eQueueKindSerial)
+ self.check_queue_kind (queue_performer_3, lldb.eQueueKindConcurrent)
+
+ self.check_queues_threads_match_queue (queue_submittor_1)
+ self.check_queues_threads_match_queue (queue_performer_1)
+ self.check_queues_threads_match_queue (queue_performer_2)
+ self.check_queues_threads_match_queue (queue_performer_3)
+
+
+
+ # We have threads running with all the different dispatch QoS service
+ # levels - find those threads and check that we can get the correct
+ # QoS name for each of them.
+
+ user_initiated_thread = lldb.SBThread()
+ user_interactive_thread = lldb.SBThread()
+ utility_thread = lldb.SBThread()
+ unspecified_thread = lldb.SBThread()
+ background_thread = lldb.SBThread()
+ for th in process.threads:
+ if th.GetName() == "user initiated QoS":
+ user_initiated_thread = th
+ if th.GetName() == "user interactive QoS":
+ user_interactive_thread = th
+ if th.GetName() == "utility QoS":
+ utility_thread = th
+ if th.GetName() == "unspecified QoS":
+ unspecified_thread = th
+ if th.GetName() == "background QoS":
+ background_thread = th
+
+ self.assertTrue(user_initiated_thread.IsValid(), "Found user initiated QoS thread")
+ self.assertTrue(user_interactive_thread.IsValid(), "Found user interactive QoS thread")
+ self.assertTrue(utility_thread.IsValid(), "Found utility QoS thread")
+ self.assertTrue(unspecified_thread.IsValid(), "Found unspecified QoS thread")
+ self.assertTrue(background_thread.IsValid(), "Found background QoS thread")
+
+ stream = lldb.SBStream()
+ self.assertTrue(user_initiated_thread.GetInfoItemByPathAsString("requested_qos.printable_name", stream), "Get QoS printable string for user initiated QoS thread")
+ self.assertTrue(stream.GetData() == "User Initiated", "user initiated QoS thread name is valid")
+ stream.Clear()
+ self.assertTrue(user_interactive_thread.GetInfoItemByPathAsString("requested_qos.printable_name", stream), "Get QoS printable string for user interactive QoS thread")
+ self.assertTrue(stream.GetData() == "User Interactive", "user interactive QoS thread name is valid")
+ stream.Clear()
+ self.assertTrue(utility_thread.GetInfoItemByPathAsString("requested_qos.printable_name", stream), "Get QoS printable string for utility QoS thread")
+ self.assertTrue(stream.GetData() == "Utility", "utility QoS thread name is valid")
+ stream.Clear()
+ self.assertTrue(unspecified_thread.GetInfoItemByPathAsString("requested_qos.printable_name", stream), "Get QoS printable string for unspecified QoS thread")
+ self.assertTrue(stream.GetData() == "User Initiated", "unspecified QoS thread name is valid")
+ stream.Clear()
+ self.assertTrue(background_thread.GetInfoItemByPathAsString("requested_qos.printable_name", stream), "Get QoS printable string for background QoS thread")
+ self.assertTrue(stream.GetData() == "Background", "background QoS thread name is valid")
+
+ def queues_with_libBacktraceRecording(self):
+ """Test queues inspection SB APIs with libBacktraceRecording present."""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ if not os.path.isfile('/Applications/Xcode.app/Contents/Developer/usr/lib/libBacktraceRecording.dylib'):
+ self.skipTest ("Skipped because libBacktraceRecording.dylib was present on the system.")
+
+ if not os.path.isfile('/usr/lib/system/introspection/libdispatch.dylib'):
+ self.skipTest ("Skipped because introspection libdispatch dylib is not present.")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ self.main_source_spec = lldb.SBFileSpec (self.main_source)
+
+ break1 = target.BreakpointCreateByName ("stopper", 'a.out')
+ self.assertTrue(break1, VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at entry point.
+ process = target.LaunchSimple (None, ['DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/usr/lib/libBacktraceRecording.dylib', 'DYLD_LIBRARY_PATH=/usr/lib/system/introspection'], self.get_process_working_directory())
+
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # The stop reason of the thread should be breakpoint.
+ threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1)
+ if len(threads) != 1:
+ self.fail ("Failed to stop at breakpoint 1.")
+
+ libbtr_module_filespec = lldb.SBFileSpec("libBacktraceRecording.dylib")
+ libbtr_module = target.FindModule (libbtr_module_filespec)
+ if not libbtr_module.IsValid():
+ self.skipTest ("Skipped because libBacktraceRecording.dylib was not loaded into the process.")
+
+ self.assertTrue(process.GetNumQueues() >= 4, "Found the correct number of queues.")
+
+ queue_submittor_1 = lldb.SBQueue()
+ queue_performer_1 = lldb.SBQueue()
+ queue_performer_2 = lldb.SBQueue()
+ queue_performer_3 = lldb.SBQueue()
+ for idx in range (0, process.GetNumQueues()):
+ q = process.GetQueueAtIndex(idx)
+ if q.GetName() == "com.apple.work_submittor_1":
+ queue_submittor_1 = q
+ if q.GetName() == "com.apple.work_performer_1":
+ queue_performer_1 = q
+ if q.GetName() == "com.apple.work_performer_2":
+ queue_performer_2 = q
+ if q.GetName() == "com.apple.work_performer_3":
+ queue_performer_3 = q
+
+ self.assertTrue(queue_submittor_1.IsValid() and queue_performer_1.IsValid() and queue_performer_2.IsValid() and queue_performer_3.IsValid(), "Got all four expected queues: %s %s %s %s" % (queue_submittor_1.IsValid(), queue_performer_1.IsValid(), queue_performer_2.IsValid(), queue_performer_3.IsValid()))
+
+ self.check_queue_for_valid_queue_id (queue_submittor_1)
+ self.check_queue_for_valid_queue_id (queue_performer_1)
+ self.check_queue_for_valid_queue_id (queue_performer_2)
+ self.check_queue_for_valid_queue_id (queue_performer_3)
+
+ self.check_running_and_pending_items_on_queue (queue_submittor_1, 1, 0)
+ self.check_running_and_pending_items_on_queue (queue_performer_1, 1, 3)
+ self.check_running_and_pending_items_on_queue (queue_performer_2, 1, 9999)
+ self.check_running_and_pending_items_on_queue (queue_performer_3, 4, 0)
+
+ self.check_number_of_threads_owned_by_queue (queue_submittor_1, 1)
+ self.check_number_of_threads_owned_by_queue (queue_performer_1, 1)
+ self.check_number_of_threads_owned_by_queue (queue_performer_2, 1)
+ self.check_number_of_threads_owned_by_queue (queue_performer_3, 4)
+
+ self.check_queue_kind (queue_submittor_1, lldb.eQueueKindSerial)
+ self.check_queue_kind (queue_performer_1, lldb.eQueueKindSerial)
+ self.check_queue_kind (queue_performer_2, lldb.eQueueKindSerial)
+ self.check_queue_kind (queue_performer_3, lldb.eQueueKindConcurrent)
+
+
+ self.check_queues_threads_match_queue (queue_submittor_1)
+ self.check_queues_threads_match_queue (queue_performer_1)
+ self.check_queues_threads_match_queue (queue_performer_2)
+ self.check_queues_threads_match_queue (queue_performer_3)
+
+ self.assertTrue(queue_performer_2.GetPendingItemAtIndex(0).IsValid(), "queue 2's pending item #0 is valid")
+ self.assertTrue(queue_performer_2.GetPendingItemAtIndex(0).GetAddress().GetSymbol().GetName() == "doing_the_work_2", "queue 2's pending item #0 should be doing_the_work_2")
+ self.assertTrue(queue_performer_2.GetNumPendingItems() == 9999, "verify that queue 2 still has 9999 pending items")
+ self.assertTrue(queue_performer_2.GetPendingItemAtIndex(9998).IsValid(), "queue 2's pending item #9998 is valid")
+ self.assertTrue(queue_performer_2.GetPendingItemAtIndex(9998).GetAddress().GetSymbol().GetName() == "doing_the_work_2", "queue 2's pending item #0 should be doing_the_work_2")
+ self.assertTrue(queue_performer_2.GetPendingItemAtIndex(9999).IsValid() == False, "queue 2's pending item #9999 is invalid")
diff --git a/packages/Python/lldbsuite/test/macosx/queues/main.c b/packages/Python/lldbsuite/test/macosx/queues/main.c
new file mode 100644
index 000000000000..fa6a3e570ae3
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/queues/main.c
@@ -0,0 +1,133 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <dispatch/dispatch.h>
+#include <pthread.h>
+
+void
+doing_the_work_1(void *in)
+{
+ while (1)
+ sleep (1);
+}
+
+void
+submit_work_1a(void *in)
+{
+ dispatch_queue_t *work_performer_1 = (dispatch_queue_t*) in;
+ dispatch_async_f (*work_performer_1, NULL, doing_the_work_1);
+ dispatch_async_f (*work_performer_1, NULL, doing_the_work_1);
+}
+
+void
+submit_work_1b(void *in)
+{
+ dispatch_queue_t *work_performer_1 = (dispatch_queue_t*) in;
+ dispatch_async_f (*work_performer_1, NULL, doing_the_work_1);
+ dispatch_async_f (*work_performer_1, NULL, doing_the_work_1);
+ while (1)
+ sleep (1);
+}
+
+void
+doing_the_work_2(void *in)
+{
+ while (1)
+ sleep (1);
+}
+
+void
+submit_work_2(void *in)
+{
+ dispatch_queue_t *work_performer_2 = (dispatch_queue_t*) in;
+ int i = 0;
+ while (i++ < 5000)
+ {
+ dispatch_async_f (*work_performer_2, NULL, doing_the_work_2);
+ dispatch_async_f (*work_performer_2, NULL, doing_the_work_2);
+ }
+}
+
+
+void
+doing_the_work_3(void *in)
+{
+ while (1)
+ sleep(1);
+}
+
+void
+submit_work_3(void *in)
+{
+ dispatch_queue_t *work_performer_3 = (dispatch_queue_t*) in;
+ dispatch_async_f (*work_performer_3, NULL, doing_the_work_3);
+ dispatch_async_f (*work_performer_3, NULL, doing_the_work_3);
+ dispatch_async_f (*work_performer_3, NULL, doing_the_work_3);
+ dispatch_async_f (*work_performer_3, NULL, doing_the_work_3);
+}
+
+
+void
+stopper ()
+{
+ while (1)
+ sleep (1);
+}
+
+int main ()
+{
+ dispatch_queue_t work_submittor_1 = dispatch_queue_create ("com.apple.work_submittor_1", DISPATCH_QUEUE_SERIAL);
+ dispatch_queue_t work_submittor_2 = dispatch_queue_create ("com.apple.work_submittor_and_quit_2", DISPATCH_QUEUE_SERIAL);
+ dispatch_queue_t work_submittor_3 = dispatch_queue_create ("com.apple.work_submittor_3", DISPATCH_QUEUE_SERIAL);
+
+ dispatch_queue_t work_performer_1 = dispatch_queue_create ("com.apple.work_performer_1", DISPATCH_QUEUE_SERIAL);
+ dispatch_queue_t work_performer_2 = dispatch_queue_create ("com.apple.work_performer_2", DISPATCH_QUEUE_SERIAL);
+
+ dispatch_queue_t work_performer_3 = dispatch_queue_create ("com.apple.work_performer_3", DISPATCH_QUEUE_CONCURRENT);
+
+ dispatch_async_f (work_submittor_1, (void*) &work_performer_1, submit_work_1a);
+ dispatch_async_f (work_submittor_1, (void*) &work_performer_1, submit_work_1b);
+
+ dispatch_async_f (work_submittor_2, (void*) &work_performer_2, submit_work_2);
+
+ dispatch_async_f (work_submittor_3, (void*) &work_performer_3, submit_work_3);
+
+
+ // Spin up threads with each of the different libdispatch QoS values.
+
+ dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
+ pthread_setname_np ("user initiated QoS");
+ while (1)
+ sleep (10);
+ });
+ dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
+ pthread_setname_np ("user interactive QoS");
+ while (1)
+ sleep (10);
+ });
+ dispatch_async (dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
+ pthread_setname_np ("default QoS");
+ while (1)
+ sleep (10);
+ });
+ dispatch_async (dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
+ pthread_setname_np ("utility QoS");
+ while (1)
+ sleep (10);
+ });
+ dispatch_async (dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
+ pthread_setname_np ("background QoS");
+ while (1)
+ sleep (10);
+ });
+ dispatch_async (dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0), ^{
+ pthread_setname_np ("unspecified QoS");
+ while (1)
+ sleep (10);
+ });
+
+
+ sleep (1);
+ stopper ();
+
+}
+
diff --git a/packages/Python/lldbsuite/test/macosx/safe-to-func-call/Makefile b/packages/Python/lldbsuite/test/macosx/safe-to-func-call/Makefile
new file mode 100644
index 000000000000..93f2f7b2f340
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/safe-to-func-call/Makefile
@@ -0,0 +1,28 @@
+CC ?= clang
+ifeq "$(ARCH)" ""
+ ARCH = x86_64
+endif
+
+ifeq "$(OS)" ""
+ OS = $(shell uname -s)
+endif
+
+CFLAGS ?= -g -O0
+CWD := $(shell pwd)
+
+LIB_PREFIX := lib
+
+ifeq "$(OS)" "Darwin"
+ CFLAGS += -arch $(ARCH)
+endif
+
+all: a.out
+
+a.out: main.o
+ $(CC) $(CFLAGS) -o a.out main.o
+
+main.o: main.c
+ $(CC) $(CFLAGS) -c main.c
+
+clean:
+ rm -rf $(wildcard *.o *~ *.dylib *.so a.out *.dSYM)
diff --git a/packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py b/packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py
new file mode 100644
index 000000000000..297223c3e84e
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/safe-to-func-call/TestSafeFuncCalls.py
@@ -0,0 +1,63 @@
+"""Test function call thread safety."""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+class TestSafeFuncCalls(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line numbers that we will step to in main:
+ self.main_source = "main.c"
+
+ @skipUnlessDarwin
+ @add_test_categories(['pyapi'])
+ def test_with_python_api(self):
+ """Test function call thread safety."""
+ self.build()
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+ self.main_source_spec = lldb.SBFileSpec (self.main_source)
+ break1 = target.BreakpointCreateByName ("stopper", 'a.out')
+ self.assertTrue(break1, VALID_BREAKPOINT)
+ process = target.LaunchSimple (None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+ threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1)
+ if len(threads) != 1:
+ self.fail ("Failed to stop at breakpoint 1.")
+
+ self.check_number_of_threads(process)
+
+ main_thread = lldb.SBThread()
+ select_thread = lldb.SBThread()
+ for idx in range (0, process.GetNumThreads()):
+ t = process.GetThreadAtIndex (idx)
+ if t.GetName() == "main thread":
+ main_thread = t
+ if t.GetName() == "select thread":
+ select_thread = t
+
+ self.assertTrue(main_thread.IsValid() and select_thread.IsValid(), "Got both expected threads")
+
+ self.safe_to_call_func_on_main_thread (main_thread)
+ self.safe_to_call_func_on_select_thread (select_thread)
+
+ def check_number_of_threads(self, process):
+ self.assertTrue(process.GetNumThreads() == 2, "Check that the process has two threads when sitting at the stopper() breakpoint")
+
+ def safe_to_call_func_on_main_thread (self, main_thread):
+ self.assertTrue(main_thread.SafeToCallFunctions() == True, "It is safe to call functions on the main thread")
+
+ def safe_to_call_func_on_select_thread (self, select_thread):
+ self.assertTrue(select_thread.SafeToCallFunctions() == False, "It is not safe to call functions on the select thread")
diff --git a/packages/Python/lldbsuite/test/macosx/safe-to-func-call/main.c b/packages/Python/lldbsuite/test/macosx/safe-to-func-call/main.c
new file mode 100644
index 000000000000..613384ff73b3
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/safe-to-func-call/main.c
@@ -0,0 +1,30 @@
+#include <sys/select.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <unistd.h>
+
+void *
+select_thread (void *in)
+{
+ pthread_setname_np ("select thread");
+ fd_set fdset;
+ FD_SET (STDIN_FILENO, &fdset);
+ while (1)
+ select (2, &fdset, NULL, NULL, NULL);
+ return NULL;
+}
+
+void stopper ()
+{
+ while (1)
+ sleep(1); // break here
+}
+
+int main ()
+{
+ pthread_setname_np ("main thread");
+ pthread_t other_thread;
+ pthread_create (&other_thread, NULL, select_thread, NULL);
+ sleep (1);
+ stopper();
+}
diff --git a/packages/Python/lldbsuite/test/macosx/universal/Makefile b/packages/Python/lldbsuite/test/macosx/universal/Makefile
new file mode 100644
index 000000000000..854c78ed8c29
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/universal/Makefile
@@ -0,0 +1,19 @@
+CC ?= clang
+
+testit: testit.i386 testit.x86_64
+ lipo -create -o testit testit.i386 testit.x86_64
+
+testit.i386: testit.i386.o
+ $(CC) -arch i386 -o testit.i386 testit.i386.o
+
+testit.x86_64: testit.x86_64.o
+ $(CC) -arch x86_64 -o testit.x86_64 testit.x86_64.o
+
+testit.i386.o: main.c
+ $(CC) -g -O0 -arch i386 -c -o testit.i386.o main.c
+
+testit.x86_64.o: main.c
+ $(CC) -g -O0 -arch x86_64 -c -o testit.x86_64.o main.c
+
+clean:
+ rm -rf $(wildcard testit* *~)
diff --git a/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py b/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py
new file mode 100644
index 000000000000..4b722b0c1d8e
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py
@@ -0,0 +1,107 @@
+"""Test aspects of lldb commands on universal binaries."""
+
+from __future__ import print_function
+
+
+
+import unittest2
+import os, time
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+class UniversalTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break inside main().
+ self.line = line_number('main.c', '// Set break point at this line.')
+
+ @add_test_categories(['pyapi'])
+ @skipUnlessDarwin
+ @unittest2.skipUnless(hasattr(os, "uname") and os.uname()[4] in ['i386', 'x86_64'],
+ "requires i386 or x86_64")
+ def test_sbdebugger_create_target_with_file_and_target_triple(self):
+ """Test the SBDebugger.CreateTargetWithFileAndTargetTriple() API."""
+ # Invoke the default build rule.
+ self.build()
+
+ # Note that "testit" is a universal binary.
+ exe = os.path.join(os.getcwd(), "testit")
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTargetWithFileAndTargetTriple(exe, "i386-apple-macosx")
+ self.assertTrue(target, VALID_TARGET)
+
+ # Now launch the process, and do not stop at entry point.
+ process = target.LaunchSimple (None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ @skipUnlessDarwin
+ @unittest2.skipUnless(hasattr(os, "uname") and os.uname()[4] in ['i386', 'x86_64'],
+ "requires i386 or x86_64")
+ def test_process_launch_for_universal(self):
+ """Test process launch of a universal binary."""
+ from lldbsuite.test.lldbutil import print_registers
+
+ # Invoke the default build rule.
+ self.build()
+
+ # Note that "testit" is a universal binary.
+ exe = os.path.join(os.getcwd(), "testit")
+
+ # By default, x86_64 is assumed if no architecture is specified.
+ self.expect("file " + exe, CURRENT_EXECUTABLE_SET,
+ startstr = "Current executable set to ",
+ substrs = ["testit' (x86_64)."])
+
+ # Break inside the main.
+ lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
+
+ # We should be able to launch the x86_64 executable.
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # Check whether we have a 64-bit process launched.
+ target = self.dbg.GetSelectedTarget()
+ process = target.GetProcess()
+ self.assertTrue(target and process and
+ self.invoke(process, 'GetAddressByteSize') == 8,
+ "64-bit process launched")
+
+ frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
+ registers = print_registers(frame, string_buffer=True)
+ self.expect(registers, exe=False,
+ substrs = ['Name: rax'])
+
+ self.runCmd("continue")
+
+ # Now specify i386 as the architecture for "testit".
+ self.expect("file -a i386 " + exe, CURRENT_EXECUTABLE_SET,
+ startstr = "Current executable set to ",
+ substrs = ["testit' (i386)."])
+
+ # Break inside the main.
+ lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
+
+ # We should be able to launch the i386 executable as well.
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # Check whether we have a 32-bit process launched.
+ target = self.dbg.GetSelectedTarget()
+ process = target.GetProcess()
+ self.assertTrue(target and process,
+ "32-bit process launched")
+
+ pointerSize = self.invoke(process, 'GetAddressByteSize')
+ self.assertTrue(pointerSize == 4,
+ "AddressByteSize of 32-bit process should be 4, got %d instead." % pointerSize)
+
+ frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
+ registers = print_registers(frame, string_buffer=True)
+ self.expect(registers, exe=False,
+ substrs = ['Name: eax'])
+
+ self.runCmd("continue")
diff --git a/packages/Python/lldbsuite/test/macosx/universal/main.c b/packages/Python/lldbsuite/test/macosx/universal/main.c
new file mode 100644
index 000000000000..9351c77f7146
--- /dev/null
+++ b/packages/Python/lldbsuite/test/macosx/universal/main.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+int
+main (int argc, char **argv)
+{
+ printf ("Hello there!\n"); // Set break point at this line.
+ return 0;
+}