aboutsummaryrefslogtreecommitdiff
path: root/test/lang/c
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2013-01-18 21:20:51 +0000
committerSean Callanan <scallanan@apple.com>2013-01-18 21:20:51 +0000
commitc6bdc75b993e8e16c0c035e3c6a59891568f03a4 (patch)
tree099d5a7400b0d11165efe7e95b0cde34ab1e8752 /test/lang/c
parentcec32bbcad3e99d7f797072e5e160453e29890ac (diff)
downloadlldb-c6bdc75b993e8e16c0c035e3c6a59891568f03a4.tar.gz
Made the expression handle variables with
DW_AT_const_value instead of a location. Also added a testcase covering "frame variable," "expr" using the IR interpreter, and "expr" using the LLVM JIT. <rdar://problem/12978195> git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@172848 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/lang/c')
-rw-r--r--test/lang/c/const_variables/Makefile7
-rw-r--r--test/lang/c/const_variables/TestConstVariables.py66
-rw-r--r--test/lang/c/const_variables/functions.c18
-rw-r--r--test/lang/c/const_variables/main.c19
4 files changed, 110 insertions, 0 deletions
diff --git a/test/lang/c/const_variables/Makefile b/test/lang/c/const_variables/Makefile
new file mode 100644
index 000000000..923a0d6ea
--- /dev/null
+++ b/test/lang/c/const_variables/Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c functions.c
+
+CFLAGS ?= -arch $(ARCH) -gdwarf-2 -O3
+
+include $(LEVEL)/Makefile.rules
diff --git a/test/lang/c/const_variables/TestConstVariables.py b/test/lang/c/const_variables/TestConstVariables.py
new file mode 100644
index 000000000..e3ea90c61
--- /dev/null
+++ b/test/lang/c/const_variables/TestConstVariables.py
@@ -0,0 +1,66 @@
+"""Check that compiler-generated constant values work correctly"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+import lldbutil
+
+class ConstVariableTestCase(TestBase):
+
+ mydir = os.path.join("lang", "c", "const_variables")
+
+ @dsym_test
+ def test_with_dsym_and_run_command(self):
+ """Test interpreted and JITted expressions on constant values."""
+ self.buildDsym()
+ self.const_variable()
+
+ @dwarf_test
+ def test_with_dwarf_and_run_command(self):
+ """Test interpreted and JITted expressions on constant values."""
+ self.buildDwarf()
+ self.const_variable()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+
+ def const_variable(self):
+ """Test interpreted and JITted expressions on constant values."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Break inside the main.
+ lldbutil.run_break_set_by_symbol (self, "main", num_expected_locations=1)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['stopped',
+ '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'])
+
+ # Try frame variable.
+ self.expect("frame variable index", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs = ['(int32_t) index = 512'])
+
+ # Try an interpreted expression.
+ self.expect("expr (index + 512)", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs = ['(int) $0 = 1024'])
+
+ # Try a JITted expression.
+ self.expect("expr (int)getpid(); (index - 256)", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs = ['(int) $1 = 256'])
+
+ self.runCmd("kill")
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/test/lang/c/const_variables/functions.c b/test/lang/c/const_variables/functions.c
new file mode 100644
index 000000000..c9ea63837
--- /dev/null
+++ b/test/lang/c/const_variables/functions.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+void foo()
+{
+ printf("foo()\n");
+}
+
+int bar()
+{
+ int ret = 3;
+ printf("bar()->%d\n", ret);
+ return ret;
+}
+
+void baaz(int i)
+{
+ printf("baaz(%d)\n", i);
+}
diff --git a/test/lang/c/const_variables/main.c b/test/lang/c/const_variables/main.c
new file mode 100644
index 000000000..086fa6f0f
--- /dev/null
+++ b/test/lang/c/const_variables/main.c
@@ -0,0 +1,19 @@
+#include <stdint.h>
+
+extern int foo();
+extern int bar();
+extern int baaz(int i);
+
+int main()
+{
+ int32_t index;
+
+ foo();
+
+ index = 512;
+
+ if (bar())
+ index = 256;
+
+ baaz(index);
+}