[Lldb-commits] [lldb] [lldb] do not show misleading error when there is no frame (PR #119103)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Dec 9 09:44:52 PST 2024
https://github.com/oltolm updated https://github.com/llvm/llvm-project/pull/119103
>From 8e649d4a2a23a5d644761611c285c5b8d753b007 Mon Sep 17 00:00:00 2001
From: oltolm <oleg.tolmatcev at gmail.com>
Date: Sat, 7 Dec 2024 17:24:07 +0100
Subject: [PATCH] lldb: do not show misleading error when there is no frame
---
lldb/source/API/SBFrame.cpp | 45 +++++++------------
.../python_api/run_locker/TestRunLocker.py | 4 +-
2 files changed, 17 insertions(+), 32 deletions(-)
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 2300bec4d685d2..9285d21cf55805 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//
-#include <algorithm>
#include <set>
#include <string>
@@ -18,11 +17,8 @@
#include "lldb/Core/Address.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Expression/ExpressionVariable.h"
-#include "lldb/Expression/UserExpression.h"
-#include "lldb/Host/Host.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/Function.h"
-#include "lldb/Symbol/Symbol.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Symbol/VariableList.h"
@@ -33,7 +29,6 @@
#include "lldb/Target/StackFrameRecognizer.h"
#include "lldb/Target/StackID.h"
#include "lldb/Target/Target.h"
-#include "lldb/Target/Thread.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Instrumentation.h"
#include "lldb/Utility/LLDBLog.h"
@@ -43,7 +38,6 @@
#include "lldb/ValueObject/ValueObjectVariable.h"
#include "lldb/API/SBAddress.h"
-#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBExpressionOptions.h"
#include "lldb/API/SBFormat.h"
#include "lldb/API/SBStream.h"
@@ -790,7 +784,7 @@ SBValueList SBFrame::GetVariables(const lldb::SBVariablesOptions &options) {
const bool statics = options.GetIncludeStatics();
const bool arguments = options.GetIncludeArguments();
const bool recognized_arguments =
- options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
+ options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
const bool locals = options.GetIncludeLocals();
const bool in_scope_only = options.GetInScopeOnly();
const bool include_runtime_support_values =
@@ -817,7 +811,7 @@ SBValueList SBFrame::GetVariables(const lldb::SBVariablesOptions &options) {
size_t num_produced = 0;
for (const VariableSP &variable_sp : *variable_list) {
if (INTERRUPT_REQUESTED(dbg,
- "Interrupted getting frame variables with {0} of {1} "
+ "Interrupted getting frame variables with {0} of {1} "
"produced.", num_produced, num_variables))
return {};
@@ -1012,33 +1006,26 @@ bool SBFrame::GetDescription(SBStream &description) {
SBValue SBFrame::EvaluateExpression(const char *expr) {
LLDB_INSTRUMENT_VA(this, expr);
- SBValue result;
std::unique_lock<std::recursive_mutex> lock;
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
StackFrame *frame = exe_ctx.GetFramePtr();
Target *target = exe_ctx.GetTargetPtr();
+ SBExpressionOptions options;
if (frame && target) {
- SBExpressionOptions options;
lldb::DynamicValueType fetch_dynamic_value =
frame->CalculateTarget()->GetPreferDynamicValue();
options.SetFetchDynamicValue(fetch_dynamic_value);
- options.SetUnwindOnError(true);
- options.SetIgnoreBreakpoints(true);
- SourceLanguage language = target->GetLanguage();
- if (!language)
- language = frame->GetLanguage();
- options.SetLanguage((SBSourceLanguageName)language.name, language.version);
- return EvaluateExpression(expr, options);
- } else {
- Status error;
- error = Status::FromErrorString("can't evaluate expressions when the "
- "process is running.");
- ValueObjectSP error_val_sp =
- ValueObjectConstResult::Create(nullptr, std::move(error));
- result.SetSP(error_val_sp, false);
}
- return result;
+ options.SetUnwindOnError(true);
+ options.SetIgnoreBreakpoints(true);
+ SourceLanguage language;
+ if (target)
+ language = target->GetLanguage();
+ if (!language && frame)
+ language = frame->GetLanguage();
+ options.SetLanguage((SBSourceLanguageName)language.name, language.version);
+ return EvaluateExpression(expr, options);
}
SBValue
@@ -1135,10 +1122,10 @@ lldb::SBValue SBFrame::EvaluateExpression(const char *expr,
expr_result.SetSP(expr_value_sp, false);
}
} else {
- Status error;
- error = Status::FromErrorString("sbframe object is not valid.");
- expr_value_sp = ValueObjectConstResult::Create(nullptr, std::move(error));
- expr_result.SetSP(expr_value_sp, false);
+ Status error;
+ error = Status::FromErrorString("sbframe object is not valid.");
+ expr_value_sp = ValueObjectConstResult::Create(nullptr, std::move(error));
+ expr_result.SetSP(expr_value_sp, false);
}
if (expr_result.GetError().Success())
diff --git a/lldb/test/API/python_api/run_locker/TestRunLocker.py b/lldb/test/API/python_api/run_locker/TestRunLocker.py
index d525bbf6b406f1..b7b4941214e863 100644
--- a/lldb/test/API/python_api/run_locker/TestRunLocker.py
+++ b/lldb/test/API/python_api/run_locker/TestRunLocker.py
@@ -107,6 +107,4 @@ def runlocker_test(self, stop_at_entry):
"script var = lldb.frame.EvaluateExpression('SomethingToCall()'); var.GetError().GetCString()",
result,
)
- self.assertIn(
- "can't evaluate expressions when the process is running", result.GetOutput()
- )
+ self.assertIn("sbframe object is not valid", result.GetOutput())
More information about the lldb-commits
mailing list