[lldb] FormatManager::GetPossibleMatches assumes all ValueObjects have targets. (#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
This commit is contained in:
jimingham 2024-05-31 10:43:05 -07:00 committed by GitHub
parent 7caa812f27
commit 1e81b67925
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -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());

View File

@ -85,6 +85,13 @@ class TestRunLocker(TestBase):
# 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(