[Lldb-commits] [lldb] dc057e8 - [LLDB] Fix how ObjCBOOLSummaryProvider deals with BOOL

Shafik Yaghmour via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 22 10:05:42 PST 2021


Author: Shafik Yaghmour
Date: 2021-01-22T10:05:24-08:00
New Revision: dc057e87f6c18c24d17c7cae97ebe95f78b6d934

URL: https://github.com/llvm/llvm-project/commit/dc057e87f6c18c24d17c7cae97ebe95f78b6d934
DIFF: https://github.com/llvm/llvm-project/commit/dc057e87f6c18c24d17c7cae97ebe95f78b6d934.diff

LOG: [LLDB] Fix how ObjCBOOLSummaryProvider deals with BOOL

ObjCBOOLSummaryProvider was incorrectly treating BOOL as unsigned and this is now fixed.
Also adding tests for one bit bit-fields of BOOL and unsigned char.

Added: 
    

Modified: 
    lldb/source/Plugins/Language/ObjC/Cocoa.cpp
    lldb/test/API/functionalities/data-formatter/boolreference/TestFormattersBoolRefPtr.py
    lldb/test/API/functionalities/data-formatter/boolreference/main.mm
    lldb/test/API/lang/objc/bitfield_ivars/TestBitfieldIvars.py
    lldb/test/API/lang/objc/bitfield_ivars/main.m

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
index ca4f7332f258..d871d3470e70 100644
--- a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
+++ b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
@@ -1035,7 +1035,7 @@ bool lldb_private::formatters::ObjCBOOLSummaryProvider(
     if (!real_guy_sp)
       return false;
   }
-  uint8_t value = (real_guy_sp->GetValueAsUnsigned(0) & 0xFF);
+  int8_t value = (real_guy_sp->GetValueAsSigned(0) & 0xFF);
   switch (value) {
   case 0:
     stream.Printf("NO");
@@ -1044,7 +1044,7 @@ bool lldb_private::formatters::ObjCBOOLSummaryProvider(
     stream.Printf("YES");
     break;
   default:
-    stream.Printf("%u", value);
+    stream.Printf("%d", value);
     break;
   }
   return true;

diff  --git a/lldb/test/API/functionalities/data-formatter/boolreference/TestFormattersBoolRefPtr.py b/lldb/test/API/functionalities/data-formatter/boolreference/TestFormattersBoolRefPtr.py
index 7435409939e4..815a8ab903c0 100644
--- a/lldb/test/API/functionalities/data-formatter/boolreference/TestFormattersBoolRefPtr.py
+++ b/lldb/test/API/functionalities/data-formatter/boolreference/TestFormattersBoolRefPtr.py
@@ -75,3 +75,12 @@ def cleanup():
                     substrs=['NO'])
         if not(isArm):
             self.expect('frame variable unset', substrs=['12'])
+
+        self.expect_expr('myField', result_type="BoolBitFields",
+                 result_children=[
+                     ValueCheck(name="fieldOne", summary="NO"),
+                     ValueCheck(name="fieldTwo", summary="-1"),
+                     ValueCheck(name="fieldThree", summary="NO"),
+                     ValueCheck(name="fieldFour", summary="NO"),
+                     ValueCheck(name="fieldFive", summary="-1")
+                 ])

diff  --git a/lldb/test/API/functionalities/data-formatter/boolreference/main.mm b/lldb/test/API/functionalities/data-formatter/boolreference/main.mm
index ce25c0b46e98..121849201bb1 100644
--- a/lldb/test/API/functionalities/data-formatter/boolreference/main.mm
+++ b/lldb/test/API/functionalities/data-formatter/boolreference/main.mm
@@ -1,12 +1,20 @@
 #import <Foundation/Foundation.h>
 
+typedef struct {
+    BOOL fieldOne : 1;
+    BOOL fieldTwo : 1;
+    BOOL fieldThree : 1;
+    BOOL fieldFour : 1;
+    BOOL fieldFive : 1;
+} BoolBitFields;
+
 int main (int argc, const char * argv[])
 {
-    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 
 	BOOL yes  = YES;
 	BOOL no = NO;
-    BOOL unset = 12;
+  BOOL unset = 12;
 	
 	BOOL &yes_ref = yes;
 	BOOL &no_ref = no;
@@ -16,6 +24,10 @@ int main (int argc, const char * argv[])
 	BOOL* no_ptr = &no;
 	BOOL* unset_ptr = &unset;
 
+  BoolBitFields myField = {0};
+  myField.fieldTwo = YES;
+  myField.fieldFive = YES;
+
     [pool drain];// Set break point at this line.
     return 0;
 }

diff  --git a/lldb/test/API/lang/objc/bitfield_ivars/TestBitfieldIvars.py b/lldb/test/API/lang/objc/bitfield_ivars/TestBitfieldIvars.py
index 644dca52a464..4e7590de608e 100644
--- a/lldb/test/API/lang/objc/bitfield_ivars/TestBitfieldIvars.py
+++ b/lldb/test/API/lang/objc/bitfield_ivars/TestBitfieldIvars.py
@@ -25,6 +25,15 @@ def test(self):
                                              'field2 =', '3',
                                              'field3 =', '4'])
 
+        self.expect_expr('myField', result_type="UCBitFields",
+                 result_children=[
+                     ValueCheck(name="fieldOne", value="'\\0'"),
+                     ValueCheck(name="fieldTwo", value="'\\x01'"),
+                     ValueCheck(name="fieldThree", value="'\\0'"),
+                     ValueCheck(name="fieldFour", value="'\\0'"),
+                     ValueCheck(name="fieldFive", value="'\\x01'")
+                 ])
+
     # This test is meant to be xfailed, but running the test triggers an ASan
     # issue, so it must be skipped for now.
     @skipIf

diff  --git a/lldb/test/API/lang/objc/bitfield_ivars/main.m b/lldb/test/API/lang/objc/bitfield_ivars/main.m
index 841464d38fe7..ce0ca31b7669 100644
--- a/lldb/test/API/lang/objc/bitfield_ivars/main.m
+++ b/lldb/test/API/lang/objc/bitfield_ivars/main.m
@@ -1,5 +1,13 @@
 #import <Foundation/Foundation.h>
 
+typedef struct {
+    unsigned char fieldOne : 1;
+    unsigned char fieldTwo : 1;
+    unsigned char fieldThree : 1;
+    unsigned char fieldFour : 1;
+    unsigned char fieldFive : 1;
+} UCBitFields;
+
 @interface HasBitfield : NSObject {
 @public
     unsigned field1 : 1;
@@ -59,6 +67,10 @@ int main(int argc, const char * argv[]) {
     hb2->field2 = 3;
     hb2->field3 = 4;
 
+    UCBitFields myField = {0};
+    myField.fieldTwo = 1;
+    myField.fieldFive = 1;
+
     return 0; // break here
 }
 


        


More information about the lldb-commits mailing list