summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/expression_command
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2019-06-28 21:40:05 +0000
committerJim Ingham <jingham@apple.com>2019-06-28 21:40:05 +0000
commitf2128b28cdb73d0ccfa2cbf508e8f9d8dc9f8eb5 (patch)
treed8bfb2647511301e8808c210b0952323cc6a22de /lldb/packages/Python/lldbsuite/test/expression_command
parentb671535983fa9ceff10501bc22267e3e6c6c549e (diff)
downloadbcm5719-llvm-f2128b28cdb73d0ccfa2cbf508e8f9d8dc9f8eb5.tar.gz
bcm5719-llvm-f2128b28cdb73d0ccfa2cbf508e8f9d8dc9f8eb5.zip
Get the expression parser to handle missing weak symbols.
MachO only for this patch. Differential Revision: https://reviews.llvm.org/D63914 <rdar://problem/51463642> llvm-svn: 364686
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/expression_command')
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/Makefile26
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/TestWeakSymbols.py83
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.c14
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.h8
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/main.c23
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/module.modulemap3
6 files changed, 157 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/Makefile b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/Makefile
new file mode 100644
index 00000000000..7c70b509fe7
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/Makefile
@@ -0,0 +1,26 @@
+LEVEL = ../../make
+CFLAGS_EXTRAS += -std=c99
+LD_FLAGS := -dynamiclib
+include $(LEVEL)/Makefile.rules
+
+all: a.out dylib missing
+
+dylib: dylib.o
+ $(CC) $(LD_FLAGS) -o libdylib.dylib dylib.o
+
+missing: dylib2.o
+ mkdir hidden
+ $(CC) $(LD_FLAGS) -o hidden/libdylib.dylib dylib2.o
+
+a.out: main.o dylib missing
+ $(CC) $(CFLAGS) -L. -ldylib main.o
+
+dylib.o: dylib.h $(SRCDIR)/dylib.c
+ $(CC) -DHAS_THEM $(CFLAGS) -c $(SRCDIR)/dylib.c
+
+dylib2.o: dylib.h $(SRCDIR)/dylib.c
+ $(CC) $(CFLAGS) -c $(SRCDIR)/dylib.c -o dylib2.o
+
+main.o: dylib.h $(SRCDIR)/main.c
+ $(CC) $(CFLAGS) -c $(SRCDIR)/main.c -fmodules
+
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/TestWeakSymbols.py b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/TestWeakSymbols.py
new file mode 100644
index 00000000000..a5d7a4b7e6a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/TestWeakSymbols.py
@@ -0,0 +1,83 @@
+"""
+Test that we can compile expressions referring to
+absent weak symbols from a dylib.
+"""
+
+from __future__ import print_function
+
+
+import os
+import time
+import re
+import lldb
+from lldbsuite.test import decorators
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+class TestWeakSymbolsInExpressions(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ NO_DEBUG_INFO_TESTCASE = True
+
+ @decorators.skipUnlessDarwin
+ def test_weak_symbol_in_expr(self):
+ """Tests that we can refer to weak symbols in expressions."""
+ self.build()
+ self.main_source_file = lldb.SBFileSpec("main.c")
+ self.do_test()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+
+ def run_weak_var_check (self, weak_varname, present):
+ # The expression will modify present_weak_int to signify which branch
+ # was taken. Set it to so we don't get confused by a previous run.
+ value = self.target.FindFirstGlobalVariable("present_weak_int")
+ value.SetValueFromCString("0")
+ if present:
+ correct_value = 10
+ else:
+ correct_value = 20
+
+ # Note, I'm adding the "; 10" at the end of the expression to work around
+ # the bug that expressions with no result currently return False for Success()...
+ expr = "if (&" + weak_varname + " != NULL) { present_weak_int = 10; } else { present_weak_int = 20;}; 10"
+ result = self.frame.EvaluateExpression(expr)
+ self.assertTrue(result.GetError().Success(), "absent_weak_int expr failed: %s"%(result.GetError().GetCString()))
+ self.assertEqual(value.GetValueAsSigned(), correct_value, "Didn't change present_weak_int correctly.")
+
+ def do_test(self):
+ hidden_dir = os.path.join(self.getBuildDir(), "hidden")
+
+ launch_info = lldb.SBLaunchInfo(None)
+ launch_info.SetWorkingDirectory(self.getBuildDir())
+ # We have to point to the hidden directory to pick up the
+ # version of the dylib without the weak symbols:
+ env_expr = self.platformContext.shlib_environment_var + "=" + hidden_dir
+ launch_info.SetEnvironmentEntries([env_expr], True)
+
+ (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
+ "Set a breakpoint here", self.main_source_file,
+ launch_info = launch_info)
+ # First we have to import the Dylib module so we get the type info
+ # for the weak symbol. We need to add the source dir to the module
+ # search paths, and then run @import to introduce it into the expression
+ # context:
+ self.dbg.HandleCommand("settings set target.clang-module-search-paths " + self.getSourceDir())
+
+ self.frame = thread.frames[0]
+ self.assertTrue(self.frame.IsValid(), "Got a good frame")
+ options = lldb.SBExpressionOptions()
+ options.SetLanguage(lldb.eLanguageTypeObjC)
+ result = self.frame.EvaluateExpression("@import Dylib", options)
+
+ # Now run an expression that references an absent weak symbol:
+ self.run_weak_var_check("absent_weak_int", False)
+ self.run_weak_var_check("absent_weak_function", False)
+
+ # Make sure we can do the same thing with present weak symbols
+ self.run_weak_var_check("present_weak_int", True)
+ self.run_weak_var_check("present_weak_function", True)
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.c b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.c
new file mode 100644
index 00000000000..dc513e5c5fb
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.c
@@ -0,0 +1,14 @@
+#include "dylib.h"
+
+int present_weak_int = 10;
+int present_weak_function()
+{
+ return present_weak_int;
+}
+
+#if defined HAS_THEM
+int absent_weak_int = 10;
+int absent_weak_function() {
+ return absent_weak_int;
+}
+#endif
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.h b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.h
new file mode 100644
index 00000000000..f668ec0a784
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.h
@@ -0,0 +1,8 @@
+extern int absent_weak_int __attribute__((weak_import));
+
+extern int present_weak_int __attribute__((weak_import));
+
+extern int absent_weak_function() __attribute__((weak_import));
+
+extern int present_weak_function() __attribute__((weak_import));
+
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/main.c b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/main.c
new file mode 100644
index 00000000000..5ea257bae5b
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/main.c
@@ -0,0 +1,23 @@
+#include "dylib.h"
+#include <stdio.h>
+
+int
+doSomething()
+{
+ // Set a breakpoint here.
+ if (&absent_weak_int != NULL)
+ printf("In absent_weak_int: %d\n", absent_weak_int);
+ if (absent_weak_function != NULL)
+ printf("In absent_weak_func: %p\n", absent_weak_function);
+ if (&present_weak_int != NULL)
+ printf("In present_weak_int: %d\n", present_weak_int);
+ if (present_weak_function != NULL)
+ printf("In present_weak_func: %p\n", present_weak_function);
+
+}
+
+int
+main()
+{
+ return doSomething();
+}
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/module.modulemap b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/module.modulemap
new file mode 100644
index 00000000000..6f7671400bc
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/module.modulemap
@@ -0,0 +1,3 @@
+module Dylib {
+ header "dylib.h"
+}
OpenPOWER on IntegriCloud