From c5d7df90356b1b3d1e384220e34ba5cb87583829 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Tue, 8 Nov 2016 04:52:16 +0000 Subject: [PATCH] Convert some Expression parser functions to StringRef. llvm-svn: 286208 --- lldb/include/lldb/Core/RegularExpression.h | 8 +- .../lldb/Expression/ExpressionVariable.h | 23 +-- .../lldb/Expression/LLVMUserExpression.h | 4 +- lldb/include/lldb/Expression/UserExpression.h | 6 +- lldb/include/lldb/Interpreter/Args.h | 5 +- lldb/include/lldb/Symbol/ClangASTContext.h | 2 +- lldb/include/lldb/Symbol/GoASTContext.h | 2 +- lldb/include/lldb/Symbol/TypeSystem.h | 2 +- lldb/include/lldb/Target/Target.h | 4 +- lldb/source/Breakpoint/BreakpointLocation.cpp | 2 +- lldb/source/Breakpoint/Watchpoint.cpp | 2 +- lldb/source/Core/RegularExpression.cpp | 15 +- lldb/source/Expression/LLVMUserExpression.cpp | 7 +- lldb/source/Expression/UserExpression.cpp | 28 ++- lldb/source/Interpreter/Args.cpp | 176 +++++++++--------- .../Clang/ClangUserExpression.cpp | 8 +- .../Clang/ClangUserExpression.h | 4 +- .../ExpressionParser/Go/GoUserExpression.cpp | 6 +- .../ExpressionParser/Go/GoUserExpression.h | 4 +- lldb/source/Symbol/ClangASTContext.cpp | 4 +- lldb/source/Symbol/GoASTContext.cpp | 6 +- lldb/source/Target/StopInfo.cpp | 11 +- lldb/source/Target/Target.cpp | 20 +- 23 files changed, 174 insertions(+), 175 deletions(-) diff --git a/lldb/include/lldb/Core/RegularExpression.h b/lldb/include/lldb/Core/RegularExpression.h index 8ae23183759a..5e36f5516ed4 100644 --- a/lldb/include/lldb/Core/RegularExpression.h +++ b/lldb/include/lldb/Core/RegularExpression.h @@ -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. diff --git a/lldb/include/lldb/Expression/ExpressionVariable.h b/lldb/include/lldb/Expression/ExpressionVariable.h index 459d15bb3e71..3f6b020139de 100644 --- a/lldb/include/lldb/Expression/ExpressionVariable.h +++ b/lldb/include/lldb/Expression/ExpressionVariable.h @@ -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) { diff --git a/lldb/include/lldb/Expression/LLVMUserExpression.h b/lldb/include/lldb/Expression/LLVMUserExpression.h index 8b525f4b3901..48d0161991d7 100644 --- a/lldb/include/lldb/Expression/LLVMUserExpression.h +++ b/lldb/include/lldb/Expression/LLVMUserExpression.h @@ -51,8 +51,8 @@ public: std::shared_ptr 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; diff --git a/lldb/include/lldb/Expression/UserExpression.h b/lldb/include/lldb/Expression/UserExpression.h index 55f34e89aaac..fca667e8ee96 100644 --- a/lldb/include/lldb/Expression/UserExpression.h +++ b/lldb/include/lldb/Expression/UserExpression.h @@ -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); diff --git a/lldb/include/lldb/Interpreter/Args.h b/lldb/include/lldb/Interpreter/Args.h index 2177ef72ebb7..70610f2566fc 100644 --- a/lldb/include/lldb/Interpreter/Args.h +++ b/lldb/include/lldb/Interpreter/Args.h @@ -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); diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index 5bc8b932bc06..4262ecb4bf0e 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -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; diff --git a/lldb/include/lldb/Symbol/GoASTContext.h b/lldb/include/lldb/Symbol/GoASTContext.h index 0482454012a6..5530a35493dc 100644 --- a/lldb/include/lldb/Symbol/GoASTContext.h +++ b/lldb/include/lldb/Symbol/GoASTContext.h @@ -416,7 +416,7 @@ class GoASTContextForExpr : public GoASTContext { 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; diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h index 341cf0bf9445..b4f84c0dd67c 100644 --- a/lldb/include/lldb/Symbol/TypeSystem.h +++ b/lldb/include/lldb/Symbol/TypeSystem.h @@ -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) { diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index fa29f0d944af..b81da488be85 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -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); diff --git a/lldb/source/Breakpoint/BreakpointLocation.cpp b/lldb/source/Breakpoint/BreakpointLocation.cpp index 22918026d6ec..578267a412d8 100644 --- a/lldb/source/Breakpoint/BreakpointLocation.cpp +++ b/lldb/source/Breakpoint/BreakpointLocation.cpp @@ -224,7 +224,7 @@ bool BreakpointLocation::ConditionSaysStop(ExecutionContext &exe_ctx, 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) diff --git a/lldb/source/Breakpoint/Watchpoint.cpp b/lldb/source/Breakpoint/Watchpoint.cpp index ce2ce8ba27cf..b213d0ee1b0f 100644 --- a/lldb/source/Breakpoint/Watchpoint.cpp +++ b/lldb/source/Breakpoint/Watchpoint.cpp @@ -288,7 +288,7 @@ void Watchpoint::SetCondition(const char *condition) { // 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... diff --git a/lldb/source/Core/RegularExpression.cpp b/lldb/source/Core/RegularExpression.cpp index 6be67f2450f6..54e0231556db 100644 --- a/lldb/source/Core/RegularExpression.cpp +++ b/lldb/source/Core/RegularExpression.cpp @@ -122,7 +122,7 @@ bool RegularExpression::Execute(llvm::StringRef str, Match *match) const { 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::GetMatchAtIndex(const char *s, uint32_t idx, } 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::GetMatchAtIndex( 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::GetMatchAtIndex( } 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::GetMatchSpanningIndices( 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; } } diff --git a/lldb/source/Expression/LLVMUserExpression.cpp b/lldb/source/Expression/LLVMUserExpression.cpp index 92347debd329..78207df56b09 100644 --- a/lldb/source/Expression/LLVMUserExpression.cpp +++ b/lldb/source/Expression/LLVMUserExpression.cpp @@ -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(), diff --git a/lldb/source/Expression/UserExpression.cpp b/lldb/source/Expression/UserExpression.cpp index 52ef6fa70033..041caf57bd31 100644 --- a/lldb/source/Expression/UserExpression.cpp +++ b/lldb/source/Expression/UserExpression.cpp @@ -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::GetObjectPointer(lldb::StackFrameSP frame_sp, 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::Evaluate( 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::Evaluate( } 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::Evaluate( 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(); diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp index 6653fbb6e5a4..a0a300affdd4 100644 --- a/lldb/source/Interpreter/Args.cpp +++ b/lldb/source/Interpreter/Args.cpp @@ -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') { + 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 - } - // Try base 16 with no prefix... - addr = ::strtoull(s, &end, 16); - if (*end == '\0') { - 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); + } 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, ®ex_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] == '+'; - ExpressionResults expr_result = target->EvaluateExpression( - s, exe_ctx->GetFramePtr(), valobj_sp, options); + if (regex_match.GetMatchAtIndex(s, 3, str)) { + offset = StringConvert::ToUInt64(str.c_str(), 0, 0, &success); - 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, ®ex_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 (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\"", diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index c456e411b19b..59dd137edd33 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -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() == diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h index 1aea69fd45f8..155c153b873c 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h @@ -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); diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp index 67b62ceaf7ef..ff20be1d22e5 100644 --- a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp @@ -198,12 +198,12 @@ CompilerType LookupType(TargetSP target, ConstString name) { } 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, diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h index 4976f694bd7a..03ceb76b8431 100644 --- a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h +++ b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h @@ -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); diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 75b7c3beaa22..0c2cfe58462b 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -10050,14 +10050,14 @@ ClangASTContextForExpressions::ClangASTContextForExpressions(Target &target) 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); } diff --git a/lldb/source/Symbol/GoASTContext.cpp b/lldb/source/Symbol/GoASTContext.cpp index 0393691f45c0..a28a6d756846 100644 --- a/lldb/source/Symbol/GoASTContext.cpp +++ b/lldb/source/Symbol/GoASTContext.cpp @@ -1435,12 +1435,12 @@ DWARFASTParser *GoASTContext::GetDWARFParser() { } 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; } diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp index d796071e968d..1f221d687e60 100644 --- a/lldb/source/Target/StopInfo.cpp +++ b/lldb/source/Target/StopInfo.cpp @@ -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; diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 3fb53009415e..53909d2218a9 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1961,7 +1961,7 @@ Target::GetPersistentExpressionStateForLanguage(lldb::LanguageType language) { } 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::GetUserExpressionForLanguage( 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(const ExecutionContext *exe_ctx_ptr, } 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::EvaluateExpression( // 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::EvaluateExpression( } 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;