[Lldb-commits] [lldb] r374108 - Add test coverage to printing of enums and fix display of unsigned values

Frederic Riss via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 8 12:52:01 PDT 2019


Author: friss
Date: Tue Oct  8 12:52:01 2019
New Revision: 374108

URL: http://llvm.org/viewvc/llvm-project?rev=374108&view=rev
Log:
Add test coverage to printing of enums and fix display of unsigned values

TestCPP11EnumTypes.py should have covered all our bases when it comes
to typed enums, but it missed the regression introduced in r374066.
The reason it didn't catch it is somewhat funny: the test was copied
over from another test that recompiled a source file with a different
base type every time, but neither the test source nor the python code
was adapted for testing enums. As a result, this test was just running
8 times the exact same checks on the exact same binary.

This commit fixes the coverage and addresses the issue revealed by
the new tests.

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/enum_types/TestCPP11EnumTypes.py
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/enum_types/main.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/enum_types/TestCPP11EnumTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/enum_types/TestCPP11EnumTypes.py?rev=374108&r1=374107&r2=374108&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/enum_types/TestCPP11EnumTypes.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/enum_types/TestCPP11EnumTypes.py Tue Oct  8 12:52:01 2019
@@ -19,8 +19,8 @@ class CPP11EnumTypesTestCase(TestBase):
         """Test C++11 enumeration class types as int8_t types."""
         self.build(
             dictionary={
-                'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int8_t"'})
-        self.image_lookup_for_enum_type()
+                'CFLAGS_EXTRAS': '"-DSIGNED_ENUM_CLASS_TYPE=int8_t"'})
+        self.image_lookup_for_enum_type(True)
 
     @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr36527')
     @skipIf(dwarf_version=['<', '4'])
@@ -28,8 +28,8 @@ class CPP11EnumTypesTestCase(TestBase):
         """Test C++11 enumeration class types as int16_t types."""
         self.build(
             dictionary={
-                'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int16_t"'})
-        self.image_lookup_for_enum_type()
+                'CFLAGS_EXTRAS': '"-DSIGNED_ENUM_CLASS_TYPE=int16_t"'})
+        self.image_lookup_for_enum_type(True)
 
     @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr36527')
     @skipIf(dwarf_version=['<', '4'])
@@ -37,8 +37,8 @@ class CPP11EnumTypesTestCase(TestBase):
         """Test C++11 enumeration class types as int32_t types."""
         self.build(
             dictionary={
-                'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int32_t"'})
-        self.image_lookup_for_enum_type()
+                'CFLAGS_EXTRAS': '"-DSIGNED_ENUM_CLASS_TYPE=int32_t"'})
+        self.image_lookup_for_enum_type(True)
 
     @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr36527')
     @skipIf(dwarf_version=['<', '4'])
@@ -46,8 +46,8 @@ class CPP11EnumTypesTestCase(TestBase):
         """Test C++11 enumeration class types as int64_t types."""
         self.build(
             dictionary={
-                'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int64_t"'})
-        self.image_lookup_for_enum_type()
+                'CFLAGS_EXTRAS': '"-DSIGNED_ENUM_CLASS_TYPE=int64_t"'})
+        self.image_lookup_for_enum_type(True)
 
     @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr36527')
     @skipIf(dwarf_version=['<', '4'])
@@ -55,8 +55,8 @@ class CPP11EnumTypesTestCase(TestBase):
         """Test C++11 enumeration class types as uint8_t types."""
         self.build(
             dictionary={
-                'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint8_t"'})
-        self.image_lookup_for_enum_type()
+                'CFLAGS_EXTRAS': '"-DUNSIGNED_ENUM_CLASS_TYPE=uint8_t"'})
+        self.image_lookup_for_enum_type(False)
 
     @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr36527')
     @skipIf(dwarf_version=['<', '4'])
@@ -64,8 +64,8 @@ class CPP11EnumTypesTestCase(TestBase):
         """Test C++11 enumeration class types as uint16_t types."""
         self.build(
             dictionary={
-                'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint16_t"'})
-        self.image_lookup_for_enum_type()
+                'CFLAGS_EXTRAS': '"-DUNSIGNED_ENUM_CLASS_TYPE=uint16_t"'})
+        self.image_lookup_for_enum_type(False)
 
     @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr36527')
     @skipIf(dwarf_version=['<', '4'])
@@ -73,8 +73,8 @@ class CPP11EnumTypesTestCase(TestBase):
         """Test C++11 enumeration class types as uint32_t types."""
         self.build(
             dictionary={
-                'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint32_t"'})
-        self.image_lookup_for_enum_type()
+                'CFLAGS_EXTRAS': '"-DUNSIGNED_ENUM_CLASS_TYPE=uint32_t"'})
+        self.image_lookup_for_enum_type(False)
 
     @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr36527')
     @skipIf(dwarf_version=['<', '4'])
@@ -82,8 +82,8 @@ class CPP11EnumTypesTestCase(TestBase):
         """Test C++11 enumeration class types as uint64_t types."""
         self.build(
             dictionary={
-                'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint64_t"'})
-        self.image_lookup_for_enum_type()
+                'CFLAGS_EXTRAS': '"-DUNSIGNED_ENUM_CLASS_TYPE=uint64_t"'})
+        self.image_lookup_for_enum_type(False)
 
     def setUp(self):
         # Call super's setUp().
@@ -91,7 +91,7 @@ class CPP11EnumTypesTestCase(TestBase):
         # Find the line number to break inside main().
         self.line = line_number('main.cpp', '// Set break point at this line.')
 
-    def image_lookup_for_enum_type(self):
+    def image_lookup_for_enum_type(self, is_signed):
         """Test C++11 enumeration class types."""
         exe = self.getBuildArtifact("a.out")
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
@@ -125,16 +125,28 @@ class CPP11EnumTypesTestCase(TestBase):
                              'kNumDays',
                              '}'])
 
-        enum_values = ['-4',
-                       'Monday',
-                       'Tuesday',
-                       'Wednesday',
-                       'Thursday',
-                       'Friday',
-                       'Saturday',
-                       'Sunday',
-                       'kNumDays',
-                       '5']
+        if is_signed:
+            enum_values = ['-4',
+                           'Monday',
+                           'Tuesday',
+                           'Wednesday',
+                           'Thursday',
+                           'Friday',
+                           'Saturday',
+                           'Sunday',
+                           'kNumDays',
+                           '5']
+        else:
+            enum_values = ['199',
+                           'Monday',
+                           'Tuesday',
+                           'Wednesday',
+                           'Thursday',
+                           'Friday',
+                           'Saturday',
+                           'Sunday',
+                           'kNumDays',
+                           '208']
 
         bkpt = self.target().FindBreakpointByID(bkpt_id)
         for enum_value in enum_values:

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/enum_types/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/enum_types/main.cpp?rev=374108&r1=374107&r2=374108&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/enum_types/main.cpp (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/enum_types/main.cpp Tue Oct  8 12:52:01 2019
@@ -11,7 +11,8 @@
 
 int main (int argc, char const *argv[])
 {
-    typedef int16_t enum_integer_t;
+#ifdef SIGNED_ENUM_CLASS_TYPE
+    typedef SIGNED_ENUM_CLASS_TYPE enum_integer_t;
     enum class DayType : enum_integer_t {
         Monday = -3,
         Tuesday,
@@ -23,10 +24,25 @@ int main (int argc, char const *argv[])
         kNumDays
     };
     enum_integer_t day_value;
+#else
+    typedef UNSIGNED_ENUM_CLASS_TYPE enum_integer_t;
+    enum class DayType : enum_integer_t {
+        Monday = 200,
+        Tuesday,
+        Wednesday,
+        Thursday,
+        Friday,
+        Saturday,
+        Sunday,
+        kNumDays
+    };
+    enum_integer_t day_value;
+#endif
+
     for (day_value = (enum_integer_t)DayType::Monday - 1; day_value <= (enum_integer_t)DayType::kNumDays + 1; ++day_value)
     {
         DayType day = (DayType)day_value;
         printf("day as int is %i\n", (int)day); // Set break point at this line.
     }
-    return 0;
+    return 0; // Break here for char tests
 }

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=374108&r1=374107&r2=374108&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Oct  8 12:52:01 2019
@@ -9386,18 +9386,21 @@ static bool DumpEnumValue(const clang::Q
     }
   }
 
+  // Unsigned values make more sense for flags.
+  offset = byte_offset;
+  const uint64_t enum_uvalue = data.GetMaxU64Bitfield(
+      &offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
+
   // No exact match, but we don't think this is a bitfield. Print the value as
   // decimal.
   if (!can_be_bitfield) {
-    s->Printf("%" PRIi64, enum_svalue);
+    if (qual_type->isSignedIntegerOrEnumerationType())
+      s->Printf("%" PRIi64, enum_svalue);
+    else
+      s->Printf("%" PRIu64, enum_uvalue);
     return true;
   }
 
-  // Unsigned values make more sense for flags.
-  offset = byte_offset;
-  const uint64_t enum_uvalue = data.GetMaxU64Bitfield(
-      &offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
-
   uint64_t remaining_value = enum_uvalue;
   std::vector<std::pair<uint64_t, llvm::StringRef>> values;
   values.reserve(num_enumerators);




More information about the lldb-commits mailing list