[Lldb-commits] [lldb] r286208 - Convert some Expression parser functions to StringRef.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 7 20:52:17 PST 2016


Author: zturner
Date: Mon Nov  7 22:52:16 2016
New Revision: 286208

URL: http://llvm.org/viewvc/llvm-project?rev=286208&view=rev
Log:
Convert some Expression parser functions to StringRef.

Modified:
    lldb/trunk/include/lldb/Core/RegularExpression.h
    lldb/trunk/include/lldb/Expression/ExpressionVariable.h
    lldb/trunk/include/lldb/Expression/LLVMUserExpression.h
    lldb/trunk/include/lldb/Expression/UserExpression.h
    lldb/trunk/include/lldb/Interpreter/Args.h
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/include/lldb/Symbol/GoASTContext.h
    lldb/trunk/include/lldb/Symbol/TypeSystem.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/source/Breakpoint/BreakpointLocation.cpp
    lldb/trunk/source/Breakpoint/Watchpoint.cpp
    lldb/trunk/source/Core/RegularExpression.cpp
    lldb/trunk/source/Expression/LLVMUserExpression.cpp
    lldb/trunk/source/Expression/UserExpression.cpp
    lldb/trunk/source/Interpreter/Args.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
    lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
    lldb/trunk/source/Symbol/ClangASTContext.cpp
    lldb/trunk/source/Symbol/GoASTContext.cpp
    lldb/trunk/source/Target/StopInfo.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Core/RegularExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/RegularExpression.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/RegularExpression.h (original)
+++ lldb/trunk/include/lldb/Core/RegularExpression.h Mon Nov  7 22:52:16 2016
@@ -77,13 +77,14 @@ public:
       return (m_matches.empty() ? nullptr : m_matches.data());
     }
 
-    bool GetMatchAtIndex(const char *s, uint32_t idx,
+    bool GetMatchAtIndex(llvm::StringRef s, uint32_t idx,
                          std::string &match_str) const;
 
-    bool GetMatchAtIndex(const char *s, uint32_t idx,
+    bool GetMatchAtIndex(llvm::StringRef s, uint32_t idx,
                          llvm::StringRef &match_str) const;
 
-    bool GetMatchSpanningIndices(const char *s, uint32_t idx1, uint32_t idx2,
+    bool GetMatchSpanningIndices(llvm::StringRef s, uint32_t idx1,
+                                 uint32_t idx2,
                                  llvm::StringRef &match_str) const;
 
   protected:
@@ -100,7 +101,6 @@ public:
   RegularExpression();
 
   explicit RegularExpression(llvm::StringRef string);
-  explicit RegularExpression(const char *) = delete;
 
   //------------------------------------------------------------------
   /// Destructor.

Modified: lldb/trunk/include/lldb/Expression/ExpressionVariable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ExpressionVariable.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ExpressionVariable.h (original)
+++ lldb/trunk/include/lldb/Expression/ExpressionVariable.h Mon Nov  7 22:52:16 2016
@@ -189,20 +189,17 @@ public:
     return var_sp;
   }
 
-  lldb::ExpressionVariableSP GetVariable(const char *name) {
-    lldb::ExpressionVariableSP var_sp;
-    if (name && name[0]) {
-      for (size_t index = 0, size = GetSize(); index < size; ++index) {
-        var_sp = GetVariableAtIndex(index);
-        const char *var_name_cstr = var_sp->GetName().GetCString();
-        if (!var_name_cstr || !name)
-          continue;
-        if (::strcmp(var_name_cstr, name) == 0)
-          return var_sp;
-      }
-      var_sp.reset();
+  lldb::ExpressionVariableSP GetVariable(llvm::StringRef name) {
+    if (name.empty())
+      return nullptr;
+
+    for (size_t index = 0, size = GetSize(); index < size; ++index) {
+      auto var_sp = GetVariableAtIndex(index);
+      llvm::StringRef var_name_str = var_sp->GetName().GetStringRef();
+      if (var_name_str == name)
+        return var_sp;
     }
-    return var_sp;
+    return nullptr;
   }
 
   void RemoveVariable(lldb::ExpressionVariableSP var_sp) {

Modified: lldb/trunk/include/lldb/Expression/LLVMUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/LLVMUserExpression.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/LLVMUserExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/LLVMUserExpression.h Mon Nov  7 22:52:16 2016
@@ -51,8 +51,8 @@ public:
     std::shared_ptr<llvm::legacy::PassManager> LatePasses;
   };
 
-  LLVMUserExpression(ExecutionContextScope &exe_scope, const char *expr,
-                     const char *expr_prefix, lldb::LanguageType language,
+  LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
+                     llvm::StringRef prefix, lldb::LanguageType language,
                      ResultType desired_type,
                      const EvaluateExpressionOptions &options);
   ~LLVMUserExpression() override;

Modified: lldb/trunk/include/lldb/Expression/UserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/UserExpression.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/UserExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/UserExpression.h Mon Nov  7 22:52:16 2016
@@ -62,8 +62,8 @@ public:
   ///     If not eResultTypeAny, the type to use for the expression
   ///     result.
   //------------------------------------------------------------------
-  UserExpression(ExecutionContextScope &exe_scope, const char *expr,
-                 const char *expr_prefix, lldb::LanguageType language,
+  UserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
+                 llvm::StringRef prefix, lldb::LanguageType language,
                  ResultType desired_type,
                  const EvaluateExpressionOptions &options);
 
@@ -258,7 +258,7 @@ public:
   //------------------------------------------------------------------
   static lldb::ExpressionResults
   Evaluate(ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options,
-           const char *expr_cstr, const char *expr_prefix,
+           llvm::StringRef expr_cstr, llvm::StringRef expr_prefix,
            lldb::ValueObjectSP &result_valobj_sp, Error &error,
            uint32_t line_offset = 0, std::string *fixed_expression = nullptr,
            lldb::ModuleSP *jit_module_sp_ptr = nullptr);

Modified: lldb/trunk/include/lldb/Interpreter/Args.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Args.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/Args.h (original)
+++ lldb/trunk/include/lldb/Interpreter/Args.h Mon Nov  7 22:52:16 2016
@@ -358,10 +358,9 @@ public:
     return min <= sval64 && sval64 <= max;
   }
 
-  // TODO: Make this function take a StringRef
   static lldb::addr_t StringToAddress(const ExecutionContext *exe_ctx,
-                                      const char *s, lldb::addr_t fail_value,
-                                      Error *error);
+                                      llvm::StringRef s,
+                                      lldb::addr_t fail_value, Error *error);
 
   static bool StringToBoolean(llvm::StringRef s, bool fail_value,
                               bool *success_ptr);

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Mon Nov  7 22:52:16 2016
@@ -1010,7 +1010,7 @@ public:
   ~ClangASTContextForExpressions() override = default;
 
   UserExpression *
-  GetUserExpression(const char *expr, const char *expr_prefix,
+  GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix,
                     lldb::LanguageType language,
                     Expression::ResultType desired_type,
                     const EvaluateExpressionOptions &options) override;

Modified: lldb/trunk/include/lldb/Symbol/GoASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/GoASTContext.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/GoASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/GoASTContext.h Mon Nov  7 22:52:16 2016
@@ -416,7 +416,7 @@ class GoASTContextForExpr : public GoAST
 public:
   GoASTContextForExpr(lldb::TargetSP target) : m_target_wp(target) {}
   UserExpression *
-  GetUserExpression(const char *expr, const char *expr_prefix,
+  GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix,
                     lldb::LanguageType language,
                     Expression::ResultType desired_type,
                     const EvaluateExpressionOptions &options) override;

Modified: lldb/trunk/include/lldb/Symbol/TypeSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeSystem.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/TypeSystem.h (original)
+++ lldb/trunk/include/lldb/Symbol/TypeSystem.h Mon Nov  7 22:52:16 2016
@@ -450,7 +450,7 @@ public:
   }
 
   virtual UserExpression *
-  GetUserExpression(const char *expr, const char *expr_prefix,
+  GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix,
                     lldb::LanguageType language,
                     Expression::ResultType desired_type,
                     const EvaluateExpressionOptions &options) {

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Mon Nov  7 22:52:16 2016
@@ -984,7 +984,7 @@ public:
   // Returns a new-ed object which the caller owns.
 
   UserExpression *GetUserExpressionForLanguage(
-      const char *expr, const char *expr_prefix, lldb::LanguageType language,
+      llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language,
       Expression::ResultType desired_type,
       const EvaluateExpressionOptions &options, Error &error);
 
@@ -1049,7 +1049,7 @@ public:
   // If an expression is going to be run, then it should have a frame filled
   // in in th execution context.
   lldb::ExpressionResults EvaluateExpression(
-      const char *expression, ExecutionContextScope *exe_scope,
+      llvm::StringRef expression, ExecutionContextScope *exe_scope,
       lldb::ValueObjectSP &result_valobj_sp,
       const EvaluateExpressionOptions &options = EvaluateExpressionOptions(),
       std::string *fixed_expression = nullptr);

Modified: lldb/trunk/source/Breakpoint/BreakpointLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocation.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointLocation.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Mon Nov  7 22:52:16 2016
@@ -224,7 +224,7 @@ bool BreakpointLocation::ConditionSaysSt
       language = comp_unit->GetLanguage();
 
     m_user_expression_sp.reset(GetTarget().GetUserExpressionForLanguage(
-        condition_text, nullptr, language, Expression::eResultTypeAny,
+        condition_text, llvm::StringRef(), language, Expression::eResultTypeAny,
         EvaluateExpressionOptions(), error));
     if (error.Fail()) {
       if (log)

Modified: lldb/trunk/source/Breakpoint/Watchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/Watchpoint.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/Watchpoint.cpp (original)
+++ lldb/trunk/source/Breakpoint/Watchpoint.cpp Mon Nov  7 22:52:16 2016
@@ -288,7 +288,7 @@ void Watchpoint::SetCondition(const char
     // Pass nullptr for expr_prefix (no translation-unit level definitions).
     Error error;
     m_condition_ap.reset(m_target.GetUserExpressionForLanguage(
-        condition, nullptr, lldb::eLanguageTypeUnknown,
+        condition, llvm::StringRef(), lldb::eLanguageTypeUnknown,
         UserExpression::eResultTypeAny, EvaluateExpressionOptions(), error));
     if (error.Fail()) {
       // FIXME: Log something...

Modified: lldb/trunk/source/Core/RegularExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegularExpression.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Core/RegularExpression.cpp (original)
+++ lldb/trunk/source/Core/RegularExpression.cpp Mon Nov  7 22:52:16 2016
@@ -122,7 +122,7 @@ bool RegularExpression::Execute(llvm::St
   return true;
 }
 
-bool RegularExpression::Match::GetMatchAtIndex(const char *s, uint32_t idx,
+bool RegularExpression::Match::GetMatchAtIndex(llvm::StringRef s, uint32_t idx,
                                                std::string &match_str) const {
   llvm::StringRef match_str_ref;
   if (GetMatchAtIndex(s, idx, match_str_ref)) {
@@ -133,7 +133,7 @@ bool RegularExpression::Match::GetMatchA
 }
 
 bool RegularExpression::Match::GetMatchAtIndex(
-    const char *s, uint32_t idx, llvm::StringRef &match_str) const {
+    llvm::StringRef s, uint32_t idx, llvm::StringRef &match_str) const {
   if (idx < m_matches.size()) {
     if (m_matches[idx].rm_eo == -1 && m_matches[idx].rm_so == -1)
       return false;
@@ -143,8 +143,8 @@ bool RegularExpression::Match::GetMatchA
       match_str = llvm::StringRef();
       return true;
     } else if (m_matches[idx].rm_eo > m_matches[idx].rm_so) {
-      match_str = llvm::StringRef(s + m_matches[idx].rm_so,
-                                  m_matches[idx].rm_eo - m_matches[idx].rm_so);
+      match_str = s.substr(m_matches[idx].rm_so,
+                           m_matches[idx].rm_eo - m_matches[idx].rm_so);
       return true;
     }
   }
@@ -152,7 +152,7 @@ bool RegularExpression::Match::GetMatchA
 }
 
 bool RegularExpression::Match::GetMatchSpanningIndices(
-    const char *s, uint32_t idx1, uint32_t idx2,
+    llvm::StringRef s, uint32_t idx1, uint32_t idx2,
     llvm::StringRef &match_str) const {
   if (idx1 < m_matches.size() && idx2 < m_matches.size()) {
     if (m_matches[idx1].rm_so == m_matches[idx2].rm_eo) {
@@ -160,9 +160,8 @@ bool RegularExpression::Match::GetMatchS
       match_str = llvm::StringRef();
       return true;
     } else if (m_matches[idx1].rm_so < m_matches[idx2].rm_eo) {
-      match_str =
-          llvm::StringRef(s + m_matches[idx1].rm_so,
-                          m_matches[idx2].rm_eo - m_matches[idx1].rm_so);
+      match_str = s.substr(m_matches[idx1].rm_so,
+                           m_matches[idx2].rm_eo - m_matches[idx1].rm_so);
       return true;
     }
   }

Modified: lldb/trunk/source/Expression/LLVMUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/LLVMUserExpression.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Expression/LLVMUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/LLVMUserExpression.cpp Mon Nov  7 22:52:16 2016
@@ -42,13 +42,12 @@
 using namespace lldb_private;
 
 LLVMUserExpression::LLVMUserExpression(ExecutionContextScope &exe_scope,
-                                       const char *expr,
-                                       const char *expr_prefix,
+                                       llvm::StringRef expr,
+                                       llvm::StringRef prefix,
                                        lldb::LanguageType language,
                                        ResultType desired_type,
                                        const EvaluateExpressionOptions &options)
-    : UserExpression(exe_scope, expr, expr_prefix, language, desired_type,
-                     options),
+    : UserExpression(exe_scope, expr, prefix, language, desired_type, options),
       m_stack_frame_bottom(LLDB_INVALID_ADDRESS),
       m_stack_frame_top(LLDB_INVALID_ADDRESS), m_transformed_text(),
       m_execution_unit_sp(), m_materializer_ap(), m_jit_module_wp(),

Modified: lldb/trunk/source/Expression/UserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/UserExpression.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Expression/UserExpression.cpp (original)
+++ lldb/trunk/source/Expression/UserExpression.cpp Mon Nov  7 22:52:16 2016
@@ -47,13 +47,12 @@
 using namespace lldb_private;
 
 UserExpression::UserExpression(ExecutionContextScope &exe_scope,
-                               const char *expr, const char *expr_prefix,
+                               llvm::StringRef expr, llvm::StringRef prefix,
                                lldb::LanguageType language,
                                ResultType desired_type,
                                const EvaluateExpressionOptions &options)
-    : Expression(exe_scope), m_expr_text(expr),
-      m_expr_prefix(expr_prefix ? expr_prefix : ""), m_language(language),
-      m_desired_type(desired_type), m_options(options) {}
+    : Expression(exe_scope), m_expr_text(expr), m_expr_prefix(prefix),
+      m_language(language), m_desired_type(desired_type), m_options(options) {}
 
 UserExpression::~UserExpression() {}
 
@@ -140,7 +139,7 @@ lldb::addr_t UserExpression::GetObjectPo
 
 lldb::ExpressionResults UserExpression::Evaluate(
     ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options,
-    const char *expr_cstr, const char *expr_prefix,
+    llvm::StringRef expr, llvm::StringRef prefix,
     lldb::ValueObjectSP &result_valobj_sp, Error &error, uint32_t line_offset,
     std::string *fixed_expression, lldb::ModuleSP *jit_module_sp_ptr) {
   Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
@@ -187,16 +186,15 @@ lldb::ExpressionResults UserExpression::
   ThreadList::ExpressionExecutionThreadPusher execution_thread_pusher(
       thread_sp);
 
-  const char *full_prefix = NULL;
-  const char *option_prefix = options.GetPrefix();
+  llvm::StringRef full_prefix;
+  llvm::StringRef option_prefix(options.GetPrefix());
   std::string full_prefix_storage;
-  if (expr_prefix && option_prefix) {
-    full_prefix_storage.assign(expr_prefix);
+  if (!prefix.empty() && !option_prefix.empty()) {
+    full_prefix_storage = prefix;
     full_prefix_storage.append(option_prefix);
-    if (!full_prefix_storage.empty())
-      full_prefix = full_prefix_storage.c_str();
-  } else if (expr_prefix)
-    full_prefix = expr_prefix;
+    full_prefix = full_prefix_storage;
+  } else if (!prefix.empty())
+    full_prefix = prefix;
   else
     full_prefix = option_prefix;
 
@@ -211,7 +209,7 @@ lldb::ExpressionResults UserExpression::
   }
 
   lldb::UserExpressionSP user_expression_sp(
-      target->GetUserExpressionForLanguage(expr_cstr, full_prefix, language,
+      target->GetUserExpressionForLanguage(expr, full_prefix, language,
                                            desired_type, options, error));
   if (error.Fail()) {
     if (log)
@@ -222,7 +220,7 @@ lldb::ExpressionResults UserExpression::
 
   if (log)
     log->Printf("== [UserExpression::Evaluate] Parsing expression %s ==",
-                expr_cstr);
+                expr.str().c_str());
 
   const bool keep_expression_in_memory = true;
   const bool generate_debug_info = options.GetGenerateDebugInfo();

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Mon Nov  7 22:52:16 2016
@@ -550,106 +550,114 @@ void Args::Clear() {
 }
 
 lldb::addr_t Args::StringToAddress(const ExecutionContext *exe_ctx,
-                                   const char *s, lldb::addr_t fail_value,
+                                   llvm::StringRef s, lldb::addr_t fail_value,
                                    Error *error_ptr) {
   bool error_set = false;
-  if (s && s[0]) {
-    llvm::StringRef sref = s;
+  if (s.empty()) {
+    if (error_ptr)
+      error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
+                                          s.str().c_str());
+    return fail_value;
+  }
 
-    char *end = nullptr;
-    lldb::addr_t addr = ::strtoull(s, &end, 0);
-    if (*end == '\0') {
-      if (error_ptr)
-        error_ptr->Clear();
-      return addr; // All characters were used, return the result
-    }
-    // Try base 16 with no prefix...
-    addr = ::strtoull(s, &end, 16);
-    if (*end == '\0') {
+  llvm::StringRef sref = s;
+
+  lldb::addr_t addr = LLDB_INVALID_ADDRESS;
+  if (!s.getAsInteger(0, addr)) {
+    if (error_ptr)
+      error_ptr->Clear();
+    return addr;
+  }
+
+  // Try base 16 with no prefix...
+  if (!s.getAsInteger(16, addr)) {
+    if (error_ptr)
+      error_ptr->Clear();
+    return addr;
+  }
+
+  Target *target = nullptr;
+  if (!exe_ctx || !(target = exe_ctx->GetTargetPtr())) {
+    if (error_ptr)
+      error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
+                                          s.str().c_str());
+    return fail_value;
+  }
+
+  lldb::ValueObjectSP valobj_sp;
+  EvaluateExpressionOptions options;
+  options.SetCoerceToId(false);
+  options.SetUnwindOnError(true);
+  options.SetKeepInMemory(false);
+  options.SetTryAllThreads(true);
+
+  ExpressionResults expr_result =
+      target->EvaluateExpression(s, exe_ctx->GetFramePtr(), valobj_sp, options);
+
+  bool success = false;
+  if (expr_result == eExpressionCompleted) {
+    if (valobj_sp)
+      valobj_sp = valobj_sp->GetQualifiedRepresentationIfAvailable(
+          valobj_sp->GetDynamicValueType(), true);
+    // Get the address to watch.
+    if (valobj_sp)
+      addr = valobj_sp->GetValueAsUnsigned(fail_value, &success);
+    if (success) {
       if (error_ptr)
         error_ptr->Clear();
-      return addr; // All characters were used, return the result
+      return addr;
+    } else {
+      if (error_ptr) {
+        error_set = true;
+        error_ptr->SetErrorStringWithFormat(
+            "address expression \"%s\" resulted in a value whose type "
+            "can't be converted to an address: %s",
+            s, valobj_sp->GetTypeName().GetCString());
+      }
     }
 
-    if (exe_ctx) {
-      Target *target = exe_ctx->GetTargetPtr();
-      if (target) {
-        lldb::ValueObjectSP valobj_sp;
-        EvaluateExpressionOptions options;
-        options.SetCoerceToId(false);
-        options.SetUnwindOnError(true);
-        options.SetKeepInMemory(false);
-        options.SetTryAllThreads(true);
-
-        ExpressionResults expr_result = target->EvaluateExpression(
-            s, exe_ctx->GetFramePtr(), valobj_sp, options);
-
-        bool success = false;
-        if (expr_result == eExpressionCompleted) {
-          if (valobj_sp)
-            valobj_sp = valobj_sp->GetQualifiedRepresentationIfAvailable(
-                valobj_sp->GetDynamicValueType(), true);
-          // Get the address to watch.
-          if (valobj_sp)
-            addr = valobj_sp->GetValueAsUnsigned(fail_value, &success);
-          if (success) {
-            if (error_ptr)
-              error_ptr->Clear();
-            return addr;
-          } else {
-            if (error_ptr) {
-              error_set = true;
-              error_ptr->SetErrorStringWithFormat(
-                  "address expression \"%s\" resulted in a value whose type "
-                  "can't be converted to an address: %s",
-                  s, valobj_sp->GetTypeName().GetCString());
-            }
-          }
-
-        } else {
-          // Since the compiler can't handle things like "main + 12" we should
-          // try to do this for now. The compiler doesn't like adding offsets
-          // to function pointer types.
-          static RegularExpression g_symbol_plus_offset_regex(llvm::StringRef(
-              "^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$"));
-          RegularExpression::Match regex_match(3);
-          if (g_symbol_plus_offset_regex.Execute(sref, &regex_match)) {
-            uint64_t offset = 0;
-            bool add = true;
-            std::string name;
-            std::string str;
-            if (regex_match.GetMatchAtIndex(s, 1, name)) {
-              if (regex_match.GetMatchAtIndex(s, 2, str)) {
-                add = str[0] == '+';
-
-                if (regex_match.GetMatchAtIndex(s, 3, str)) {
-                  offset = StringConvert::ToUInt64(str.c_str(), 0, 0, &success);
-
-                  if (success) {
-                    Error error;
-                    addr = StringToAddress(exe_ctx, name.c_str(),
-                                           LLDB_INVALID_ADDRESS, &error);
-                    if (addr != LLDB_INVALID_ADDRESS) {
-                      if (add)
-                        return addr + offset;
-                      else
-                        return addr - offset;
-                    }
-                  }
-                }
+  } else {
+    // Since the compiler can't handle things like "main + 12" we should
+    // try to do this for now. The compiler doesn't like adding offsets
+    // to function pointer types.
+    static RegularExpression g_symbol_plus_offset_regex(
+        "^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
+    RegularExpression::Match regex_match(3);
+    if (g_symbol_plus_offset_regex.Execute(sref, &regex_match)) {
+      uint64_t offset = 0;
+      bool add = true;
+      std::string name;
+      std::string str;
+      if (regex_match.GetMatchAtIndex(s, 1, name)) {
+        if (regex_match.GetMatchAtIndex(s, 2, str)) {
+          add = str[0] == '+';
+
+          if (regex_match.GetMatchAtIndex(s, 3, str)) {
+            offset = StringConvert::ToUInt64(str.c_str(), 0, 0, &success);
+
+            if (success) {
+              Error error;
+              addr = StringToAddress(exe_ctx, name.c_str(),
+                                     LLDB_INVALID_ADDRESS, &error);
+              if (addr != LLDB_INVALID_ADDRESS) {
+                if (add)
+                  return addr + offset;
+                else
+                  return addr - offset;
               }
             }
           }
-
-          if (error_ptr) {
-            error_set = true;
-            error_ptr->SetErrorStringWithFormat(
-                "address expression \"%s\" evaluation failed", s);
-          }
         }
       }
     }
+
+    if (error_ptr) {
+      error_set = true;
+      error_ptr->SetErrorStringWithFormat(
+          "address expression \"%s\" evaluation failed", s);
+    }
   }
+
   if (error_ptr) {
     if (!error_set)
       error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp Mon Nov  7 22:52:16 2016
@@ -58,10 +58,10 @@
 using namespace lldb_private;
 
 ClangUserExpression::ClangUserExpression(
-    ExecutionContextScope &exe_scope, const char *expr, const char *expr_prefix,
-    lldb::LanguageType language, ResultType desired_type,
-    const EvaluateExpressionOptions &options)
-    : LLVMUserExpression(exe_scope, expr, expr_prefix, language, desired_type,
+    ExecutionContextScope &exe_scope, llvm::StringRef expr,
+    llvm::StringRef prefix, lldb::LanguageType language,
+    ResultType desired_type, const EvaluateExpressionOptions &options)
+    : LLVMUserExpression(exe_scope, expr, prefix, language, desired_type,
                          options),
       m_type_system_helper(*m_target_wp.lock().get(),
                            options.GetExecutionPolicy() ==

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h Mon Nov  7 22:52:16 2016
@@ -111,8 +111,8 @@ public:
   ///     If not eResultTypeAny, the type to use for the expression
   ///     result.
   //------------------------------------------------------------------
-  ClangUserExpression(ExecutionContextScope &exe_scope, const char *expr,
-                      const char *expr_prefix, lldb::LanguageType language,
+  ClangUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
+                      llvm::StringRef prefix, lldb::LanguageType language,
                       ResultType desired_type,
                       const EvaluateExpressionOptions &options);
 

Modified: lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp Mon Nov  7 22:52:16 2016
@@ -198,12 +198,12 @@ CompilerType LookupType(TargetSP target,
 }
 
 GoUserExpression::GoUserExpression(ExecutionContextScope &exe_scope,
-                                   const char *expr, const char *expr_prefix,
+                                   llvm::StringRef expr, llvm::StringRef prefix,
                                    lldb::LanguageType language,
                                    ResultType desired_type,
                                    const EvaluateExpressionOptions &options)
-    : UserExpression(exe_scope, expr, expr_prefix, language, desired_type,
-                     options) {}
+    : UserExpression(exe_scope, expr, prefix, language, desired_type, options) {
+}
 
 bool GoUserExpression::Parse(DiagnosticManager &diagnostic_manager,
                              ExecutionContext &exe_ctx,

Modified: lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h Mon Nov  7 22:52:16 2016
@@ -57,8 +57,8 @@ private:
 //----------------------------------------------------------------------
 class GoUserExpression : public UserExpression {
 public:
-  GoUserExpression(ExecutionContextScope &exe_scope, const char *expr,
-                   const char *expr_prefix, lldb::LanguageType language,
+  GoUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
+                   llvm::StringRef prefix, lldb::LanguageType language,
                    ResultType desired_type,
                    const EvaluateExpressionOptions &options);
 

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Mon Nov  7 22:52:16 2016
@@ -10050,14 +10050,14 @@ ClangASTContextForExpressions::ClangASTC
       m_persistent_variables(new ClangPersistentVariables) {}
 
 UserExpression *ClangASTContextForExpressions::GetUserExpression(
-    const char *expr, const char *expr_prefix, lldb::LanguageType language,
+    llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language,
     Expression::ResultType desired_type,
     const EvaluateExpressionOptions &options) {
   TargetSP target_sp = m_target_wp.lock();
   if (!target_sp)
     return nullptr;
 
-  return new ClangUserExpression(*target_sp.get(), expr, expr_prefix, language,
+  return new ClangUserExpression(*target_sp.get(), expr, prefix, language,
                                  desired_type, options);
 }
 

Modified: lldb/trunk/source/Symbol/GoASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/GoASTContext.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/GoASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/GoASTContext.cpp Mon Nov  7 22:52:16 2016
@@ -1435,12 +1435,12 @@ DWARFASTParser *GoASTContext::GetDWARFPa
 }
 
 UserExpression *GoASTContextForExpr::GetUserExpression(
-    const char *expr, const char *expr_prefix, lldb::LanguageType language,
+    llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language,
     Expression::ResultType desired_type,
     const EvaluateExpressionOptions &options) {
   TargetSP target = m_target_wp.lock();
   if (target)
-    return new GoUserExpression(*target, expr, expr_prefix, language,
-                                desired_type, options);
+    return new GoUserExpression(*target, expr, prefix, language, desired_type,
+                                options);
   return nullptr;
 }

Modified: lldb/trunk/source/Target/StopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StopInfo.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Target/StopInfo.cpp (original)
+++ lldb/trunk/source/Target/StopInfo.cpp Mon Nov  7 22:52:16 2016
@@ -764,8 +764,8 @@ protected:
 
         if (m_should_stop && wp_sp->GetConditionText() != nullptr) {
           // We need to make sure the user sees any parse errors in their
-          // condition, so we'll hook the
-          // constructor errors up to the debugger's Async I/O.
+          // condition, so we'll hook the constructor errors up to the
+          // debugger's Async I/O.
           ExpressionResults result_code;
           EvaluateExpressionOptions expr_options;
           expr_options.SetUnwindOnError(true);
@@ -773,8 +773,8 @@ protected:
           ValueObjectSP result_value_sp;
           Error error;
           result_code = UserExpression::Evaluate(
-              exe_ctx, expr_options, wp_sp->GetConditionText(), nullptr,
-              result_value_sp, error);
+              exe_ctx, expr_options, wp_sp->GetConditionText(),
+              llvm::StringRef(), result_value_sp, error);
 
           if (result_code == eExpressionCompleted) {
             if (result_value_sp) {
@@ -784,8 +784,7 @@ protected:
                   // We have been vetoed.  This takes precedence over querying
                   // the watchpoint whether it should stop (aka ignore count and
                   // friends).  See also StopInfoWatchpoint::ShouldStop() as
-                  // well
-                  // as Process::ProcessEventData::DoOnRemoval().
+                  // well as Process::ProcessEventData::DoOnRemoval().
                   m_should_stop = false;
                 } else
                   m_should_stop = true;

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=286208&r1=286207&r2=286208&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon Nov  7 22:52:16 2016
@@ -1961,7 +1961,7 @@ Target::GetPersistentExpressionStateForL
 }
 
 UserExpression *Target::GetUserExpressionForLanguage(
-    const char *expr, const char *expr_prefix, lldb::LanguageType language,
+    llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language,
     Expression::ResultType desired_type,
     const EvaluateExpressionOptions &options, Error &error) {
   Error type_system_error;
@@ -1978,7 +1978,7 @@ UserExpression *Target::GetUserExpressio
     return nullptr;
   }
 
-  user_expr = type_system->GetUserExpression(expr, expr_prefix, language,
+  user_expr = type_system->GetUserExpression(expr, prefix, language,
                                              desired_type, options);
   if (!user_expr)
     error.SetErrorStringWithFormat(
@@ -2118,14 +2118,14 @@ Target *Target::GetTargetFromContexts(co
 }
 
 ExpressionResults Target::EvaluateExpression(
-    const char *expr_cstr, ExecutionContextScope *exe_scope,
+    llvm::StringRef expr, ExecutionContextScope *exe_scope,
     lldb::ValueObjectSP &result_valobj_sp,
     const EvaluateExpressionOptions &options, std::string *fixed_expression) {
   result_valobj_sp.reset();
 
   ExpressionResults execution_results = eExpressionSetupError;
 
-  if (expr_cstr == nullptr || expr_cstr[0] == '\0')
+  if (expr.empty())
     return execution_results;
 
   // We shouldn't run stop hooks in expressions.
@@ -2147,10 +2147,10 @@ ExpressionResults Target::EvaluateExpres
   // variable (something like "$0")
   lldb::ExpressionVariableSP persistent_var_sp;
   // Only check for persistent variables the expression starts with a '$'
-  if (expr_cstr[0] == '$')
+  if (expr[0] == '$')
     persistent_var_sp = GetScratchTypeSystemForLanguage(nullptr, eLanguageTypeC)
                             ->GetPersistentExpressionState()
-                            ->GetVariable(expr_cstr);
+                            ->GetVariable(expr);
 
   if (persistent_var_sp) {
     result_valobj_sp = persistent_var_sp->GetValueObject();
@@ -2158,10 +2158,10 @@ ExpressionResults Target::EvaluateExpres
   } else {
     const char *prefix = GetExpressionPrefixContentsAsCString();
     Error error;
-    execution_results = UserExpression::Evaluate(
-        exe_ctx, options, expr_cstr, prefix, result_valobj_sp, error,
-        0, // Line Number
-        fixed_expression);
+    execution_results = UserExpression::Evaluate(exe_ctx, options, expr, prefix,
+                                                 result_valobj_sp, error,
+                                                 0, // Line Number
+                                                 fixed_expression);
   }
 
   m_suppress_stop_hooks = old_suppress_value;




More information about the lldb-commits mailing list