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.

llvm-svn: 137500
This commit is contained in:
Johnny Chen 2011-08-12 20:19:22 +00:00
parent 60138eaf93
commit 9f4f5d94cd
5 changed files with 135 additions and 0 deletions

View File

@ -0,0 +1,5 @@
LEVEL = ../../make
C_SOURCES := main.c
include $(LEVEL)/Makefile.rules

View File

@ -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()

View File

@ -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.
}

View File

@ -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.
}

View File

@ -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):
"""