[Lldb-commits] [lldb] r129717 - in /lldb/trunk: source/Commands/CommandObjectTarget.cpp test/lldbtest.py test/make/Makefile.rules test/target/ test/target/Makefile test/target/TestTargetCommand.py test/target/a.c test/target/b.c test/target/c.c
Johnny Chen
johnny.chen at apple.com
Mon Apr 18 14:08:05 PDT 2011
Author: johnny
Date: Mon Apr 18 16:08:05 2011
New Revision: 129717
URL: http://llvm.org/viewvc/llvm-project?rev=129717&view=rev
Log:
Add a test script for exercising the "taregt create", "target list", and "target select" commands.
Added:
lldb/trunk/test/target/
lldb/trunk/test/target/Makefile
lldb/trunk/test/target/TestTargetCommand.py
lldb/trunk/test/target/a.c
lldb/trunk/test/target/b.c
lldb/trunk/test/target/c.c
Modified:
lldb/trunk/source/Commands/CommandObjectTarget.cpp
lldb/trunk/test/lldbtest.py
lldb/trunk/test/make/Makefile.rules
Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=129717&r1=129716&r2=129717&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Mon Apr 18 16:08:05 2011
@@ -300,6 +300,7 @@
{
strm.PutCString ("No targets.\n");
}
+ result.SetStatus (eReturnStatusSuccessFinishResult);
}
else
{
@@ -355,6 +356,7 @@
target_list.SetSelectedTarget (target_sp.get());
bool show_stopped_process_status = false;
DumpTargetList (target_list, show_stopped_process_status, strm);
+ result.SetStatus (eReturnStatusSuccessFinishResult);
}
else
{
Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=129717&r1=129716&r2=129717&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Mon Apr 18 16:08:05 2011
@@ -546,6 +546,9 @@
# These are for customized teardown cleanup.
self.dict = None
self.doTearDownCleanup = False
+ # And in rare cases where there are multiple teardown cleanups.
+ self.dicts = []
+ self.doTearDownCleanups = False
# Create a string buffer to record the session info, to be dumped into a
# test case specific file if test failure is encountered.
@@ -644,6 +647,11 @@
self.dict = dictionary
self.doTearDownCleanup = True
+ def addTearDownCleanup(self, dictionary):
+ """Add a cleanup action at tearDown() time with a dictinary"""
+ self.dicts.append(dictionary)
+ self.doTearDownCleanups = True
+
def addTearDownHook(self, hook):
"""
Add a function to be run during tearDown() time.
@@ -686,7 +694,15 @@
if doCleanup and self.doTearDownCleanup:
module = __import__(sys.platform)
if not module.cleanup(self, dictionary=self.dict):
- raise Exception("Don't know how to do cleanup")
+ raise Exception("Don't know how to do cleanup with dictionary: " + self.dict)
+
+ # In rare cases where there are multiple teardown cleanups added.
+ if doCleanup and self.doTearDownCleanups:
+ module = __import__(sys.platform)
+ if self.dicts:
+ for dict in reversed(self.dicts):
+ if not module.cleanup(self, dictionary=dict):
+ raise Exception("Don't know how to do cleanup with dictionary: " + dict)
# Decide whether to dump the session info.
self.dumpSessionInfo()
Modified: lldb/trunk/test/make/Makefile.rules
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/make/Makefile.rules?rev=129717&r1=129716&r2=129717&view=diff
==============================================================================
--- lldb/trunk/test/make/Makefile.rules (original)
+++ lldb/trunk/test/make/Makefile.rules Mon Apr 18 16:08:05 2011
@@ -38,7 +38,7 @@
LD = $(CC)
LDFLAGS ?= $(CFLAGS)
OBJECTS =
-EXE = a.out
+EXE ?= a.out
DSYM = $(EXE).dSYM
# Function that returns the counterpart C++ compiler, given $(CC) as arg.
Added: lldb/trunk/test/target/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/target/Makefile?rev=129717&view=auto
==============================================================================
--- lldb/trunk/test/target/Makefile (added)
+++ lldb/trunk/test/target/Makefile Mon Apr 18 16:08:05 2011
@@ -0,0 +1,8 @@
+LEVEL = ../make
+
+# Example:
+#
+# C_SOURCES := b.c
+# EXE := b.out
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/target/TestTargetCommand.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/target/TestTargetCommand.py?rev=129717&view=auto
==============================================================================
--- lldb/trunk/test/target/TestTargetCommand.py (added)
+++ lldb/trunk/test/target/TestTargetCommand.py Mon Apr 18 16:08:05 2011
@@ -0,0 +1,95 @@
+"""
+Test some target commands: create, list, select.
+"""
+
+import unittest2
+import lldb
+import sys
+from lldbtest import *
+
+class targetCommandTestCase(TestBase):
+
+ mydir = "target"
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line numbers for our breakpoints.
+ self.line_b = line_number('b.c', '// Set break point at this line.')
+ self.line_c = line_number('c.c', '// Set break point at this line.')
+
+ def test_target_command_with_dwarf(self):
+ """Test some target commands: create, list, select."""
+ da = {'C_SOURCES': 'a.c', 'EXE': 'a.out'}
+ self.buildDefault(dictionary=da)
+ self.addTearDownCleanup(dictionary=da)
+
+ db = {'C_SOURCES': 'b.c', 'EXE': 'b.out'}
+ self.buildDefault(dictionary=db)
+ self.addTearDownCleanup(dictionary=db)
+
+ dc = {'C_SOURCES': 'c.c', 'EXE': 'c.out'}
+ self.buildDefault(dictionary=dc)
+ self.addTearDownCleanup(dictionary=dc)
+
+ self.do_target_command()
+
+ def do_target_command(self):
+ """Exercise 'target create', 'target list', 'target select' commands."""
+ exe_a = os.path.join(os.getcwd(), "a.out")
+ exe_b = os.path.join(os.getcwd(), "b.out")
+ exe_c = os.path.join(os.getcwd(), "c.out")
+
+ self.runCmd("target list")
+ output = self.res.GetOutput()
+ if output.startswith("No targets"):
+ # We start from index 0.
+ base = 0
+ else:
+ # Find the largest index of the existing list.
+ import re
+ pattern = re.compile("target #(\d+):")
+ for line in reversed(output.split(os.linesep)):
+ match = pattern.search(line)
+ if match:
+ # We will start from (index + 1) ....
+ base = int(match.group(1), 10) + 1
+ #print "base is:", base
+ break;
+
+ self.runCmd("target create " + exe_a, CURRENT_EXECUTABLE_SET)
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ self.runCmd("target create " + exe_b, CURRENT_EXECUTABLE_SET)
+ self.runCmd("breakpoint set -f %s -l %d" % ('b.c', self.line_b),
+ BREAKPOINT_CREATED)
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ self.runCmd("target create " + exe_c, CURRENT_EXECUTABLE_SET)
+ self.runCmd("breakpoint set -f %s -l %d" % ('c.c', self.line_c),
+ BREAKPOINT_CREATED)
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ self.runCmd("target list")
+
+ self.runCmd("target select %d" % base)
+ self.runCmd("thread backtrace")
+
+ self.runCmd("target select %d" % (base + 2))
+ self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['c.c:%d' % self.line_c,
+ 'stop reason = breakpoint'])
+
+ self.runCmd("target select %d" % (base + 1))
+ self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['b.c:%d' % self.line_b,
+ 'stop reason = breakpoint'])
+
+ self.runCmd("target list")
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
Added: lldb/trunk/test/target/a.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/target/a.c?rev=129717&view=auto
==============================================================================
--- lldb/trunk/test/target/a.c (added)
+++ lldb/trunk/test/target/a.c Mon Apr 18 16:08:05 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/target/b.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/target/b.c?rev=129717&view=auto
==============================================================================
--- lldb/trunk/test/target/b.c (added)
+++ lldb/trunk/test/target/b.c Mon Apr 18 16:08:05 2011
@@ -0,0 +1,13 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main (int argc, char const *argv[])
+{
+ return 0; // Set break point at this line.
+}
Added: lldb/trunk/test/target/c.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/target/c.c?rev=129717&view=auto
==============================================================================
--- lldb/trunk/test/target/c.c (added)
+++ lldb/trunk/test/target/c.c Mon Apr 18 16:08:05 2011
@@ -0,0 +1,29 @@
+//===-- 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, char const *argv[])
+{
+ enum days {
+ Monday = 10,
+ Tuesday,
+ Wednesday,
+ Thursday,
+ Friday,
+ Saturday,
+ Sunday,
+ kNumDays
+ };
+ enum days day;
+ for (day = Monday - 1; day <= kNumDays + 1; day++)
+ {
+ printf("day as int is %i\n", (int)day);
+ }
+ return 0; // Set break point at this line.
+}
More information about the lldb-commits
mailing list