https://github.com/GlobalStar117 updated https://github.com/llvm/llvm-project/pull/176801
>From 6c1d83f5ab858357d1c07889c32dad942d88e626 Mon Sep 17 00:00:00 2001 From: Globalstar117 <[email protected]> Date: Tue, 20 Jan 2026 05:39:38 +1100 Subject: [PATCH] [LLDB] Fix register dematerialization failure in Python script context When evaluating expressions that reference registers (e.g., 'po $x0') from Python scripts via HandleCommand, the dematerialization step could fail with 'couldn't dematerialize register x0 without a stack frame'. Root cause: The Dematerializer stores a weak pointer to the thread and a stack ID during materialization. During dematerialization, if the weak pointer has expired or the stack ID is no longer valid, the frame_sp becomes null. This causes EntityRegister::Dematerialize to fail since it requires a valid stack frame to write back register values. The fix adds a fallback: if the stored weak pointer/stack ID doesn't yield a valid frame, try to get the frame from GetBestExecutionContextScope(). This handles cases where the execution context is still valid but the stored references have become stale, which is common in Python scripting scenarios. Fixes #176717 This is a Gittensor contribution --- lldb/source/Expression/Materializer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp index 771a9ab84a20c..594362f07dfff 100644 --- a/lldb/source/Expression/Materializer.cpp +++ b/lldb/source/Expression/Materializer.cpp @@ -1575,6 +1575,15 @@ void Materializer::Dematerializer::Dematerialize(Status &error, if (!exe_scope) exe_scope = m_map->GetBestExecutionContextScope(); + // If we couldn't get the frame from the stored weak pointer/stack ID, + // try to get it from the best execution context scope as a fallback. + // This handles cases where the expression evaluation is triggered from + // Python scripts where the stored thread reference may have expired + // but the execution context is still valid. + if (!frame_sp && exe_scope) { + frame_sp = exe_scope->CalculateStackFrame(); + } + if (!IsValid()) { error = Status::FromErrorString( "Couldn't dematerialize: invalid dematerializer"); _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
