[Lldb-commits] [lldb] r133772 - in /lldb/trunk: source/Commands/CommandObjectType.cpp test/data-formatter/ test/data-formatter/Makefile test/data-formatter/TestDataFormatter.py test/data-formatter/main.cpp
Johnny Chen
johnny.chen at apple.com
Thu Jun 23 16:14:10 PDT 2011
Author: johnny
Date: Thu Jun 23 18:14:10 2011
New Revision: 133772
URL: http://llvm.org/viewvc/llvm-project?rev=133772&view=rev
Log:
Add an initial test file for the newly added data formatter command.
main.cpp is contributed from Enrico.
Modify CommandObjectType.cpp to set status on the CommandReturnObject when succeeded as well.
Added:
lldb/trunk/test/data-formatter/
lldb/trunk/test/data-formatter/Makefile
lldb/trunk/test/data-formatter/TestDataFormatter.py
lldb/trunk/test/data-formatter/main.cpp
Modified:
lldb/trunk/source/Commands/CommandObjectType.cpp
Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=133772&r1=133771&r2=133772&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Thu Jun 23 18:14:10 2011
@@ -156,7 +156,7 @@
Debugger::AddFormatForType(typeCS, format, m_options.m_cascade);
}
-
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
return result.Succeeded();
}
@@ -214,8 +214,11 @@
const char* typeA = command.GetArgumentAtIndex(0);
ConstString typeCS(typeA);
- if(Debugger::DeleteFormatForType(typeCS))
+ if (Debugger::DeleteFormatForType(typeCS))
+ {
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
return result.Succeeded();
+ }
else
{
result.AppendErrorWithFormat ("no custom format for %s.\n", typeA);
@@ -283,6 +286,7 @@
param = new CommandObjectTypeList_LoopCallbackParam(this,&result);
Debugger::LoopThroughFormatList(CommandObjectTypeList_LoopCallback, param);
delete param;
+ result.SetStatus(eReturnStatusSuccessFinishResult);
return result.Succeeded();
}
Added: lldb/trunk/test/data-formatter/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/data-formatter/Makefile?rev=133772&view=auto
==============================================================================
--- lldb/trunk/test/data-formatter/Makefile (added)
+++ lldb/trunk/test/data-formatter/Makefile Thu Jun 23 18:14:10 2011
@@ -0,0 +1,5 @@
+LEVEL = ../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/data-formatter/TestDataFormatter.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/data-formatter/TestDataFormatter.py?rev=133772&view=auto
==============================================================================
--- lldb/trunk/test/data-formatter/TestDataFormatter.py (added)
+++ lldb/trunk/test/data-formatter/TestDataFormatter.py Thu Jun 23 18:14:10 2011
@@ -0,0 +1,96 @@
+"""
+Test lldb data formatter subsystem.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class DataFormatterTestCase(TestBase):
+
+ mydir = "data-formatter"
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_with_dsym_and_run_command(self):
+ """Test data formatter commands."""
+ self.buildDsym()
+ self.data_formatter_commands()
+
+ def test_with_dwarf_and_run_command(self):
+ """Test data formatter commands."""
+ self.buildDwarf()
+ self.data_formatter_commands()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break at.
+ self.line = line_number('main.cpp', '// Set break point at this line.')
+
+ def data_formatter_commands(self):
+ """Test that that file and class static variables display correctly."""
+ self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+ self.expect("breakpoint set -f main.cpp -l %d" % self.line,
+ BREAKPOINT_CREATED,
+ startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" %
+ self.line)
+
+ 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.expect("frame variable",
+ substrs = ['(Speed) SPILookHex = 5.55' # Speed by default is 5.55.
+ ]);
+
+ # This is the function to remove the custom formats in order to have a
+ # clean slate for the next test case.
+ def cleanup():
+ self.runCmd('type format delete Speed', check=False)
+ self.runCmd('type format delete Bitfield', check=False)
+ self.runCmd('type format delete RealNumber', check=False)
+ self.runCmd('type format delete Type2', check=False)
+ self.runCmd('type format delete Type1', check=False)
+
+ # Execute the cleanup function during test case tear down.
+ self.addTearDownHook(cleanup)
+
+ self.runCmd("type format add -c yes x Speed BitField")
+ self.runCmd("type format add -c no c RealNumber")
+ self.runCmd("type format add -c no x Type2")
+ self.runCmd("type format add -c yes c Type1")
+
+ # The type format list should show our custom formats.
+ self.expect("type format list",
+ substrs = ['RealNumber',
+ 'Speed',
+ 'BitField',
+ 'Type1',
+ 'Type2'])
+
+ self.expect("frame variable",
+ patterns = ['\(Speed\) SPILookHex = 0x[0-9a-f]+' # Speed should look hex-ish now.
+ ]);
+
+ # Now let's delete the 'Speed' custom format.
+ self.runCmd("type format delete Speed")
+
+ # The type format list should not show 'Speed' at this point.
+ self.expect("type format list", matching=False,
+ substrs = ['Speed'])
+
+ # Delete type format for 'Speed', we should expect an error message.
+ self.expect("type format delete Speed", error=True,
+ substrs = ['no custom format for Speed'])
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
Added: lldb/trunk/test/data-formatter/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/data-formatter/main.cpp?rev=133772&view=auto
==============================================================================
--- lldb/trunk/test/data-formatter/main.cpp (added)
+++ lldb/trunk/test/data-formatter/main.cpp Thu Jun 23 18:14:10 2011
@@ -0,0 +1,62 @@
+//===-- main.cpp ------------------------------------------------*- 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>
+#include <stdint.h>
+
+typedef float RealNumber; // should show as char
+typedef RealNumber Temperature; // should show as float
+typedef RealNumber Speed; // should show as hex
+
+typedef int Counter; // should show as int
+typedef int BitField; // should show as hex
+
+typedef BitField SignalMask; // should show as hex
+typedef BitField Modifiers; // should show as hex
+
+typedef Counter Accumulator; // should show as int
+
+typedef int Type1; // should show as char
+typedef Type1 Type2; // should show as hex
+typedef Type2 Type3; // should show as char
+typedef Type3 Type4; // should show as char
+
+typedef int ChildType; // should show as int
+typedef int AnotherChildType; // should show as int
+
+int main (int argc, const char * argv[])
+{
+
+ int iAmInt = 1;
+ const float& IAmFloat = float(2.45);
+
+ RealNumber RNILookChar = 3.14;
+ Temperature TMILookFloat = 4.97;
+ Speed SPILookHex = 5.55;
+
+ Counter CTILookInt = 6;
+ BitField BFILookHex = 7;
+ SignalMask SMILookHex = 8;
+ Modifiers MFILookHex = 9;
+
+ Accumulator* ACILookInt = new Accumulator(10);
+
+ const Type1& T1ILookChar = 11;
+ Type2 T2ILookHex = 12;
+ Type3 T3ILookChar = 13;
+ Type4 T4ILookChar = 14;
+
+ AnotherChildType AHILookInt = 15;
+
+ Speed* SPPtrILookHex = new Speed(16);
+
+ return 0; // Set break point at this line.
+}
+
More information about the lldb-commits
mailing list