diff options
| -rw-r--r-- | lldb/test/functionalities/inferior-changed/Makefile | 5 | ||||
| -rw-r--r-- | lldb/test/functionalities/inferior-changed/TestInferiorChanged.py | 90 | ||||
| -rw-r--r-- | lldb/test/functionalities/inferior-changed/main.c | 16 | ||||
| -rw-r--r-- | lldb/test/functionalities/inferior-changed/main2.c | 18 | ||||
| -rw-r--r-- | lldb/test/lldbtest.py | 6 |
5 files changed, 135 insertions, 0 deletions
diff --git a/lldb/test/functionalities/inferior-changed/Makefile b/lldb/test/functionalities/inferior-changed/Makefile new file mode 100644 index 00000000000..0d70f259501 --- /dev/null +++ b/lldb/test/functionalities/inferior-changed/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/functionalities/inferior-changed/TestInferiorChanged.py b/lldb/test/functionalities/inferior-changed/TestInferiorChanged.py new file mode 100644 index 00000000000..40fb54dc287 --- /dev/null +++ b/lldb/test/functionalities/inferior-changed/TestInferiorChanged.py @@ -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() diff --git a/lldb/test/functionalities/inferior-changed/main.c b/lldb/test/functionalities/inferior-changed/main.c new file mode 100644 index 00000000000..9d0706a0862 --- /dev/null +++ b/lldb/test/functionalities/inferior-changed/main.c @@ -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. +} diff --git a/lldb/test/functionalities/inferior-changed/main2.c b/lldb/test/functionalities/inferior-changed/main2.c new file mode 100644 index 00000000000..9173e8c30b5 --- /dev/null +++ b/lldb/test/functionalities/inferior-changed/main2.c @@ -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. +} diff --git a/lldb/test/lldbtest.py b/lldb/test/lldbtest.py index 1ce5b900d5a..5d48cfea86f 100644 --- a/lldb/test/lldbtest.py +++ b/lldb/test/lldbtest.py @@ -770,6 +770,12 @@ class Base(unittest2.TestCase): 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): """ |

