[Lldb-commits] [lldb] r137500 - in /lldb/trunk/test: functionalities/inferior-changed/ functionalities/inferior-changed/Makefile functionalities/inferior-changed/TestInferiorChanged.py functionalities/inferior-changed/main.c functionalities/inferior-changed/main2.c lldbtest.py

Johnny Chen johnny.chen at apple.com
Fri Aug 12 13:19:22 PDT 2011


Author: johnny
Date: Fri Aug 12 15:19:22 2011
New Revision: 137500

URL: http://llvm.org/viewvc/llvm-project?rev=137500&view=rev
Log:
Add TestInferiorChanged.py to test that lldb reloads the inferior after it was changed during the debug session.
First, main.c causes a crash, the inferior then gets re-built with main2.c which is not crashing.

Add Base.cleanup(self, dictionary=None) for platform specfic way to do cleanup after build.
This plugin method is used by the above test case to cleanup the main.c build before rebuild for main2.c.

Added:
    lldb/trunk/test/functionalities/inferior-changed/
    lldb/trunk/test/functionalities/inferior-changed/Makefile
    lldb/trunk/test/functionalities/inferior-changed/TestInferiorChanged.py
    lldb/trunk/test/functionalities/inferior-changed/main.c
    lldb/trunk/test/functionalities/inferior-changed/main2.c
Modified:
    lldb/trunk/test/lldbtest.py

Added: lldb/trunk/test/functionalities/inferior-changed/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/inferior-changed/Makefile?rev=137500&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/inferior-changed/Makefile (added)
+++ lldb/trunk/test/functionalities/inferior-changed/Makefile Fri Aug 12 15:19:22 2011
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/functionalities/inferior-changed/TestInferiorChanged.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/inferior-changed/TestInferiorChanged.py?rev=137500&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/inferior-changed/TestInferiorChanged.py (added)
+++ lldb/trunk/test/functionalities/inferior-changed/TestInferiorChanged.py Fri Aug 12 15:19:22 2011
@@ -0,0 +1,90 @@
+"""Test lldb reloads the inferior after it was changed during the session."""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class ChangedInferiorTestCase(TestBase):
+
+    mydir = os.path.join("functionalities", "inferior-changed")
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_inferior_crashing_dsym(self):
+        """Test lldb reloads the inferior after it was changed during the session."""
+        self.buildDsym()
+        self.inferior_crashing()
+        self.cleanup()
+        d = {'C_SOURCES': 'main2.c'}
+        self.buildDsym(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        self.inferior_not_crashing()
+
+    def test_inferior_crashing_dwarf(self):
+        """Test lldb reloads the inferior after it was changed during the session."""
+        self.buildDwarf()
+        self.inferior_crashing()
+        self.cleanup()
+        d = {'C_SOURCES': 'main2.c'}
+        self.buildDwarf(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        self.inferior_not_crashing()
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find the line number of the crash.
+        self.line1 = line_number('main.c', '// Crash here.')
+        self.line2 = line_number('main2.c', '// Not crash here.')
+
+    def inferior_crashing(self):
+        """Inferior crashes upon launching; lldb should catch the event and stop."""
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # The stop reason of the thread should be a bad access exception.
+        self.expect("thread list", STOPPED_DUE_TO_EXC_BAD_ACCESS,
+            substrs = ['stopped',
+                       'stop reason = EXC_BAD_ACCESS'])
+
+        # And it should report the correct line number.
+        self.expect("thread backtrace all",
+            substrs = ['stop reason = EXC_BAD_ACCESS',
+                       'main.c:%d' % self.line1])
+
+    def inferior_not_crashing(self):
+        """Test lldb reloads the inferior after it was changed during the session."""
+        self.runCmd("process kill")
+        self.runCmd("run", RUN_SUCCEEDED)
+        self.runCmd("process status")
+
+        if 'EXC_BAD_ACCESS' in self.res.GetOutput():
+            self.fail("Inferior changed, but lldb did not perform a reload")
+
+        # Break inside the main.
+        self.expect("breakpoint set -f main2.c -l %d" % self.line2,
+                    BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='main2.c', line = %d, locations = 1" %
+                        self.line2)
+
+        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 int_ptr")
+        self.expect("frame variable *int_ptr",
+            substrs = ['= 7'])
+        self.expect("expression *int_ptr",
+            substrs = ['= 7'])
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/functionalities/inferior-changed/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/inferior-changed/main.c?rev=137500&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/inferior-changed/main.c (added)
+++ lldb/trunk/test/functionalities/inferior-changed/main.c Fri Aug 12 15:19:22 2011
@@ -0,0 +1,16 @@
+//===-- 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 <stdio.h>
+
+int main(int argc, const char* argv[])
+{
+    int *null_ptr = 0;
+    printf("Hello, segfault!\n");
+    printf("Now crash %d\n", *null_ptr); // Crash here.
+}

Added: lldb/trunk/test/functionalities/inferior-changed/main2.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/inferior-changed/main2.c?rev=137500&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/inferior-changed/main2.c (added)
+++ lldb/trunk/test/functionalities/inferior-changed/main2.c Fri Aug 12 15:19:22 2011
@@ -0,0 +1,18 @@
+//===-- main2.c -------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, const char* argv[])
+{
+    int *int_ptr = (int *)malloc(sizeof(int));
+    *int_ptr = 7;
+    printf("Hello, world!\n");
+    printf("Now not crash %d\n", *int_ptr); // Not crash here.
+}

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=137500&r1=137499&r2=137500&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Fri Aug 12 15:19:22 2011
@@ -770,6 +770,12 @@
         if not module.buildDwarf(self, architecture, compiler, dictionary):
             raise Exception("Don't know how to build binary with dwarf")
 
+    def cleanup(self, dictionary=None):
+        """Platform specific way to do cleanup after build."""
+        module = builder_module()
+        if not module.cleanup(self, dictionary):
+            raise Exception("Don't know how to do cleanup")
+
 
 class TestBase(Base):
     """





More information about the lldb-commits mailing list