diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -729,12 +729,8 @@ TypeCategoryImpl::SharedPointer sys_category_sp = GetCategory(m_system_category_name); - sys_category_sp->GetTypeSummariesContainer()->Add(ConstString("char *"), - string_format); - sys_category_sp->GetTypeSummariesContainer()->Add( - ConstString("unsigned char *"), string_format); - sys_category_sp->GetTypeSummariesContainer()->Add( - ConstString("signed char *"), string_format); + sys_category_sp->GetRegexTypeSummariesContainer()->Add( + RegularExpression(R"(^((un)?signed )?char ?(\*|\[\])$)"), string_format); sys_category_sp->GetRegexTypeSummariesContainer()->Add( std::move(any_size_char_arr), string_array_format); diff --git a/lldb/test/API/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py b/lldb/test/API/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py --- a/lldb/test/API/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py +++ b/lldb/test/API/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py @@ -25,8 +25,8 @@ self.expect( 'type summary list char', substrs=[ - 'char *', - 'unsigned char']) + 'char ?(\*|\[\])', + 'char ?\[[0-9]+\]']) self.expect( 'type summary list -w default', @@ -40,5 +40,7 @@ matching=False) self.expect( 'type summary list -w system char', - substrs=['unsigned char *'], + substrs=[ + 'char ?(\*|\[\])', + 'char ?\[[0-9]+\]'], matching=True) diff --git a/lldb/test/API/lang/c/flexible-array-members/Makefile b/lldb/test/API/lang/c/flexible-array-members/Makefile new file mode 100644 --- /dev/null +++ b/lldb/test/API/lang/c/flexible-array-members/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := main.c + +include Makefile.rules diff --git a/lldb/test/API/lang/c/flexible-array-members/TestCFlexibleArrayMembers.py b/lldb/test/API/lang/c/flexible-array-members/TestCFlexibleArrayMembers.py new file mode 100644 --- /dev/null +++ b/lldb/test/API/lang/c/flexible-array-members/TestCFlexibleArrayMembers.py @@ -0,0 +1,29 @@ +""" +Tests C99's flexible array members. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test(self): + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", + lldb.SBFileSpec("main.c")) + + self.expect_var_path("c->flexible", type="char[]", summary='"contents"') + self.expect_var_path("sc->flexible", type="signed char[]", summary='"contents"') + self.expect_var_path("uc->flexible", type="unsigned char[]", summary='"contents"') + # TODO: Make this work + self.expect("expr c->flexible", error=True, + substrs=["incomplete", "char[]"]) + self.expect("expr sc->flexible", error=True, + substrs=["incomplete", "signed char[]"]) + self.expect("expr uc->flexible", error=True, + substrs=["incomplete", "unsigned char[]"]) diff --git a/lldb/test/API/lang/c/flexible-array-members/main.c b/lldb/test/API/lang/c/flexible-array-members/main.c new file mode 100644 --- /dev/null +++ b/lldb/test/API/lang/c/flexible-array-members/main.c @@ -0,0 +1,37 @@ +#include +#include + +struct WithFlexChar { + int member; + char flexible[]; +}; + +struct WithFlexSChar { + int member; + signed char flexible[]; +}; + +struct WithFlexUChar { + int member; + unsigned char flexible[]; +}; + +#define CONTENTS "contents" + +int main() { + struct WithFlexChar *c = + (struct WithFlexChar *)malloc(sizeof(int) + sizeof(CONTENTS)); + c->member = 1; + strcpy(c->flexible, CONTENTS); + + struct WithFlexSChar *sc = + (struct WithFlexSChar *)malloc(sizeof(int) + sizeof(CONTENTS)); + sc->member = 1; + strcpy((char *)sc->flexible, CONTENTS); + + struct WithFlexUChar *uc = + (struct WithFlexUChar *)malloc(sizeof(int) + sizeof(CONTENTS)); + uc->member = 1; + strcpy((char *)uc->flexible, CONTENTS); + return 0; // break here +}