[Lldb-commits] [lldb] [lldb] Improve user expression diagnostics (PR #123242)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Jan 16 13:18:40 PST 2025
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/123242
>From db80b44d603bd00127d8de52fa32577ec352dc22 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Thu, 16 Jan 2025 12:57:15 -0800
Subject: [PATCH 1/2] [lldb] Improve user expression diagnostics
This patch rewords some of the user expression diagnostics.
- Differentiate between being interrupted and hitting a breakpoint.
- Use "expression execution" to make it more obvious that the
diagnostic is associated with the user expression.
- Consistently use a colon instead of semicolons and commas.
---
lldb/source/Expression/LLVMUserExpression.cpp | 48 +++++++++++--------
1 file changed, 28 insertions(+), 20 deletions(-)
diff --git a/lldb/source/Expression/LLVMUserExpression.cpp b/lldb/source/Expression/LLVMUserExpression.cpp
index 529ac462dfd8f4..fac3ce6f5799d5 100644
--- a/lldb/source/Expression/LLVMUserExpression.cpp
+++ b/lldb/source/Expression/LLVMUserExpression.cpp
@@ -187,18 +187,22 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
if (execution_result == lldb::eExpressionInterrupted ||
execution_result == lldb::eExpressionHitBreakpoint) {
const char *error_desc = nullptr;
+ const char *explanation = execution_result == lldb::eExpressionInterrupted
+ ? "was interrupted"
+ : "hit a breakpoint";
if (user_expression_plan) {
if (auto real_stop_info_sp = user_expression_plan->GetRealStopInfo())
error_desc = real_stop_info_sp->GetDescription();
}
+
if (error_desc)
diagnostic_manager.Printf(lldb::eSeverityError,
- "Execution was interrupted, reason: %s.",
+ "Expression execution %s: %s.", explanation,
error_desc);
else
- diagnostic_manager.PutString(lldb::eSeverityError,
- "Execution was interrupted.");
+ diagnostic_manager.Printf(lldb::eSeverityError,
+ "Expression execution %s.", explanation);
if ((execution_result == lldb::eExpressionInterrupted &&
options.DoesUnwindOnError()) ||
@@ -212,31 +216,35 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
user_expression_plan->TransferExpressionOwnership();
diagnostic_manager.AppendMessageToDiagnostic(
"The process has been left at the point where it was "
- "interrupted, "
- "use \"thread return -x\" to return to the state before "
- "expression evaluation.");
+ "interrupted, use \"thread return -x\" to return to the state "
+ "before expression evaluation.");
}
return execution_result;
- } else if (execution_result == lldb::eExpressionStoppedForDebug) {
+ }
+
+ if (execution_result == lldb::eExpressionStoppedForDebug) {
diagnostic_manager.PutString(
lldb::eSeverityInfo,
- "Execution was halted at the first instruction of the expression "
- "function because \"debug\" was requested.\n"
+ "Expression execution was halted at the first instruction of the "
+ "expression function because \"debug\" was requested.\n"
"Use \"thread return -x\" to return to the state before expression "
"evaluation.");
return execution_result;
- } else if (execution_result == lldb::eExpressionThreadVanished) {
- diagnostic_manager.Printf(
- lldb::eSeverityError,
- "Couldn't complete execution; the thread "
- "on which the expression was being run: 0x%" PRIx64
- " exited during its execution.",
- expr_thread_id);
+ }
+
+ if (execution_result == lldb::eExpressionThreadVanished) {
+ diagnostic_manager.Printf(lldb::eSeverityError,
+ "Couldn't execute expression: the thread on "
+ "which the expression was being run (0x%" PRIx64
+ ") exited during its execution.",
+ expr_thread_id);
return execution_result;
- } else if (execution_result != lldb::eExpressionCompleted) {
+ }
+
+ if (execution_result != lldb::eExpressionCompleted) {
diagnostic_manager.Printf(lldb::eSeverityError,
- "Couldn't execute function; result was %s",
+ "Couldn't execute expression: result was %s",
toString(execution_result).c_str());
return execution_result;
}
@@ -245,9 +253,9 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
if (FinalizeJITExecution(diagnostic_manager, exe_ctx, result,
function_stack_bottom, function_stack_top)) {
return lldb::eExpressionCompleted;
- } else {
- return lldb::eExpressionResultUnavailable;
}
+
+ return lldb::eExpressionResultUnavailable;
}
bool LLVMUserExpression::FinalizeJITExecution(
>From 695e4757a3584819e144f302d0c92ba56e8b2a59 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Thu, 16 Jan 2025 13:18:20 -0800
Subject: [PATCH 2/2] Update tests
---
.../expression/call-function/TestCallStopAndContinue.py | 2 +-
.../expression/unwind_expression/TestUnwindExpression.py | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/lldb/test/API/commands/expression/call-function/TestCallStopAndContinue.py b/lldb/test/API/commands/expression/call-function/TestCallStopAndContinue.py
index 69f02ec99f64b2..d856b5c23a5eab 100644
--- a/lldb/test/API/commands/expression/call-function/TestCallStopAndContinue.py
+++ b/lldb/test/API/commands/expression/call-function/TestCallStopAndContinue.py
@@ -31,7 +31,7 @@ def test(self):
self.expect(
"expr -i false -- returnsFive()",
error=True,
- substrs=["Execution was interrupted, reason: breakpoint"],
+ substrs=["Expression execution hit a breakpoint: breakpoint"],
)
self.runCmd("continue", "Continue completed")
diff --git a/lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py b/lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py
index 82f062876a773f..c61fe5d01fd5b5 100644
--- a/lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py
+++ b/lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py
@@ -2,7 +2,6 @@
Test stopping at a breakpoint in an expression, and unwinding from there.
"""
-
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
@@ -71,7 +70,7 @@ def do_unwind_test(self, thread, bkpt, timeout):
self.assertTrue(val.GetError().Fail(), "We did not complete the execution.")
error_str = val.GetError().GetCString()
self.assertIn(
- "Execution was interrupted, reason: breakpoint",
+ "Expression execution hit a breakpoint: breakpoint",
error_str,
"And the reason was right.",
)
More information about the lldb-commits
mailing list