Skip to content

Commit ec39954

Browse files
augusto2112sr-tream
authored andcommitted
[lldb] Add interface to check if UserExpression::Parse() is cacheable (llvm#66826)
When setting conditional breakpoints, we currently assume that a call to UserExpression::Parse() can be cached and resued multiple times. This may not be true for every user expression. Add a new method so subclasses of UserExpression can customize if they are parseable or not.
1 parent 8290fd2 commit ec39954

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lldb/include/lldb/Expression/UserExpression.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ class UserExpression : public Expression {
192192
/// expression. Text() should contain the definition of this function.
193193
const char *FunctionName() override { return "$__lldb_expr"; }
194194

195+
/// Returns whether the call to Parse on this user expression is cacheable.
196+
/// This function exists to provide an escape hatch for supporting languages
197+
/// where parsing an expression in the exact same context is unsafe. For
198+
/// example, languages where generic functions aren't monomorphized, but
199+
/// implement some other mechanism to represent generic values, may be unsafe
200+
/// to cache, as the concrete type substitution may be different in every
201+
/// expression evaluation.
202+
virtual bool IsParseCacheable() { return true; }
195203
/// Return the language that should be used when parsing. To use the
196204
/// default, return eLanguageTypeUnknown.
197205
lldb::LanguageType Language() const override { return m_language; }

lldb/source/Breakpoint/BreakpointLocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ bool BreakpointLocation::ConditionSaysStop(ExecutionContext &exe_ctx,
250250
DiagnosticManager diagnostics;
251251

252252
if (condition_hash != m_condition_hash || !m_user_expression_sp ||
253+
!m_user_expression_sp->IsParseCacheable() ||
253254
!m_user_expression_sp->MatchesContext(exe_ctx)) {
254255
LanguageType language = eLanguageTypeUnknown;
255256
// See if we can figure out the language from the frame, otherwise use the

0 commit comments

Comments
 (0)