Skip to content

Commit

Permalink
Add data formatter for libc++'s forward_list
Browse files Browse the repository at this point in the history
Summary:
This adds a data formatter for the implementation of forward_list in
libc++. I've refactored the existing std::list data formatter a bit to
enable more sharing of code (mainly the loop detection stuff).

Reviewers: jingham, EricWF

Subscribers: srhines, eugene, lldb-commits

Differential Revision: https://reviews.llvm.org/D35556

llvm-svn: 316992
  • Loading branch information
labath committed Oct 31, 2017
1 parent e443564 commit 89ac0c7
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LEVEL = ../../../../../make

CXX_SOURCES := main.cpp

USE_LIBCPP := 1
include $(LEVEL)/Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
Test lldb data formatter subsystem.
"""

from __future__ import print_function


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestDataFormatterLibcxxForwardList(TestBase):

mydir = TestBase.compute_mydir(__file__)

def setUp(self):
TestBase.setUp(self)
self.line = line_number('main.cpp', '// break here')
ns = 'ndk' if lldbplatformutil.target_is_android() else ''
self.namespace = 'std::__' + ns + '1'

@add_test_categories(["libc++"])
def test(self):
"""Test that std::forward_list is displayed correctly"""
self.build()
lldbutil.run_to_source_breakpoint(self, '// break here',
lldb.SBFileSpec("main.cpp", False))

forward_list = self.namespace + '::forward_list'
self.expect("frame variable empty",
substrs=[forward_list,
'size=0',
'{}'])

self.expect("frame variable one_elt",
substrs=[forward_list,
'size=1',
'{',
'[0] = 47',
'}'])

self.expect("frame variable five_elts",
substrs=[forward_list,
'size=5',
'{',
'[0] = 1',
'[1] = 22',
'[2] = 333',
'[3] = 4444',
'[4] = 55555',
'}'])
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <forward_list>

int main()
{
std::forward_list<int> empty{}, one_elt{47}, five_elts{1,22,333,4444,55555};
return 0; // break here
}
11 changes: 11 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
"libc++ std::vector synthetic children",
ConstString("^std::__(ndk)?1::vector<.+>(( )?&)?$"), stl_synth_flags,
true);
AddCXXSynthetic(
cpp_category_sp,
lldb_private::formatters::LibcxxStdForwardListSyntheticFrontEndCreator,
"libc++ std::forward_list synthetic children",
ConstString("^std::__(ndk)?1::forward_list<.+>(( )?&)?$"),
stl_synth_flags, true);
AddCXXSynthetic(
cpp_category_sp,
lldb_private::formatters::LibcxxStdListSyntheticFrontEndCreator,
Expand Down Expand Up @@ -500,6 +506,11 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
"libc++ std::vector summary provider",
ConstString("^std::__(ndk)?1::vector<.+>(( )?&)?$"),
stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
lldb_private::formatters::LibcxxContainerSummaryProvider,
"libc++ std::list summary provider",
ConstString("^std::__(ndk)?1::forward_list<.+>(( )?&)?$"),
stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
lldb_private::formatters::LibcxxContainerSummaryProvider,
"libc++ std::list summary provider",
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ SyntheticChildrenFrontEnd *
LibcxxStdListSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);

SyntheticChildrenFrontEnd *
LibcxxStdForwardListSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);

SyntheticChildrenFrontEnd *
LibcxxStdMapSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
Expand Down
Loading

0 comments on commit 89ac0c7

Please sign in to comment.