[Lldb-commits] [lldb] FormatManager::GetPossibleMatches assumes all ValueObjects have targets. (PR #93880)
via lldb-commits
lldb-commits at lists.llvm.org
Thu May 30 14:11:02 PDT 2024
https://github.com/jimingham created https://github.com/llvm/llvm-project/pull/93880
But one made in a situation where that's impossible might only have an error, and no symbol context, so that's not necessarily true. Check for the target's validity before using it.
Fixes issue #93313
>From 007bab454cd9aa2c73ce167ee15900523d3b7318 Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Thu, 30 May 2024 13:48:02 -0700
Subject: [PATCH] FormatManager::GetPossibleMatches assumes all ValueObjects
have targets. But one made in a situation where that's impossible might only
have an error, and no symbol context, so that's not necessarily true. Check
for the target's validity before using it.
Fixes issue #93313
---
lldb/source/DataFormatters/FormatManager.cpp | 8 +++++++-
lldb/test/API/python_api/run_locker/TestRunLocker.py | 3 +++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp
index d7ba5b4b70c94..60765952760a2 100644
--- a/lldb/source/DataFormatters/FormatManager.cpp
+++ b/lldb/source/DataFormatters/FormatManager.cpp
@@ -176,8 +176,14 @@ void FormatManager::GetPossibleMatches(
FormattersMatchCandidate::Flags current_flags, bool root_level) {
compiler_type = compiler_type.GetTypeForFormatters();
ConstString type_name(compiler_type.GetTypeName());
+ // A ValueObject that couldn't be made correctly won't necessarily have a
+ // target. We aren't going to find a formatter in this case anyway, so we
+ // should just exit.
+ TargetSP target_sp = valobj.GetTargetSP();
+ if (!target_sp)
+ return;
ScriptInterpreter *script_interpreter =
- valobj.GetTargetSP()->GetDebugger().GetScriptInterpreter();
+ target_sp->GetDebugger().GetScriptInterpreter();
if (valobj.GetBitfieldBitSize() > 0) {
StreamString sstring;
sstring.Printf("%s:%d", type_name.AsCString(), valobj.GetBitfieldBitSize());
diff --git a/lldb/test/API/python_api/run_locker/TestRunLocker.py b/lldb/test/API/python_api/run_locker/TestRunLocker.py
index 4e0dd26bff70d..2f6892c6cbbc1 100644
--- a/lldb/test/API/python_api/run_locker/TestRunLocker.py
+++ b/lldb/test/API/python_api/run_locker/TestRunLocker.py
@@ -85,6 +85,9 @@ def runlocker_test(self, stop_at_entry):
# you aren't supposed to do while running, and that we get some
# actual error:
val = target.EvaluateExpression("SomethingToCall()")
+ # There was a bug [#93313] in the printing that would cause repr to crash, so I'm
+ # testing that separately.
+ self.assertIn("can't evaluate expressions when the process is running", repr(val), "repr works")
error = val.GetError()
self.assertTrue(error.Fail(), "Failed to run expression")
self.assertIn(
More information about the lldb-commits
mailing list