Skip to content

Commit 36d4f95

Browse files
committed
Fix parsing, remove dereferencing, add unit tests
1 parent 58c4f08 commit 36d4f95

File tree

17 files changed

+1856
-15
lines changed

17 files changed

+1856
-15
lines changed

lldb/docs/dil-expr-lang.ebnf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
66
expression = unary_expression ;
77
8-
unary_expression = unary_operator primary_expression ;
8+
unary_expression = unary_operator expression
9+
| primary_expression ;
10+
11+
unary_operator = "*" | "&" ;
912
1013
primary_expression = id_expression
1114
| "(" expression ")";

lldb/include/lldb/API/SBFrame.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ class LLDB_API SBFrame {
182182
// variable value.
183183
lldb::SBValue GetValueForVariablePath(const char *var_expr_cstr,
184184
DynamicValueType use_dynamic);
185+
lldb::SBValue TestGetValueForVariablePath(const char *var_expr_cstr,
186+
DynamicValueType use_dynamic,
187+
bool use_DIL = false);
185188

186189
/// The version that doesn't supply a 'use_dynamic' value will use the
187190
/// target's default.

lldb/include/lldb/Target/StackFrame.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ class StackFrame : public ExecutionContextScope,
308308
lldb::ValueObjectSP GetValueForVariableExpressionPath(
309309
llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic,
310310
uint32_t options, lldb::VariableSP &var_sp, Status &error);
311+
lldb::ValueObjectSP GetValueForVariableExpressionPath(
312+
llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic,
313+
uint32_t options, lldb::VariableSP &var_sp, Status &error, bool use_DIL);
311314

312315
/// Determine whether this StackFrame has debug information available or not.
313316
///

lldb/source/API/SBFrame.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,41 @@ lldb::SBValue SBFrame::GetValueForVariablePath(const char *var_path,
492492
return sb_value;
493493
}
494494

495+
lldb::SBValue SBFrame::TestGetValueForVariablePath(const char *var_path,
496+
DynamicValueType use_dynamic,
497+
bool use_DIL) {
498+
LLDB_INSTRUMENT_VA(this, var_path, use_dynamic);
499+
500+
SBValue sb_value;
501+
if (var_path == nullptr || var_path[0] == '\0') {
502+
return sb_value;
503+
}
504+
505+
std::unique_lock<std::recursive_mutex> lock;
506+
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
507+
508+
StackFrame *frame = nullptr;
509+
Target *target = exe_ctx.GetTargetPtr();
510+
Process *process = exe_ctx.GetProcessPtr();
511+
if (target && process) {
512+
Process::StopLocker stop_locker;
513+
if (stop_locker.TryLock(&process->GetRunLock())) {
514+
frame = exe_ctx.GetFramePtr();
515+
if (frame) {
516+
VariableSP var_sp;
517+
Status error;
518+
ValueObjectSP value_sp(frame->GetValueForVariableExpressionPath(
519+
var_path, eNoDynamicValues,
520+
StackFrame::eExpressionPathOptionCheckPtrVsMember |
521+
StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
522+
var_sp, error, use_DIL));
523+
sb_value.SetSP(value_sp, use_dynamic);
524+
}
525+
}
526+
}
527+
return sb_value;
528+
}
529+
495530
SBValue SBFrame::FindVariable(const char *name) {
496531
LLDB_INSTRUMENT_VA(this, name);
497532

lldb/source/Target/StackFrame.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,17 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
523523
var_sp, error);
524524
}
525525

526+
ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
527+
llvm::StringRef var_expr, DynamicValueType use_dynamic, uint32_t options,
528+
VariableSP &var_sp, Status &error, bool use_DIL) {
529+
if (use_DIL)
530+
return DILGetValueForVariableExpressionPath(var_expr, use_dynamic, options,
531+
var_sp, error);
532+
533+
return LegacyGetValueForVariableExpressionPath(var_expr, use_dynamic, options,
534+
var_sp, error);
535+
}
536+
526537
ValueObjectSP StackFrame::DILGetValueForVariableExpressionPath(
527538
llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic,
528539
uint32_t options, lldb::VariableSP &var_sp, Status &error) {
@@ -538,7 +549,7 @@ ValueObjectSP StackFrame::DILGetValueForVariableExpressionPath(
538549
auto lex_or_err = dil::DILLexer::Create(var_expr);
539550
if (!lex_or_err) {
540551
error = Status::FromError(lex_or_err.takeError());
541-
return ValueObjectSP();
552+
return ValueObjectConstResult::Create(nullptr, std::move(error));
542553
}
543554

544555
// Parse the expression.
@@ -547,7 +558,7 @@ ValueObjectSP StackFrame::DILGetValueForVariableExpressionPath(
547558
!no_synth_child, !no_fragile_ivar, check_ptr_vs_member);
548559
if (!tree_or_error) {
549560
error = Status::FromError(tree_or_error.takeError());
550-
return ValueObjectSP();
561+
return ValueObjectConstResult::Create(nullptr, std::move(error));
551562
}
552563

553564
// Evaluate the parsed expression.
@@ -558,7 +569,7 @@ ValueObjectSP StackFrame::DILGetValueForVariableExpressionPath(
558569
auto valobj_or_error = interpreter.Evaluate((*tree_or_error).get());
559570
if (!valobj_or_error) {
560571
error = Status::FromError(valobj_or_error.takeError());
561-
return ValueObjectSP();
572+
return ValueObjectConstResult::Create(nullptr, std::move(error));
562573
}
563574

564575
return *valobj_or_error;

lldb/source/ValueObject/DILEval.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,6 @@ Interpreter::Visit(const UnaryOpNode *node) {
275275
}
276276
lldb::ValueObjectSP rhs = *rhs_or_err;
277277

278-
if (rhs->GetCompilerType().IsReferenceType()) {
279-
rhs = rhs->Dereference(error);
280-
if (error.Fail()) {
281-
return llvm::make_error<DILDiagnosticError>(m_expr, error.AsCString(),
282-
node->GetLocation());
283-
}
284-
}
285278
CompilerType rhs_type = rhs->GetCompilerType();
286279
switch (node->kind()) {
287280
case UnaryOpKind::Deref: {
@@ -292,8 +285,14 @@ Interpreter::Visit(const UnaryOpNode *node) {
292285
if (dynamic_rhs)
293286
rhs = dynamic_rhs;
294287

295-
if (rhs->GetCompilerType().IsPointerType())
288+
if (rhs->GetCompilerType().IsPointerType()) {
289+
if (rhs->GetCompilerType().IsPointerToVoid()) {
290+
return llvm::make_error<DILDiagnosticError>(
291+
m_expr, "indirection not permitted on operand of type 'void *'",
292+
node->GetLocation(), 1);
293+
}
296294
return EvaluateDereference(rhs);
295+
}
297296
lldb::ValueObjectSP child_sp = rhs->Dereference(error);
298297
if (error.Success())
299298
rhs = child_sp;

lldb/source/ValueObject/DILParser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ ASTNodeUP DILParser::ParseExpression() { return ParseUnaryExpression(); }
8787
// Parse an unary_expression.
8888
//
8989
// unary_expression:
90-
// unary_operator primary_expression
90+
// unary_operator expression
91+
// primary_expression
9192
//
9293
// unary_operator:
9394
// "&"
@@ -98,7 +99,7 @@ ASTNodeUP DILParser::ParseUnaryExpression() {
9899
Token token = CurToken();
99100
uint32_t loc = token.GetLocation();
100101
m_dil_lexer.Advance();
101-
auto rhs = ParsePrimaryExpression();
102+
auto rhs = ParseExpression();
102103
switch (token.GetKind()) {
103104
case Token::star:
104105
return std::make_unique<UnaryOpNode>(loc, UnaryOpKind::Deref,

lldb/unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ endif()
5454
add_subdirectory(Breakpoint)
5555
add_subdirectory(Callback)
5656
add_subdirectory(Core)
57+
add_subdirectory(DIL)
5758
add_subdirectory(DataFormatter)
5859
add_subdirectory(Disassembler)
5960
add_subdirectory(Editline)

lldb/unittests/DIL/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
add_lldb_unittest(DILTests
2+
DILTests.cpp
3+
DILLexerTests.cpp
4+
Runner.cpp
5+
6+
LINK_LIBS
7+
liblldb
8+
lldbUtilityHelpers
9+
lldbValueObject
10+
LLVMTestingSupport
11+
)
12+
add_subdirectory(Inputs)
13+
add_dependencies(DILTests test_binary)
14+
15+
add_unittest_inputs(DILTests "test_binary.cpp")

0 commit comments

Comments
 (0)