[Lldb-commits] [lldb] 8bc97a3 - [lldb][NFC] Factor out CommandObject code filtering results based on scope

Felipe de Azevedo Piovezan via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 19 06:14:33 PDT 2023


Author: Felipe de Azevedo Piovezan
Date: 2023-07-19T09:14:02-04:00
New Revision: 8bc97a3ee4f411e583a13e0966239848080d753d

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

LOG: [lldb][NFC] Factor out CommandObject code filtering results based on scope

We will need this code in a subsequent commit.

Differential Revision: https://reviews.llvm.org/D155332

Added: 
    

Modified: 
    lldb/source/Commands/CommandObjectFrame.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index 3f68425e91d3c3..7638076a0ebeea 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -480,6 +480,25 @@ may even involve JITing and running code in the target program.)");
     return llvm::StringRef();
   }
 
+  /// Returns true if `scope` matches any of the options in `m_option_variable`.
+  bool ScopeRequested(lldb::ValueType scope) {
+    switch (scope) {
+    case eValueTypeVariableGlobal:
+    case eValueTypeVariableStatic:
+      return m_option_variable.show_globals;
+    case eValueTypeVariableArgument:
+      return m_option_variable.show_args;
+    case eValueTypeVariableLocal:
+      return m_option_variable.show_locals;
+    case eValueTypeInvalid:
+    case eValueTypeRegister:
+    case eValueTypeRegisterSet:
+    case eValueTypeConstResult:
+    case eValueTypeVariableThreadLocal:
+      return false;
+    }
+  }
+
   bool DoExecute(Args &command, CommandReturnObject &result) override {
     // No need to check "frame" for validity as eCommandRequiresFrame ensures
     // it is valid
@@ -630,27 +649,8 @@ may even involve JITing and running code in the target program.)");
         if (num_variables > 0) {
           for (size_t i = 0; i < num_variables; i++) {
             var_sp = variable_list->GetVariableAtIndex(i);
-            switch (var_sp->GetScope()) {
-            case eValueTypeVariableGlobal:
-              if (!m_option_variable.show_globals)
-                continue;
-              break;
-            case eValueTypeVariableStatic:
-              if (!m_option_variable.show_globals)
+            if (!ScopeRequested(var_sp->GetScope()))
                 continue;
-              break;
-            case eValueTypeVariableArgument:
-              if (!m_option_variable.show_args)
-                continue;
-              break;
-            case eValueTypeVariableLocal:
-              if (!m_option_variable.show_locals)
-                continue;
-              break;
-            default:
-              continue;
-              break;
-            }
             std::string scope_string;
             if (m_option_variable.show_scope)
               scope_string = GetScopeString(var_sp).str();


        


More information about the lldb-commits mailing list