diff options
author | Frederic Riss <friss@apple.com> | 2019-10-08 15:35:59 +0000 |
---|---|---|
committer | Frederic Riss <friss@apple.com> | 2019-10-08 15:35:59 +0000 |
commit | 41ff39605ea1c9278f6ff15208475f5f3c863f44 (patch) | |
tree | 0f98515be82aa0f5d30ba7254a29626ed93b1ac4 /lldb/packages/Python | |
parent | d6470fb01a08b7e51870e27bab5271e2fea04ff6 (diff) | |
download | bcm5719-llvm-41ff39605ea1c9278f6ff15208475f5f3c863f44.tar.gz bcm5719-llvm-41ff39605ea1c9278f6ff15208475f5f3c863f44.zip |
Add pretty printing of Clang "bitfield" enums
Summary:
Using enumerators as flags is standard practice. This patch adds
support to LLDB to display such enum values symbolically, eg:
(E) e1 = A | B
If enumerators don't cover the whole value, the remaining bits are
displayed as hexadecimal:
(E) e4 = A | 0x10
Detecting whether an enum is used as a bitfield or not is
complicated. This patch implements a heuristic that assumes that such
enumerators will either have only 1 bit set or will be a combination
of previous values.
This patch doesn't change the way we currently display enums which the
above heuristic would not consider as bitfields.
Reviewers: jingham, labath
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D67520
llvm-svn: 374067
Diffstat (limited to 'lldb/packages/Python')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/lang/c/enum_types/TestEnumTypes.py | 28 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/lang/c/enum_types/main.c | 21 |
2 files changed, 46 insertions, 3 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/enum_types/TestEnumTypes.py b/lldb/packages/Python/lldbsuite/test/lang/c/enum_types/TestEnumTypes.py index f6cf3c7f67c..7ab1199fa95 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/c/enum_types/TestEnumTypes.py +++ b/lldb/packages/Python/lldbsuite/test/lang/c/enum_types/TestEnumTypes.py @@ -25,11 +25,35 @@ class EnumTypesTestCase(TestBase): exe = self.getBuildArtifact("a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + lldbutil.run_to_source_breakpoint( + self, '// Breakpoint for bitfield', lldb.SBFileSpec("main.c")) + + self.expect("fr var a", DATA_TYPES_DISPLAYED_CORRECTLY, + patterns=[' = A$']) + self.expect("fr var b", DATA_TYPES_DISPLAYED_CORRECTLY, + patterns=[' = B$']) + self.expect("fr var c", DATA_TYPES_DISPLAYED_CORRECTLY, + patterns=[' = C$']) + self.expect("fr var ab", DATA_TYPES_DISPLAYED_CORRECTLY, + patterns=[' = AB$']) + self.expect("fr var ac", DATA_TYPES_DISPLAYED_CORRECTLY, + patterns=[' = A | C$']) + self.expect("fr var all", DATA_TYPES_DISPLAYED_CORRECTLY, + patterns=[' = ALL$']) + # Test that an enum that doesn't match the heuristic we use in + # ClangASTContext::DumpEnumValue, gets printed as a raw integer. + self.expect("fr var omega", DATA_TYPES_DISPLAYED_CORRECTLY, + patterns=[' = 7$']) + # Test the behavior in case have a variable of a type considered + # 'bitfield' by the heuristic, but the value isn't actually fully + # covered by the enumerators. + self.expect("p (enum bitfield)nonsense", DATA_TYPES_DISPLAYED_CORRECTLY, + patterns=[' = B | C | 0x10$']) + # Break inside the main. bkpt_id = lldbutil.run_break_set_by_file_and_line( self, "main.c", self.line, num_expected_locations=1, loc_exact=True) - - self.runCmd("run", RUN_SUCCEEDED) + self.runCmd("c", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/enum_types/main.c b/lldb/packages/Python/lldbsuite/test/lang/c/enum_types/main.c index 924336e97e0..675af5ecec5 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/c/enum_types/main.c +++ b/lldb/packages/Python/lldbsuite/test/lang/c/enum_types/main.c @@ -18,6 +18,20 @@ struct foo { int main (int argc, char const *argv[]) { + enum bitfield { + None = 0, + A = 1 << 0, + B = 1 << 1, + C = 1 << 2, + AB = A | B, + ALL = A | B | C, + }; + + enum non_bitfield { + Alpha = 3, + Beta = 4 + }; + enum days { Monday = -3, Tuesday, @@ -28,9 +42,14 @@ int main (int argc, char const *argv[]) Sunday, kNumDays }; + + enum bitfield a = A, b = B, c = C, ab = AB, ac = A | C, all = ALL; + int nonsense = a + b + c + ab + ac + all; + enum non_bitfield omega = Alpha | Beta; + enum days day; struct foo f; - f.op = NULL; + f.op = NULL; // Breakpoint for bitfield for (day = Monday - 1; day <= kNumDays + 1; day++) { printf("day as int is %i\n", (int)day); // Set break point at this line. |