6
6
#include " Expressions.h"
7
7
#include " Variables.h"
8
8
#include " WasmModule.h"
9
+ #include " WasmVendorPlugins.h"
9
10
#include " api.h"
10
11
11
12
#include " lldb/API/SBAddress.h"
@@ -628,9 +629,31 @@ class SBValueArena {
628
629
629
630
static SBValueArena arena;
630
631
632
+ llvm::Expected<lldb::ProcessSP> ApiContext::GetProcess (
633
+ std::string stop_id,
634
+ std::shared_ptr<WasmModule> module,
635
+ const api::DebuggerProxy& proxy,
636
+ size_t frame_offset) {
637
+ lldb::ProcessSP process;
638
+ if (last_process_ && last_process_->process &&
639
+ last_process_->stop_id == stop_id) {
640
+ process = last_process_->process ;
641
+ } else {
642
+ auto maybe_process = ::symbols_backend::CreateProcess (*module);
643
+ if (!maybe_process) {
644
+ return maybe_process.takeError ();
645
+ }
646
+ process = maybe_process.get ();
647
+ last_process_ = LastProcessInfo{process, stop_id};
648
+ }
649
+ static_cast <WasmProcess*>(process.get ())
650
+ ->SetProxyAndFrameOffset (proxy, frame_offset);
651
+ return process;
652
+ }
631
653
632
654
api::EvaluateExpressionResponse ApiContext::EvaluateExpression (
633
655
RawLocation location,
656
+ std::string stop_id,
634
657
std::string expression,
635
658
emscripten::val debug_proxy) {
636
659
std::string raw_module_id = location.GetRawModuleId ();
@@ -640,8 +663,7 @@ api::EvaluateExpressionResponse ApiContext::EvaluateExpression(
640
663
MakeNotFoundError (raw_module_id));
641
664
}
642
665
DebuggerProxy proxy{debug_proxy};
643
- auto process = ::symbols_backend::CreateProcess (*module, proxy,
644
- location.GetCodeOffset ());
666
+ auto process = GetProcess (stop_id, module, proxy, location.GetCodeOffset ());
645
667
if (!process) {
646
668
return api::EvaluateExpressionResponse ().SetError (
647
669
MakeError (Error::Code::kEvalError , process.takeError ()));
@@ -672,6 +694,12 @@ api::GetValueSummaryResponse ApiContext::GetValueSummary(api::Sbvalue rawValue)
672
694
.SetError (MakeError (Error::Code::kEvalError , " Invalid SBValue passed to GetValueSummary" ));
673
695
}
674
696
697
+ if (!value.IsInScope ()) {
698
+ return api::GetValueSummaryResponse ()
699
+ .SetDisplayValue (std::nullopt)
700
+ .SetError (MakeError (Error::Code::kEvalError , " SBValue is not in scope" ));
701
+ }
702
+
675
703
auto tryStringify = [&](lldb::SBValue value) -> std::optional<std::string> {
676
704
// Use GetSummary() if available.
677
705
if (const char *summary = value.GetSummary ()) {
@@ -689,6 +717,11 @@ api::GetValueSummaryResponse ApiContext::GetValueSummary(api::Sbvalue rawValue)
689
717
return api::GetValueSummaryResponse ().SetDisplayValue (display_value);
690
718
}
691
719
720
+ if (!value.GetError ().Success ()) {
721
+ auto err = value.GetError ();
722
+ return api::GetValueSummaryResponse ().SetError (MakeError (Error::Code::kInternalError , err.GetCString ()));
723
+ }
724
+
692
725
// If the value is a pointer or reference, dereference it and try again.
693
726
if (value.GetType ().IsPointerType () || value.GetType ().IsReferenceType ()) {
694
727
if (auto display_value = tryStringify (value.Dereference ())) {
0 commit comments