blob: 25a445e6a0b3ac9e0dc69155075eb349acebd7cb [file] [log] [blame]
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "third_party/mlir_edge/iree/tools/debugger/debug_prompt.h"
#include "third_party/mlir_edge/iree/base/status.h"
#include "third_party/mlir_edge/iree/vm/debug/debug_client.h"
namespace iree {
namespace vm {
namespace debug {
namespace {
class DebugPrompt : private DebugClient::Listener {
public:
Status Connect(absl::string_view debug_service_uri) {
// Connect to the debug service.
ASSIGN_OR_RETURN(debug_client_,
DebugClient::Connect(debug_service_uri, this));
return OkStatus();
}
Status Run() {
// Query commands, transmit requests, and dispatch responses.
while (true) {
RETURN_IF_ERROR(debug_client_->Poll());
// TODO(benvanik): ask for a command.
// TODO(benvanik): display stuff.
}
}
private:
Status OnContextRegistered(const RemoteContext& context) override {
// Ack.
return debug_client_->MakeReady();
}
Status OnContextUnregistered(const RemoteContext& context) override {
// Ack.
return debug_client_->MakeReady();
}
Status OnModuleLoaded(const RemoteContext& context,
const RemoteModule& module) override {
// Ack.
return debug_client_->MakeReady();
}
Status OnFiberRegistered(const RemoteFiberState& fiber_state) override {
// Ack.
return debug_client_->MakeReady();
}
Status OnFiberUnregistered(const RemoteFiberState& fiber_state) override {
// Ack.
return debug_client_->MakeReady();
}
Status OnBreakpointHit(const RemoteBreakpoint& breakpoint,
const RemoteFiberState& fiber_state) override {
// Ack.
return debug_client_->MakeReady();
}
std::unique_ptr<DebugClient> debug_client_;
};
} // namespace
Status AttachDebugPrompt(absl::string_view debug_service_uri) {
DebugPrompt debug_prompt;
RETURN_IF_ERROR(debug_prompt.Connect(debug_service_uri));
return debug_prompt.Run();
}
} // namespace debug
} // namespace vm
} // namespace iree