summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-11-08 04:52:16 +0000
committerZachary Turner <zturner@google.com>2016-11-08 04:52:16 +0000
commit6b8dd6564c9448d029bea805443ab4b168e9a07d (patch)
tree117d624162d8fa9d02f251218ee93d3bb38e144c
parent5f20ace184af891d91faa6a77b4fc3c9c3ac3672 (diff)
Convert some Expression parser functions to StringRef.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@286208 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/lldb/Core/RegularExpression.h8
-rw-r--r--include/lldb/Expression/ExpressionVariable.h23
-rw-r--r--include/lldb/Expression/LLVMUserExpression.h4
-rw-r--r--include/lldb/Expression/UserExpression.h6
-rw-r--r--include/lldb/Interpreter/Args.h5
-rw-r--r--include/lldb/Symbol/ClangASTContext.h2
-rw-r--r--include/lldb/Symbol/GoASTContext.h2
-rw-r--r--include/lldb/Symbol/TypeSystem.h2
-rw-r--r--include/lldb/Target/Target.h4
-rw-r--r--source/Breakpoint/BreakpointLocation.cpp2
-rw-r--r--source/Breakpoint/Watchpoint.cpp2
-rw-r--r--source/Core/RegularExpression.cpp15
-rw-r--r--source/Expression/LLVMUserExpression.cpp7
-rw-r--r--source/Expression/UserExpression.cpp28
-rw-r--r--source/Interpreter/Args.cpp180
-rw-r--r--source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp8
-rw-r--r--source/Plugins/ExpressionParser/Clang/ClangUserExpression.h4
-rw-r--r--source/Plugins/ExpressionParser/Go/GoUserExpression.cpp6
-rw-r--r--source/Plugins/ExpressionParser/Go/GoUserExpression.h4
-rw-r--r--source/Symbol/ClangASTContext.cpp4
-rw-r--r--source/Symbol/GoASTContext.cpp6
-rw-r--r--source/Target/StopInfo.cpp11
-rw-r--r--source/Target/Target.cpp20
23 files changed, 176 insertions, 177 deletions
diff --git a/include/lldb/Core/RegularExpression.h b/include/lldb/Core/RegularExpression.h
index 8ae231837..5e36f5516 100644
--- a/include/lldb/Core/RegularExpression.h
+++ b/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/include/lldb/Expression/ExpressionVariable.h b/include/lldb/Expression/ExpressionVariable.h
index 459d15bb3..3f6b02013 100644
--- a/include/lldb/Expression/ExpressionVariable.h
+++ b/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/include/lldb/Expression/LLVMUserExpression.h b/include/lldb/Expression/LLVMUserExpression.h
index 8b525f4b3..48d016199 100644
--- a/include/lldb/Expression/LLVMUserExpression.h
+++ b/include/lldb/Expression/LLVMUserExpression.h
@@ -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;
diff --git a/include/lldb/Expression/UserExpression.h b/include/lldb/Expression/UserExpression.h
index 55f34e89a..fca667e8e 100644
--- a/include/lldb/Expression/UserExpression.h
+++ b/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/include/lldb/Interpreter/Args.h b/include/lldb/Interpreter/Args.h
index 2177ef72e..70610f256 100644
--- a/include/lldb/Interpreter/Args.h
+++ b/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/include/lldb/Symbol/ClangASTContext.h b/include/lldb/Symbol/ClangASTContext.h
index 5bc8b932b..4262ecb4b 100644
--- a/include/lldb/Symbol/ClangASTContext.h
+++ b/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/include/lldb/Symbol/GoASTContext.h b/include/lldb/Symbol/GoASTContext.h
index 048245401..5530a3549 100644
--- a/include/lldb/Symbol/GoASTContext.h
+++ b/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/include/lldb/Symbol/TypeSystem.h b/include/lldb/Symbol/TypeSystem.h
index 341cf0bf9..b4f84c0dd 100644
--- a/include/lldb/Symbol/TypeSystem.h
+++ b/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/include/lldb/Target/Target.h b/include/lldb/Target/Target.h
index fa29f0d94..b81da488b 100644
--- a/include/lldb/Target/Target.h
+++ b/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/source/Breakpoint/BreakpointLocation.cpp b/source/Breakpoint/BreakpointLocation.cpp
index 22918026d..578267a41 100644
--- a/source/Breakpoint/BreakpointLocation.cpp
+++ b/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/source/Breakpoint/Watchpoint.cpp b/source/Breakpoint/Watchpoint.cpp
index ce2ce8ba2..b213d0ee1 100644
--- a/source/Breakpoint/Watchpoint.cpp
+++ b/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/source/Core/RegularExpression.cpp b/source/Core/RegularExpression.cpp
index 6be67f245..54e023155 100644
--- a/source/Core/RegularExpression.cpp
+++ b/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/source/Expression/LLVMUserExpression.cpp b/source/Expression/LLVMUserExpression.cpp
index 92347debd..78207df56 100644
--- a/source/Expression/LLVMUserExpression.cpp
+++ b/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/source/Expression/UserExpression.cpp b/source/Expression/UserExpression.cpp
index 52ef6fa70..041caf57b 100644
--- a/source/Expression/UserExpression.cpp
+++ b/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/source/Interpreter/Args.cpp b/source/Interpreter/Args.cpp
index 6653fbb6e..a0a300aff 100644
--- a/source/Interpreter/Args.cpp
+++ b/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') {
- 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\"",
diff --git a/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
index c456e411b..59dd137ed 100644
--- a/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ b/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/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h b/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
index 1aea69fd4..155c153b8 100644
--- a/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
+++ b/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/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp b/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
index 67b62ceaf..ff20be1d2 100644
--- a/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
+++ b/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/source/Plugins/ExpressionParser/Go/GoUserExpression.h b/source/Plugins/ExpressionParser/Go/GoUserExpression.h
index 4976f694b..03ceb76b8 100644
--- a/source/Plugins/ExpressionParser/Go/GoUserExpression.h
+++ b/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/source/Symbol/ClangASTContext.cpp b/source/Symbol/ClangASTContext.cpp
index 75b7c3bea..0c2cfe584 100644
--- a/source/Symbol/ClangASTContext.cpp
+++ b/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/source/Symbol/GoASTContext.cpp b/source/Symbol/GoASTContext.cpp
index 0393691f4..a28a6d756 100644
--- a/source/Symbol/GoASTContext.cpp
+++ b/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/source/Target/StopInfo.cpp b/source/Target/StopInfo.cpp
index d796071e9..1f221d687 100644
--- a/source/Target/StopInfo.cpp
+++ b/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/source/Target/Target.cpp b/source/Target/Target.cpp
index 3fb530094..53909d221 100644
--- a/source/Target/Target.cpp
+++ b/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;