[Lldb-commits] [lldb] r287367 - Re-add the StringRef interface changes for Variable.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 18 11:23:40 PST 2016


Author: zturner
Date: Fri Nov 18 13:23:39 2016
New Revision: 287367

URL: http://llvm.org/viewvc/llvm-project?rev=287367&view=rev
Log:
Re-add the StringRef interface changes for Variable.

This concludes the changes I originally tried to make and then
had to back out.  This way if anything is still broken, it
should be easier to bisect it back to a more specific changeset.

Modified:
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Symbol/Variable.h
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Symbol/Variable.cpp

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=287367&r1=287366&r2=287367&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Fri Nov 18 13:23:39 2016
@@ -394,7 +394,7 @@ public:
       GetExpressionPathFormat = eGetExpressionPathFormatDereferencePointers);
 
   lldb::ValueObjectSP GetValueForExpressionPath(
-      const char *expression,
+      llvm::StringRef expression,
       ExpressionPathScanEndReason *reason_to_stop = nullptr,
       ExpressionPathEndResultType *final_value_type = nullptr,
       const GetValueForExpressionPathOptions &options =
@@ -1002,7 +1002,8 @@ private:
   virtual CompilerType MaybeCalculateCompleteType();
 
   lldb::ValueObjectSP GetValueForExpressionPath_Impl(
-      const char *expression_cstr, ExpressionPathScanEndReason *reason_to_stop,
+      llvm::StringRef expression_cstr,
+      ExpressionPathScanEndReason *reason_to_stop,
       ExpressionPathEndResultType *final_value_type,
       const GetValueForExpressionPathOptions &options,
       ExpressionPathAftermath *final_task_on_target);

Modified: lldb/trunk/include/lldb/Symbol/Variable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Variable.h?rev=287367&r1=287366&r2=287367&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Variable.h (original)
+++ lldb/trunk/include/lldb/Symbol/Variable.h Fri Nov 18 13:23:39 2016
@@ -98,7 +98,7 @@ public:
                                         VariableList &var_list);
 
   static Error GetValuesForVariableExpressionPath(
-      const char *variable_expr_path, ExecutionContextScope *scope,
+      llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
       GetVariableCallback callback, void *baton, VariableList &variable_list,
       ValueObjectList &valobj_list);
 

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=287367&r1=287366&r2=287367&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Fri Nov 18 13:23:39 2016
@@ -2166,7 +2166,7 @@ void ValueObject::GetExpressionPath(Stre
 }
 
 ValueObjectSP ValueObject::GetValueForExpressionPath(
-    const char *expression, ExpressionPathScanEndReason *reason_to_stop,
+    llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop,
     ExpressionPathEndResultType *final_value_type,
     const GetValueForExpressionPathOptions &options,
     ExpressionPathAftermath *final_task_on_target) {
@@ -2234,16 +2234,16 @@ ValueObjectSP ValueObject::GetValueForEx
 }
 
 ValueObjectSP ValueObject::GetValueForExpressionPath_Impl(
-    const char *expression_cstr2, ExpressionPathScanEndReason *reason_to_stop,
+    llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop,
     ExpressionPathEndResultType *final_result,
     const GetValueForExpressionPathOptions &options,
     ExpressionPathAftermath *what_next) {
   ValueObjectSP root = GetSP();
 
-  if (!root.get())
-    return ValueObjectSP();
+  if (!root)
+    return nullptr;
 
-  llvm::StringRef remainder(expression_cstr2);
+  llvm::StringRef remainder = expression;
 
   while (true) {
     llvm::StringRef temp_expression = remainder;
@@ -2565,7 +2565,7 @@ ValueObjectSP ValueObject::GetValueForEx
               pointee_compiler_type_info.Test(eTypeIsScalar)) {
             Error error;
             root = root->Dereference(error);
-            if (error.Fail() || !root.get()) {
+            if (error.Fail() || !root) {
               *reason_to_stop =
                   ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
               *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
@@ -2588,7 +2588,7 @@ ValueObjectSP ValueObject::GetValueForEx
               root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
             } else
               root = root->GetSyntheticArrayMember(index, true);
-            if (!root.get()) {
+            if (!root) {
               *reason_to_stop =
                   ValueObject::eExpressionPathScanEndReasonNoSuchChild;
               *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
@@ -2602,7 +2602,7 @@ ValueObjectSP ValueObject::GetValueForEx
           }
         } else if (root_compiler_type_info.Test(eTypeIsScalar)) {
           root = root->GetSyntheticBitFieldChild(index, index, true);
-          if (!root.get()) {
+          if (!root) {
             *reason_to_stop =
                 ValueObject::eExpressionPathScanEndReasonNoSuchChild;
             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
@@ -2617,7 +2617,7 @@ ValueObjectSP ValueObject::GetValueForEx
           }
         } else if (root_compiler_type_info.Test(eTypeIsVector)) {
           root = root->GetChildAtIndex(index, true);
-          if (!root.get()) {
+          if (!root) {
             *reason_to_stop =
                 ValueObject::eExpressionPathScanEndReasonNoSuchChild;
             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
@@ -2645,14 +2645,14 @@ ValueObjectSP ValueObject::GetValueForEx
           // if we are here, then root itself is a synthetic VO.. should be good
           // to go
 
-          if (!root.get()) {
+          if (!root) {
             *reason_to_stop =
                 ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
             return nullptr;
           }
           root = root->GetChildAtIndex(index, true);
-          if (!root.get()) {
+          if (!root) {
             *reason_to_stop =
                 ValueObject::eExpressionPathScanEndReasonNoSuchChild;
             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
@@ -2689,7 +2689,7 @@ ValueObjectSP ValueObject::GetValueForEx
                 eTypeIsScalar)) // expansion only works for scalars
         {
           root = root->GetSyntheticBitFieldChild(low_index, high_index, true);
-          if (!root.get()) {
+          if (!root) {
             *reason_to_stop =
                 ValueObject::eExpressionPathScanEndReasonNoSuchChild;
             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
@@ -2710,7 +2710,7 @@ ValueObjectSP ValueObject::GetValueForEx
                    pointee_compiler_type_info.Test(eTypeIsScalar)) {
           Error error;
           root = root->Dereference(error);
-          if (error.Fail() || !root.get()) {
+          if (error.Fail() || !root) {
             *reason_to_stop =
                 ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;

Modified: lldb/trunk/source/Symbol/Variable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Variable.cpp?rev=287367&r1=287366&r2=287367&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Variable.cpp (original)
+++ lldb/trunk/source/Symbol/Variable.cpp Fri Nov 18 13:23:39 2016
@@ -331,119 +331,127 @@ bool Variable::IsInScope(StackFrame *fra
 }
 
 Error Variable::GetValuesForVariableExpressionPath(
-    const char *variable_expr_path, ExecutionContextScope *scope,
+    llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
     GetVariableCallback callback, void *baton, VariableList &variable_list,
     ValueObjectList &valobj_list) {
   Error error;
-  if (variable_expr_path && callback) {
-    switch (variable_expr_path[0]) {
-    case '*': {
-      error = Variable::GetValuesForVariableExpressionPath(
-          variable_expr_path + 1, scope, callback, baton, variable_list,
-          valobj_list);
-      if (error.Success()) {
-        for (uint32_t i = 0; i < valobj_list.GetSize();) {
-          Error tmp_error;
-          ValueObjectSP valobj_sp(
-              valobj_list.GetValueObjectAtIndex(i)->Dereference(tmp_error));
-          if (tmp_error.Fail()) {
-            variable_list.RemoveVariableAtIndex(i);
-            valobj_list.RemoveValueObjectAtIndex(i);
-          } else {
-            valobj_list.SetValueObjectAtIndex(i, valobj_sp);
-            ++i;
-          }
-        }
+  if (!callback || variable_expr_path.empty()) {
+    error.SetErrorString("unknown error");
+    return error;
+  }
+
+  switch (variable_expr_path.front()) {
+  case '*':
+    error = Variable::GetValuesForVariableExpressionPath(
+        variable_expr_path.drop_front(), scope, callback, baton, variable_list,
+        valobj_list);
+    if (error.Fail()) {
+      error.SetErrorString("unknown error");
+      return error;
+    }
+    for (uint32_t i = 0; i < valobj_list.GetSize();) {
+      Error tmp_error;
+      ValueObjectSP valobj_sp(
+          valobj_list.GetValueObjectAtIndex(i)->Dereference(tmp_error));
+      if (tmp_error.Fail()) {
+        variable_list.RemoveVariableAtIndex(i);
+        valobj_list.RemoveValueObjectAtIndex(i);
       } else {
-        error.SetErrorString("unknown error");
+        valobj_list.SetValueObjectAtIndex(i, valobj_sp);
+        ++i;
       }
-      return error;
-    } break;
-
-    case '&': {
-      error = Variable::GetValuesForVariableExpressionPath(
-          variable_expr_path + 1, scope, callback, baton, variable_list,
-          valobj_list);
-      if (error.Success()) {
-        for (uint32_t i = 0; i < valobj_list.GetSize();) {
-          Error tmp_error;
-          ValueObjectSP valobj_sp(
-              valobj_list.GetValueObjectAtIndex(i)->AddressOf(tmp_error));
-          if (tmp_error.Fail()) {
-            variable_list.RemoveVariableAtIndex(i);
-            valobj_list.RemoveValueObjectAtIndex(i);
-          } else {
-            valobj_list.SetValueObjectAtIndex(i, valobj_sp);
-            ++i;
-          }
+    }
+    return error;
+  case '&': {
+    error = Variable::GetValuesForVariableExpressionPath(
+        variable_expr_path.drop_front(), scope, callback, baton, variable_list,
+        valobj_list);
+    if (error.Success()) {
+      for (uint32_t i = 0; i < valobj_list.GetSize();) {
+        Error tmp_error;
+        ValueObjectSP valobj_sp(
+            valobj_list.GetValueObjectAtIndex(i)->AddressOf(tmp_error));
+        if (tmp_error.Fail()) {
+          variable_list.RemoveVariableAtIndex(i);
+          valobj_list.RemoveValueObjectAtIndex(i);
+        } else {
+          valobj_list.SetValueObjectAtIndex(i, valobj_sp);
+          ++i;
         }
-      } else {
-        error.SetErrorString("unknown error");
       }
+    } else {
+      error.SetErrorString("unknown error");
+    }
+    return error;
+  } break;
+
+  default: {
+    static RegularExpression g_regex(
+        llvm::StringRef("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)"));
+    RegularExpression::Match regex_match(1);
+    std::string variable_name;
+    variable_list.Clear();
+    if (!g_regex.Execute(variable_expr_path, &regex_match)) {
+      error.SetErrorStringWithFormat(
+          "unable to extract a variable name from '%s'", variable_expr_path);
       return error;
-    } break;
+    }
+    if (!regex_match.GetMatchAtIndex(variable_expr_path, 1, variable_name)) {
+      error.SetErrorStringWithFormat(
+          "unable to extract a variable name from '%s'", variable_expr_path);
+      return error;
+    }
+    if (!callback(baton, variable_name.c_str(), variable_list)) {
+      error.SetErrorString("unknown error");
+      return error;
+    }
+    uint32_t i = 0;
+    while (i < variable_list.GetSize()) {
+      VariableSP var_sp(variable_list.GetVariableAtIndex(i));
+      ValueObjectSP valobj_sp;
+      if (!var_sp) {
+        variable_list.RemoveVariableAtIndex(i);
+        continue;
+      }
+      ValueObjectSP variable_valobj_sp(
+          ValueObjectVariable::Create(scope, var_sp));
+      if (!variable_valobj_sp) {
+        variable_list.RemoveVariableAtIndex(i);
+        continue;
+      }
 
-    default: {
-      static RegularExpression g_regex(
-          llvm::StringRef("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)"));
-      RegularExpression::Match regex_match(1);
-      if (g_regex.Execute(llvm::StringRef::withNullAsEmpty(variable_expr_path),
-                          &regex_match)) {
-        std::string variable_name;
-        if (regex_match.GetMatchAtIndex(variable_expr_path, 1, variable_name)) {
-          variable_list.Clear();
-          if (callback(baton, variable_name.c_str(), variable_list)) {
-            uint32_t i = 0;
-            while (i < variable_list.GetSize()) {
-              VariableSP var_sp(variable_list.GetVariableAtIndex(i));
-              ValueObjectSP valobj_sp;
-              if (var_sp) {
-                ValueObjectSP variable_valobj_sp(
-                    ValueObjectVariable::Create(scope, var_sp));
-                if (variable_valobj_sp) {
-                  const char *variable_sub_expr_path =
-                      variable_expr_path + variable_name.size();
-                  if (*variable_sub_expr_path) {
-                    ValueObject::ExpressionPathScanEndReason reason_to_stop;
-                    ValueObject::ExpressionPathEndResultType final_value_type;
-                    ValueObject::GetValueForExpressionPathOptions options;
-                    ValueObject::ExpressionPathAftermath final_task_on_target;
-
-                    valobj_sp = variable_valobj_sp->GetValueForExpressionPath(
-                        variable_sub_expr_path, &reason_to_stop,
-                        &final_value_type, options, &final_task_on_target);
-                    if (!valobj_sp) {
-                      error.SetErrorStringWithFormat(
-                          "invalid expression path '%s' for variable '%s'",
-                          variable_sub_expr_path,
-                          var_sp->GetName().GetCString());
-                    }
-                  } else {
-                    // Just the name of a variable with no extras
-                    valobj_sp = variable_valobj_sp;
-                  }
-                }
-              }
-
-              if (!var_sp || !valobj_sp) {
-                variable_list.RemoveVariableAtIndex(i);
-              } else {
-                valobj_list.Append(valobj_sp);
-                ++i;
-              }
-            }
-
-            if (variable_list.GetSize() > 0) {
-              error.Clear();
-              return error;
-            }
-          }
+      llvm::StringRef variable_sub_expr_path =
+          variable_expr_path.drop_front(variable_name.size());
+      if (!variable_sub_expr_path.empty()) {
+        ValueObject::ExpressionPathScanEndReason reason_to_stop;
+        ValueObject::ExpressionPathEndResultType final_value_type;
+        ValueObject::GetValueForExpressionPathOptions options;
+        ValueObject::ExpressionPathAftermath final_task_on_target;
+
+        valobj_sp = variable_valobj_sp->GetValueForExpressionPath(
+            variable_sub_expr_path, &reason_to_stop, &final_value_type, options,
+            &final_task_on_target);
+        if (!valobj_sp) {
+          error.SetErrorStringWithFormat(
+              "invalid expression path '%s' for variable '%s'",
+              variable_sub_expr_path, var_sp->GetName().GetCString());
+          variable_list.RemoveVariableAtIndex(i);
+          continue;
         }
+      } else {
+        // Just the name of a variable with no extras
+        valobj_sp = variable_valobj_sp;
       }
-      error.SetErrorStringWithFormat(
-          "unable to extract a variable name from '%s'", variable_expr_path);
-    } break;
+
+      valobj_list.Append(valobj_sp);
+      ++i;
+    }
+
+    if (variable_list.GetSize() > 0) {
+      error.Clear();
+      return error;
     }
+  } break;
   }
   error.SetErrorString("unknown error");
   return error;




More information about the lldb-commits mailing list