Skip to content

Commit 6af87f9

Browse files
committed
lldb: do not show misleading error when there is no frame
1 parent 66f9448 commit 6af87f9

File tree

2 files changed

+25
-39
lines changed

2 files changed

+25
-39
lines changed

lldb/source/API/SBFrame.cpp

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <algorithm>
109
#include <set>
1110
#include <string>
1211

@@ -18,11 +17,8 @@
1817
#include "lldb/Core/Address.h"
1918
#include "lldb/Core/Debugger.h"
2019
#include "lldb/Expression/ExpressionVariable.h"
21-
#include "lldb/Expression/UserExpression.h"
22-
#include "lldb/Host/Host.h"
2320
#include "lldb/Symbol/Block.h"
2421
#include "lldb/Symbol/Function.h"
25-
#include "lldb/Symbol/Symbol.h"
2622
#include "lldb/Symbol/SymbolContext.h"
2723
#include "lldb/Symbol/Variable.h"
2824
#include "lldb/Symbol/VariableList.h"
@@ -33,7 +29,6 @@
3329
#include "lldb/Target/StackFrameRecognizer.h"
3430
#include "lldb/Target/StackID.h"
3531
#include "lldb/Target/Target.h"
36-
#include "lldb/Target/Thread.h"
3732
#include "lldb/Utility/ConstString.h"
3833
#include "lldb/Utility/Instrumentation.h"
3934
#include "lldb/Utility/LLDBLog.h"
@@ -43,7 +38,6 @@
4338
#include "lldb/ValueObject/ValueObjectVariable.h"
4439

4540
#include "lldb/API/SBAddress.h"
46-
#include "lldb/API/SBDebugger.h"
4741
#include "lldb/API/SBExpressionOptions.h"
4842
#include "lldb/API/SBFormat.h"
4943
#include "lldb/API/SBStream.h"
@@ -603,11 +597,11 @@ SBValue SBFrame::FindValue(const char *name, ValueType value_type,
603597
stop_if_block_is_inlined_function,
604598
[frame](Variable *v) { return v->IsInScope(frame); },
605599
&variable_list);
606-
if (value_type == eValueTypeVariableGlobal
607-
|| value_type == eValueTypeVariableStatic) {
600+
if (value_type == eValueTypeVariableGlobal ||
601+
value_type == eValueTypeVariableStatic) {
608602
const bool get_file_globals = true;
609-
VariableList *frame_vars = frame->GetVariableList(get_file_globals,
610-
nullptr);
603+
VariableList *frame_vars =
604+
frame->GetVariableList(get_file_globals, nullptr);
611605
if (frame_vars)
612606
frame_vars->AppendVariablesIfUnique(variable_list);
613607
}
@@ -790,14 +784,13 @@ SBValueList SBFrame::GetVariables(const lldb::SBVariablesOptions &options) {
790784
const bool statics = options.GetIncludeStatics();
791785
const bool arguments = options.GetIncludeArguments();
792786
const bool recognized_arguments =
793-
options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
787+
options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
794788
const bool locals = options.GetIncludeLocals();
795789
const bool in_scope_only = options.GetInScopeOnly();
796790
const bool include_runtime_support_values =
797791
options.GetIncludeRuntimeSupportValues();
798792
const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
799793

800-
801794
std::set<VariableSP> variable_set;
802795
Process *process = exe_ctx.GetProcessPtr();
803796
if (target && process) {
@@ -816,9 +809,11 @@ SBValueList SBFrame::GetVariables(const lldb::SBVariablesOptions &options) {
816809
if (num_variables) {
817810
size_t num_produced = 0;
818811
for (const VariableSP &variable_sp : *variable_list) {
819-
if (INTERRUPT_REQUESTED(dbg,
820-
"Interrupted getting frame variables with {0} of {1} "
821-
"produced.", num_produced, num_variables))
812+
if (INTERRUPT_REQUESTED(
813+
dbg,
814+
"Interrupted getting frame variables with {0} of {1} "
815+
"produced.",
816+
num_produced, num_variables))
822817
return {};
823818

824819
if (variable_sp) {
@@ -1012,33 +1007,26 @@ bool SBFrame::GetDescription(SBStream &description) {
10121007
SBValue SBFrame::EvaluateExpression(const char *expr) {
10131008
LLDB_INSTRUMENT_VA(this, expr);
10141009

1015-
SBValue result;
10161010
std::unique_lock<std::recursive_mutex> lock;
10171011
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
10181012

10191013
StackFrame *frame = exe_ctx.GetFramePtr();
10201014
Target *target = exe_ctx.GetTargetPtr();
1015+
SBExpressionOptions options;
10211016
if (frame && target) {
1022-
SBExpressionOptions options;
10231017
lldb::DynamicValueType fetch_dynamic_value =
10241018
frame->CalculateTarget()->GetPreferDynamicValue();
10251019
options.SetFetchDynamicValue(fetch_dynamic_value);
1026-
options.SetUnwindOnError(true);
1027-
options.SetIgnoreBreakpoints(true);
1028-
SourceLanguage language = target->GetLanguage();
1029-
if (!language)
1030-
language = frame->GetLanguage();
1031-
options.SetLanguage((SBSourceLanguageName)language.name, language.version);
1032-
return EvaluateExpression(expr, options);
1033-
} else {
1034-
Status error;
1035-
error = Status::FromErrorString("can't evaluate expressions when the "
1036-
"process is running.");
1037-
ValueObjectSP error_val_sp =
1038-
ValueObjectConstResult::Create(nullptr, std::move(error));
1039-
result.SetSP(error_val_sp, false);
10401020
}
1041-
return result;
1021+
options.SetUnwindOnError(true);
1022+
options.SetIgnoreBreakpoints(true);
1023+
SourceLanguage language;
1024+
if (target)
1025+
language = target->GetLanguage();
1026+
if (!language && frame)
1027+
language = frame->GetLanguage();
1028+
options.SetLanguage((SBSourceLanguageName)language.name, language.version);
1029+
return EvaluateExpression(expr, options);
10421030
}
10431031

10441032
SBValue
@@ -1135,10 +1123,10 @@ lldb::SBValue SBFrame::EvaluateExpression(const char *expr,
11351123
expr_result.SetSP(expr_value_sp, false);
11361124
}
11371125
} else {
1138-
Status error;
1139-
error = Status::FromErrorString("sbframe object is not valid.");
1140-
expr_value_sp = ValueObjectConstResult::Create(nullptr, std::move(error));
1141-
expr_result.SetSP(expr_value_sp, false);
1126+
Status error;
1127+
error = Status::FromErrorString("sbframe object is not valid.");
1128+
expr_value_sp = ValueObjectConstResult::Create(nullptr, std::move(error));
1129+
expr_result.SetSP(expr_value_sp, false);
11421130
}
11431131

11441132
if (expr_result.GetError().Success())

lldb/test/API/python_api/run_locker/TestRunLocker.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,4 @@ def runlocker_test(self, stop_at_entry):
107107
"script var = lldb.frame.EvaluateExpression('SomethingToCall()'); var.GetError().GetCString()",
108108
result,
109109
)
110-
self.assertIn(
111-
"can't evaluate expressions when the process is running", result.GetOutput()
112-
)
110+
self.assertIn("sbframe object is not valid", result.GetOutput())

0 commit comments

Comments
 (0)