[Lldb-commits] [lldb] r129542 - in /lldb/trunk/test/inferior-crashing: ./ Makefile TestInferiorCrashing.py main.c
Johnny Chen
johnny.chen at apple.com
Thu Apr 14 15:20:37 PDT 2011
Author: johnny
Date: Thu Apr 14 17:20:36 2011
New Revision: 129542
URL: http://llvm.org/viewvc/llvm-project?rev=129542&view=rev
Log:
Add a test to check that lldb reliably catches a crashing inferior (both command and Python API).
Added:
lldb/trunk/test/inferior-crashing/
lldb/trunk/test/inferior-crashing/Makefile
lldb/trunk/test/inferior-crashing/TestInferiorCrashing.py
lldb/trunk/test/inferior-crashing/main.c
Added: lldb/trunk/test/inferior-crashing/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/inferior-crashing/Makefile?rev=129542&view=auto
==============================================================================
--- lldb/trunk/test/inferior-crashing/Makefile (added)
+++ lldb/trunk/test/inferior-crashing/Makefile Thu Apr 14 17:20:36 2011
@@ -0,0 +1,5 @@
+LEVEL = ../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/inferior-crashing/TestInferiorCrashing.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/inferior-crashing/TestInferiorCrashing.py?rev=129542&view=auto
==============================================================================
--- lldb/trunk/test/inferior-crashing/TestInferiorCrashing.py (added)
+++ lldb/trunk/test/inferior-crashing/TestInferiorCrashing.py Thu Apr 14 17:20:36 2011
@@ -0,0 +1,79 @@
+"""Test that lldb reliably catches the inferior crashing."""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class CrashingInferiorTestCase(TestBase):
+
+ mydir = "inferior-crashing"
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_inferior_crashing_dsym(self):
+ """Test that lldb reliably catches the inferior crashing (command)."""
+ self.buildDsym()
+ self.inferior_crashing()
+
+ def test_inferior_crashing_dwarf(self):
+ """Test that lldb reliably catches the inferior crashing (command)."""
+ self.buildDwarf()
+ self.inferior_crashing()
+
+ @python_api_test
+ def test_inferior_crashing_python(self):
+ """Test that lldb reliably catches the inferior crashing (Python API)."""
+ self.buildDefault()
+ self.inferior_crashing_python()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number of the crash.
+ self.line = line_number('main.c', '// 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 = ['state is stopped',
+ 'stop reason = EXC_BAD_ACCESS'])
+
+ # And it should report the correct line number.
+ self.expect("thread backtrace",
+ substrs = ['stop reason = EXC_BAD_ACCESS',
+ 'main.c:%d' % self.line])
+
+ def inferior_crashing_python(self):
+ """Inferior crashes upon launching; lldb should catch the event and stop."""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target.IsValid(), VALID_TARGET)
+
+ # Now launch the process, and do not stop at entry point.
+ # Both argv and envp are null.
+ self.process = target.LaunchSimple(None, None, os.getcwd())
+
+ import lldbutil
+ if self.process.GetState() != lldb.eStateStopped:
+ self.fail("Process should be in the 'stopped' state, "
+ "instead the actual state is: '%s'" %
+ lldbutil.StateTypeString(self.process.GetState()))
+
+ thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonException)
+ if not thread:
+ self.fail("Fail to stop the thread due to exception")
+
+ lldbutil.PrintStackTrace(thread)
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
Added: lldb/trunk/test/inferior-crashing/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/inferior-crashing/main.c?rev=129542&view=auto
==============================================================================
--- lldb/trunk/test/inferior-crashing/main.c (added)
+++ lldb/trunk/test/inferior-crashing/main.c Thu Apr 14 17:20:36 2011
@@ -0,0 +1,8 @@
+#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.
+}
More information about the lldb-commits
mailing list