diff options
author | Enrico Granata <egranata@apple.com> | 2013-01-12 01:22:57 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2013-01-12 01:22:57 +0000 |
commit | e274088db052f89254a050c3f255bad9f92ddea5 (patch) | |
tree | b7fee06cf4494f037df9b6febea9004f164b2efd | |
parent | a7edaad3b66ceb038b6240e32a96e14803e7802c (diff) | |
download | bcm5719-llvm-e274088db052f89254a050c3f255bad9f92ddea5.tar.gz bcm5719-llvm-e274088db052f89254a050c3f255bad9f92ddea5.zip |
<rdar://problem/12239827>
Making a summary for std::wstring as provided by libstdc++ along with a relevant test case
llvm-svn: 172286
6 files changed, 123 insertions, 6 deletions
diff --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py index 815c76f78ad..5037187d956 100644 --- a/lldb/examples/synthetic/libcxx.py +++ b/lldb/examples/synthetic/libcxx.py @@ -6,6 +6,9 @@ import lldb.formatters.Logger # ships with current releases of OS X - They will not work for other implementations # of the standard C++ library - and they are bound to use the libc++-specific namespace +# the std::string summary is just an example for your convenience +# the actual summary that LLDB uses is C++ code inside the debugger's own core + # this could probably be made more efficient but since it only reads a handful of bytes at a time # we probably don't need to worry too much about this for the time being def make_string(F,L): diff --git a/lldb/include/lldb/Core/FormatManager.h b/lldb/include/lldb/Core/FormatManager.h index 26d19e7ea79..5bf544d4ebd 100644 --- a/lldb/include/lldb/Core/FormatManager.h +++ b/lldb/include/lldb/Core/FormatManager.h @@ -759,16 +759,16 @@ private: // most would actually belong to the users' lldbinit file or to some other form of configurable // storage void - LoadSTLFormatters(); + LoadLibStdcppFormatters (); void - LoadLibcxxFormatters(); + LoadLibcxxFormatters (); void - LoadSystemFormatters(); + LoadSystemFormatters (); void - LoadObjCFormatters(); + LoadObjCFormatters (); }; } // namespace lldb_private diff --git a/lldb/source/Core/FormatManager.cpp b/lldb/source/Core/FormatManager.cpp index 144ddbff37c..edcccc88ef5 100644 --- a/lldb/source/Core/FormatManager.cpp +++ b/lldb/source/Core/FormatManager.cpp @@ -704,7 +704,7 @@ FormatManager::FormatManager() : { LoadSystemFormatters(); - LoadSTLFormatters(); + LoadLibStdcppFormatters(); LoadLibcxxFormatters(); LoadObjCFormatters(); @@ -777,7 +777,7 @@ static void AddCXXSynthetic (TypeCategoryImpl::SharedPointer category_sp, #endif void -FormatManager::LoadSTLFormatters() +FormatManager::LoadLibStdcppFormatters() { TypeSummaryImpl::Flags stl_summary_flags; stl_summary_flags.SetCascades(true) @@ -802,6 +802,19 @@ FormatManager::LoadSTLFormatters() gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"), std_string_summary_sp); + // making sure we force-pick the summary for printing wstring (_M_p is a wchar_t*) + lldb::TypeSummaryImplSP std_wstring_summary_sp(new StringSummaryFormat(stl_summary_flags, + "${var._M_dataplus._M_p%S}")); + + gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::wstring"), + std_wstring_summary_sp); + gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string<wchar_t>"), + std_wstring_summary_sp); + gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >"), + std_wstring_summary_sp); + gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >"), + std_wstring_summary_sp); + #ifndef LLDB_DISABLE_PYTHON diff --git a/lldb/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/Makefile b/lldb/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/Makefile new file mode 100644 index 00000000000..b736f92449d --- /dev/null +++ b/lldb/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules + +CXXFLAGS += -stdlib=libstdc++ -O0 +LDFLAGS += -stdlib=libstdc++
\ No newline at end of file diff --git a/lldb/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py b/lldb/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py new file mode 100644 index 00000000000..ac67b90a10f --- /dev/null +++ b/lldb/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py @@ -0,0 +1,81 @@ +#coding=utf8 +""" +Test lldb data formatter subsystem. +""" + +import os, time +import unittest2 +import lldb +from lldbtest import * +import lldbutil + +class StdStringDataFormatterTestCase(TestBase): + + mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "libstdcpp", "string") + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @dsym_test + def test_with_dsym_and_run_command(self): + """Test data formatter commands.""" + self.buildDsym() + self.data_formatter_commands() + + @skipOnLinux # No standard locations for libc++ on Linux, so skip for now + @dwarf_test + 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) + + lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1) + + 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']) + + # 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) + self.runCmd('type filter clear', check=False) + self.runCmd('type synth clear', check=False) + self.runCmd("settings set target.max-children-count 256", check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.expect("frame variable", + substrs = ['(std::wstring) s = L"hello world! מזל טוב!"', + '(std::wstring) S = L"!!!!"', + '(const wchar_t *) mazeltov = 0x','L"מזל טוב"', + '(std::string) q = "hello world"', + '(std::string) Q = "quite a long std::strin with lots of info inside it"']) + + self.runCmd("n") + + self.expect("frame variable", + substrs = ['(std::wstring) s = L"hello world! מזל טוב!"', + '(std::wstring) S = L"!!!!!"', + '(const wchar_t *) mazeltov = 0x','L"מזל טוב"', + '(std::string) q = "hello world"', + '(std::string) Q = "quite a long std::strin with lots of info inside it"']) + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp b/lldb/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp new file mode 100644 index 00000000000..4a9b4fc7d0d --- /dev/null +++ b/lldb/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp @@ -0,0 +1,12 @@ +#include <string> + +int main() +{ + std::wstring s(L"hello world! מזל טוב!"); + std::wstring S(L"!!!!"); + const wchar_t *mazeltov = L"מזל טוב"; + std::string q("hello world"); + std::string Q("quite a long std::strin with lots of info inside it"); + S.assign(L"!!!!!"); // Set break point at this line. + return 0; +}
\ No newline at end of file |