[Lldb-commits] [lldb] r199857 - If a user specifies a format option to frame variable or expression, that format should prevail over whatever format(s) a summary specifies
Enrico Granata
egranata at apple.com
Wed Jan 22 17:21:18 PST 2014
Author: enrico
Date: Wed Jan 22 19:21:18 2014
New Revision: 199857
URL: http://llvm.org/viewvc/llvm-project?rev=199857&view=rev
Log:
If a user specifies a format option to frame variable or expression, that format should prevail over whatever format(s) a summary specifies
(see test case for an example)
Added:
lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/
lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/Makefile
lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/TestUserFormatVsSummary.py
lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/main.cpp
Modified:
lldb/trunk/source/Core/ValueObject.cpp
lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp
Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=199857&r1=199856&r2=199857&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Wed Jan 22 19:21:18 2014
@@ -1685,8 +1685,12 @@ ValueObject::DumpPrintableRepresentation
// area for cases where our desired output is not backed by some other longer-term storage
StreamString strm;
- if (custom_format != eFormatInvalid)
+ bool reset_format = false;
+ if (custom_format != eFormatInvalid && GetFormat() == lldb::eFormatDefault)
+ {
+ reset_format = true;
SetFormat(custom_format);
+ }
switch(val_obj_display)
{
@@ -1741,10 +1745,17 @@ ValueObject::DumpPrintableRepresentation
}
}
+
if (cstr)
+ {
s.PutCString(cstr);
+ if (reset_format)
+ SetFormat(lldb::eFormatDefault);
+ }
else
{
+ if (reset_format)
+ SetFormat(lldb::eFormatDefault);
if (m_error.Fail())
{
if (do_dump_error)
@@ -1766,9 +1777,6 @@ ValueObject::DumpPrintableRepresentation
// even if we have an error message as output, that's a success
// from our callers' perspective, so return true
var_success = true;
-
- if (custom_format != eFormatInvalid)
- SetFormat(eFormatDefault);
}
return var_success;
Modified: lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp?rev=199857&r1=199856&r2=199857&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp (original)
+++ lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp Wed Jan 22 19:21:18 2014
@@ -282,17 +282,15 @@ ValueObjectPrinter::GetValueSummaryError
std::string& summary,
std::string& error)
{
- if (options.m_format != eFormatDefault && options.m_format != m_valobj->GetFormat())
+ lldb::Format original_format;
+ bool custom_format = options.m_format != eFormatDefault && options.m_format != m_valobj->GetFormat();
+ if (custom_format)
{
- m_valobj->GetValueAsCString(options.m_format,
- value);
- }
- else
- {
- const char* val_cstr = m_valobj->GetValueAsCString();
- if (val_cstr)
- value.assign(val_cstr);
+ original_format = m_valobj->GetFormat();
+ m_valobj->SetFormat(options.m_format);
}
+ const char* val_cstr = m_valobj->GetValueAsCString();
+ value.assign(val_cstr ? val_cstr : "");
const char* err_cstr = m_valobj->GetError().AsCString();
if (err_cstr)
error.assign(err_cstr);
@@ -314,6 +312,8 @@ ValueObjectPrinter::GetValueSummaryError
}
}
}
+ if (custom_format)
+ m_valobj->SetFormat(original_format);
}
bool
Added: lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/Makefile?rev=199857&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/Makefile (added)
+++ lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/Makefile Wed Jan 22 19:21:18 2014
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/TestUserFormatVsSummary.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/TestUserFormatVsSummary.py?rev=199857&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/TestUserFormatVsSummary.py (added)
+++ lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/TestUserFormatVsSummary.py Wed Jan 22 19:21:18 2014
@@ -0,0 +1,74 @@
+"""
+Test that the user can input a format and it will prevail over summary format's choices.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+import lldbutil
+
+class UserFormatVSSummaryTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @dsym_test
+ def test_with_dsym_and_run_command(self):
+ """Test that the user can input a format and it will prevail over summary format's choices."""
+ self.buildDsym()
+ self.data_formatter_commands()
+
+ @dwarf_test
+ def test_with_dwarf_and_run_command(self):
+ """Test that the user can input a format and it will prevail over summary format's choices."""
+ 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 the user can input a format and it will prevail over summary format's choices."""
+ self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+ lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
+
+ 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 p1", substrs = ['(Pair) p1 = (x = 3, y = -3)']);
+
+ # 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 clear', check=False)
+ self.runCmd('type summary clear', check=False)
+
+ # Execute the cleanup function during test case tear down.
+ self.addTearDownHook(cleanup)
+
+ self.runCmd('type summary add Pair -s "x=${var.x%d},y=${var.y%u}"')
+
+ self.expect("frame variable p1", substrs = ['(Pair) p1 = x=3,y=4294967293']);
+ self.expect("frame variable -f x p1", substrs = ['(Pair) p1 = x=0x00000003,y=0xfffffffd']);
+ self.expect("frame variable -f d p1", substrs = ['(Pair) p1 = x=3,y=-3']);
+ self.expect("frame variable p1", substrs = ['(Pair) p1 = x=3,y=4294967293']);
+
+ self.runCmd('type summary add Pair -s "x=${var.x%x},y=${var.y%u}"')
+
+ self.expect("frame variable p1", substrs = ['(Pair) p1 = x=0x00000003,y=4294967293']);
+ self.expect("frame variable -f d p1", substrs = ['(Pair) p1 = x=3,y=-3']);
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
Added: lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/main.cpp?rev=199857&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/main.cpp (added)
+++ lldb/trunk/test/functionalities/data-formatter/user-format-vs-summary/main.cpp Wed Jan 22 19:21:18 2014
@@ -0,0 +1,20 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+struct Pair {
+ int x;
+ int y;
+
+ Pair(int _x, int _y) : x(_x), y(_y) {}
+};
+
+int main() {
+ Pair p1(3,-3);
+ return p1.x + p1.y; // Set break point at this line.
+}
More information about the lldb-commits
mailing list