[Lldb-commits] [lldb] r285226 - Fix an issue where frame variable -s <varname> would not show the scope even though the user asked for it

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 26 12:17:50 PDT 2016


Author: enrico
Date: Wed Oct 26 14:17:49 2016
New Revision: 285226

URL: http://llvm.org/viewvc/llvm-project?rev=285226&view=rev
Log:
Fix an issue where frame variable -s <varname> would not show the scope even though the user asked for it

Part of rdar://28434047


Added:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/Makefile
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/TestFrameVariableScope.py
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/main.c
Modified:
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/unsigned_types/TestUnsignedTypes.py
    lldb/trunk/source/Commands/CommandObjectFrame.cpp

Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/Makefile?rev=285226&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/Makefile Wed Oct 26 14:17:49 2016
@@ -0,0 +1,3 @@
+LEVEL = ../../make
+C_SOURCES := main.c
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/TestFrameVariableScope.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/TestFrameVariableScope.py?rev=285226&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/TestFrameVariableScope.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/TestFrameVariableScope.py Wed Oct 26 14:17:49 2016
@@ -0,0 +1,5 @@
+from lldbsuite.test import lldbinline
+from lldbsuite.test import decorators
+
+lldbinline.MakeInlineTest(
+    __file__, globals(), [])

Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/main.c?rev=285226&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/main.c (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/frame_var_scope/main.c Wed Oct 26 14:17:49 2016
@@ -0,0 +1,21 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int foo(int x, int y) {
+    int z = 3 + x;
+    return z + y; //% self.expect("frame variable -s", substrs=['ARG: (int) x = -3','ARG: (int) y = 0'])
+     //% self.expect("frame variable -s x", substrs=['ARG: (int) x = -3'])
+     //% self.expect("frame variable -s y", substrs=['ARG: (int) y = 0'])
+     //% self.expect("frame variable -s z", substrs=['LOCAL: (int) z = 0'])
+}
+
+int main (int argc, char const *argv[])
+{
+    return foo(-3,0);  //% self.expect("frame variable -s argc argv", substrs=['ARG: (int) argc ='])
+}

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/unsigned_types/TestUnsignedTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/unsigned_types/TestUnsignedTypes.py?rev=285226&r1=285225&r2=285226&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/unsigned_types/TestUnsignedTypes.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/unsigned_types/TestUnsignedTypes.py Wed Oct 26 14:17:49 2016
@@ -55,9 +55,9 @@ class UnsignedTypesTestCase(TestBase):
         self.expect(
             "frame variable --show-types --no-args",
             VARIABLES_DISPLAYED_CORRECTLY,
-            startstr="(unsigned char) the_unsigned_char = 'c'",
             patterns=["\((short unsigned int|unsigned short)\) the_unsigned_short = 99"],
             substrs=[
+                "(unsigned char) the_unsigned_char = 'c'",
                 "(unsigned int) the_unsigned_int = 99",
                 "(unsigned long) the_unsigned_long = 99",
                 "(unsigned long long) the_unsigned_long_long = 99",

Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=285226&r1=285225&r2=285226&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Wed Oct 26 14:17:49 2016
@@ -489,6 +489,28 @@ public:
   }
 
 protected:
+  llvm::StringRef GetScopeString(VariableSP var_sp) {
+    if (!var_sp)
+      return llvm::StringRef::withNullAsEmpty(nullptr);
+
+    switch (var_sp->GetScope()) {
+    case eValueTypeVariableGlobal:
+      return "GLOBAL: ";
+    case eValueTypeVariableStatic:
+      return "STATIC: ";
+    case eValueTypeVariableArgument:
+      return "ARG: ";
+    case eValueTypeVariableLocal:
+      return "LOCAL: ";
+    case eValueTypeVariableThreadLocal:
+      return "THREAD: ";
+    default:
+      break;
+    }
+
+    return llvm::StringRef::withNullAsEmpty(nullptr);
+  }
+
   bool DoExecute(Args &command, CommandReturnObject &result) override {
     // No need to check "frame" for validity as eCommandRequiresFrame ensures it
     // is valid
@@ -564,6 +586,13 @@ protected:
                       //                                                valobj_sp->SetFormat
                       //                                                (format);
 
+                      std::string scope_string;
+                      if (m_option_variable.show_scope)
+                        scope_string = GetScopeString(var_sp).str();
+
+                      if (!scope_string.empty())
+                        s.PutCString(scope_string.c_str());
+
                       if (m_option_variable.show_decl &&
                           var_sp->GetDeclaration().GetFile()) {
                         bool show_fullpaths = false;
@@ -603,6 +632,13 @@ protected:
                 name_cstr, m_varobj_options.use_dynamic, expr_path_options,
                 var_sp, error);
             if (valobj_sp) {
+              std::string scope_string;
+              if (m_option_variable.show_scope)
+                scope_string = GetScopeString(var_sp).str();
+
+              if (!scope_string.empty())
+                s.PutCString(scope_string.c_str());
+
               //                            if (format != eFormatDefault)
               //                                valobj_sp->SetFormat (format);
               if (m_option_variable.show_decl && var_sp &&
@@ -639,41 +675,8 @@ protected:
             var_sp = variable_list->GetVariableAtIndex(i);
             bool dump_variable = true;
             std::string scope_string;
-            switch (var_sp->GetScope()) {
-            case eValueTypeVariableGlobal:
-              // Always dump globals since we only fetched them if
-              // m_option_variable.show_scope was true
-              if (dump_variable && m_option_variable.show_scope)
-                scope_string = "GLOBAL: ";
-              break;
-
-            case eValueTypeVariableStatic:
-              // Always dump globals since we only fetched them if
-              // m_option_variable.show_scope was true, or this is
-              // a static variable from a block in the current scope
-              if (dump_variable && m_option_variable.show_scope)
-                scope_string = "STATIC: ";
-              break;
-
-            case eValueTypeVariableArgument:
-              dump_variable = m_option_variable.show_args;
-              if (dump_variable && m_option_variable.show_scope)
-                scope_string = "   ARG: ";
-              break;
-
-            case eValueTypeVariableLocal:
-              dump_variable = m_option_variable.show_locals;
-              if (dump_variable && m_option_variable.show_scope)
-                scope_string = " LOCAL: ";
-              break;
-
-            case eValueTypeVariableThreadLocal:
-              if (dump_variable && m_option_variable.show_scope)
-                scope_string = "THREAD: ";
-              break;
-            default:
-              break;
-            }
+            if (dump_variable && m_option_variable.show_scope)
+              scope_string = GetScopeString(var_sp).str();
 
             if (dump_variable) {
               // Use the variable object code to make sure we are




More information about the lldb-commits mailing list