summaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py')
-rw-r--r--packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py223
1 files changed, 141 insertions, 82 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py b/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
index 3a703b2ee04e2..027968a727f1f 100644
--- a/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
+++ b/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
@@ -5,18 +5,19 @@ Test that breakpoint by symbol name works correctly with dynamic libs.
from __future__ import print_function
-
-import os, time
+import os
+import time
import re
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
-@skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
+
+@skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
class LoadUnloadTestCase(TestBase):
- def getCategories (self):
+ def getCategories(self):
return ['basic_process']
mydir = TestBase.compute_mydir(__file__)
@@ -25,19 +26,30 @@ class LoadUnloadTestCase(TestBase):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break for main.cpp.
- self.line = line_number('main.cpp',
- '// Set break point at this line for test_lldb_process_load_and_unload_commands().')
- self.line_d_function = line_number('d.cpp',
- '// Find this line number within d_dunction().')
+ self.line = line_number(
+ 'main.cpp',
+ '// Set break point at this line for test_lldb_process_load_and_unload_commands().')
+ self.line_d_function = line_number(
+ 'd.cpp', '// Find this line number within d_dunction().')
if not self.platformIsDarwin():
if not lldb.remote_platform and "LD_LIBRARY_PATH" in os.environ:
- self.runCmd("settings set target.env-vars " + self.dylibPath + "=" + os.environ["LD_LIBRARY_PATH"] + ":" + os.getcwd())
+ self.runCmd(
+ "settings set target.env-vars " +
+ self.dylibPath +
+ "=" +
+ os.environ["LD_LIBRARY_PATH"] +
+ ":" +
+ os.getcwd())
else:
if lldb.remote_platform:
wd = lldb.remote_platform.GetWorkingDirectory()
else:
wd = os.getcwd()
- self.runCmd("settings set target.env-vars " + self.dylibPath + "=" + wd)
+ self.runCmd(
+ "settings set target.env-vars " +
+ self.dylibPath +
+ "=" +
+ wd)
def copy_shlibs_to_remote(self, hidden_dir=False):
""" Copies the shared libs required by this test suite to remote.
@@ -72,9 +84,9 @@ class LoadUnloadTestCase(TestBase):
"Unable copy 'libloadunload_d.so' to '%s'.\n>>> %s" %
(wd, err.GetCString()))
- @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
+ @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
@not_remote_testsuite_ready
- @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
+ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
def test_modules_search_paths(self):
"""Test target modules list after loading a different copy of the library libd.dylib, and verifies that it works with 'target modules search-paths add'."""
@@ -96,17 +108,22 @@ class LoadUnloadTestCase(TestBase):
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
self.expect("target modules list",
- substrs = [old_dylib])
- #self.expect("target modules list -t 3",
+ substrs=[old_dylib])
+ # self.expect("target modules list -t 3",
# patterns = ["%s-[^-]*-[^-]*" % self.getArchitecture()])
# Add an image search path substitution pair.
- self.runCmd("target modules search-paths add %s %s" % (os.getcwd(), new_dir))
+ 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])
+ substrs=[os.getcwd(), new_dir])
- self.expect("target modules search-paths query %s" % os.getcwd(), "Image search path successfully transformed",
- substrs = [new_dir])
+ self.expect(
+ "target modules search-paths query %s" %
+ os.getcwd(),
+ "Image search path successfully transformed",
+ substrs=[new_dir])
# Obliterate traces of libd from the old location.
os.remove(old_dylib)
@@ -118,16 +135,19 @@ class LoadUnloadTestCase(TestBase):
self.runCmd("settings show target.env-vars")
remove_dyld_path_cmd = "settings remove target.env-vars " + self.dylibPath
- self.addTearDownHook(lambda: self.dbg.HandleCommand(remove_dyld_path_cmd))
+ self.addTearDownHook(
+ lambda: self.dbg.HandleCommand(remove_dyld_path_cmd))
self.runCmd("run")
- self.expect("target modules list", "LLDB successfully locates the relocated dynamic library",
- substrs = [new_dylib])
+ self.expect(
+ "target modules list",
+ "LLDB successfully locates the relocated dynamic library",
+ substrs=[new_dylib])
- @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
- @expectedFailureAndroid # wrong source file shows up for hidden library
- @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
+ @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
+ @expectedFailureAndroid # wrong source file shows up for hidden library
+ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
def test_dyld_library_path(self):
"""Test (DY)LD_LIBRARY_PATH after moving libd.dylib, which defines d_function, somewhere else."""
@@ -138,6 +158,10 @@ class LoadUnloadTestCase(TestBase):
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+ # Shut off ANSI color usage so we don't get ANSI escape sequences
+ # mixed in with stop locations.
+ self.dbg.SetUseColor(False)
+
if self.platformIsDarwin():
dylibName = 'libloadunload_d.dylib'
dsymName = 'libloadunload_d.dylib.dSYM'
@@ -156,15 +180,17 @@ class LoadUnloadTestCase(TestBase):
old_dylib = os.path.join(old_dir, dylibName)
remove_dyld_path_cmd = "settings remove target.env-vars " + self.dylibPath
- self.addTearDownHook(lambda: self.dbg.HandleCommand(remove_dyld_path_cmd))
+ self.addTearDownHook(
+ lambda: self.dbg.HandleCommand(remove_dyld_path_cmd))
# For now we don't track (DY)LD_LIBRARY_PATH, so the old library will be in
# the modules list.
self.expect("target modules list",
- substrs = [os.path.basename(old_dylib)],
+ substrs=[os.path.basename(old_dylib)],
matching=True)
- lldbutil.run_break_set_by_file_and_line (self, "d.cpp", self.line_d_function, num_expected_locations=1)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "d.cpp", self.line_d_function, num_expected_locations=1)
# After run, make sure the non-hidden library is picked up.
self.expect("run", substrs=["return", "700"])
@@ -180,9 +206,14 @@ class LoadUnloadTestCase(TestBase):
# This time, the hidden library should be picked up.
self.expect("run", substrs=["return", "12345"])
- @expectedFailureAll(bugnumber="llvm.org/pr25805", hostoslist=["windows"], compiler="gcc", archs=["i386"], triple='.*-android')
- @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
- @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
+ @expectedFailureAll(
+ bugnumber="llvm.org/pr25805",
+ hostoslist=["windows"],
+ compiler="gcc",
+ archs=["i386"],
+ triple='.*-android')
+ @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
+ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
def test_lldb_process_load_and_unload_commands(self):
"""Test that lldb process load/unload command work correctly."""
@@ -196,7 +227,8 @@ class LoadUnloadTestCase(TestBase):
# Break at main.cpp before the call to dlopen().
# Use lldb's process load command to load the dylib, instead.
- lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_SUCCEEDED)
@@ -211,13 +243,23 @@ class LoadUnloadTestCase(TestBase):
dylibName = 'libloadunload_a.so'
# 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"])
+ self.expect(
+ "image lookup -n a_function",
+ "a_function should not exist yet",
+ error=True,
+ matching=False,
+ patterns=["1 match found"])
# Use lldb 'process load' to load the dylib.
- self.expect("process load %s --install" % dylibName, "%s loaded correctly" % dylibName,
- patterns = ['Loading "%s".*ok' % dylibName,
- 'Image [0-9]+ loaded'])
+ self.expect(
+ "process load %s --install" %
+ dylibName,
+ "%s loaded correctly" %
+ dylibName,
+ patterns=[
+ 'Loading "%s".*ok' %
+ dylibName,
+ 'Image [0-9]+ loaded'])
# Search for and match the "Image ([0-9]+) loaded" pattern.
output = self.res.GetOutput()
@@ -230,16 +272,26 @@ class LoadUnloadTestCase(TestBase):
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" % dylibName])
+ self.expect(
+ "image lookup -n a_function",
+ "a_function should now exist",
+ patterns=[
+ "1 match found .*%s" %
+ dylibName])
# Use lldb 'process unload' to unload the dylib.
- self.expect("process unload %s" % index, "%s unloaded correctly" % dylibName,
- patterns = ["Unloading .* with index %s.*ok" % index])
+ self.expect(
+ "process unload %s" %
+ index,
+ "%s unloaded correctly" %
+ dylibName,
+ patterns=[
+ "Unloading .* with index %s.*ok" %
+ index])
self.runCmd("process continue")
- @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
+ @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
def test_load_unload(self):
"""Test breakpoint by name works correctly with dlopen'ing."""
@@ -251,19 +303,20 @@ class LoadUnloadTestCase(TestBase):
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Break by function name a_function (not yet loaded).
- lldbutil.run_break_set_by_symbol (self, "a_function", num_expected_locations=0)
+ lldbutil.run_break_set_by_symbol(
+ self, "a_function", num_expected_locations=0)
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'])
+ 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'])
+ 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.
@@ -272,17 +325,17 @@ class LoadUnloadTestCase(TestBase):
# 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'])
+ 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'])
+ substrs=[' resolved, hit count = 2'])
- @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
- @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
- def test_step_over_load (self):
+ @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
+ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
+ def test_step_over_load(self):
"""Test stepping over code that loads a shared library works correctly."""
# Invoke the default build rule.
@@ -293,26 +346,29 @@ class LoadUnloadTestCase(TestBase):
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Break by function name a_function (not yet loaded).
- lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
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',
- 'stop reason = breakpoint'])
+ substrs=['stopped',
+ 'stop reason = breakpoint'])
+
+ self.runCmd(
+ "thread step-over",
+ "Stepping over function that loads library")
- self.runCmd("thread step-over", "Stepping over function that loads library")
-
# The stop reason should be step end.
- self.expect("thread list", "step over succeeded.",
- substrs = ['stopped',
- 'stop reason = step over'])
+ self.expect("thread list", "step over succeeded.",
+ substrs=['stopped',
+ 'stop reason = step over'])
- @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
- @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
+ @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
+ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
@unittest2.expectedFailure("llvm.org/pr25806")
- def test_static_init_during_load (self):
+ def test_static_init_during_load(self):
"""Test that we can set breakpoints correctly in static initializers"""
self.build()
@@ -321,33 +377,36 @@ class LoadUnloadTestCase(TestBase):
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
- a_init_bp_num = lldbutil.run_break_set_by_symbol(self, "a_init", num_expected_locations=0)
- b_init_bp_num = lldbutil.run_break_set_by_symbol(self, "b_init", num_expected_locations=0)
- d_init_bp_num = lldbutil.run_break_set_by_symbol(self, "d_init", num_expected_locations=1)
+ a_init_bp_num = lldbutil.run_break_set_by_symbol(
+ self, "a_init", num_expected_locations=0)
+ b_init_bp_num = lldbutil.run_break_set_by_symbol(
+ self, "b_init", num_expected_locations=0)
+ d_init_bp_num = lldbutil.run_break_set_by_symbol(
+ self, "d_init", num_expected_locations=1)
self.runCmd("run", RUN_SUCCEEDED)
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
- substrs = ['stopped',
- 'd_init',
- 'stop reason = breakpoint %d' % d_init_bp_num])
+ substrs=['stopped',
+ 'd_init',
+ 'stop reason = breakpoint %d' % d_init_bp_num])
self.runCmd("continue")
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
- substrs = ['stopped',
- 'a_init',
- 'stop reason = breakpoint %d' % a_init_bp_num])
+ substrs=['stopped',
+ 'a_init',
+ 'stop reason = breakpoint %d' % a_init_bp_num])
self.expect("thread backtrace",
- substrs = ['a_init',
- 'dlopen',
- 'main'])
+ substrs=['a_init',
+ 'dlopen',
+ 'main'])
self.runCmd("continue")
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
- substrs = ['stopped',
- 'b_init',
- 'stop reason = breakpoint %d' % b_init_bp_num])
+ substrs=['stopped',
+ 'b_init',
+ 'stop reason = breakpoint %d' % b_init_bp_num])
self.expect("thread backtrace",
- substrs = ['b_init',
- 'dlopen',
- 'main'])
+ substrs=['b_init',
+ 'dlopen',
+ 'main'])