vbalu created this revision.

"target variable" at main not printing all the global variables if we have 
print ant global variable before starting execution. Instead it show only 
variables that we printed before starting execution. 
It wont work on three scenarios.
case 1:

(lldb) print my_global_char                ==> global variable
(char) $0 = 'X'
(lldb) b main
(lldb) r 
(lldb) target variable
 Global variables for ******
 (char) my_global_char = 'X'               ==> not showing other global 
variables
 (lldb)
case 2:

(lldb) target variable -r my_global_ch*                ==> global variable
(char) $0 = 'X'
(lldb) b main
(lldb) r 
(lldb) target variable
 Global variables for ******
 (char) my_global_char = 'X'               ==> not showing other global 
variables
 (lldb)
case 3:

(lldb) target variable my_global_char               ==> global variable
(char) $0 = 'X'
(lldb) b main
(lldb) r 
(lldb) target variable
 Global variables for ******
 (char) my_global_char = 'X'               ==> not showing other global 
variables
 (lldb)
For all other scopes we parse all the variables before we look for the required 
variable, so it would be updated in m_varibles.
For global scope, we look for required variable and only that updated 
m_variables which taken back for "target variable"


Repository:
  rL LLVM

https://reviews.llvm.org/D32732

Files:
  source/Commands/CommandObjectTarget.cpp
  source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h

Index: source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
@@ -303,6 +303,23 @@
   TargetInfo GetTargetInfo();
 
   //------------------------------------------------------------------
+  /// Used to parse all the variable declared in globa score before accssing
+  /// indivually  when user try to see the global symbol before starting
+  /// execution.
+  ///
+  /// @param[in] target
+  ///     The target to find the symbol in.
+  ///
+  /// @param[in] name
+  ///     Symbol name that user try to print.
+  ///
+  /// @return
+  ///     True on success; false otherwise.
+  //------------------------------------------------------------------
+
+  void ParseGlobalVariablesInScopeZero(Target &target, const ConstString name);
+
+  //------------------------------------------------------------------
   /// [Used by ClangASTSource] Find all entities matching a given name,
   /// using a NameSearchContext to make Decls for them.
   ///
Index: source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -733,6 +733,28 @@
       frame_decl_context.GetTypeSystem());
 }
 
+void ClangExpressionDeclMap::ParseGlobalVariablesInScopeZero(
+    Target &target, const ConstString name) {
+  const Symbol *symbol = FindGlobalDataSymbol(target, name, NULL);
+  ModuleSP module;
+
+  if (!symbol)
+    return;
+
+  if (symbol->ValueIsAddress())
+    module = symbol->GetAddressRef().GetModule();
+
+  SymbolVendor *vendor_sym = module->GetSymbolVendor(true, NULL);
+  SymbolContext sc;
+
+  sc.module_sp = module;
+  sc.comp_unit = symbol->GetAddress().CalculateSymbolContextCompileUnit();
+
+  vendor_sym->ParseVariablesForContext(sc);
+
+  return;
+}
+
 // Interface for ClangASTSource
 
 void ClangExpressionDeclMap::FindExternalVisibleDecls(
@@ -1229,6 +1251,11 @@
       }
     }
     if (target) {
+      // Looks like trying to find a variable before program is run.
+      // So parse the global variable for declaration.
+
+      ParseGlobalVariablesInScopeZero(*target, name);
+
       var = FindGlobalVariable(*target, module_sp, name, &namespace_decl, NULL);
 
       if (var) {
Index: source/Commands/CommandObjectTarget.cpp
===================================================================
--- source/Commands/CommandObjectTarget.cpp
+++ source/Commands/CommandObjectTarget.cpp
@@ -836,9 +836,25 @@
             return false;
           }
           use_var_name = true;
+          if (!m_exe_ctx.GetFramePtr()) {
+            VariableList list;
+            lldb_private::RegularExpression all_globals_regex(".");
+            target->GetImages().FindGlobalVariables(all_globals_regex, true,
+                                                    UINT32_MAX, list);
+          }
           matches = target->GetImages().FindGlobalVariables(
               regex, true, UINT32_MAX, variable_list);
         } else {
+          // if there is no frame then it is before "r" ing the exe, so just
+          // parse all the variables
+          // before picking proper otherwise we end up adding only this variable
+          // in m_variables
+          if (!m_exe_ctx.GetFramePtr()) {
+            VariableList list;
+            lldb_private::RegularExpression all_globals_regex(".");
+            target->GetImages().FindGlobalVariables(all_globals_regex, true,
+                                                    UINT32_MAX, list);
+          }
           Error error(Variable::GetValuesForVariableExpressionPath(
               arg, m_exe_ctx.GetBestExecutionContextScope(),
               GetVariableCallback, target, variable_list, valobj_list));
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to