[Lldb-commits] [lldb] 35870c4 - [lldb] Summary provider for char flexible array members
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Dec 20 03:30:51 PST 2021
Author: Pavel Labath
Date: 2021-12-20T12:30:34+01:00
New Revision: 35870c442210b885391926f6ae8546beba70906f
URL: https://github.com/llvm/llvm-project/commit/35870c442210b885391926f6ae8546beba70906f
DIFF: https://github.com/llvm/llvm-project/commit/35870c442210b885391926f6ae8546beba70906f.diff
LOG: [lldb] Summary provider for char flexible array members
Add a summary provider which can print char[] members at the ends of
structs.
Differential Revision: https://reviews.llvm.org/D113174
Added:
lldb/test/API/lang/c/flexible-array-members/Makefile
lldb/test/API/lang/c/flexible-array-members/TestCFlexibleArrayMembers.py
lldb/test/API/lang/c/flexible-array-members/main.c
Modified:
lldb/source/DataFormatters/FormatManager.cpp
lldb/test/API/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py
Removed:
################################################################################
diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp
index 924b7b6948f3c..0ef5f0adc8327 100644
--- a/lldb/source/DataFormatters/FormatManager.cpp
+++ b/lldb/source/DataFormatters/FormatManager.cpp
@@ -729,12 +729,8 @@ void FormatManager::LoadSystemFormatters() {
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
index e1dc52e8394ff..a47d91434822e 100644
--- 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 @@ def test_type_summary_list_with_arg(self):
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 @@ def test_type_summary_list_with_arg(self):
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
index 0000000000000..10495940055b6
--- /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
index 0000000000000..a95fa34b3766c
--- /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
index 0000000000000..7decb4ac85244
--- /dev/null
+++ b/lldb/test/API/lang/c/flexible-array-members/main.c
@@ -0,0 +1,37 @@
+#include <stdlib.h>
+#include <string.h>
+
+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
+}
More information about the lldb-commits
mailing list