================
@@ -204,9 +209,64 @@ bool ScriptedThread::LoadArtificialStackFrames() {
     SymbolContext sc;
     symbol_addr.CalculateSymbolContext(&sc);
 
-    StackFrameSP synth_frame_sp = std::make_shared<StackFrame>(
+    return std::make_shared<StackFrame>(
         this->shared_from_this(), idx, idx, cfa, cfa_is_valid, pc,
         StackFrame::Kind::Artificial, behaves_like_zeroth_frame, &sc);
+  };
+
+  auto create_frame_from_script_object =
+      [this, arr_sp](size_t idx) -> llvm::Expected<StackFrameSP> {
+    Status error;
+    StructuredData::ObjectSP object_sp = arr_sp->GetItemAtIndex(idx);
+    if (!object_sp || !object_sp->GetAsGeneric()) {
+      ScriptedInterface::ErrorWithMessage<bool>(
+          LLVM_PRETTY_FUNCTION,
+          llvm::Twine("Couldn't get artificial stackframe object at index (" +
+                      llvm::Twine(idx) +
+                      llvm::Twine(") from stackframe array."))
+              .str(),
+          error, LLDBLog::Thread);
+      return error.ToError();
+    }
+
+    auto frame_or_error =
+        ScriptedFrame::Create(*this, nullptr, object_sp->GetAsGeneric());
+
+    if (!frame_or_error) {
+      ScriptedInterface::ErrorWithMessage<bool>(
+          LLVM_PRETTY_FUNCTION, toString(frame_or_error.takeError()), error);
+      return error.ToError();
+    }
+
+    StackFrameSP frame_sp = frame_or_error.get();
+    lldbassert(frame_sp && "Couldn't initialize scripted frame.");
+
+    return frame_sp;
+  };
+
+  StackFrameListSP frames = GetStackFrameList();
+
+  for (size_t idx = 0; idx < arr_size; idx++) {
+    StackFrameSP synth_frame_sp = nullptr;
+
+    auto frame_from_dict_or_err = create_frame_from_dict(idx);
----------------
medismailben wrote:

For a given frame index, you can only have a dictionary or a script object at 
the time, not both. I'm not sure what failure mode you have in mind, but in 
this implementation, we:
1. Try to create the synthetic frame from a dictionary (since it's the legacy 
option).
2. If it succeeds, we use that.
3. Otherwise, we try to create the synthetic frame from a script object 
(`ScriptedFrame`)
4. If it succeeds, we consume the dictionary error and use scripted object 
synthetic frame.
5. Otherwise, raise an error and log that we failed to create a synthetic frame.

Let me know if you have a different scenario in mind.

https://github.com/llvm/llvm-project/pull/149622
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to