[Lldb-commits] [lldb] r253613 - Fix up LLDB for a change in the way clang represents anonymous unions such that the 'frame variable' command can still find the members of such union as if they were top-level variables in the current scope

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 19 14:28:58 PST 2015


Author: enrico
Date: Thu Nov 19 16:28:58 2015
New Revision: 253613

URL: http://llvm.org/viewvc/llvm-project?rev=253613&view=rev
Log:
Fix up LLDB for a change in the way clang represents anonymous unions such that the 'frame variable' command can still find the members of such union as if they were top-level variables in the current scope


Added:
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/Makefile
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/main.cpp
Modified:
    lldb/trunk/include/lldb/Target/StackFrame.h
    lldb/trunk/source/Commands/CommandObjectFrame.cpp
    lldb/trunk/source/Target/StackFrame.cpp

Modified: lldb/trunk/include/lldb/Target/StackFrame.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/StackFrame.h?rev=253613&r1=253612&r2=253613&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/StackFrame.h (original)
+++ lldb/trunk/include/lldb/Target/StackFrame.h Thu Nov 19 16:28:58 2015
@@ -47,11 +47,12 @@ class StackFrame :
 public:
     enum ExpressionPathOption
     {
-        eExpressionPathOptionCheckPtrVsMember       = (1u << 0),
-        eExpressionPathOptionsNoFragileObjcIvar     = (1u << 1),
-        eExpressionPathOptionsNoSyntheticChildren   = (1u << 2),
-        eExpressionPathOptionsNoSyntheticArrayRange = (1u << 3),
-        eExpressionPathOptionsAllowDirectIVarAccess = (1u << 4)
+        eExpressionPathOptionCheckPtrVsMember        = (1u << 0),
+        eExpressionPathOptionsNoFragileObjcIvar      = (1u << 1),
+        eExpressionPathOptionsNoSyntheticChildren    = (1u << 2),
+        eExpressionPathOptionsNoSyntheticArrayRange  = (1u << 3),
+        eExpressionPathOptionsAllowDirectIVarAccess  = (1u << 4),
+        eExpressionPathOptionsInspectAnonymousUnions = (1u << 5)
     };
 
     //------------------------------------------------------------------

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/Makefile?rev=253613&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/Makefile Thu Nov 19 16:28:58 2015
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py?rev=253613&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py Thu Nov 19 16:28:58 2015
@@ -0,0 +1,27 @@
+"""
+Tests that frame variable looks into anonymous unions
+"""
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+class FrameVariableAnonymousUnionsTestCase(TestBase):
+    
+    mydir = TestBase.compute_mydir(__file__)
+    
+    def test_with_run_command(self):
+        """Tests that frame variable looks into anonymous unions"""
+        self.build()
+        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+        line = line_number('main.cpp', '// break here')
+        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", line, num_expected_locations=-1, loc_exact=False)
+
+        self.runCmd("process launch", RUN_SUCCEEDED)
+
+        self.expect('frame variable -f x i', substrs=['ffffff41'])
+        self.expect('frame variable c', substrs=["'A"])
+
+        self.expect('frame variable x', matching=False, substrs=['3'])
+        self.expect('frame variable y', matching=False, substrs=["'B'"])
+        self.expect('frame variable z', matching=False, substrs=['14'])

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/main.cpp?rev=253613&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/main.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/main.cpp Thu Nov 19 16:28:58 2015
@@ -0,0 +1,23 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main() {
+  union {
+    int i;
+    char c;
+  };
+  struct {
+    int x;
+    char y;
+    short z;
+  } s{3,'B',14};
+  i = 0xFFFFFF00;
+  c = 'A';
+  return c; // break here
+}

Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=253613&r1=253612&r2=253613&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Thu Nov 19 16:28:58 2015
@@ -478,7 +478,8 @@ protected:
                     {
                         Error error;
                         uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
-                                                     StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
+                                                     StackFrame::eExpressionPathOptionsAllowDirectIVarAccess |
+                                                     StackFrame::eExpressionPathOptionsInspectAnonymousUnions;
                         lldb::VariableSP var_sp;
                         valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr, 
                                                                               m_varobj_options.use_dynamic, 

Modified: lldb/trunk/source/Target/StackFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrame.cpp?rev=253613&r1=253612&r2=253613&view=diff
==============================================================================
--- lldb/trunk/source/Target/StackFrame.cpp (original)
+++ lldb/trunk/source/Target/StackFrame.cpp Thu Nov 19 16:28:58 2015
@@ -24,6 +24,7 @@
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/Symbol.h"
 #include "lldb/Symbol/SymbolContextScope.h"
+#include "lldb/Symbol/Type.h"
 #include "lldb/Symbol/VariableList.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
@@ -667,7 +668,8 @@ StackFrame::GetValueForVariableExpressio
             {
                 var_path.erase (0, name_const_string.GetLength ());
             }
-            else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
+            
+            if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess))
             {
                 // Check for direct ivars access which helps us with implicit
                 // access to ivars with the "this->" or "self->"
@@ -689,13 +691,43 @@ StackFrame::GetValueForVariableExpressio
                     }
                 }
             }
+            
+            if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions))
+            {
+                // Check if any anonymous unions are there which contain a variable with the name we need
+                for (size_t i = 0;
+                     i < variable_list->GetSize();
+                     i++)
+                {
+                    if (VariableSP variable_sp = variable_list->GetVariableAtIndex(i))
+                    {
+                        if (variable_sp->GetName().IsEmpty())
+                        {
+                            if (Type *var_type = variable_sp->GetType())
+                            {
+                                if (var_type->GetForwardCompilerType().IsAnonymousType())
+                                {
+                                    valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
+                                    if (!valobj_sp)
+                                        return valobj_sp;
+                                    valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string, true);
+                                    if (valobj_sp)
+                                        break;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
 
-            if (var_sp)
+            if (var_sp && !valobj_sp)
             {
                 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
                 if (!valobj_sp)
                     return valobj_sp;
-                    
+            }
+            if (valobj_sp)
+            {
                 // We are dumping at least one child
                 while (separator_idx != std::string::npos)
                 {




More information about the lldb-commits mailing list