[Lldb-commits] [lldb] r136760 - in /lldb/trunk/test/functionalities/non-overlapping-index-variable-i: ./ Makefile TestIndexVariable.py main.cpp

Johnny Chen johnny.chen at apple.com
Tue Aug 2 18:34:29 PDT 2011


Author: johnny
Date: Tue Aug  2 20:34:29 2011
New Revision: 136760

URL: http://llvm.org/viewvc/llvm-project?rev=136760&view=rev
Log:
Add a test file to go with r136745.  It fails, though, for:

expr ptr[i]->point.x

Radar to be filed.

Added:
    lldb/trunk/test/functionalities/non-overlapping-index-variable-i/
    lldb/trunk/test/functionalities/non-overlapping-index-variable-i/Makefile
    lldb/trunk/test/functionalities/non-overlapping-index-variable-i/TestIndexVariable.py
    lldb/trunk/test/functionalities/non-overlapping-index-variable-i/main.cpp

Added: lldb/trunk/test/functionalities/non-overlapping-index-variable-i/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/non-overlapping-index-variable-i/Makefile?rev=136760&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/non-overlapping-index-variable-i/Makefile (added)
+++ lldb/trunk/test/functionalities/non-overlapping-index-variable-i/Makefile Tue Aug  2 20:34:29 2011
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/functionalities/non-overlapping-index-variable-i/TestIndexVariable.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/non-overlapping-index-variable-i/TestIndexVariable.py?rev=136760&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/non-overlapping-index-variable-i/TestIndexVariable.py (added)
+++ lldb/trunk/test/functionalities/non-overlapping-index-variable-i/TestIndexVariable.py Tue Aug  2 20:34:29 2011
@@ -0,0 +1,52 @@
+"""Test evaluating expressions which ref. index variable 'i' which just goes
+from out of scope to in scope when stopped at the breakpoint."""
+
+import unittest2
+import lldb
+from lldbtest import *
+
+class NonOverlappingIndexVariableCase(TestBase):
+
+    mydir = os.path.join("functionalities", "non-overlapping-index-variable-i")
+
+    def setUp(self):
+        TestBase.setUp(self)
+        self.source = 'main.cpp'
+        self.line_to_break = line_number(self.source, '// Set breakpoint here.')
+        self.lldb_avg = None
+        self.gdb_avg = None
+
+    def test_eval_index_variable(self):
+        """Test expressions of variable 'i' which appears in two for loops."""
+        self.buildDefault()
+        self.exe_name = 'a.out'
+        self.eval_index_variable_i(self.exe_name)
+
+    def eval_index_variable_i(self, exe_name):
+        """Test expressions of variable 'i' which appears in two for loops."""
+        self.runCmd("file %s" % exe_name, CURRENT_EXECUTABLE_SET)
+
+        self.expect('breakpoint set -f %s -l %d' % (self.source, self.line_to_break),
+                    BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
+                        (self.source, self.line_to_break))
+
+        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'])
+
+        self.runCmd('frame variable i')
+        self.runCmd('expr i')
+        self.runCmd('expr ptr[0]->point.x')
+        self.runCmd('expr ptr[0]->point.y')
+        self.runCmd('expr ptr[i]->point.x')
+        self.runCmd('expr ptr[i]->point.y')
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/functionalities/non-overlapping-index-variable-i/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/non-overlapping-index-variable-i/main.cpp?rev=136760&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/non-overlapping-index-variable-i/main.cpp (added)
+++ lldb/trunk/test/functionalities/non-overlapping-index-variable-i/main.cpp Tue Aug  2 20:34:29 2011
@@ -0,0 +1,43 @@
+#include <stdio.h>
+
+class Point {
+public:
+    int x;
+    int y;
+    Point(int a, int b):
+        x(a),
+        y(b)
+    {}
+};
+
+class Data {
+public:
+    int id;
+    Point point;
+    Data(int i):
+        id(i),
+        point(0, 0)
+    {}
+};
+
+int main(int argc, char const *argv[]) {
+    Data *data[1000];
+    Data **ptr = data;
+    for (int i = 0; i < 1000; ++i) {
+        ptr[i] = new Data(i);
+        ptr[i]->point.x = i;
+        ptr[i]->point.y = i+1;
+    }
+
+    printf("Finished populating data.\n");
+    for (int i = 0; i < 1000; ++i) {
+        bool dump = argc > 1; // Set breakpoint here.
+                              // Evaluate a couple of expressions (2*1000 = 2000 exprs):
+                              // expr ptr[i]->point.x
+                              // expr ptr[i]->point.y
+        if (dump) {
+            printf("data[%d] = %d (%d, %d)\n", i, ptr[i]->id, ptr[i]->point.x, ptr[i]->point.y);
+        }
+    }
+    return 0;
+}





More information about the lldb-commits mailing list