Skip to content

Commit d1ea418

Browse files
authored
Add unit tests from lldb-eval (#5)
Add unit tests ported from lldb-eval. In order for the test suite to pass without errors, some tests were adjusted: * XFailed tests: caused by bugs currently present in DIL * Skipped tests under `GTEST_SKIP`: critical bugs that cause the test suite to crash * `DISABLED_` tests for unimplemented features (scoped evaluation, evaluation with context, separate parsing, UTF-8 support)
1 parent 21d4384 commit d1ea418

File tree

11 files changed

+5299
-0
lines changed

11 files changed

+5299
-0
lines changed

lldb/include/lldb/API/SBFrame.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class LLDB_API SBFrame {
122122
lldb::SBValue EvaluateExpression(const char *expr,
123123
const SBExpressionOptions &options);
124124

125+
lldb::SBValue EvaluateExpressionViaDIL(const char *expr,
126+
lldb::DynamicValueType use_dynamic);
127+
125128
/// Language plugins can use this API to report language-specific
126129
/// runtime information about this compile unit, such as additional
127130
/// language version details or feature flags.

lldb/source/API/SBFrame.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,82 @@ lldb::SBValue SBFrame::EvaluateExpression(const char *expr,
11551155
return expr_result;
11561156
}
11571157

1158+
lldb::SBValue
1159+
SBFrame::EvaluateExpressionViaDIL(const char *expr,
1160+
lldb::DynamicValueType use_dynamic) {
1161+
LLDB_INSTRUMENT_VA(this, expr);
1162+
Log *expr_log = GetLog(LLDBLog::Expressions);
1163+
SBValue expr_result;
1164+
if (expr == nullptr || expr[0] == '\0') {
1165+
return expr_result;
1166+
}
1167+
ValueObjectSP expr_value_sp;
1168+
std::unique_lock<std::recursive_mutex> lock;
1169+
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1170+
StackFrame *frame = nullptr;
1171+
Target *target = exe_ctx.GetTargetPtr();
1172+
Process *process = exe_ctx.GetProcessPtr();
1173+
SBExpressionOptions options;
1174+
options.SetFetchDynamicValue(use_dynamic);
1175+
if (target && process) {
1176+
Process::StopLocker stop_locker;
1177+
if (stop_locker.TryLock(&process->GetRunLock())) {
1178+
frame = exe_ctx.GetFramePtr();
1179+
if (frame) {
1180+
std::unique_ptr<llvm::PrettyStackTraceFormat> stack_trace;
1181+
if (target->GetDisplayExpressionsInCrashlogs()) {
1182+
StreamString frame_description;
1183+
frame->DumpUsingSettingsFormat(&frame_description);
1184+
stack_trace = std::make_unique<llvm::PrettyStackTraceFormat>(
1185+
"SBFrame::EvaluateExpressionViaDIL (expr = \"%s\", "
1186+
"fetch_dynamic_value "
1187+
"= %u) %s",
1188+
expr, options.GetFetchDynamicValue(),
1189+
frame_description.GetData());
1190+
}
1191+
VariableSP var_sp;
1192+
Status error;
1193+
expr_value_sp =
1194+
frame->GetValueForVariableExpressionPath( // DIL in ths branch
1195+
expr, use_dynamic,
1196+
StackFrame::eExpressionPathOptionCheckPtrVsMember |
1197+
StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
1198+
var_sp, error);
1199+
if (!error.Success()) {
1200+
expr_value_sp =
1201+
ValueObjectConstResult::Create(nullptr, std::move(error));
1202+
expr_result.SetSP(expr_value_sp, false);
1203+
} else {
1204+
expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
1205+
}
1206+
}
1207+
} else {
1208+
Status error;
1209+
error = Status::FromErrorString("can't evaluate expressions when the "
1210+
"process is running.");
1211+
expr_value_sp = ValueObjectConstResult::Create(nullptr, std::move(error));
1212+
expr_result.SetSP(expr_value_sp, false);
1213+
}
1214+
} else {
1215+
Status error;
1216+
error = Status::FromErrorString("sbframe object is not valid.");
1217+
expr_value_sp = ValueObjectConstResult::Create(nullptr, std::move(error));
1218+
expr_result.SetSP(expr_value_sp, false);
1219+
}
1220+
if (expr_result.GetError().Success())
1221+
LLDB_LOGF(expr_log,
1222+
"** [SBFrame::EvaluateExpressionViaDIL] Expression result is "
1223+
"%s, summary %s **",
1224+
expr_result.GetValue(), expr_result.GetSummary());
1225+
else
1226+
LLDB_LOGF(
1227+
expr_log,
1228+
"** [SBFrame::EvaluateExpressionViaDIL] Expression evaluation failed: "
1229+
"%s **",
1230+
expr_result.GetError().GetCString());
1231+
return expr_result;
1232+
}
1233+
11581234
SBStructuredData SBFrame::GetLanguageSpecificData() const {
11591235
LLDB_INSTRUMENT_VA(this);
11601236

lldb/unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ add_subdirectory(Breakpoint)
5555
add_subdirectory(Callback)
5656
add_subdirectory(Core)
5757
add_subdirectory(DataFormatter)
58+
add_subdirectory(DIL)
5859
add_subdirectory(Disassembler)
5960
add_subdirectory(Editline)
6061
add_subdirectory(Expression)

lldb/unittests/DIL/CMakeLists.txt

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

0 commit comments

Comments
 (0)