summaryrefslogtreecommitdiffstats
path: root/lldb/test/functionalities
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2011-06-27 18:17:24 +0000
committerJohnny Chen <johnny.chen@apple.com>2011-06-27 18:17:24 +0000
commit85f21f2029a9be360c734c8ce09a8f01bd7ee3f6 (patch)
treecfaac19cfe476f63946701b8e4f4ee6ae87a7e2e /lldb/test/functionalities
parent31f25bc66f93ff275c03efbbd9bb3793002e80ac (diff)
downloadbcm5719-llvm-85f21f2029a9be360c734c8ce09a8f01bd7ee3f6.tar.gz
bcm5719-llvm-85f21f2029a9be360c734c8ce09a8f01bd7ee3f6.zip
Move top level test dirs inlined_breakpoints, load_unload, and embedded_interpreter to reside under functionalities.
llvm-svn: 133918
Diffstat (limited to 'lldb/test/functionalities')
-rw-r--r--lldb/test/functionalities/breakpoint/inlined_breakpoints/Makefile5
-rw-r--r--lldb/test/functionalities/breakpoint/inlined_breakpoints/TestInlinedBreakpoints.py57
-rw-r--r--lldb/test/functionalities/breakpoint/inlined_breakpoints/basic_type.cpp178
-rw-r--r--lldb/test/functionalities/breakpoint/inlined_breakpoints/int.cpp9
-rw-r--r--lldb/test/functionalities/embedded_interpreter/Makefile5
-rw-r--r--lldb/test/functionalities/embedded_interpreter/TestConvenienceVariables.py87
-rw-r--r--lldb/test/functionalities/embedded_interpreter/main.c6
-rw-r--r--lldb/test/functionalities/load_unload/Makefile45
-rw-r--r--lldb/test/functionalities/load_unload/TestLoadUnload.py218
-rw-r--r--lldb/test/functionalities/load_unload/a.c15
-rw-r--r--lldb/test/functionalities/load_unload/b.c13
-rw-r--r--lldb/test/functionalities/load_unload/c.c13
-rw-r--r--lldb/test/functionalities/load_unload/cmds.txt2
-rw-r--r--lldb/test/functionalities/load_unload/d.c13
-rw-r--r--lldb/test/functionalities/load_unload/main.c75
15 files changed, 741 insertions, 0 deletions
diff --git a/lldb/test/functionalities/breakpoint/inlined_breakpoints/Makefile b/lldb/test/functionalities/breakpoint/inlined_breakpoints/Makefile
new file mode 100644
index 00000000000..5b73ae626f3
--- /dev/null
+++ b/lldb/test/functionalities/breakpoint/inlined_breakpoints/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := int.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/functionalities/breakpoint/inlined_breakpoints/TestInlinedBreakpoints.py b/lldb/test/functionalities/breakpoint/inlined_breakpoints/TestInlinedBreakpoints.py
new file mode 100644
index 00000000000..6e2706fbb34
--- /dev/null
+++ b/lldb/test/functionalities/breakpoint/inlined_breakpoints/TestInlinedBreakpoints.py
@@ -0,0 +1,57 @@
+"""
+Test that inlined breakpoints (breakpoint set on a file/line included from
+another source file) works correctly.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class InlinedBreakpointsTestCase(TestBase):
+ """Bug fixed: rdar://problem/8464339"""
+
+ mydir = os.path.join("functionalities", "breakpoint", "inlined_breakpoints")
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_with_dsym_and_run_command(self):
+ """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp)."""
+ self.buildDsym()
+ self.inlined_breakpoints()
+
+ def test_with_dwarf_and_run_command(self):
+ """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp)."""
+ self.buildDwarf()
+ self.inlined_breakpoints()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break inside basic_type.cpp.
+ self.line = line_number('basic_type.cpp', '// Set break point at this line.')
+
+ def inlined_breakpoints(self):
+ """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp)."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ self.expect("breakpoint set -f basic_type.cpp -l %d" % self.line,
+ BREAKPOINT_CREATED,
+ startstr = "Breakpoint created: 1: file ='basic_type.cpp', line = %d, locations = 1" %
+ self.line)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint.
+ # And it should break at basic_type.cpp:176.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['stopped',
+ 'stop reason = breakpoint',
+ 'basic_type.cpp:%d' % self.line])
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/lldb/test/functionalities/breakpoint/inlined_breakpoints/basic_type.cpp b/lldb/test/functionalities/breakpoint/inlined_breakpoints/basic_type.cpp
new file mode 100644
index 00000000000..5881afe1f39
--- /dev/null
+++ b/lldb/test/functionalities/breakpoint/inlined_breakpoints/basic_type.cpp
@@ -0,0 +1,178 @@
+// This file must have the following defined before it is included:
+// T defined to the type to test (int, float, etc)
+// T_CSTR a C string representation of the type T ("int", "float")
+// T_VALUE_1 defined to a valid initializer value for TEST_TYPE (7 for int, 2.0 for float)
+// T_VALUE_2, T_VALUE_3, T_VALUE_4 defined to a valid initializer value for TEST_TYPE that is different from TEST_VALUE_1
+// T_PRINTF_FORMAT defined if T can be printed with printf
+//
+// An example for integers is below
+#if 0
+
+#define T int
+#define T_CSTR "int"
+#define T_VALUE_1 11001110
+#define T_VALUE_2 22002220
+#define T_VALUE_3 33003330
+#define T_VALUE_4 44044440
+#define T_PRINTF_FORMAT "%i"
+
+#include "basic_type.cpp"
+
+#endif
+
+class a_class
+{
+public:
+ a_class (const T& a, const T& b) :
+ m_a (a),
+ m_b (b)
+ {
+ }
+
+ ~a_class ()
+ {
+ }
+
+ const T&
+ get_a()
+ {
+ return m_a;
+ }
+
+ void
+ set_a (const T& a)
+ {
+ m_a = a;
+ }
+
+ const T&
+ get_b()
+ {
+ return m_b;
+ }
+
+ void
+ set_b (const T& b)
+ {
+ m_b = b;
+ }
+
+protected:
+ T m_a;
+ T m_b;
+};
+
+typedef struct a_struct_tag {
+ T a;
+ T b;
+} a_struct_t;
+
+
+typedef union a_union_zero_tag {
+ T a;
+ double a_double;
+} a_union_zero_t;
+
+typedef struct a_union_nonzero_tag {
+ double a_double;
+ a_union_zero_t u;
+} a_union_nonzero_t;
+
+
+#include <stdint.h>
+#include <stdio.h>
+
+void Puts(char const *msg)
+{
+ puts(msg);
+}
+
+int
+main (int argc, char const *argv[])
+{
+ T a = T_VALUE_1;
+ T* a_ptr = &a;
+ T& a_ref = a;
+ T a_array_bounded[2] = { T_VALUE_1, T_VALUE_2 };
+ T a_array_unbounded[] = { T_VALUE_1, T_VALUE_2 };
+
+ a_class a_class_instance (T_VALUE_1, T_VALUE_2);
+ a_class *a_class_ptr = &a_class_instance;
+ a_class &a_class_ref = a_class_instance;
+
+ a_struct_t a_struct = { T_VALUE_1, T_VALUE_2 };
+ a_struct_t *a_struct_ptr = &a_struct;
+ a_struct_t &a_struct_ref = a_struct;
+
+ // Create a union with type T at offset zero
+ a_union_zero_t a_union_zero;
+ a_union_zero.a = T_VALUE_1;
+ a_union_zero_t *a_union_zero_ptr = &a_union_zero;
+ a_union_zero_t &a_union_zero_ref = a_union_zero;
+
+ // Create a union with type T at a non-zero offset
+ a_union_nonzero_t a_union_nonzero;
+ a_union_nonzero.u.a = T_VALUE_1;
+ a_union_nonzero_t *a_union_nonzero_ptr = &a_union_nonzero;
+ a_union_nonzero_t &a_union_nonzero_ref = a_union_nonzero;
+
+ a_struct_t a_struct_array_bounded[2] = {{ T_VALUE_1, T_VALUE_2 }, { T_VALUE_3, T_VALUE_4 }};
+ a_struct_t a_struct_array_unbounded[] = {{ T_VALUE_1, T_VALUE_2 }, { T_VALUE_3, T_VALUE_4 }};
+ a_union_zero_t a_union_zero_array_bounded[2];
+ a_union_zero_array_bounded[0].a = T_VALUE_1;
+ a_union_zero_array_bounded[1].a = T_VALUE_2;
+ a_union_zero_t a_union_zero_array_unbounded[] = {{ T_VALUE_1 }, { T_VALUE_2 }};
+
+#ifdef T_PRINTF_FORMAT
+ printf ("%s: a = '" T_PRINTF_FORMAT "'\n", T_CSTR, a);
+ printf ("%s*: %p => *a_ptr = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_ptr, *a_ptr);
+ printf ("%s&: @%p => a_ref = '" T_PRINTF_FORMAT "'\n", T_CSTR, &a_ref, a_ref);
+
+ printf ("%s[2]: a_array_bounded[0] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_bounded[0]);
+ printf ("%s[2]: a_array_bounded[1] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_bounded[1]);
+
+ printf ("%s[]: a_array_unbounded[0] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_unbounded[0]);
+ printf ("%s[]: a_array_unbounded[1] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_unbounded[1]);
+
+ printf ("(a_class) a_class_instance.m_a = '" T_PRINTF_FORMAT "'\n", a_class_instance.get_a());
+ printf ("(a_class) a_class_instance.m_b = '" T_PRINTF_FORMAT "'\n", a_class_instance.get_b());
+ printf ("(a_class*) a_class_ptr = %p, a_class_ptr->m_a = '" T_PRINTF_FORMAT "'\n", a_class_ptr, a_class_ptr->get_a());
+ printf ("(a_class*) a_class_ptr = %p, a_class_ptr->m_b = '" T_PRINTF_FORMAT "'\n", a_class_ptr, a_class_ptr->get_b());
+ printf ("(a_class&) a_class_ref = %p, a_class_ref.m_a = '" T_PRINTF_FORMAT "'\n", &a_class_ref, a_class_ref.get_a());
+ printf ("(a_class&) a_class_ref = %p, a_class_ref.m_b = '" T_PRINTF_FORMAT "'\n", &a_class_ref, a_class_ref.get_b());
+
+ printf ("(a_struct_t) a_struct.a = '" T_PRINTF_FORMAT "'\n", a_struct.a);
+ printf ("(a_struct_t) a_struct.b = '" T_PRINTF_FORMAT "'\n", a_struct.b);
+ printf ("(a_struct_t*) a_struct_ptr = %p, a_struct_ptr->a = '" T_PRINTF_FORMAT "'\n", a_struct_ptr, a_struct_ptr->a);
+ printf ("(a_struct_t*) a_struct_ptr = %p, a_struct_ptr->b = '" T_PRINTF_FORMAT "'\n", a_struct_ptr, a_struct_ptr->b);
+ printf ("(a_struct_t&) a_struct_ref = %p, a_struct_ref.a = '" T_PRINTF_FORMAT "'\n", &a_struct_ref, a_struct_ref.a);
+ printf ("(a_struct_t&) a_struct_ref = %p, a_struct_ref.b = '" T_PRINTF_FORMAT "'\n", &a_struct_ref, a_struct_ref.b);
+
+ printf ("(a_union_zero_t) a_union_zero.a = '" T_PRINTF_FORMAT "'\n", a_union_zero.a);
+ printf ("(a_union_zero_t*) a_union_zero_ptr = %p, a_union_zero_ptr->a = '" T_PRINTF_FORMAT "'\n", a_union_zero_ptr, a_union_zero_ptr->a);
+ printf ("(a_union_zero_t&) a_union_zero_ref = %p, a_union_zero_ref.a = '" T_PRINTF_FORMAT "'\n", &a_union_zero_ref, a_union_zero_ref.a);
+
+ printf ("(a_union_nonzero_t) a_union_nonzero.u.a = '" T_PRINTF_FORMAT "'\n", a_union_nonzero.u.a);
+ printf ("(a_union_nonzero_t*) a_union_nonzero_ptr = %p, a_union_nonzero_ptr->u.a = '" T_PRINTF_FORMAT "'\n", a_union_nonzero_ptr, a_union_nonzero_ptr->u.a);
+ printf ("(a_union_nonzero_t&) a_union_nonzero_ref = %p, a_union_nonzero_ref.u.a = '" T_PRINTF_FORMAT "'\n", &a_union_nonzero_ref, a_union_nonzero_ref.u.a);
+
+ printf ("(a_struct_t[2]) a_struct_array_bounded[0].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[0].a);
+ printf ("(a_struct_t[2]) a_struct_array_bounded[0].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[0].b);
+ printf ("(a_struct_t[2]) a_struct_array_bounded[1].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[1].a);
+ printf ("(a_struct_t[2]) a_struct_array_bounded[1].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[1].b);
+
+ printf ("(a_struct_t[]) a_struct_array_unbounded[0].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[0].a);
+ printf ("(a_struct_t[]) a_struct_array_unbounded[0].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[0].b);
+ printf ("(a_struct_t[]) a_struct_array_unbounded[1].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[1].a);
+ printf ("(a_struct_t[]) a_struct_array_unbounded[1].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_unbounded[1].b);
+
+ printf ("(a_union_zero_t[2]) a_union_zero_array_bounded[0].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_bounded[0].a);
+ printf ("(a_union_zero_t[2]) a_union_zero_array_bounded[1].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_bounded[1].a);
+
+ printf ("(a_union_zero_t[]) a_union_zero_array_unbounded[0].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_unbounded[0].a);
+ printf ("(a_union_zero_t[]) a_union_zero_array_unbounded[1].a = '" T_PRINTF_FORMAT "'\n", a_union_zero_array_unbounded[1].a);
+
+#endif
+ Puts("About to exit, break here to check values..."); // Set break point at this line.
+ return 0;
+}
diff --git a/lldb/test/functionalities/breakpoint/inlined_breakpoints/int.cpp b/lldb/test/functionalities/breakpoint/inlined_breakpoints/int.cpp
new file mode 100644
index 00000000000..922398b1c6e
--- /dev/null
+++ b/lldb/test/functionalities/breakpoint/inlined_breakpoints/int.cpp
@@ -0,0 +1,9 @@
+#define T int
+#define T_CSTR "int"
+#define T_VALUE_1 11001110
+#define T_VALUE_2 22002220
+#define T_VALUE_3 33003330
+#define T_VALUE_4 44004440
+#define T_PRINTF_FORMAT "%i"
+
+#include "basic_type.cpp"
diff --git a/lldb/test/functionalities/embedded_interpreter/Makefile b/lldb/test/functionalities/embedded_interpreter/Makefile
new file mode 100644
index 00000000000..0d70f259501
--- /dev/null
+++ b/lldb/test/functionalities/embedded_interpreter/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/functionalities/embedded_interpreter/TestConvenienceVariables.py b/lldb/test/functionalities/embedded_interpreter/TestConvenienceVariables.py
new file mode 100644
index 00000000000..2e5b2c13607
--- /dev/null
+++ b/lldb/test/functionalities/embedded_interpreter/TestConvenienceVariables.py
@@ -0,0 +1,87 @@
+"""Test convenience variables when you drop in from lldb prompt into an embedded interpreter."""
+
+import os
+import unittest2
+import lldb
+import pexpect
+from lldbtest import *
+
+class ConvenienceVariablesCase(TestBase):
+
+ mydir = os.path.join("functionalities", "embedded_interpreter")
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_with_dsym_and_run_command(self):
+ """Test convenience variables lldb.debugger, lldb.target, lldb.process, lldb.thread, and lldb.frame."""
+ self.buildDsym()
+ self.convenience_variables()
+
+ def test_with_dwarf_and_run_commands(self):
+ """Test convenience variables lldb.debugger, lldb.target, lldb.process, lldb.thread, and lldb.frame."""
+ self.buildDwarf()
+ self.convenience_variables()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break on inside main.cpp.
+ self.line = line_number('main.c', 'Hello world.')
+
+ def convenience_variables(self):
+ """Test convenience variables lldb.debugger, lldb.target, lldb.process, lldb.thread, and lldb.frame."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ prompt = "(lldb) "
+ python_prompt = ">>> "
+
+ # So that the child gets torn down after the test.
+ self.child = pexpect.spawn('%s %s' % (self.lldbExec, exe))
+ child = self.child
+ # Turn on logging for what the child sends back.
+ if self.TraceOn():
+ child.logfile_read = sys.stdout
+
+ # Set the breakpoint, run the inferior, when it breaks, issue print on
+ # the various convenience variables.
+ child.expect_exact(prompt)
+ child.sendline('breakpoint set -f main.c -l %d' % self.line)
+ child.expect_exact(prompt)
+ child.sendline('run')
+ child.expect_exact(prompt)
+ child.sendline('script')
+ child.expect_exact(python_prompt)
+
+ # Set a flag so that we know during teardown time, we need to exit the
+ # Python interpreter, then the lldb interpreter.
+ self.child_in_script_interpreter = True
+
+ child.sendline('print lldb.debugger')
+ child.expect_exact(python_prompt)
+ self.expect(child.before, exe=False,
+ patterns = ['Debugger \(instance: .*, id: \d\)'])
+
+ child.sendline('print lldb.target')
+ child.expect_exact(python_prompt)
+ self.expect(child.before, exe=False,
+ substrs = ['a.out'])
+
+ child.sendline('print lldb.process')
+ child.expect_exact(python_prompt)
+ self.expect(child.before, exe=False,
+ patterns = ['SBProcess: pid = \d+, state = stopped, threads = \d, executable = a.out'])
+
+ child.sendline('print lldb.thread')
+ child.expect_exact(python_prompt)
+ self.expect(child.before, exe=False,
+ patterns = ['SBThread: tid = 0x[0-9a-f]+'])
+
+ child.sendline('print lldb.frame')
+ child.expect_exact(python_prompt)
+ self.expect(child.before, exe=False,
+ substrs = ['frame #0', 'main.c:%d' % self.line])
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/lldb/test/functionalities/embedded_interpreter/main.c b/lldb/test/functionalities/embedded_interpreter/main.c
new file mode 100644
index 00000000000..277aa54a4ee
--- /dev/null
+++ b/lldb/test/functionalities/embedded_interpreter/main.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(int argc, char const *argv[]) {
+ printf("Hello world.\n");
+ return 0;
+}
diff --git a/lldb/test/functionalities/load_unload/Makefile b/lldb/test/functionalities/load_unload/Makefile
new file mode 100644
index 00000000000..a77b507e52f
--- /dev/null
+++ b/lldb/test/functionalities/load_unload/Makefile
@@ -0,0 +1,45 @@
+all: a.out liba.dylib libb.dylib libc.dylib libd.dylib
+
+CC ?= gcc
+ifeq "$(CC)" "cc"
+ CC = gcc
+endif
+CFLAGS ?=-arch x86_64 -gdwarf-2 -O0
+CWD := $(shell pwd)
+
+a.out: main.o libd.dylib
+ $(CC) $(CFLAGS) -o a.out main.o -L. -ld
+
+main.o: main.c
+ $(CC) $(CFLAGS) -c main.c
+
+liba.dylib: a.o libb.dylib
+ $(CC) $(CFLAGS) -dynamiclib -install_name "@executable_path/liba.dylib" -o liba.dylib a.o -L. -lb
+ dsymutil liba.dylib
+
+a.o: a.c
+ $(CC) $(CFLAGS) -c a.c
+
+libb.dylib: b.o
+ $(CC) $(CFLAGS) -dynamiclib -install_name "@executable_path/libb.dylib" -o libb.dylib b.o
+ dsymutil libb.dylib
+
+b.o: b.c
+ $(CC) $(CFLAGS) -c b.c
+
+libc.dylib: c.o
+ $(CC) $(CFLAGS) -dynamiclib -install_name "@executable_path/libc.dylib" -o libc.dylib c.o
+ dsymutil libc.dylib
+
+c.o: c.c
+ $(CC) $(CFLAGS) -c c.c
+
+libd.dylib: d.o
+ $(CC) $(CFLAGS) -dynamiclib -install_name "$(CWD)/libd.dylib" -o libd.dylib d.o
+ dsymutil libd.dylib
+
+d.o: d.c
+ $(CC) $(CFLAGS) -c d.c
+
+clean:
+ rm -rf *.o *~ *.dylib a.out *.dSYM
diff --git a/lldb/test/functionalities/load_unload/TestLoadUnload.py b/lldb/test/functionalities/load_unload/TestLoadUnload.py
new file mode 100644
index 00000000000..d3ebdc950b4
--- /dev/null
+++ b/lldb/test/functionalities/load_unload/TestLoadUnload.py
@@ -0,0 +1,218 @@
+"""
+Test that breakpoint by symbol name works correctly with dynamic libs.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb
+from lldbtest import *
+
+class LoadUnloadTestCase(TestBase):
+
+ mydir = os.path.join("functionalities", "load_unload")
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break for main.cpp.
+ self.line = line_number('main.c',
+ '// Set break point at this line for test_lldb_process_load_and_unload_commands().')
+ self.line_d_function = line_number('d.c',
+ '// Find this line number within d_dunction().')
+
+ @unittest2.expectedFailure
+ def test_modules_search_paths(self):
+ """Test target modules list after moving libd.dylib, and verifies that it works with 'target modules search-paths add'."""
+
+ # Invoke the default build rule.
+ self.buildDefault()
+
+ if sys.platform.startswith("darwin"):
+ dylibName = 'libd.dylib'
+
+ # Now let's move the dynamic library to a different directory than $CWD.
+
+ # The directory to relocate the dynamic library to.
+ new_dir = os.path.join(os.getcwd(), "dyld_path")
+
+ # This is the function to remove the dyld_path directory after the test.
+ def remove_dyld_dir():
+ import shutil
+ shutil.rmtree(new_dir)
+
+ old_dylib = os.path.join(os.getcwd(), dylibName)
+ new_dylib = os.path.join(new_dir, dylibName)
+
+ os.mkdir(new_dir)
+ os.rename(old_dylib, new_dylib)
+ self.addTearDownHook(remove_dyld_dir)
+
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ self.expect("target modules list",
+ substrs = [old_dylib])
+ self.expect("target modules list -t 3",
+ patterns = ["%s-[^-]*-[^-]*" % self.getArchitecture()])
+ self.runCmd("target modules search-paths add %s %s" % (os.getcwd(), new_dir))
+
+ self.expect("target modules search-paths list",
+ substrs = [os.getcwd(), new_dir])
+
+ # Add teardown hook to clear image-search-paths after the test.
+ self.addTearDownHook(lambda: self.runCmd("target modules search-paths clear"))
+ self.expect("target modules list", "LLDB successfully locates the relocated dynamic library",
+ substrs = [new_dylib])
+
+
+ def test_dyld_library_path(self):
+ """Test DYLD_LIBRARY_PATH after moving libd.dylib, which defines d_function, somewhere else."""
+
+ # Invoke the default build rule.
+ self.buildDefault()
+
+ if sys.platform.startswith("darwin"):
+ dylibName = 'libd.dylib'
+ dsymName = 'libd.dylib.dSYM'
+ dylibPath = 'DYLD_LIBRARY_PATH'
+
+ # Now let's move the dynamic library to a different directory than $CWD.
+
+ # The directory to relocate the dynamic library and its debugging info.
+ new_dir = os.path.join(os.getcwd(), "dyld_path")
+
+ # This is the function to remove the dyld_path directory after the test.
+ def remove_dyld_dir():
+ import shutil
+ shutil.rmtree(new_dir)
+
+ old_dylib = os.path.join(os.getcwd(), dylibName)
+ new_dylib = os.path.join(new_dir, dylibName)
+ old_dSYM = os.path.join(os.getcwd(), dsymName)
+ new_dSYM = os.path.join(new_dir, dsymName)
+ #system(["ls", "-lR", "."])
+ os.mkdir(new_dir)
+ os.rename(old_dylib, new_dylib)
+ if dsymName:
+ os.rename(old_dSYM, new_dSYM)
+ self.addTearDownHook(remove_dyld_dir)
+ #system(["ls", "-lR", "."])
+
+ # With libd.dylib moved, a.out run should fail.
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+ # Set breakpoint by function name d_function.
+ self.expect("breakpoint set -n d_function", BREAKPOINT_CREATED,
+ substrs = ["Breakpoint created",
+ "name = 'd_function'",
+ "locations = 0 (pending)"])
+ self.runCmd("run")
+ self.expect("process status", "Not expected to hit the d_function breakpoint",
+ matching=False,
+ substrs = ["stop reason = breakpoint"])
+ # Kill the inferior process.
+ self.runCmd("process kill")
+
+ # Try again with the DYLD_LIBRARY_PATH environment variable properly set.
+ os.environ[dylibPath] = new_dir
+ self.addTearDownHook(lambda: os.environ.pop(dylibPath))
+ self.runCmd("run")
+ self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
+ patterns = ["frame #0.*d_function.*at d.c:%d" % self.line_d_function])
+
+ def test_lldb_process_load_and_unload_commands(self):
+ """Test that lldb process load/unload command work correctly."""
+
+ # Invoke the default build rule.
+ self.buildDefault()
+
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Break at main.c before the call to dlopen().
+ # Use lldb's process load command to load the dylib, instead.
+
+ self.expect("breakpoint set -f main.c -l %d" % self.line,
+ BREAKPOINT_CREATED,
+ startstr = "Breakpoint created: 1: file ='main.c', line = %d" %
+ self.line)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # Make sure that a_function does not exist at this point.
+ self.expect("image lookup -n a_function", "a_function should not exist yet",
+ error=True, matching=False,
+ patterns = ["1 match found .* %s" % self.mydir])
+
+ # Use lldb 'process load' to load the dylib.
+ self.expect("process load liba.dylib", "liba.dylib loaded correctly",
+ patterns = ['Loading "liba.dylib".*ok',
+ 'Image [0-9]+ loaded'])
+
+ # Search for and match the "Image ([0-9]+) loaded" pattern.
+ output = self.res.GetOutput()
+ pattern = re.compile("Image ([0-9]+) loaded")
+ for l in output.split(os.linesep):
+ #print "l:", l
+ match = pattern.search(l)
+ if match:
+ break
+ index = match.group(1)
+
+ # Now we should have an entry for a_function.
+ self.expect("image lookup -n a_function", "a_function should now exist",
+ patterns = ["1 match found .*%s" % self.mydir])
+
+ # Use lldb 'process unload' to unload the dylib.
+ self.expect("process unload %s" % index, "liba.dylib unloaded correctly",
+ patterns = ["Unloading .* with index %s.*ok" % index])
+
+ self.runCmd("process continue")
+
+ def test_load_unload(self):
+ """Test breakpoint by name works correctly with dlopen'ing."""
+
+ # Invoke the default build rule.
+ self.buildDefault()
+
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Break by function name a_function (not yet loaded).
+ self.expect("breakpoint set -n a_function", BREAKPOINT_CREATED,
+ startstr = "Breakpoint created: 1: name = 'a_function', locations = 0 (pending)")
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint and at a_function.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['stopped',
+ 'a_function',
+ 'stop reason = breakpoint'])
+
+ # The breakpoint should have a hit count of 1.
+ self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
+ substrs = [' resolved, hit count = 1'])
+
+ # Issue the 'contnue' command. We should stop agaian at a_function.
+ # The stop reason of the thread should be breakpoint and at a_function.
+ self.runCmd("continue")
+
+ # rdar://problem/8508987
+ # The a_function breakpoint should be encountered twice.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['stopped',
+ 'a_function',
+ 'stop reason = breakpoint'])
+
+ # The breakpoint should have a hit count of 2.
+ self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
+ substrs = [' resolved, hit count = 2'])
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/lldb/test/functionalities/load_unload/a.c b/lldb/test/functionalities/load_unload/a.c
new file mode 100644
index 00000000000..9d4711772dd
--- /dev/null
+++ b/lldb/test/functionalities/load_unload/a.c
@@ -0,0 +1,15 @@
+//===-- a.c -----------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+extern int b_function ();
+
+int
+a_function ()
+{
+ return b_function ();
+}
diff --git a/lldb/test/functionalities/load_unload/b.c b/lldb/test/functionalities/load_unload/b.c
new file mode 100644
index 00000000000..6c629323655
--- /dev/null
+++ b/lldb/test/functionalities/load_unload/b.c
@@ -0,0 +1,13 @@
+//===-- b.c -----------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+int
+b_function ()
+{
+ return 500;
+}
diff --git a/lldb/test/functionalities/load_unload/c.c b/lldb/test/functionalities/load_unload/c.c
new file mode 100644
index 00000000000..b1778b462d0
--- /dev/null
+++ b/lldb/test/functionalities/load_unload/c.c
@@ -0,0 +1,13 @@
+//===-- c.c -----------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+int
+c_function ()
+{
+ return 600;
+}
diff --git a/lldb/test/functionalities/load_unload/cmds.txt b/lldb/test/functionalities/load_unload/cmds.txt
new file mode 100644
index 00000000000..1e4b198dc0d
--- /dev/null
+++ b/lldb/test/functionalities/load_unload/cmds.txt
@@ -0,0 +1,2 @@
+breakpoint set -n a_function
+run
diff --git a/lldb/test/functionalities/load_unload/d.c b/lldb/test/functionalities/load_unload/d.c
new file mode 100644
index 00000000000..af5725cb406
--- /dev/null
+++ b/lldb/test/functionalities/load_unload/d.c
@@ -0,0 +1,13 @@
+//===-- c.c -----------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+int
+d_function ()
+{
+ return 700; // Find this line number within d_dunction().
+}
diff --git a/lldb/test/functionalities/load_unload/main.c b/lldb/test/functionalities/load_unload/main.c
new file mode 100644
index 00000000000..da44abfa0c2
--- /dev/null
+++ b/lldb/test/functionalities/load_unload/main.c
@@ -0,0 +1,75 @@
+//===-- 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>
+#include <dlfcn.h>
+#include <limits.h>
+#include <string.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <stdlib.h>
+
+int
+main (int argc, char const *argv[])
+{
+ const char *a_name = "@executable_path/liba.dylib";
+ const char *c_name = "@executable_path/libc.dylib";
+ void *a_dylib_handle = NULL;
+ void *c_dylib_handle = NULL;
+ int (*a_function) (void);
+
+ a_dylib_handle = dlopen (a_name, RTLD_NOW); // Set break point at this line for test_lldb_process_load_and_unload_commands().
+ if (a_dylib_handle == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (1);
+ }
+
+ a_function = (int (*) ()) dlsym (a_dylib_handle, "a_function");
+ if (a_function == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (2);
+ }
+ printf ("First time around, got: %d\n", a_function ());
+ dlclose (a_dylib_handle);
+
+ c_dylib_handle = dlopen (c_name, RTLD_NOW);
+ if (c_dylib_handle == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (3);
+ }
+ a_function = (int (*) ()) dlsym (c_dylib_handle, "c_function");
+ if (a_function == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (4);
+ }
+
+ a_dylib_handle = dlopen (a_name, RTLD_NOW);
+ if (a_dylib_handle == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (5);
+ }
+
+ a_function = (int (*) ()) dlsym (a_dylib_handle, "a_function");
+ if (a_function == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (6);
+ }
+ printf ("Second time around, got: %d\n", a_function ());
+ dlclose (a_dylib_handle);
+
+ int d_function(void);
+ printf ("d_function returns: %d\n", d_function());
+
+ return 0;
+}
OpenPOWER on IntegriCloud