monarch_messages/
debugger.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9// NOTE: Until https://github.com/PyO3/pyo3/pull/4674, `pyo3::pymethods` trigger
10// and unsafe-op-in-unsafe-fn warnings.
11#![allow(unsafe_op_in_unsafe_fn)]
12
13use derive_more::From;
14use hyperactor::Handler;
15use hyperactor::Named;
16use pyo3::Bound;
17use pyo3::PyResult;
18use pyo3::types::PyModule;
19use pyo3::types::PyModuleMethods;
20use serde::Deserialize;
21use serde::Serialize;
22
23pub fn register_python_bindings(debugger: &Bound<'_, PyModule>) -> PyResult<()> {
24    debugger.add_class::<DebuggerAction>()?;
25    Ok(())
26}
27
28/// Enumerates the actions relevant to PDB debugging sessions.
29#[derive(Debug, Deserialize, Clone, Serialize, PartialEq)]
30#[pyo3::pyclass(frozen, module = "monarch._rust_bindings.monarch_messages.debugger")]
31pub enum DebuggerAction {
32    /// Sent from worker to client to indicate that the worker has entered
33    /// a pdb debugging session.
34    Paused(),
35
36    /// Sent from client to worker to indicate that the client has started
37    /// the debugging session.
38    Attach(),
39
40    /// Sent to client or to worker to end the debugging session.
41    Detach(),
42
43    /// Sent to client or to worker to write bytes to receiver's stdout.
44    Write {
45        #[serde(with = "serde_bytes")]
46        bytes: Vec<u8>,
47    },
48
49    /// Sent from worker to client to read bytes from client's stdin.
50    Read { requested_size: usize },
51}
52
53#[derive(Serialize, Deserialize, Debug, Clone, Named, From, Handler)]
54pub enum DebuggerMessage {
55    Action { action: DebuggerAction },
56}
57
58hyperactor::alias!(
59    DebuggerActor,
60    DebuggerMessage { cast = true },
61);