blob: d3e7fb0daa34ad64aff459df0577510565c4b214 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#ifndef SRC_DEVELOPER_DEBUG_DEBUG_AGENT_EXCEPTION_HANDLE_H_
#define SRC_DEVELOPER_DEBUG_DEBUG_AGENT_EXCEPTION_HANDLE_H_
#include <lib/fitx/result.h>
#include <memory>
#include "src/developer/debug/ipc/records.h"
#include "src/lib/fxl/macros.h"
namespace debug_agent {
class ThreadHandle;
// ExceptionHandle abstracts zx::exception, allowing for a more straightforward implementation in
// tests in overrides of this class.
class ExceptionHandle {
public:
ExceptionHandle() = default;
virtual ~ExceptionHandle() = default;
// Returns a handle to the excepting thread. Will return a null pointer on failure.
virtual std::unique_ptr<ThreadHandle> GetThreadHandle() const = 0;
// Returns the type of the exception for this and the current thread state.
//
// This requires getting the debug registers for the thread so the thread handle is passed in.
// This could be implemented without the parameter because this object can create thread handles,
// but that would be less efficient and all callers currently have existing ThreadHandles.
virtual debug_ipc::ExceptionType GetType(const ThreadHandle& thread) const = 0;
// Returns the associated ZX_EXCEPTION_STATE_* constant characterizing the state of the exception.
virtual fitx::result<zx_status_t, uint32_t> GetState() const = 0;
// Given a ZX_EXCEPTION_STATE_* constant, sets the state of the exception.
virtual zx_status_t SetState(uint32_t state) = 0;
// Returns the associated the exception handling strategy.
virtual fitx::result<zx_status_t, debug_ipc::ExceptionStrategy> GetStrategy() const = 0;
// Sets the handling strategy.
virtual zx_status_t SetStrategy(debug_ipc::ExceptionStrategy strategy) = 0;
};
} // namespace debug_agent
#endif // SRC_DEVELOPER_DEBUG_DEBUG_AGENT_EXCEPTION_HANDLE_H_