[Lldb-commits] [lldb] r182115 - Adds a test case for bugzilla #15671 patterned after TestInferiorCrashing.py.
Ashok Thirumurthi
ashok.thirumurthi at intel.com
Fri May 17 08:35:15 PDT 2013
Author: athirumu
Date: Fri May 17 10:35:15 2013
New Revision: 182115
URL: http://llvm.org/viewvc/llvm-project?rev=182115&view=rev
Log:
Adds a test case for bugzilla #15671 patterned after TestInferiorCrashing.py.
- On Linux, the partial back-trace after an assert can cause the basic test to fail as discussed on lldb-dev.
- Uses SBFrame to walk up the stack to the assert site and tests expression evaluation of locals, globals and arguments.
Thanks to Daniel for review and testing on OS/X.
Added:
lldb/trunk/test/functionalities/inferior-assert/
lldb/trunk/test/functionalities/inferior-assert/Makefile
lldb/trunk/test/functionalities/inferior-assert/TestInferiorAssert.py
lldb/trunk/test/functionalities/inferior-assert/main.c
Modified:
lldb/trunk/test/lldbtest.py
Added: lldb/trunk/test/functionalities/inferior-assert/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/inferior-assert/Makefile?rev=182115&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/inferior-assert/Makefile (added)
+++ lldb/trunk/test/functionalities/inferior-assert/Makefile Fri May 17 10:35:15 2013
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/functionalities/inferior-assert/TestInferiorAssert.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/inferior-assert/TestInferiorAssert.py?rev=182115&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/inferior-assert/TestInferiorAssert.py (added)
+++ lldb/trunk/test/functionalities/inferior-assert/TestInferiorAssert.py Fri May 17 10:35:15 2013
@@ -0,0 +1,218 @@
+"""Test that lldb functions correctly after the inferior has asserted."""
+
+import os, time
+import unittest2
+import lldb, lldbutil
+from lldbtest import *
+
+class AssertingInferiorTestCase(TestBase):
+
+ mydir = os.path.join("functionalities", "inferior-assert")
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_inferior_asserting_dsym(self):
+ """Test that lldb reliably catches the inferior asserting (command)."""
+ self.buildDsym()
+ self.inferior_asserting()
+
+ @expectedFailureLinux # bugzilla 15671 - backtrace does not include the assert site
+ def test_inferior_asserting_dwarf(self):
+ """Test that lldb reliably catches the inferior asserting (command)."""
+ self.buildDwarf()
+ self.inferior_asserting()
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_inferior_asserting_registers_dsym(self):
+ """Test that lldb reliably reads registers from the inferior after asserting (command)."""
+ self.buildDsym()
+ self.inferior_asserting_registers()
+
+ def test_inferior_asserting_register_dwarf(self):
+ """Test that lldb reliably reads registers from the inferior after asserting (command)."""
+ self.buildDwarf()
+ self.inferior_asserting_registers()
+
+ @python_api_test
+ def test_inferior_asserting_python(self):
+ """Test that lldb reliably catches the inferior asserting (Python API)."""
+ self.buildDefault()
+ self.inferior_asserting_python()
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_inferior_asserting_expr(self):
+ """Test that the lldb expression interpreter can read from the inferior after asserting (command)."""
+ self.buildDsym()
+ self.inferior_asserting_expr()
+
+ @expectedFailureLinux # bugzilla 15671 - backtrace does not include the assert site
+ def test_inferior_asserting_expr(self):
+ """Test that the lldb expression interpreter can read from the inferior after asserting (command)."""
+ self.buildDwarf()
+ self.inferior_asserting_expr()
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_inferior_asserting_step(self):
+ """Test that lldb functions correctly after stepping through a call to assert()."""
+ self.buildDsym()
+ self.inferior_asserting_step()
+
+ @expectedFailureLinux # bugzilla 15671 - backtrace does not include the assert site
+ def test_inferior_asserting_step(self):
+ """Test that lldb functions correctly after stepping through a call to assert()."""
+ self.buildDwarf()
+ self.inferior_asserting_step()
+
+ def set_breakpoint(self, line):
+ lldbutil.run_break_set_by_file_and_line (self, "main.c", line, num_expected_locations=1, loc_exact=True)
+
+ def check_stop_reason(self):
+ stop_reason = 'stop reason = signal SIGABRT'
+
+ # The stop reason of the thread should be an abort signal or exception.
+ self.expect("thread list", STOPPED_DUE_TO_ASSERT,
+ substrs = ['stopped',
+ stop_reason])
+
+ return stop_reason
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number of the call to assert.
+ self.line = line_number('main.c', '// Assert here.')
+
+ def inferior_asserting(self):
+ """Inferior asserts 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)
+ stop_reason = self.check_stop_reason()
+
+ # And it should report a backtrace that includes the assert site.
+ self.expect("thread backtrace all",
+ substrs = [stop_reason, 'main', 'argc', 'argv'])
+
+ # And it should report the correct line number.
+ self.expect("thread backtrace all",
+ substrs = [stop_reason,
+ 'main.c:%d' % self.line])
+
+ def inferior_asserting_python(self):
+ """Inferior asserts 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, VALID_TARGET)
+
+ # Now launch the process, and do not stop at entry point.
+ # Both argv and envp are null.
+ process = target.LaunchSimple(None, None, os.getcwd())
+
+ if process.GetState() != lldb.eStateStopped:
+ self.fail("Process should be in the 'stopped' state, "
+ "instead the actual state is: '%s'" %
+ lldbutil.state_type_to_str(process.GetState()))
+
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal)
+ if not thread:
+ self.fail("Fail to stop the thread upon assert")
+
+ if self.TraceOn():
+ lldbutil.print_stacktrace(thread)
+
+ def inferior_asserting_registers(self):
+ """Test that lldb can read registers after asserting."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+ self.check_stop_reason()
+
+ # lldb should be able to read from registers from the inferior after asserting.
+ self.expect("register read eax",
+ substrs = ['eax = 0x'])
+
+ def check_expr_in_main(self, thread):
+ depth = thread.GetNumFrames()
+ for i in range(depth):
+ frame = thread.GetFrameAtIndex(i)
+ self.assertTrue(frame.IsValid(), "current frame is valid")
+ if self.TraceOn():
+ print "Checking if function %s is main" % frame.GetFunctionName()
+
+ if 'main' == frame.GetFunctionName():
+ frame_id = frame.GetFrameID()
+ self.runCmd("frame select " + str(frame_id), RUN_SUCCEEDED)
+ self.expect("p argc", substrs = ['(int)', ' = 1'])
+ self.expect("p hello_world", substrs = ['Hello'])
+ self.expect("p argv[0]", substrs = ['a.out'])
+ self.expect("p null_ptr", substrs = ['= 0x0'])
+ return True
+ return False
+
+ def inferior_asserting_expr(self):
+ """Test that the lldb expression interpreter can read symbols after asserting."""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Launch the process, and do not stop at the entry point.
+ target.LaunchSimple(None, None, os.getcwd())
+ self.check_stop_reason()
+
+ process = target.GetProcess()
+ self.assertTrue(process.IsValid(), "current process is valid")
+
+ thread = process.GetThreadAtIndex(0)
+ self.assertTrue(thread.IsValid(), "current thread is valid")
+
+ # The lldb expression interpreter should be able to read from addresses of the inferior after a call to assert().
+ self.assertTrue(self.check_expr_in_main(thread), "cannot find 'main' in the backtrace")
+
+ def inferior_asserting_step(self):
+ """Test that lldb functions correctly after stepping through a call to assert()."""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Launch the process, and do not stop at the entry point.
+ self.set_breakpoint(self.line)
+ target.LaunchSimple(None, None, os.getcwd())
+
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['main.c:%d' % self.line,
+ 'stop reason = breakpoint'])
+
+ self.runCmd("next")
+ stop_reason = self.check_stop_reason()
+
+ # lldb should be able to read from registers from the inferior after asserting.
+ if "x86_64" in self.getArchitecture():
+ self.expect("register read rbp", substrs = ['rbp = 0x'])
+ if "i386" in self.getArchitecture():
+ self.expect("register read ebp", substrs = ['ebp = 0x'])
+
+ process = target.GetProcess()
+ self.assertTrue(process.IsValid(), "current process is valid")
+
+ thread = process.GetThreadAtIndex(0)
+ self.assertTrue(thread.IsValid(), "current thread is valid")
+
+ # The lldb expression interpreter should be able to read from addresses of the inferior after a call to assert().
+ self.assertTrue(self.check_expr_in_main(thread), "cannot find 'main' in the backtrace")
+
+ # And it should report the correct line number.
+ self.expect("thread backtrace all",
+ substrs = [stop_reason,
+ 'main.c:%d' % self.line])
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
Added: lldb/trunk/test/functionalities/inferior-assert/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/inferior-assert/main.c?rev=182115&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/inferior-assert/main.c (added)
+++ lldb/trunk/test/functionalities/inferior-assert/main.c Fri May 17 10:35:15 2013
@@ -0,0 +1,19 @@
+//===-- 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>
+#include <assert.h>
+
+const char *hello_world = "Hello, assertion!";
+
+int main(int argc, const char* argv[])
+{
+ int *null_ptr = 0;
+ printf("%s\n", hello_world);
+ assert(null_ptr); // Assert here.
+}
Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=182115&r1=182114&r2=182115&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Fri May 17 10:35:15 2013
@@ -101,6 +101,8 @@ STEP_OUT_SUCCEEDED = "Thread step-out su
STOPPED_DUE_TO_EXC_BAD_ACCESS = "Process should be stopped due to bad access exception"
+STOPPED_DUE_TO_ASSERT = "Process should be stopped due to an assertion"
+
STOPPED_DUE_TO_BREAKPOINT = "Process should be stopped due to breakpoint"
STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS = "%s, %s" % (
More information about the lldb-commits
mailing list