evgeny777 updated this revision to Diff 40508.
evgeny777 added a comment.

Minor code cleanups


http://reviews.llvm.org/D13350

Files:
  packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py
  packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp
  packages/Python/lldbsuite/test/lang/cpp/nsimport/TestCppNsImport.py
  source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

Index: source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -1337,10 +1337,17 @@
 
         if (frame && !namespace_decl)
         {
-            CompilerDeclContext compiler_decl_context = sym_ctx.block != nullptr ? sym_ctx.block->GetDeclContext() : CompilerDeclContext();
-
+            CompilerDeclContext compiler_decl_context = sym_ctx.block != nullptr ? sym_ctx.block->GetDeclContext() : CompilerDeclContext();            
             if (compiler_decl_context)
-            {
+            {                
+                if (context.m_decl_context->shouldUseQualifiedLookup())
+                {
+                    // We're looking for global variable, so we need root DeclContext
+                    clang::DeclContext* dc = (clang::DeclContext*)compiler_decl_context.GetOpaqueDeclContext();
+                    while (dc->getParent())
+                        dc = dc->getParent();
+                    compiler_decl_context.SetDeclContext(compiler_decl_context.GetTypeSystem(), dc);
+                }
                 // Make sure that the variables are parsed so that we have the declarations
                 VariableListSP vars = frame->GetInScopeVariableList(true);
                 for (size_t i = 0; i < vars->GetSize(); i++)
Index: packages/Python/lldbsuite/test/lang/cpp/nsimport/TestCppNsImport.py
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/nsimport/TestCppNsImport.py
+++ packages/Python/lldbsuite/test/lang/cpp/nsimport/TestCppNsImport.py
@@ -72,9 +72,8 @@
         test_result = frame.EvaluateExpression("not_imported")
         self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 35, "not_imported = 35")
 
-        # Currently there is no way to distinguish between "::imported" and "imported" in ClangExpressionDeclMap so this fails
-        #test_result = frame.EvaluateExpression("::imported")
-        #self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 89, "::imported = 89")
+        test_result = frame.EvaluateExpression("::imported")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 89, "::imported = 89")
 
         test_result = frame.EvaluateExpression("Imported::imported")
         self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 99, "Imported::imported = 99")
Index: packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp
+++ packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp
@@ -9,6 +9,8 @@
 
 #include <cstdarg>
 
+int gvar = 10;
+
 namespace {
     typedef unsigned int my_uint_t;
     int i; // Find the line number for anonymous namespace variable i.
@@ -74,19 +76,21 @@
 
 namespace ns1 {
     int value = 100;
+    int gvar = 20;
 }
 
 namespace ns2 {
     int value = 200;
 }
 
 #include <stdio.h>
 void test_namespace_scopes() {
+    int gvar = 1;
     do {
         using namespace ns1;
-        printf("ns1::value = %d\n", value); // Evaluate ns1::value
+        printf("ns1::value = %d, gvar=%d, ::gvar=%d\n", value, gvar, ::gvar); // Evaluate ns1::value and gvar
     } while(0);
-    
+
     do {
         using namespace ns2;
         printf("ns2::value = %d\n", value); // Evaluate ns2::value
Index: packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py
+++ packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py
@@ -27,7 +27,7 @@
         self.line_break = line_number('main.cpp',
                 '// Set break point at this line.')
         # Break inside do {} while and evaluate value
-        self.line_break_ns1 = line_number('main.cpp', '// Evaluate ns1::value')
+        self.line_break_ns1 = line_number('main.cpp', '// Evaluate ns1::value and gvar')
         self.line_break_ns2 = line_number('main.cpp', '// Evaluate ns2::value')
 
     def runToBkpt(self, command):
@@ -51,10 +51,14 @@
         self.runToBkpt("run")
         # Evaluate ns1::value
         self.expect("expression -- value", startstr = "(int) $0 = 100")
-
+        # Evaluate gvar in different scopes
+        self.expect("expression -- gvar", startstr = "(int) $1 = 1")
+        self.expect("expression -- ns1::gvar", startstr = "(int) $2 = 20")
+        self.expect("expression -- ::gvar", startstr = "(int) $3 = 10")
+        
         self.runToBkpt("continue")
         # Evaluate ns2::value
-        self.expect("expression -- value", startstr = "(int) $1 = 200")
+        self.expect("expression -- value", startstr = "(int) $4 = 200")
         
         self.runToBkpt("continue")
         # On Mac OS X, gcc 4.2 emits the wrong debug info with respect to types.
@@ -97,8 +101,8 @@
         # test/namespace: 'expression -- i+j' not working
         # This has been fixed.
         self.expect("expression -- i + j",
-            startstr = "(int) $2 = 7")
-        # (int) $2 = 7
+            startstr = "(int) $5 = 7")
+        # (int) $5 = 7
 
         self.runCmd("expression -- i")
         self.runCmd("expression -- j")
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to