From 85f21f2029a9be360c734c8ce09a8f01bd7ee3f6 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Mon, 27 Jun 2011 18:17:24 +0000 Subject: Move top level test dirs inlined_breakpoints, load_unload, and embedded_interpreter to reside under functionalities. llvm-svn: 133918 --- lldb/test/embedded_interpreter/Makefile | 5 - .../TestConvenienceVariables.py | 87 -------- lldb/test/embedded_interpreter/main.c | 6 - .../breakpoint/inlined_breakpoints/Makefile | 5 + .../inlined_breakpoints/TestInlinedBreakpoints.py | 57 ++++++ .../breakpoint/inlined_breakpoints/basic_type.cpp | 178 +++++++++++++++++ .../breakpoint/inlined_breakpoints/int.cpp | 9 + .../functionalities/embedded_interpreter/Makefile | 5 + .../TestConvenienceVariables.py | 87 ++++++++ .../functionalities/embedded_interpreter/main.c | 6 + lldb/test/functionalities/load_unload/Makefile | 45 +++++ .../functionalities/load_unload/TestLoadUnload.py | 218 +++++++++++++++++++++ lldb/test/functionalities/load_unload/a.c | 15 ++ lldb/test/functionalities/load_unload/b.c | 13 ++ lldb/test/functionalities/load_unload/c.c | 13 ++ lldb/test/functionalities/load_unload/cmds.txt | 2 + lldb/test/functionalities/load_unload/d.c | 13 ++ lldb/test/functionalities/load_unload/main.c | 75 +++++++ lldb/test/inlined_breakpoints/Makefile | 5 - .../inlined_breakpoints/TestInlinedBreakpoints.py | 57 ------ lldb/test/inlined_breakpoints/basic_type.cpp | 178 ----------------- lldb/test/inlined_breakpoints/int.cpp | 9 - lldb/test/load_unload/Makefile | 45 ----- lldb/test/load_unload/TestLoadUnload.py | 218 --------------------- lldb/test/load_unload/a.c | 15 -- lldb/test/load_unload/b.c | 13 -- lldb/test/load_unload/c.c | 13 -- lldb/test/load_unload/cmds.txt | 2 - lldb/test/load_unload/d.c | 13 -- lldb/test/load_unload/main.c | 75 ------- 30 files changed, 741 insertions(+), 741 deletions(-) delete mode 100644 lldb/test/embedded_interpreter/Makefile delete mode 100644 lldb/test/embedded_interpreter/TestConvenienceVariables.py delete mode 100644 lldb/test/embedded_interpreter/main.c create mode 100644 lldb/test/functionalities/breakpoint/inlined_breakpoints/Makefile create mode 100644 lldb/test/functionalities/breakpoint/inlined_breakpoints/TestInlinedBreakpoints.py create mode 100644 lldb/test/functionalities/breakpoint/inlined_breakpoints/basic_type.cpp create mode 100644 lldb/test/functionalities/breakpoint/inlined_breakpoints/int.cpp create mode 100644 lldb/test/functionalities/embedded_interpreter/Makefile create mode 100644 lldb/test/functionalities/embedded_interpreter/TestConvenienceVariables.py create mode 100644 lldb/test/functionalities/embedded_interpreter/main.c create mode 100644 lldb/test/functionalities/load_unload/Makefile create mode 100644 lldb/test/functionalities/load_unload/TestLoadUnload.py create mode 100644 lldb/test/functionalities/load_unload/a.c create mode 100644 lldb/test/functionalities/load_unload/b.c create mode 100644 lldb/test/functionalities/load_unload/c.c create mode 100644 lldb/test/functionalities/load_unload/cmds.txt create mode 100644 lldb/test/functionalities/load_unload/d.c create mode 100644 lldb/test/functionalities/load_unload/main.c delete mode 100644 lldb/test/inlined_breakpoints/Makefile delete mode 100644 lldb/test/inlined_breakpoints/TestInlinedBreakpoints.py delete mode 100644 lldb/test/inlined_breakpoints/basic_type.cpp delete mode 100644 lldb/test/inlined_breakpoints/int.cpp delete mode 100644 lldb/test/load_unload/Makefile delete mode 100644 lldb/test/load_unload/TestLoadUnload.py delete mode 100644 lldb/test/load_unload/a.c delete mode 100644 lldb/test/load_unload/b.c delete mode 100644 lldb/test/load_unload/c.c delete mode 100644 lldb/test/load_unload/cmds.txt delete mode 100644 lldb/test/load_unload/d.c delete mode 100644 lldb/test/load_unload/main.c diff --git a/lldb/test/embedded_interpreter/Makefile b/lldb/test/embedded_interpreter/Makefile deleted file mode 100644 index d6cd0db0506..00000000000 --- a/lldb/test/embedded_interpreter/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -LEVEL = ../make - -C_SOURCES := main.c - -include $(LEVEL)/Makefile.rules diff --git a/lldb/test/embedded_interpreter/TestConvenienceVariables.py b/lldb/test/embedded_interpreter/TestConvenienceVariables.py deleted file mode 100644 index 46450ae6323..00000000000 --- a/lldb/test/embedded_interpreter/TestConvenienceVariables.py +++ /dev/null @@ -1,87 +0,0 @@ -"""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 = "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/embedded_interpreter/main.c b/lldb/test/embedded_interpreter/main.c deleted file mode 100644 index 277aa54a4ee..00000000000 --- a/lldb/test/embedded_interpreter/main.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char const *argv[]) { - printf("Hello world.\n"); - return 0; -} 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 +#include + +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 + +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 +#include +#include +#include +#include +#include +#include + +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; +} diff --git a/lldb/test/inlined_breakpoints/Makefile b/lldb/test/inlined_breakpoints/Makefile deleted file mode 100644 index 7f155e15aae..00000000000 --- a/lldb/test/inlined_breakpoints/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -LEVEL = ../make - -CXX_SOURCES := int.cpp - -include $(LEVEL)/Makefile.rules diff --git a/lldb/test/inlined_breakpoints/TestInlinedBreakpoints.py b/lldb/test/inlined_breakpoints/TestInlinedBreakpoints.py deleted file mode 100644 index be512844a43..00000000000 --- a/lldb/test/inlined_breakpoints/TestInlinedBreakpoints.py +++ /dev/null @@ -1,57 +0,0 @@ -""" -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 = "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/inlined_breakpoints/basic_type.cpp b/lldb/test/inlined_breakpoints/basic_type.cpp deleted file mode 100644 index 5881afe1f39..00000000000 --- a/lldb/test/inlined_breakpoints/basic_type.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// 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 -#include - -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/inlined_breakpoints/int.cpp b/lldb/test/inlined_breakpoints/int.cpp deleted file mode 100644 index 922398b1c6e..00000000000 --- a/lldb/test/inlined_breakpoints/int.cpp +++ /dev/null @@ -1,9 +0,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 44004440 -#define T_PRINTF_FORMAT "%i" - -#include "basic_type.cpp" diff --git a/lldb/test/load_unload/Makefile b/lldb/test/load_unload/Makefile deleted file mode 100644 index a77b507e52f..00000000000 --- a/lldb/test/load_unload/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -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/load_unload/TestLoadUnload.py b/lldb/test/load_unload/TestLoadUnload.py deleted file mode 100644 index 0bceb4705ea..00000000000 --- a/lldb/test/load_unload/TestLoadUnload.py +++ /dev/null @@ -1,218 +0,0 @@ -""" -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 = "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/load_unload/a.c b/lldb/test/load_unload/a.c deleted file mode 100644 index 9d4711772dd..00000000000 --- a/lldb/test/load_unload/a.c +++ /dev/null @@ -1,15 +0,0 @@ -//===-- 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/load_unload/b.c b/lldb/test/load_unload/b.c deleted file mode 100644 index 6c629323655..00000000000 --- a/lldb/test/load_unload/b.c +++ /dev/null @@ -1,13 +0,0 @@ -//===-- 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/load_unload/c.c b/lldb/test/load_unload/c.c deleted file mode 100644 index b1778b462d0..00000000000 --- a/lldb/test/load_unload/c.c +++ /dev/null @@ -1,13 +0,0 @@ -//===-- 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/load_unload/cmds.txt b/lldb/test/load_unload/cmds.txt deleted file mode 100644 index 1e4b198dc0d..00000000000 --- a/lldb/test/load_unload/cmds.txt +++ /dev/null @@ -1,2 +0,0 @@ -breakpoint set -n a_function -run diff --git a/lldb/test/load_unload/d.c b/lldb/test/load_unload/d.c deleted file mode 100644 index af5725cb406..00000000000 --- a/lldb/test/load_unload/d.c +++ /dev/null @@ -1,13 +0,0 @@ -//===-- 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/load_unload/main.c b/lldb/test/load_unload/main.c deleted file mode 100644 index da44abfa0c2..00000000000 --- a/lldb/test/load_unload/main.c +++ /dev/null @@ -1,75 +0,0 @@ -//===-- 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 -#include -#include -#include -#include -#include -#include - -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; -} -- cgit v1.2.1